From 4aebf1d67b8735afd1e5525b483f51562f49c4c9 Mon Sep 17 00:00:00 2001 From: Daniel Cronqvist Date: Mon, 12 Aug 2024 21:24:09 +0200 Subject: [PATCH] Remove old maps from tests and seperate model more --- DotTiled.Benchmark/Program.cs | 2 +- DotTiled.Tests/Serialization/TestData.cs | 2 + .../TestData/Map/default-map/default-map.cs | 96 ++++++++++ .../default-map.tmj} | 0 .../default-map.tmx} | 0 .../TestData/Map/empty-map-base64-gzip.tmj | 30 --- .../TestData/Map/empty-map-base64-gzip.tmx | 8 - .../TestData/Map/empty-map-base64-zlib.tmj | 30 --- .../TestData/Map/empty-map-base64-zlib.tmx | 8 - .../TestData/Map/empty-map-base64.tmj | 30 --- .../TestData/Map/empty-map-base64.tmx | 8 - .../TestData/Map/empty-map-properties.cs | 56 ------ .../TestData/Map/empty-map-properties.tmj | 69 ------- .../TestData/Map/empty-map-properties.tmx | 21 --- .../Serialization/TestData/Map/empty-map.cs | 47 ----- .../TestData/Map/map-with-group.cs | 94 ---------- .../TestData/Map/map-with-group.tmj | 80 -------- .../TestData/Map/map-with-group.tmx | 26 --- .../TestData/Map/map-with-object-template.cs | 125 ------------- .../TestData/Map/map-with-object-template.tmj | 104 ----------- .../TestData/Map/map-with-object-template.tmx | 35 ---- .../TestData/Map/simple-tileset-embed.cs | 65 ------- .../TestData/Map/simple-tileset-embed.tmj | 45 ----- .../TestData/Map/simple-tileset-embed.tmx | 15 -- .../Template/map-with-object-template.tj | 28 --- .../Template/map-with-object-template.tx | 14 -- .../Serialization/Tmj/TmjMapReaderTests.cs | 37 +--- .../Serialization/Tmx/TmxMapReaderTests.cs | 148 +-------------- DotTiled/Model/IProperty.cs | 173 ------------------ DotTiled/Model/Map.cs | 1 - DotTiled/Model/Properties/BoolProperty.cs | 14 ++ DotTiled/Model/Properties/ClassProperty.cs | 19 ++ DotTiled/Model/Properties/ColorProperty.cs | 14 ++ .../CustomTypes/CustomClassDefinition.cs | 27 +++ .../CustomTypes/CustomEnumDefinition.cs | 16 ++ .../CustomTypes/CustomTypeDefinition.cs | 7 + DotTiled/Model/Properties/FileProperty.cs | 14 ++ DotTiled/Model/Properties/FloatProperty.cs | 14 ++ DotTiled/Model/Properties/IProperty.cs | 9 + DotTiled/Model/Properties/IntProperty.cs | 14 ++ DotTiled/Model/Properties/ObjectProperty.cs | 14 ++ DotTiled/Model/Properties/PropertyType.cs | 13 ++ DotTiled/Model/Properties/StringProperty.cs | 14 ++ 43 files changed, 290 insertions(+), 1296 deletions(-) create mode 100644 DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs rename DotTiled.Tests/Serialization/TestData/Map/{empty-map-csv.tmj => default-map/default-map.tmj} (100%) rename DotTiled.Tests/Serialization/TestData/Map/{empty-map-csv.tmx => default-map/default-map.tmx} (100%) delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.cs delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/empty-map.cs delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-group.cs delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.cs delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.cs delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmj delete mode 100644 DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmx delete mode 100644 DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tj delete mode 100644 DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tx delete mode 100644 DotTiled/Model/IProperty.cs create mode 100644 DotTiled/Model/Properties/BoolProperty.cs create mode 100644 DotTiled/Model/Properties/ClassProperty.cs create mode 100644 DotTiled/Model/Properties/ColorProperty.cs create mode 100644 DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs create mode 100644 DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs create mode 100644 DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs create mode 100644 DotTiled/Model/Properties/FileProperty.cs create mode 100644 DotTiled/Model/Properties/FloatProperty.cs create mode 100644 DotTiled/Model/Properties/IProperty.cs create mode 100644 DotTiled/Model/Properties/IntProperty.cs create mode 100644 DotTiled/Model/Properties/ObjectProperty.cs create mode 100644 DotTiled/Model/Properties/PropertyType.cs create mode 100644 DotTiled/Model/Properties/StringProperty.cs diff --git a/DotTiled.Benchmark/Program.cs b/DotTiled.Benchmark/Program.cs index 8397495..b432b7e 100644 --- a/DotTiled.Benchmark/Program.cs +++ b/DotTiled.Benchmark/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Immutable; using System.Security.Cryptography; using System.Text; diff --git a/DotTiled.Tests/Serialization/TestData.cs b/DotTiled.Tests/Serialization/TestData.cs index d31956f..9b3b13f 100644 --- a/DotTiled.Tests/Serialization/TestData.cs +++ b/DotTiled.Tests/Serialization/TestData.cs @@ -6,6 +6,8 @@ public static partial class TestData { public static XmlReader GetXmlReaderFor(string testDataFile) { + var names = typeof(TestData).Assembly.GetManifestResourceNames(); + var fullyQualifiedTestDataFile = $"DotTiled.Tests.{testDataFile}"; using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile) ?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found"); diff --git a/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs b/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs new file mode 100644 index 0000000..44c909e --- /dev/null +++ b/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs @@ -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 + ] + } + } + ] + }; +} diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-csv.tmj b/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj similarity index 100% rename from DotTiled.Tests/Serialization/TestData/Map/empty-map-csv.tmj rename to DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-csv.tmx b/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx similarity index 100% rename from DotTiled.Tests/Serialization/TestData/Map/empty-map-csv.tmx rename to DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmj b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmj deleted file mode 100644 index de94421..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmx b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmx deleted file mode 100644 index d3e0f29..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-gzip.tmx +++ /dev/null @@ -1,8 +0,0 @@ - - - - - H4sIAAAAAAAACmNgoD0AAMrGiJlkAAAA - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmj b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmj deleted file mode 100644 index 4cf9e84..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmx b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmx deleted file mode 100644 index d35b438..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64-zlib.tmx +++ /dev/null @@ -1,8 +0,0 @@ - - - - - eJxjYKA9AAAAZAAB - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmj b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmj deleted file mode 100644 index b13707c..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmx b/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmx deleted file mode 100644 index 0e98f67..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-base64.tmx +++ /dev/null @@ -1,8 +0,0 @@ - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.cs b/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.cs deleted file mode 100644 index 79df5a5..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.cs +++ /dev/null @@ -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 - { - ["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" } - } - }; -} diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmj b/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmj deleted file mode 100644 index 237546d..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmx b/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmx deleted file mode 100644 index 5a14d94..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map-properties.tmx +++ /dev/null @@ -1,21 +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,0,0 - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/empty-map.cs b/DotTiled.Tests/Serialization/TestData/Map/empty-map.cs deleted file mode 100644 index b51aeba..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/empty-map.cs +++ /dev/null @@ -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 - ] - } - } - ] - }; -} diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.cs b/DotTiled.Tests/Serialization/TestData/Map/map-with-group.cs deleted file mode 100644 index 14a2c8c..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.cs +++ /dev/null @@ -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, - } - ] - } - ] - } - ] - }; -} diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmj b/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmj deleted file mode 100644 index 6bce8c8..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmx b/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmx deleted file mode 100644 index 61191c4..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-group.tmx +++ /dev/null @@ -1,26 +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,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,0,0 - - - - - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.cs b/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.cs deleted file mode 100644 index 1f9cb1c..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.cs +++ /dev/null @@ -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 - { - ["Bool"] = new BoolProperty { Name = "Bool", Value = true }, - ["TestClassInTemplate"] = new ClassProperty - { - Name = "TestClassInTemplate", - PropertyType = "TestClass", - Properties = new Dictionary - { - ["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 - { - ["Bool"] = new BoolProperty { Name = "Bool", Value = true }, - ["TestClassInTemplate"] = new ClassProperty - { - Name = "TestClassInTemplate", - PropertyType = "TestClass", - Properties = new Dictionary - { - ["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 - { - ["Bool"] = new BoolProperty { Name = "Bool", Value = true }, - ["TestClassInTemplate"] = new ClassProperty - { - Name = "TestClassInTemplate", - PropertyType = "TestClass", - Properties = new Dictionary - { - ["Amount"] = new FloatProperty { Name = "Amount", Value = 0.0f }, - ["Name"] = new StringProperty { Name = "Name", Value = "I am here 3" } - } - } - } - } - ] - } - ] - }; -} diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmj b/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmj deleted file mode 100644 index 398403b..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmx b/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmx deleted file mode 100644 index 83716a0..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/map-with-object-template.tmx +++ /dev/null @@ -1,35 +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,0,0 - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.cs b/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.cs deleted file mode 100644 index d6a5f10..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.cs +++ /dev/null @@ -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 - ] - }, - } - ] - }; -} diff --git a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmj b/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmj deleted file mode 100644 index fa5a4ef..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmj +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmx b/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmx deleted file mode 100644 index 3d91b9d..0000000 --- a/DotTiled.Tests/Serialization/TestData/Map/simple-tileset-embed.tmx +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - -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 - - - diff --git a/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tj b/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tj deleted file mode 100644 index ec2b065..0000000 --- a/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tj +++ /dev/null @@ -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" -} \ No newline at end of file diff --git a/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tx b/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tx deleted file mode 100644 index 3039be2..0000000 --- a/DotTiled.Tests/Serialization/TestData/Template/map-with-object-template.tx +++ /dev/null @@ -1,14 +0,0 @@ - - diff --git a/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs b/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs index 7e220a9..e04423b 100644 --- a/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs +++ b/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs @@ -2,44 +2,9 @@ namespace DotTiled.Tests; public partial class TmjMapReaderTests { - public static IEnumerable 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 DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => [ - ["Serialization.TestData.Map.map-with-object-template.tmj", TestData.MapWithObjectTemplate("tj")], - ["Serialization.TestData.Map.map-with-group.tmj", TestData.MapWithGroup()], + ["Serialization.TestData.Map.default_map.default-map.tmj", TestData.DefaultMap()] ]; [Theory] diff --git a/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs b/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs index 3556893..5ee162f 100644 --- a/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs +++ b/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs @@ -4,155 +4,9 @@ namespace DotTiled.Tests; public partial class TmxMapReaderTests { - [Fact] - public void TmxMapReaderConstructor_XmlReaderIsNull_ThrowsArgumentNullException() - { - // Arrange - XmlReader xmlReader = null!; - Func externalTilesetResolver = (_) => new Tileset(); - Func externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } }; - - // Act - Action act = () => - { - using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []); - }; - - // Assert - Assert.Throws(act); - } - - [Fact] - public void TmxMapReaderConstructor_ExternalTilesetResolverIsNull_ThrowsArgumentNullException() - { - // Arrange - using var stringReader = new StringReader(""); - using var xmlReader = XmlReader.Create(stringReader); - Func externalTilesetResolver = null!; - Func externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } }; - - // Act - Action act = () => - { - using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []); - }; - - // Assert - Assert.Throws(act); - } - - [Fact] - public void TmxMapReaderConstructor_ExternalTemplateResolverIsNull_ThrowsArgumentNullException() - { - // Arrange - using var stringReader = new StringReader(""); - using var xmlReader = XmlReader.Create(stringReader); - Func externalTilesetResolver = (_) => new Tileset(); - Func externalTemplateResolver = null!; - - // Act - Action act = () => - { - using var _ = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []); - }; - - // Assert - Assert.Throws(act); - } - - [Fact] - public void TmxMapReaderConstructor_NoneNull_DoesNotThrow() - { - // Arrange - using var stringReader = new StringReader(""); - using var xmlReader = XmlReader.Create(stringReader); - Func externalTilesetResolver = (_) => new Tileset(); - Func externalTemplateResolver = (_) => new Template { Object = new RectangleObject { } }; - - // Act - using var tmxMapReader = new TmxMapReader(xmlReader, externalTilesetResolver, externalTemplateResolver, []); - - // Assert - Assert.NotNull(tmxMapReader); - } - - public static IEnumerable 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 DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => [ - ["Serialization.TestData.Map.map-with-object-template.tmx", TestData.MapWithObjectTemplate("tx")], - ["Serialization.TestData.Map.map-with-group.tmx", TestData.MapWithGroup()], + ["Serialization.TestData.Map.default_map.default-map.tmx", TestData.DefaultMap()] ]; [Theory] diff --git a/DotTiled/Model/IProperty.cs b/DotTiled/Model/IProperty.cs deleted file mode 100644 index ae522f2..0000000 --- a/DotTiled/Model/IProperty.cs +++ /dev/null @@ -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 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 Members { get; set; } -} - -public enum CustomEnumStorageType -{ - Int, - String -} - -public class CustomEnumDefinition : CustomTypeDefinition -{ - public CustomEnumStorageType StorageType { get; set; } - public List Values { get; set; } = []; - public bool ValueAsFlags { get; set; } -} diff --git a/DotTiled/Model/Map.cs b/DotTiled/Model/Map.cs index 246f21c..fdcdbd1 100644 --- a/DotTiled/Model/Map.cs +++ b/DotTiled/Model/Map.cs @@ -60,5 +60,4 @@ public class Map // Any number of public List Tilesets { get; set; } = []; public List Layers { get; set; } = []; - public List Groups { get; set; } = []; } diff --git a/DotTiled/Model/Properties/BoolProperty.cs b/DotTiled/Model/Properties/BoolProperty.cs new file mode 100644 index 0000000..949858f --- /dev/null +++ b/DotTiled/Model/Properties/BoolProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/ClassProperty.cs b/DotTiled/Model/Properties/ClassProperty.cs new file mode 100644 index 0000000..0b1391d --- /dev/null +++ b/DotTiled/Model/Properties/ClassProperty.cs @@ -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 Properties { get; set; } + + public IProperty Clone() => new ClassProperty + { + Name = Name, + PropertyType = PropertyType, + Properties = Properties.ToDictionary(p => p.Key, p => p.Value.Clone()) + }; +} diff --git a/DotTiled/Model/Properties/ColorProperty.cs b/DotTiled/Model/Properties/ColorProperty.cs new file mode 100644 index 0000000..07ca25e --- /dev/null +++ b/DotTiled/Model/Properties/ColorProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs b/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs new file mode 100644 index 0000000..ec92b3f --- /dev/null +++ b/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs @@ -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 Members { get; set; } = []; +} diff --git a/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs b/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs new file mode 100644 index 0000000..d570442 --- /dev/null +++ b/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs @@ -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 Values { get; set; } = []; + public bool ValueAsFlags { get; set; } +} diff --git a/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs b/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs new file mode 100644 index 0000000..1f50462 --- /dev/null +++ b/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs @@ -0,0 +1,7 @@ +namespace DotTiled; + +public abstract class CustomTypeDefinition +{ + public uint ID { get; set; } + public string Name { get; set; } = ""; +} diff --git a/DotTiled/Model/Properties/FileProperty.cs b/DotTiled/Model/Properties/FileProperty.cs new file mode 100644 index 0000000..edc939c --- /dev/null +++ b/DotTiled/Model/Properties/FileProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/FloatProperty.cs b/DotTiled/Model/Properties/FloatProperty.cs new file mode 100644 index 0000000..469cc45 --- /dev/null +++ b/DotTiled/Model/Properties/FloatProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/IProperty.cs b/DotTiled/Model/Properties/IProperty.cs new file mode 100644 index 0000000..f4294cd --- /dev/null +++ b/DotTiled/Model/Properties/IProperty.cs @@ -0,0 +1,9 @@ +namespace DotTiled; + +public interface IProperty +{ + public string Name { get; set; } + public PropertyType Type { get; } + + IProperty Clone(); +} diff --git a/DotTiled/Model/Properties/IntProperty.cs b/DotTiled/Model/Properties/IntProperty.cs new file mode 100644 index 0000000..b8fb02a --- /dev/null +++ b/DotTiled/Model/Properties/IntProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/ObjectProperty.cs b/DotTiled/Model/Properties/ObjectProperty.cs new file mode 100644 index 0000000..1591319 --- /dev/null +++ b/DotTiled/Model/Properties/ObjectProperty.cs @@ -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 + }; +} diff --git a/DotTiled/Model/Properties/PropertyType.cs b/DotTiled/Model/Properties/PropertyType.cs new file mode 100644 index 0000000..79b05cb --- /dev/null +++ b/DotTiled/Model/Properties/PropertyType.cs @@ -0,0 +1,13 @@ +namespace DotTiled; + +public enum PropertyType +{ + String, + Int, + Float, + Bool, + Color, + File, + Object, + Class +} diff --git a/DotTiled/Model/Properties/StringProperty.cs b/DotTiled/Model/Properties/StringProperty.cs new file mode 100644 index 0000000..655b7b4 --- /dev/null +++ b/DotTiled/Model/Properties/StringProperty.cs @@ -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 + }; +}