Remove old maps from tests and seperate model more

This commit is contained in:
Daniel Cronqvist 2024-08-12 21:24:09 +02:00
parent 33f1f4dcb7
commit 4aebf1d67b
43 changed files with 290 additions and 1296 deletions

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;

View file

@ -6,6 +6,8 @@ public static partial class TestData
{ {
public static XmlReader GetXmlReaderFor(string testDataFile) public static XmlReader GetXmlReaderFor(string testDataFile)
{ {
var names = typeof(TestData).Assembly.GetManifestResourceNames();
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{testDataFile}"; var fullyQualifiedTestDataFile = $"DotTiled.Tests.{testDataFile}";
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile) using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found"); ?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");

View file

@ -0,0 +1,96 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map DefaultMap() => 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 = new Color { R = 0, G = 0, B = 0, A = 0 },
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
]
}
}
]
};
}

View file

@ -1,30 +0,0 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"compression":"gzip",
"data":"H4sIAAAAAAAACmNgoD0AAMrGiJlkAAAA",
"encoding":"base64",
"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",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,8 +0,0 @@
<?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">
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="base64" compression="gzip">
H4sIAAAAAAAACmNgoD0AAMrGiJlkAAAA
</data>
</layer>
</map>

View file

@ -1,30 +0,0 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"compression":"zlib",
"data":"eJxjYKA9AAAAZAAB",
"encoding":"base64",
"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",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,8 +0,0 @@
<?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">
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="base64" compression="zlib">
eJxjYKA9AAAAZAAB
</data>
</layer>
</map>

View file

@ -1,30 +0,0 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"compression":"",
"data":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"encoding":"base64",
"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",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,8 +0,0 @@
<?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">
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="base64">
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
</data>
</layer>
</map>

View file

@ -1,56 +0,0 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map EmptyMapWithProperties() => new Map
{
Version = "1.10",
TiledVersion = "1.11.0",
Orientation = MapOrientation.Orthogonal,
RenderOrder = RenderOrder.RightDown,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
NextLayerID = 2,
NextObjectID = 1,
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
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>
{
["MapBool"] = new BoolProperty { Name = "MapBool", Value = true },
["MapColor"] = new ColorProperty { Name = "MapColor", Value = new Color { R = 255, G = 0, B = 0, A = 255 } },
["MapFile"] = new FileProperty { Name = "MapFile", Value = "file.png" },
["MapFloat"] = new FloatProperty { Name = "MapFloat", Value = 5.2f },
["MapInt"] = new IntProperty { Name = "MapInt", Value = 42 },
["MapObject"] = new ObjectProperty { Name = "MapObject", Value = 5 },
["MapString"] = new StringProperty { Name = "MapString", Value = "string in map" }
}
};
}

View file

@ -1,69 +0,0 @@
{ "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":"MapBool",
"type":"bool",
"value":true
},
{
"name":"MapColor",
"type":"color",
"value":"#ffff0000"
},
{
"name":"MapFile",
"type":"file",
"value":"file.png"
},
{
"name":"MapFloat",
"type":"float",
"value":5.2
},
{
"name":"MapInt",
"type":"int",
"value":42
},
{
"name":"MapObject",
"type":"object",
"value":5
},
{
"name":"MapString",
"type":"string",
"value":"string in map"
}],
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,21 +0,0 @@
<?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="MapBool" type="bool" value="true"/>
<property name="MapColor" type="color" value="#ffff0000"/>
<property name="MapFile" type="file" value="file.png"/>
<property name="MapFloat" type="float" value="5.2"/>
<property name="MapInt" type="int" value="42"/>
<property name="MapObject" type="object" value="5"/>
<property name="MapString" value="string in map"/>
</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>

View file

@ -1,47 +0,0 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map EmptyMapWithEncodingAndCompression(DataEncoding dataEncoding, DataCompression? compression) => new Map
{
Version = "1.10",
TiledVersion = "1.11.0",
Orientation = MapOrientation.Orthogonal,
RenderOrder = RenderOrder.RightDown,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
NextLayerID = 2,
NextObjectID = 1,
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = dataEncoding,
Compression = compression,
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
]
}
}
]
};
}

View file

@ -1,94 +0,0 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map MapWithGroup() => new Map
{
Version = "1.10",
TiledVersion = "1.11.0",
Orientation = MapOrientation.Orthogonal,
RenderOrder = RenderOrder.RightDown,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
NextLayerID = 5,
NextObjectID = 2,
Layers = [
new TileLayer
{
ID = 4,
Name = "Tile Layer 2",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
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
]
}
},
new Group
{
ID = 3,
Name = "Group 1",
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
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
]
}
},
new ObjectLayer
{
ID = 2,
Name = "Object Layer 1",
Objects = [
new RectangleObject
{
ID = 1,
Name = "Name",
X = 35.5f,
Y = 26,
Width = 64.5f,
Height = 64.5f,
}
]
}
]
}
]
};
}

View file

@ -1,80 +0,0 @@
{ "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":4,
"name":"Tile Layer 2",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":5,
"x":0,
"y":0
},
{
"id":3,
"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
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":64.5,
"id":1,
"name":"Name",
"rotation":0,
"type":"",
"visible":true,
"width":64.5,
"x":35.5,
"y":26
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":2,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,26 +0,0 @@
<?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="5" nextobjectid="2">
<layer id="4" name="Tile Layer 2" 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>
<group id="3" name="Group 1">
<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>
<objectgroup id="2" name="Object Layer 1">
<object id="1" name="Name" x="35.5" y="26" width="64.5" height="64.5"/>
</objectgroup>
</group>
</map>

View file

@ -1,125 +0,0 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map MapWithObjectTemplate(string templateExtension) => new Map
{
Version = "1.10",
TiledVersion = "1.11.0",
Orientation = MapOrientation.Orthogonal,
RenderOrder = RenderOrder.RightDown,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
NextLayerID = 3,
NextObjectID = 3,
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
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
]
}
},
new ObjectLayer
{
ID = 2,
Name = "Object Layer 1",
Objects = [
new RectangleObject
{
ID = 1,
Template = $"map-with-object-template.{templateExtension}",
Name = "Thingy 2",
X = 94.5749f,
Y = 33.6842f,
Width = 37.0156f,
Height = 37.0156f,
Properties = new Dictionary<string, IProperty>
{
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
["TestClassInTemplate"] = new ClassProperty
{
Name = "TestClassInTemplate",
PropertyType = "TestClass",
Properties = new Dictionary<string, IProperty>
{
["Amount"] = new FloatProperty { Name = "Amount", Value = 37 },
["Name"] = new StringProperty { Name = "Name", Value = "I am here" }
}
}
}
},
new RectangleObject
{
ID = 2,
Template = $"map-with-object-template.{templateExtension}",
Name = "Thingy",
X = 29.7976f,
Y = 33.8693f,
Width = 37.0156f,
Height = 37.0156f,
Properties = new Dictionary<string, IProperty>
{
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
["TestClassInTemplate"] = new ClassProperty
{
Name = "TestClassInTemplate",
PropertyType = "TestClass",
Properties = new Dictionary<string, IProperty>
{
["Amount"] = new FloatProperty { Name = "Amount", Value = 4.2f },
["Name"] = new StringProperty { Name = "Name", Value = "Hello there" }
}
}
}
},
new RectangleObject
{
ID = 3,
Template = $"map-with-object-template.{templateExtension}",
Name = "Thingy 3",
X = 5,
Y = 5,
Width = 37.0156f,
Height = 37.0156f,
Properties = new Dictionary<string, IProperty>
{
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
["TestClassInTemplate"] = new ClassProperty
{
Name = "TestClassInTemplate",
PropertyType = "TestClass",
Properties = new Dictionary<string, IProperty>
{
["Amount"] = new FloatProperty { Name = "Amount", Value = 0.0f },
["Name"] = new StringProperty { Name = "Name", Value = "I am here 3" }
}
}
}
}
]
}
]
};
}

View file

@ -1,104 +0,0 @@
{ "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
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":37.0156,
"id":1,
"template":"map-with-object-template.tj",
"name":"Thingy 2",
"properties":[
{
"name":"Bool",
"type":"bool",
"value":true
},
{
"name":"TestClassInTemplate",
"propertytype":"TestClass",
"type":"class",
"value":
{
"Amount":37,
"Name":"I am here"
}
}],
"rotation":0,
"type":"",
"visible":true,
"width":37.0156,
"x":94.5749,
"y":33.6842
},
{
"id":2,
"template":"map-with-object-template.tj",
"x":29.7976,
"y":33.8693
},
{
"height":37.0156,
"id":3,
"template":"map-with-object-template.tj",
"name":"Thingy 3",
"properties":[
{
"name":"Bool",
"type":"bool",
"value":true
},
{
"name":"TestClassInTemplate",
"propertytype":"TestClass",
"type":"class",
"value":
{
"Name":"I am here 3"
}
}],
"rotation":0,
"type":"",
"visible":true,
"width":37.0156,
"x":5,
"y":5
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,35 +0,0 @@
<?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="3" nextobjectid="3">
<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>
<objectgroup id="2" name="Object Layer 1">
<object id="1" template="map-with-object-template.tx" name="Thingy 2" x="94.5749" y="33.6842">
<properties>
<property name="Bool" type="bool" value="true"/>
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
<properties>
<property name="Amount" type="float" value="37"/>
<property name="Name" value="I am here"/>
</properties>
</property>
</properties>
</object>
<object id="2" template="map-with-object-template.tx" x="29.7976" y="33.8693"/>
<object id="3" template="map-with-object-template.tx" name="Thingy 3" x="5" y="5">
<properties>
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
<properties>
<property name="Name" value="I am here 3"/>
</properties>
</property>
</properties>
</object>
</objectgroup>
</map>

View file

@ -1,65 +0,0 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map SimpleMapWithEmbeddedTileset() => new Map
{
Version = "1.10",
TiledVersion = "1.11.0",
Orientation = MapOrientation.Orthogonal,
RenderOrder = RenderOrder.RightDown,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
NextLayerID = 2,
NextObjectID = 1,
Tilesets = [
new Tileset
{
FirstGID = 1,
Name = "Tileset 1",
TileWidth = 32,
TileHeight = 32,
TileCount = 8,
Columns = 4,
Image = new Image
{
Format = ImageFormat.Png,
Source = "tiles.png",
Width = 128,
Height = 64
}
}
],
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
Compression = null,
GlobalTileIDs = [
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
2,2,2,2,2,
2,2,2,2,2
],
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
]
},
}
]
};
}

View file

@ -1,45 +0,0 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"data":[1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
2, 2, 2, 2, 2],
"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",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":32,
"tilesets":[
{
"columns":4,
"firstgid":1,
"image":"tiles.png",
"imageheight":64,
"imagewidth":128,
"margin":0,
"name":"Tileset 1",
"spacing":0,
"tilecount":8,
"tileheight":32,
"tilewidth":32
}],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -1,15 +0,0 @@
<?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">
<tileset firstgid="1" name="Tileset 1" tilewidth="32" tileheight="32" tilecount="8" columns="4">
<image source="tiles.png" width="128" height="64"/>
</tileset>
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="csv">
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
2,2,2,2,2,
2,2,2,2,2
</data>
</layer>
</map>

View file

@ -1,28 +0,0 @@
{ "object":
{
"height":37.0156,
"id":2,
"name":"Thingy",
"properties":[
{
"name":"Bool",
"type":"bool",
"value":true
},
{
"name":"TestClassInTemplate",
"propertytype":"TestClass",
"type":"class",
"value":
{
"Amount":4.2,
"Name":"Hello there"
}
}],
"rotation":0,
"type":"",
"visible":true,
"width":37.0156
},
"type":"template"
}

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<object name="Thingy" width="37.0156" height="37.0156">
<properties>
<property name="Bool" type="bool" value="true"/>
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
<properties>
<property name="Amount" type="float" value="4.2"/>
<property name="Name" value="Hello there"/>
</properties>
</property>
</properties>
</object>
</template>

View file

@ -2,44 +2,9 @@ namespace DotTiled.Tests;
public partial class TmjMapReaderTests public partial class TmjMapReaderTests
{ {
public static IEnumerable<object[]> DeserializeMap_ValidTmjNoExternalTilesets_ReturnsMapWithoutThrowing_Data =>
[
["Serialization.TestData.Map.empty-map-csv.tmj", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Csv, null)],
["Serialization.TestData.Map.empty-map-base64.tmj", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, null)],
["Serialization.TestData.Map.empty-map-base64-gzip.tmj", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, DataCompression.GZip)],
["Serialization.TestData.Map.empty-map-base64-zlib.tmj", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, DataCompression.ZLib)],
["Serialization.TestData.Map.simple-tileset-embed.tmj", TestData.SimpleMapWithEmbeddedTileset()],
["Serialization.TestData.Map.empty-map-properties.tmj", TestData.EmptyMapWithProperties()],
];
[Theory]
[MemberData(nameof(DeserializeMap_ValidTmjNoExternalTilesets_ReturnsMapWithoutThrowing_Data))]
public void TmxMapReaderReadMap_ValidTmjNoExternalTilesets_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap)
{
// Arrange
var json = TestData.GetRawStringFor(testDataFile);
static Template ResolveTemplate(string source)
{
throw new NotSupportedException("External templates are not supported in this test.");
}
static Tileset ResolveTileset(string source)
{
throw new NotSupportedException("External tilesets are not supported in this test.");
}
using var mapReader = new TmjMapReader(json, ResolveTileset, ResolveTemplate, []);
// Act
var map = mapReader.ReadMap();
// Assert
Assert.NotNull(map);
DotTiledAssert.AssertMap(expectedMap, map);
}
public static IEnumerable<object[]> DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => public static IEnumerable<object[]> DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data =>
[ [
["Serialization.TestData.Map.map-with-object-template.tmj", TestData.MapWithObjectTemplate("tj")], ["Serialization.TestData.Map.default_map.default-map.tmj", TestData.DefaultMap()]
["Serialization.TestData.Map.map-with-group.tmj", TestData.MapWithGroup()],
]; ];
[Theory] [Theory]

View file

@ -4,155 +4,9 @@ namespace DotTiled.Tests;
public partial class TmxMapReaderTests public partial class TmxMapReaderTests
{ {
[Fact]
public void TmxMapReaderConstructor_XmlReaderIsNull_ThrowsArgumentNullException()
{
// Arrange
XmlReader xmlReader = null!;
Func<string, Tileset> externalTilesetResolver = (_) => new Tileset();
Func<string, Template> externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } };
// Act
Action act = () =>
{
using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []);
};
// Assert
Assert.Throws<ArgumentNullException>(act);
}
[Fact]
public void TmxMapReaderConstructor_ExternalTilesetResolverIsNull_ThrowsArgumentNullException()
{
// Arrange
using var stringReader = new StringReader("<map></map>");
using var xmlReader = XmlReader.Create(stringReader);
Func<string, Tileset> externalTilesetResolver = null!;
Func<string, Template> externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } };
// Act
Action act = () =>
{
using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []);
};
// Assert
Assert.Throws<ArgumentNullException>(act);
}
[Fact]
public void TmxMapReaderConstructor_ExternalTemplateResolverIsNull_ThrowsArgumentNullException()
{
// Arrange
using var stringReader = new StringReader("<map></map>");
using var xmlReader = XmlReader.Create(stringReader);
Func<string, Tileset> externalTilesetResolver = (_) => new Tileset();
Func<string, Template> externalTemplateResolver = null!;
// Act
Action act = () =>
{
using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []);
};
// Assert
Assert.Throws<ArgumentNullException>(act);
}
[Fact]
public void TmxMapReaderConstructor_NoneNull_DoesNotThrow()
{
// Arrange
using var stringReader = new StringReader("<map></map>");
using var xmlReader = XmlReader.Create(stringReader);
Func<string, Tileset> externalTilesetResolver = (_) => new Tileset();
Func<string, Template> externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } };
// Act
using var tmxMapReader = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []);
// Assert
Assert.NotNull(tmxMapReader);
}
public static IEnumerable<object[]> DeserializeMap_ValidXmlNoExternalTilesets_ReturnsMapWithoutThrowing_Data =>
[
["Serialization.TestData.Map.empty-map-csv.tmx", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Csv, null)],
["Serialization.TestData.Map.empty-map-base64.tmx", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, null)],
["Serialization.TestData.Map.empty-map-base64-gzip.tmx", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, DataCompression.GZip)],
["Serialization.TestData.Map.empty-map-base64-zlib.tmx", TestData.EmptyMapWithEncodingAndCompression(DataEncoding.Base64, DataCompression.ZLib)],
["Serialization.TestData.Map.simple-tileset-embed.tmx", TestData.SimpleMapWithEmbeddedTileset()],
["Serialization.TestData.Map.empty-map-properties.tmx", TestData.EmptyMapWithProperties()],
];
[Theory]
[MemberData(nameof(DeserializeMap_ValidXmlNoExternalTilesets_ReturnsMapWithoutThrowing_Data))]
public void TmxMapReaderReadMap_ValidXmlNoExternalTilesets_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap)
{
// Arrange
CustomTypeDefinition[] customTypeDefinitions = [
new CustomClassDefinition
{
Name = "TestClass",
ID = 1,
UseAs = CustomClassUseAs.Property,
Members = [
new StringProperty
{
Name = "Name",
Value = ""
},
new FloatProperty
{
Name = "Amount",
Value = 0f
}
]
},
new CustomClassDefinition
{
Name = "Test",
ID = 2,
UseAs = CustomClassUseAs.All,
Members = [
new ClassProperty
{
Name = "Yep",
PropertyType = "TestClass",
Properties = []
}
]
}
];
using var reader = TestData.GetXmlReaderFor(testDataFile);
Template ResolveTemplate(string source)
{
using var xmlTemplateReader = TestData.GetXmlReaderFor($"Serialization.TestData.Template.{source}");
using var templateReader = new TxTemplateReader(xmlTemplateReader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
return templateReader.ReadTemplate();
}
Tileset ResolveTileset(string source)
{
using var xmlTilesetReader = TestData.GetXmlReaderFor($"Serialization.TestData.Tileset.{source}");
using var tilesetReader = new TsxTilesetReader(xmlTilesetReader, ResolveTemplate, customTypeDefinitions);
return tilesetReader.ReadTileset();
}
using var mapReader = new TmxMapReader(reader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
// Act
var map = mapReader.ReadMap();
// Assert
Assert.NotNull(map);
DotTiledAssert.AssertMap(expectedMap, map);
}
public static IEnumerable<object[]> DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => public static IEnumerable<object[]> DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data =>
[ [
["Serialization.TestData.Map.map-with-object-template.tmx", TestData.MapWithObjectTemplate("tx")], ["Serialization.TestData.Map.default_map.default-map.tmx", TestData.DefaultMap()]
["Serialization.TestData.Map.map-with-group.tmx", TestData.MapWithGroup()],
]; ];
[Theory] [Theory]

View file

@ -1,173 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DotTiled;
public enum PropertyType
{
String,
Int,
Float,
Bool,
Color,
File,
Object,
Class
}
public interface IProperty
{
public string Name { get; set; }
public PropertyType Type { get; }
IProperty Clone();
}
public class StringProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.String;
public required string Value { get; set; }
public IProperty Clone() => new StringProperty
{
Name = Name,
Value = Value
};
}
public class IntProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Int;
public required int Value { get; set; }
public IProperty Clone() => new IntProperty
{
Name = Name,
Value = Value
};
}
public class FloatProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Float;
public required float Value { get; set; }
public IProperty Clone() => new FloatProperty
{
Name = Name,
Value = Value
};
}
public class BoolProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Bool;
public required bool Value { get; set; }
public IProperty Clone() => new BoolProperty
{
Name = Name,
Value = Value
};
}
public class ColorProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Color;
public required Color Value { get; set; }
public IProperty Clone() => new ColorProperty
{
Name = Name,
Value = Value
};
}
public class FileProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.File;
public required string Value { get; set; }
public IProperty Clone() => new FileProperty
{
Name = Name,
Value = Value
};
}
public class ObjectProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Object;
public required uint Value { get; set; }
public IProperty Clone() => new ObjectProperty
{
Name = Name,
Value = Value
};
}
public class ClassProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => DotTiled.PropertyType.Class;
public required string PropertyType { get; set; }
public required Dictionary<string, IProperty> Properties { get; set; }
public IProperty Clone() => new ClassProperty
{
Name = Name,
PropertyType = PropertyType,
Properties = Properties.ToDictionary(p => p.Key, p => p.Value.Clone())
};
}
public abstract class CustomTypeDefinition
{
public uint ID { get; set; }
public string Name { get; set; } = "";
}
[Flags]
public enum CustomClassUseAs
{
Property,
Map,
Layer,
Object,
Tile,
Tileset,
WangColor,
Wangset,
Project,
All = Property | Map | Layer | Object | Tile | Tileset | WangColor | Wangset | Project
}
public class CustomClassDefinition : CustomTypeDefinition
{
public Color Color { get; set; }
public bool DrawFill { get; set; }
public CustomClassUseAs UseAs { get; set; }
public List<IProperty> Members { get; set; }
}
public enum CustomEnumStorageType
{
Int,
String
}
public class CustomEnumDefinition : CustomTypeDefinition
{
public CustomEnumStorageType StorageType { get; set; }
public List<string> Values { get; set; } = [];
public bool ValueAsFlags { get; set; }
}

View file

@ -60,5 +60,4 @@ public class Map
// Any number of // Any number of
public List<Tileset> Tilesets { get; set; } = []; public List<Tileset> Tilesets { get; set; } = [];
public List<BaseLayer> Layers { get; set; } = []; public List<BaseLayer> Layers { get; set; } = [];
public List<Group> Groups { get; set; } = [];
} }

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class BoolProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Bool;
public required bool Value { get; set; }
public IProperty Clone() => new BoolProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Linq;
namespace DotTiled;
public class ClassProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => DotTiled.PropertyType.Class;
public required string PropertyType { get; set; }
public required Dictionary<string, IProperty> Properties { get; set; }
public IProperty Clone() => new ClassProperty
{
Name = Name,
PropertyType = PropertyType,
Properties = Properties.ToDictionary(p => p.Key, p => p.Value.Clone())
};
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class ColorProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Color;
public required Color Value { get; set; }
public IProperty Clone() => new ColorProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
namespace DotTiled;
[Flags]
public enum CustomClassUseAs
{
Property,
Map,
Layer,
Object,
Tile,
Tileset,
WangColor,
Wangset,
Project,
All = Property | Map | Layer | Object | Tile | Tileset | WangColor | Wangset | Project
}
public class CustomClassDefinition : CustomTypeDefinition
{
public Color? Color { get; set; }
public bool DrawFill { get; set; }
public CustomClassUseAs UseAs { get; set; }
public List<IProperty> Members { get; set; } = [];
}

View file

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace DotTiled;
public enum CustomEnumStorageType
{
Int,
String
}
public class CustomEnumDefinition : CustomTypeDefinition
{
public CustomEnumStorageType StorageType { get; set; }
public List<string> Values { get; set; } = [];
public bool ValueAsFlags { get; set; }
}

View file

@ -0,0 +1,7 @@
namespace DotTiled;
public abstract class CustomTypeDefinition
{
public uint ID { get; set; }
public string Name { get; set; } = "";
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class FileProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.File;
public required string Value { get; set; }
public IProperty Clone() => new FileProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class FloatProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Float;
public required float Value { get; set; }
public IProperty Clone() => new FloatProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,9 @@
namespace DotTiled;
public interface IProperty
{
public string Name { get; set; }
public PropertyType Type { get; }
IProperty Clone();
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class IntProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Int;
public required int Value { get; set; }
public IProperty Clone() => new IntProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class ObjectProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.Object;
public required uint Value { get; set; }
public IProperty Clone() => new ObjectProperty
{
Name = Name,
Value = Value
};
}

View file

@ -0,0 +1,13 @@
namespace DotTiled;
public enum PropertyType
{
String,
Int,
Float,
Bool,
Color,
File,
Object,
Class
}

View file

@ -0,0 +1,14 @@
namespace DotTiled;
public class StringProperty : IProperty
{
public required string Name { get; set; }
public PropertyType Type => PropertyType.String;
public required string Value { get; set; }
public IProperty Clone() => new StringProperty
{
Name = Name,
Value = Value
};
}