mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-09 02:26:02 +03:00
Tmx reader is now a base abstract class
This commit is contained in:
parent
eda3fbe308
commit
11f1ef783e
25 changed files with 1059 additions and 960 deletions
|
@ -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);
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
|
||||
Assert.NotNull(actual.Tilesets);
|
||||
AssertEqual(expected.Tilesets.Count, actual.Tilesets.Count, "Tilesets.Count");
|
||||
|
|
|
@ -45,4 +45,14 @@ public static partial class DotTiledAssert
|
|||
AssertEqual(expected.PropertyType, actual.PropertyType, "ClassProperty.PropertyType");
|
||||
AssertProperties(expected.Value, actual.Value);
|
||||
}
|
||||
|
||||
private static void AssertProperty(EnumProperty expected, EnumProperty actual)
|
||||
{
|
||||
AssertEqual(expected.PropertyType, actual.PropertyType, "EnumProperty.PropertyType");
|
||||
AssertEqual(expected.Value.Count, actual.Value.Count, "EnumProperty.Value.Count");
|
||||
foreach (var value in expected.Value)
|
||||
{
|
||||
Assert.Contains(actual.Value, v => v == value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,9 +141,9 @@ public static partial class DotTiledAssert
|
|||
AssertEqual(expected.Height, actual.Height, nameof(Tile.Height));
|
||||
|
||||
// Elements
|
||||
AssertProperties(actual.Properties, expected.Properties);
|
||||
AssertImage(actual.Image, expected.Image);
|
||||
AssertLayer((BaseLayer?)actual.ObjectLayer, (BaseLayer?)expected.ObjectLayer);
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
AssertImage(expected.Image, actual.Image);
|
||||
AssertLayer((BaseLayer?)expected.ObjectLayer, (BaseLayer?)actual.ObjectLayer);
|
||||
if (expected.Animation is not null)
|
||||
{
|
||||
Assert.NotNull(actual.Animation);
|
||||
|
|
|
@ -69,6 +69,30 @@ public partial class TestData
|
|||
new ObjectProperty { Name = "objectinclass", Value = 0 },
|
||||
new StringProperty { Name = "stringinclass", Value = "This is a set string" }
|
||||
]
|
||||
},
|
||||
new EnumProperty
|
||||
{
|
||||
Name = "customenumstringprop",
|
||||
PropertyType = "CustomEnumString",
|
||||
Value = new HashSet<string> { "CustomEnumString_2" }
|
||||
},
|
||||
new EnumProperty
|
||||
{
|
||||
Name = "customenumstringflagsprop",
|
||||
PropertyType = "CustomEnumStringFlags",
|
||||
Value = new HashSet<string> { "CustomEnumStringFlags_1", "CustomEnumStringFlags_2" }
|
||||
},
|
||||
new EnumProperty
|
||||
{
|
||||
Name = "customenumintprop",
|
||||
PropertyType = "CustomEnumInt",
|
||||
Value = new HashSet<string> { "CustomEnumInt_4" }
|
||||
},
|
||||
new EnumProperty
|
||||
{
|
||||
Name = "customenumintflagsprop",
|
||||
PropertyType = "CustomEnumIntFlags",
|
||||
Value = new HashSet<string> { "CustomEnumIntFlags_2", "CustomEnumIntFlags_3" }
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -116,6 +140,50 @@ public partial class TestData
|
|||
Value = ""
|
||||
}
|
||||
]
|
||||
},
|
||||
new CustomEnumDefinition
|
||||
{
|
||||
Name = "CustomEnumString",
|
||||
StorageType = CustomEnumStorageType.String,
|
||||
ValueAsFlags = false,
|
||||
Values = [
|
||||
"CustomEnumString_1",
|
||||
"CustomEnumString_2",
|
||||
"CustomEnumString_3"
|
||||
]
|
||||
},
|
||||
new CustomEnumDefinition
|
||||
{
|
||||
Name = "CustomEnumStringFlags",
|
||||
StorageType = CustomEnumStorageType.String,
|
||||
ValueAsFlags = true,
|
||||
Values = [
|
||||
"CustomEnumStringFlags_1",
|
||||
"CustomEnumStringFlags_2"
|
||||
]
|
||||
},
|
||||
new CustomEnumDefinition
|
||||
{
|
||||
Name = "CustomEnumInt",
|
||||
StorageType = CustomEnumStorageType.Int,
|
||||
ValueAsFlags = false,
|
||||
Values = [
|
||||
"CustomEnumInt_1",
|
||||
"CustomEnumInt_2",
|
||||
"CustomEnumInt_3",
|
||||
"CustomEnumInt_4",
|
||||
]
|
||||
},
|
||||
new CustomEnumDefinition
|
||||
{
|
||||
Name = "CustomEnumIntFlags",
|
||||
StorageType = CustomEnumStorageType.Int,
|
||||
ValueAsFlags = true,
|
||||
Values = [
|
||||
"CustomEnumIntFlags_1",
|
||||
"CustomEnumIntFlags_2",
|
||||
"CustomEnumIntFlags_3"
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
@ -32,6 +32,30 @@
|
|||
"floatinclass":13.37,
|
||||
"stringinclass":"This is a set string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name":"customenumintflagsprop",
|
||||
"propertytype":"CustomEnumIntFlags",
|
||||
"type":"int",
|
||||
"value":6
|
||||
},
|
||||
{
|
||||
"name":"customenumintprop",
|
||||
"propertytype":"CustomEnumInt",
|
||||
"type":"int",
|
||||
"value":3
|
||||
},
|
||||
{
|
||||
"name":"customenumstringflagsprop",
|
||||
"propertytype":"CustomEnumStringFlags",
|
||||
"type":"string",
|
||||
"value":"CustomEnumStringFlags_1,CustomEnumStringFlags_2"
|
||||
},
|
||||
{
|
||||
"name":"customenumstringprop",
|
||||
"propertytype":"CustomEnumString",
|
||||
"type":"string",
|
||||
"value":"CustomEnumString_2"
|
||||
}],
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
<property name="stringinclass" value="This is a set string"/>
|
||||
</properties>
|
||||
</property>
|
||||
<property name="customenumintflagsprop" type="int" propertytype="CustomEnumIntFlags" value="6"/>
|
||||
<property name="customenumintprop" type="int" propertytype="CustomEnumInt" value="3"/>
|
||||
<property name="customenumstringflagsprop" propertytype="CustomEnumStringFlags" value="CustomEnumStringFlags_1,CustomEnumStringFlags_2"/>
|
||||
<property name="customenumstringprop" propertytype="CustomEnumString" value="CustomEnumString_2"/>
|
||||
</properties>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
|
|
|
@ -20,16 +20,20 @@ public partial class TmxMapReaderTests
|
|||
Template ResolveTemplate(string source)
|
||||
{
|
||||
using var xmlTemplateReader = TestData.GetXmlReaderFor($"{fileDir}/{source}");
|
||||
using var templateReader = new TxTemplateReader(xmlTemplateReader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
using var templateReader = new TxTemplateReader(xmlTemplateReader, ResolveTileset, ResolveTemplate, ResolveCustomType);
|
||||
return templateReader.ReadTemplate();
|
||||
}
|
||||
Tileset ResolveTileset(string source)
|
||||
{
|
||||
using var xmlTilesetReader = TestData.GetXmlReaderFor($"{fileDir}/{source}");
|
||||
using var tilesetReader = new TsxTilesetReader(xmlTilesetReader, ResolveTemplate, customTypeDefinitions);
|
||||
using var tilesetReader = new TsxTilesetReader(xmlTilesetReader, ResolveTileset, ResolveTemplate, ResolveCustomType);
|
||||
return tilesetReader.ReadTileset();
|
||||
}
|
||||
using var mapReader = new TmxMapReader(reader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
ICustomTypeDefinition ResolveCustomType(string name)
|
||||
{
|
||||
return customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name)!;
|
||||
}
|
||||
using var mapReader = new TmxMapReader(reader, ResolveTileset, ResolveTemplate, ResolveCustomType);
|
||||
|
||||
// Act
|
||||
var map = mapReader.ReadMap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue