Restructure properties API

This commit is contained in:
Daniel Cronqvist 2024-08-24 21:38:40 +02:00
parent 3a6684a52d
commit 1c1ba326b2
20 changed files with 282 additions and 62 deletions

View file

@ -91,7 +91,7 @@ public static partial class DotTiledAssert
AssertEqual(expected.NextObjectID, actual.NextObjectID, nameof(Map.NextObjectID));
AssertEqual(expected.Infinite, actual.Infinite, nameof(Map.Infinite));
AssertProperties(actual.Properties, expected.Properties);
AssertPropertiesList(actual.Properties, expected.Properties);
Assert.NotNull(actual.Tilesets);
AssertEqual(expected.Tilesets.Count, actual.Tilesets.Count, "Tilesets.Count");

View file

@ -21,6 +21,25 @@ public static partial class DotTiledAssert
}
}
internal static void AssertPropertiesList(IList<IProperty>? expected, IList<IProperty>? actual)
{
if (expected is null)
{
Assert.Null(actual);
return;
}
Assert.NotNull(actual);
AssertEqual(expected.Count, actual.Count, "Properties.Count");
foreach (var prop in expected)
{
Assert.Contains(actual, p => p.Name == prop.Name);
var actualProp = actual.First(p => p.Name == prop.Name);
AssertProperty((dynamic)prop, (dynamic)actualProp);
}
}
private static void AssertProperty(IProperty expected, IProperty actual)
{
AssertEqual(expected.Type, actual.Type, "Property.Type");
@ -45,6 +64,6 @@ public static partial class DotTiledAssert
private static void AssertProperty(ClassProperty expected, ClassProperty actual)
{
AssertEqual(expected.PropertyType, actual.PropertyType, "ClassProperty.PropertyType");
AssertProperties(expected.Properties, actual.Properties);
AssertPropertiesList(expected.Value, actual.Value);
}
}

View file

@ -55,15 +55,15 @@ public partial class TestData
}
}
],
Properties = new Dictionary<string, IProperty>
{
["boolprop"] = new BoolProperty { Name = "boolprop", Value = true },
["colorprop"] = new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) },
["fileprop"] = new FileProperty { Name = "fileprop", Value = "file.txt" },
["floatprop"] = new FloatProperty { Name = "floatprop", Value = 4.2f },
["intprop"] = new IntProperty { Name = "intprop", Value = 8 },
["objectprop"] = new ObjectProperty { Name = "objectprop", Value = 5 },
["stringprop"] = new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }
}
Properties =
[
new BoolProperty { Name = "boolprop", Value = true },
new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) },
new FileProperty { Name = "fileprop", Value = "file.txt" },
new FloatProperty { Name = "floatprop", Value = 4.2f },
new IntProperty { Name = "intprop", Value = 8 },
new ObjectProperty { Name = "objectprop", Value = 5 },
new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }
]
};
}

View file

@ -55,24 +55,22 @@ public partial class TestData
}
}
],
Properties = new Dictionary<string, IProperty>
{
["customclassprop"] = new ClassProperty
Properties = [
new ClassProperty
{
Name = "customclassprop",
PropertyType = "CustomClass",
Properties = new Dictionary<string, IProperty>
{
["boolinclass"] = new BoolProperty { Name = "boolinclass", Value = true },
["colorinclass"] = new ColorProperty { Name = "colorinclass", Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) },
["fileinclass"] = new FileProperty { Name = "fileinclass", Value = "" },
["floatinclass"] = new FloatProperty { Name = "floatinclass", Value = 13.37f },
["intinclass"] = new IntProperty { Name = "intinclass", Value = 0 },
["objectinclass"] = new ObjectProperty { Name = "objectinclass", Value = 0 },
["stringinclass"] = new StringProperty { Name = "stringinclass", Value = "This is a set string" }
}
Value = [
new BoolProperty { Name = "boolinclass", Value = true },
new ColorProperty { Name = "colorinclass", Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) },
new FileProperty { Name = "fileinclass", Value = "" },
new FloatProperty { Name = "floatinclass", Value = 13.37f },
new IntProperty { Name = "intinclass", Value = 0 },
new ObjectProperty { Name = "objectinclass", Value = 0 },
new StringProperty { Name = "stringinclass", Value = "This is a set string" }
]
}
}
]
};
// This comes from map-with-custom-type-props/propertytypes.json