Make custom types optional

This commit is contained in:
Daniel Cronqvist 2024-11-16 21:14:23 +01:00
parent 67876c6532
commit 8c9068cc97
21 changed files with 189 additions and 59 deletions

View file

@ -1,4 +1,3 @@
using System;
using System.Globalization;
using System.Linq;
using DotTiled.Serialization;
@ -57,12 +56,12 @@ public partial class MapParser : Node2D
return templateReader.ReadTemplate();
}
private static ICustomTypeDefinition ResolveCustomType(string name)
private static Optional<ICustomTypeDefinition> ResolveCustomType(string name)
{
ICustomTypeDefinition[] allDefinedTypes =
[
new CustomClassDefinition() { Name = "a" },
];
return allDefinedTypes.FirstOrDefault(type => type.Name == name) ?? throw new InvalidOperationException();
return allDefinedTypes.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd ? new Optional<ICustomTypeDefinition>(ctd) : Optional<ICustomTypeDefinition>.Empty;
}
}