mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 17:02:49 +02:00
Add tests for custom type properties in maps
This commit is contained in:
parent
5fd05683f6
commit
7b7e499b0d
8 changed files with 243 additions and 4 deletions
|
@ -28,10 +28,11 @@ public static partial class TestData
|
||||||
return stringReader.ReadToEnd();
|
return stringReader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> MapsThatHaveTmxAndTmj =>
|
public static IEnumerable<object[]> MapTests =>
|
||||||
[
|
[
|
||||||
["Serialization.TestData.Map.default_map.default-map", TestData.DefaultMap(), Array.Empty<CustomTypeDefinition>()],
|
["Serialization.TestData.Map.default_map.default-map", TestData.DefaultMap(), Array.Empty<CustomTypeDefinition>()],
|
||||||
["Serialization.TestData.Map.map_with_common_props.map-with-common-props", TestData.MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()]
|
["Serialization.TestData.Map.map_with_common_props.map-with-common-props", TestData.MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()],
|
||||||
|
["Serialization.TestData.Map.map_with_custom_type_props.map-with-custom-type-props", TestData.MapWithCustomTypeProps(), TestData.MapWithCustomTypePropsCustomTypeDefinitions()]
|
||||||
];
|
];
|
||||||
|
|
||||||
private static CustomTypeDefinition[] typedefs = [
|
private static CustomTypeDefinition[] typedefs = [
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace DotTiled.Tests;
|
||||||
|
|
||||||
|
public partial class TestData
|
||||||
|
{
|
||||||
|
public static Map MapWithCustomTypeProps() => new Map
|
||||||
|
{
|
||||||
|
Class = "",
|
||||||
|
Orientation = MapOrientation.Orthogonal,
|
||||||
|
Width = 5,
|
||||||
|
Height = 5,
|
||||||
|
TileWidth = 32,
|
||||||
|
TileHeight = 32,
|
||||||
|
Infinite = false,
|
||||||
|
HexSideLength = null,
|
||||||
|
StaggerAxis = null,
|
||||||
|
StaggerIndex = null,
|
||||||
|
ParallaxOriginX = 0,
|
||||||
|
ParallaxOriginY = 0,
|
||||||
|
RenderOrder = RenderOrder.RightDown,
|
||||||
|
CompressionLevel = -1,
|
||||||
|
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||||
|
Version = "1.10",
|
||||||
|
TiledVersion = "1.11.0",
|
||||||
|
NextLayerID = 2,
|
||||||
|
NextObjectID = 1,
|
||||||
|
Layers = [
|
||||||
|
new TileLayer
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Name = "Tile Layer 1",
|
||||||
|
Width = 5,
|
||||||
|
Height = 5,
|
||||||
|
Data = new Data
|
||||||
|
{
|
||||||
|
Encoding = DataEncoding.Csv,
|
||||||
|
Chunks = null,
|
||||||
|
Compression = null,
|
||||||
|
GlobalTileIDs = [
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0
|
||||||
|
],
|
||||||
|
FlippingFlags = [
|
||||||
|
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||||
|
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||||
|
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||||
|
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||||
|
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Properties = new Dictionary<string, IProperty>
|
||||||
|
{
|
||||||
|
["customclassprop"] = 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" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This comes from map-with-custom-type-props/propertytypes.json
|
||||||
|
public static IReadOnlyCollection<CustomTypeDefinition> MapWithCustomTypePropsCustomTypeDefinitions() => [
|
||||||
|
new CustomClassDefinition
|
||||||
|
{
|
||||||
|
Name = "CustomClass",
|
||||||
|
UseAs = CustomClassUseAs.Property,
|
||||||
|
Members = [
|
||||||
|
new BoolProperty
|
||||||
|
{
|
||||||
|
Name = "boolinclass",
|
||||||
|
Value = false
|
||||||
|
},
|
||||||
|
new ColorProperty
|
||||||
|
{
|
||||||
|
Name = "colorinclass",
|
||||||
|
Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture)
|
||||||
|
},
|
||||||
|
new FileProperty
|
||||||
|
{
|
||||||
|
Name = "fileinclass",
|
||||||
|
Value = ""
|
||||||
|
},
|
||||||
|
new FloatProperty
|
||||||
|
{
|
||||||
|
Name = "floatinclass",
|
||||||
|
Value = 0f
|
||||||
|
},
|
||||||
|
new IntProperty
|
||||||
|
{
|
||||||
|
Name = "intinclass",
|
||||||
|
Value = 0
|
||||||
|
},
|
||||||
|
new ObjectProperty
|
||||||
|
{
|
||||||
|
Name = "objectinclass",
|
||||||
|
Value = 0
|
||||||
|
},
|
||||||
|
new StringProperty
|
||||||
|
{
|
||||||
|
Name = "stringinclass",
|
||||||
|
Value = ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
{ "compressionlevel":-1,
|
||||||
|
"height":5,
|
||||||
|
"infinite":false,
|
||||||
|
"layers":[
|
||||||
|
{
|
||||||
|
"data":[0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0],
|
||||||
|
"height":5,
|
||||||
|
"id":1,
|
||||||
|
"name":"Tile Layer 1",
|
||||||
|
"opacity":1,
|
||||||
|
"type":"tilelayer",
|
||||||
|
"visible":true,
|
||||||
|
"width":5,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"nextlayerid":2,
|
||||||
|
"nextobjectid":1,
|
||||||
|
"orientation":"orthogonal",
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"customclassprop",
|
||||||
|
"propertytype":"CustomClass",
|
||||||
|
"type":"class",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"boolinclass":true,
|
||||||
|
"floatinclass":13.37,
|
||||||
|
"stringinclass":"This is a set string"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"renderorder":"right-down",
|
||||||
|
"tiledversion":"1.11.0",
|
||||||
|
"tileheight":32,
|
||||||
|
"tilesets":[],
|
||||||
|
"tilewidth":32,
|
||||||
|
"type":"map",
|
||||||
|
"version":"1.10",
|
||||||
|
"width":5
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||||
|
<properties>
|
||||||
|
<property name="customclassprop" type="class" propertytype="CustomClass">
|
||||||
|
<properties>
|
||||||
|
<property name="boolinclass" type="bool" value="true"/>
|
||||||
|
<property name="floatinclass" type="float" value="13.37"/>
|
||||||
|
<property name="stringinclass" value="This is a set string"/>
|
||||||
|
</properties>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||||
|
<data encoding="csv">
|
||||||
|
0,0,0,0,0,
|
||||||
|
0,0,0,0,0,
|
||||||
|
0,0,0,0,0,
|
||||||
|
0,0,0,0,0,
|
||||||
|
0,0,0,0,0
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
</map>
|
|
@ -0,0 +1,49 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"color": "#ffa0a0a4",
|
||||||
|
"drawFill": true,
|
||||||
|
"id": 8,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"name": "boolinclass",
|
||||||
|
"type": "bool",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "colorinclass",
|
||||||
|
"type": "color",
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fileinclass",
|
||||||
|
"type": "file",
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "floatinclass",
|
||||||
|
"type": "float",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "intinclass",
|
||||||
|
"type": "int",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "objectinclass",
|
||||||
|
"type": "object",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stringinclass",
|
||||||
|
"type": "string",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "CustomClass",
|
||||||
|
"type": "class",
|
||||||
|
"useAs": [
|
||||||
|
"property"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
|
@ -2,7 +2,7 @@ namespace DotTiled.Tests;
|
||||||
|
|
||||||
public partial class TmjMapReaderTests
|
public partial class TmjMapReaderTests
|
||||||
{
|
{
|
||||||
public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
|
public static IEnumerable<object[]> Maps => TestData.MapTests;
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(Maps))]
|
[MemberData(nameof(Maps))]
|
||||||
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace DotTiled.Tests;
|
||||||
|
|
||||||
public partial class TmxMapReaderTests
|
public partial class TmxMapReaderTests
|
||||||
{
|
{
|
||||||
public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
|
public static IEnumerable<object[]> Maps => TestData.MapTests;
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(Maps))]
|
[MemberData(nameof(Maps))]
|
||||||
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||||
|
|
|
@ -66,4 +66,6 @@ public class Color : IParsable<Color>, IEquatable<Color>
|
||||||
public override bool Equals(object? obj) => obj is Color other && Equals(other);
|
public override bool Equals(object? obj) => obj is Color other && Equals(other);
|
||||||
|
|
||||||
public override int GetHashCode() => HashCode.Combine(R, G, B, A);
|
public override int GetHashCode() => HashCode.Combine(R, G, B, A);
|
||||||
|
|
||||||
|
public override string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue