diff --git a/docs/docs/essentials/loading-maps.md b/docs/docs/essentials/loading-maps.md index 7b6f0c1..d262ec9 100644 --- a/docs/docs/essentials/loading-maps.md +++ b/docs/docs/essentials/loading-maps.md @@ -5,10 +5,13 @@ Loading maps with DotTiled is very flexible and allows you as a developer to fre > [!TIP] > For a quick and easy way to load maps from the filesystem, please refer to the [quickstart guide](../quickstart.md). -## File formats +## File format caveats The class is a representation of a Tiled map, mimicking the structure of a Tiled XML map file. Map files can either be in the [`.tmx`/XML](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) or [`.tmj`/json](https://doc.mapeditor.org/en/stable/reference/json-map-format/) format. DotTiled supports **both** formats fully. +> [!WARNING] +> Using the `.tmj` file format will result in (the source image for image layers) not having the same amount of information as for the `.tmx` format. This is due to the fact that the `.tmj` format does not include the full information that the `.tmx` format does. This is not a problem with DotTiled, but rather a limitation of the `.tmj` format. + ## The process of loading a map Loading a map with DotTiled is not a complex process, but one that at least demands a basic understanding of how Tiled maps are structured. The process can be broken down into the following flow(-ish) chart: diff --git a/docs/docs/essentials/representation-model.md b/docs/docs/essentials/representation-model.md index ab3ce6e..b1b6ef7 100644 --- a/docs/docs/essentials/representation-model.md +++ b/docs/docs/essentials/representation-model.md @@ -12,9 +12,6 @@ Certain properties throughout the representation model are marked as *optional* The representation model is designed to be compatible with the latest version of Tiled. This means that it may not be able to read files from older versions of Tiled, or files that use features that are not yet supported by the representation model. However, here is a table of which versions of Tiled are supported by which versions of DotTiled. -You should use one of the versions of DotTiled that is compatible with the version of Tiled you are using. - -| Tiled version | Compatible DotTiled version(s) | -|----------------|--------------------------------| -| 1.11.1, 1.11.2 | 0.4.0 | -| 1.11 | 0.1.0, 0.2.0, 0.2.1, 0.3.0 | \ No newline at end of file +| Tiled version | Compatible DotTiled version(s) | +|---------------|--------------------------------| +| 1.11 | 0.1.0, 0.2.0, 0.2.1, 0.3.0 | \ No newline at end of file diff --git a/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs b/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs index 4b4c226..c0d580f 100644 --- a/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs +++ b/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs @@ -48,7 +48,7 @@ public class FromTypeUsedInLoaderTests ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -133,7 +133,7 @@ public class FromTypeUsedInLoaderTests ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -226,7 +226,7 @@ public class FromTypeUsedInLoaderTests ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs b/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs index cee4c6b..8aeae0d 100644 --- a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs +++ b/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs @@ -15,7 +15,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs b/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs index 93c4c31..2500a4d 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -47,7 +47,7 @@ public partial class TestData }, Properties = [ new BoolProperty { Name = "tilesetbool", Value = true }, - new ColorProperty { Name = "tilesetcolor", Value = TiledColor.Parse("#ffff0000", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "tilesetcolor", Value = Color.Parse("#ffff0000", CultureInfo.InvariantCulture) }, new FileProperty { Name = "tilesetfile", Value = "" }, new FloatProperty { Name = "tilesetfloat", Value = 5.2f }, new IntProperty { Name = "tilesetint", Value = 9 }, diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs b/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs index 164aa0e..756c59f 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -63,21 +63,21 @@ public partial class TestData new WangColor { Name = "Water", - Color = TiledColor.Parse("#ff0000", CultureInfo.InvariantCulture), + Color = Color.Parse("#ff0000", CultureInfo.InvariantCulture), Tile = 0, Probability = 1 }, new WangColor { Name = "Grass", - Color = TiledColor.Parse("#00ff00", CultureInfo.InvariantCulture), + Color = Color.Parse("#00ff00", CultureInfo.InvariantCulture), Tile = -1, Probability = 1 }, new WangColor { Name = "Stone", - Color = TiledColor.Parse("#0000ff", CultureInfo.InvariantCulture), + Color = Color.Parse("#0000ff", CultureInfo.InvariantCulture), Tile = 29, Probability = 1 } diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs index 32755ca..82dfd29 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 8, @@ -181,8 +181,8 @@ public partial class TestData { Format = ImageFormat.Png, Source = "tileset.png", - Width = fileExt == "tmx" ? 256 : 0, // Currently, json format does not - Height = fileExt == "tmx" ? 96 : 0 // include image dimensions in image layer https://github.com/mapeditor/tiled/issues/4028 + Width = fileExt == "tmx" ? 256u : 0, // Currently, json format does not + Height = fileExt == "tmx" ? 96u : 0 // include image dimensions in image layer https://github.com/mapeditor/tiled/issues/4028 }, RepeatX = true }, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs b/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs index 0511454..8cbd6bd 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs @@ -15,7 +15,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs b/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs index d1e7d7b..ef98d02 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs @@ -15,7 +15,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs b/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs index ff184ff..2437d0b 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00ff00", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00ff00", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -52,13 +52,13 @@ public partial class TestData Properties = [ new BoolProperty { Name = "boolprop", Value = true }, - new ColorProperty { Name = "colorprop", Value = TiledColor.Parse("#ff55ffff", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) }, new FileProperty { Name = "fileprop", Value = "file.txt" }, new FloatProperty { Name = "floatprop", Value = 4.2f }, new IntProperty { Name = "intprop", Value = 8 }, new ObjectProperty { Name = "objectprop", Value = 5 }, new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }, - new ColorProperty { Name = "unsetcolorprop", Value = Optional.Empty } + new ColorProperty { Name = "unsetcolorprop", Value = Optional.Empty } ] }; } diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs index 91d4e07..4134dac 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs index 6a2b6bf..f77638b 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -56,7 +56,7 @@ public partial class TestData PropertyType = "CustomClass", Value = [ new BoolProperty { Name = "boolinclass", Value = true }, - new ColorProperty { Name = "colorinclass", Value = TiledColor.Parse("#000000ff", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "colorinclass", Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) }, new FileProperty { Name = "fileinclass", Value = "" }, new FloatProperty { Name = "floatinclass", Value = 13.37f }, new IntProperty { Name = "intinclass", Value = 0 }, @@ -106,7 +106,7 @@ public partial class TestData new ColorProperty { Name = "colorinclass", - Value = TiledColor.Parse("#000000ff", CultureInfo.InvariantCulture) + Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) }, new FileProperty { diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs b/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs index 76e34fb..b67548a 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -61,7 +61,7 @@ public partial class TestData PropertyType = "CustomClass", Value = [ new BoolProperty { Name = "boolinclass", Value = false }, - new ColorProperty { Name = "colorinclass", Value = TiledColor.Parse("#000000ff", CultureInfo.InvariantCulture) }, + 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 }, @@ -82,7 +82,7 @@ public partial class TestData PropertyType = "CustomClass", Value = [ new BoolProperty { Name = "boolinclass", Value = true }, - new ColorProperty { Name = "colorinclass", Value = TiledColor.Parse("#000000ff", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "colorinclass", Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) }, new FileProperty { Name = "fileinclass", Value = "" }, new FloatProperty { Name = "floatinclass", Value = 13.37f }, new IntProperty { Name = "intinclass", Value = 0 }, @@ -109,7 +109,7 @@ public partial class TestData new ColorProperty { Name = "colorinclass", - Value = TiledColor.Parse("#000000ff", CultureInfo.InvariantCulture) + Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) }, new FileProperty { diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs b/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs index 8bb3724..0056fd1 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs b/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs index 34bd69f..15b9873 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs index 8dde14b..aef25d3 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 3, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs index 593eec7..1b06285 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs @@ -17,9 +17,9 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", - TiledVersion = "1.11.2", + TiledVersion = "1.11.0", NextLayerID = 8, NextObjectID = 7, Tilesets = [ @@ -172,8 +172,8 @@ public partial class TestData { Format = ImageFormat.Png, Source = "tileset.png", - Width = 256, - Height = 96 + Width = fileExt == "tmx" ? 256u : 0, // Currently, json format does not + Height = fileExt == "tmx" ? 96u : 0 // include image dimensions in image layer https://github.com/mapeditor/tiled/issues/4028 }, RepeatX = true }, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj index 427f404..9e9f669 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj @@ -114,8 +114,6 @@ { "id":4, "image":"tileset.png", - "imageheight":96, - "imagewidth":256, "name":"ImageLayer", "opacity":1, "repeatx":true, @@ -151,7 +149,7 @@ "nextobjectid":7, "orientation":"orthogonal", "renderorder":"right-down", - "tiledversion":"1.11.2", + "tiledversion":"1.11.0", "tileheight":32, "tilesets":[ { diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx index 512a7a4..5888069 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx @@ -1,5 +1,5 @@ - + diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs b/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs index 68b196c..06fc07f 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs @@ -17,7 +17,7 @@ public partial class TestData ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, CompressionLevel = -1, - BackgroundColor = TiledColor.Parse("#00ff00", CultureInfo.InvariantCulture), + BackgroundColor = Color.Parse("#00ff00", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", NextLayerID = 2, @@ -52,7 +52,7 @@ public partial class TestData Properties = [ new BoolProperty { Name = "boolprop", Value = true }, - new ColorProperty { Name = "colorprop", Value = TiledColor.Parse("#ff55ffff", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) }, new FileProperty { Name = "fileprop", Value = "file.txt" }, new FloatProperty { Name = "floatprop", Value = 4.2f }, new IntProperty { Name = "intprop", Value = 8 }, diff --git a/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs b/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs index cbf84c2..4f9ab0f 100644 --- a/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs +++ b/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs @@ -80,7 +80,7 @@ public class HasPropertiesBaseTests private sealed class MapTo { public bool MapToBool { get; set; } = false; - public TiledColor MapToColor { get; set; } = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture); + public Color MapToColor { get; set; } = Color.Parse("#00000000", CultureInfo.InvariantCulture); public float MapToFloat { get; set; } = 0.0f; public string MapToFile { get; set; } = ""; public int MapToInt { get; set; } = 0; @@ -130,7 +130,7 @@ public class HasPropertiesBaseTests PropertyType = "MapTo", Value = [ new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, new FloatProperty { Name = "MapToFloat", Value = 1.0f }, new StringProperty { Name = "MapToFile", Value = "Test" }, new IntProperty { Name = "MapToInt", Value = 1 }, @@ -146,7 +146,7 @@ public class HasPropertiesBaseTests // Assert Assert.True(mappedProperty.MapToBool); - Assert.Equal(TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); + Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); Assert.Equal(1.0f, mappedProperty.MapToFloat); Assert.Equal("Test", mappedProperty.MapToFile); Assert.Equal(1, mappedProperty.MapToInt); @@ -175,7 +175,7 @@ public class HasPropertiesBaseTests PropertyType = "MapTo", Value = [ new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, new FloatProperty { Name = "MapToFloat", Value = 1.0f }, new StringProperty { Name = "MapToFile", Value = "Test" }, new IntProperty { Name = "MapToInt", Value = 1 }, @@ -194,7 +194,7 @@ public class HasPropertiesBaseTests // Assert Assert.Equal("Test", mappedProperty.NestedMapToString); Assert.True(mappedProperty.MapToInNested.MapToBool); - Assert.Equal(TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToInNested.MapToColor); + Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToInNested.MapToColor); Assert.Equal(1.0f, mappedProperty.MapToInNested.MapToFloat); Assert.Equal("Test", mappedProperty.MapToInNested.MapToFile); Assert.Equal(1, mappedProperty.MapToInNested.MapToInt); @@ -276,7 +276,7 @@ public class HasPropertiesBaseTests // Arrange List props = [ new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, + new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, new FloatProperty { Name = "MapToFloat", Value = 1.0f }, new StringProperty { Name = "MapToFile", Value = "Test" }, new IntProperty { Name = "MapToInt", Value = 1 }, @@ -290,7 +290,7 @@ public class HasPropertiesBaseTests // Assert Assert.True(mappedProperty.MapToBool); - Assert.Equal(TiledColor.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); + Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); Assert.Equal(1.0f, mappedProperty.MapToFloat); Assert.Equal("Test", mappedProperty.MapToFile); Assert.Equal(1, mappedProperty.MapToInt); diff --git a/src/DotTiled/Properties/TiledColor.cs b/src/DotTiled/Color.cs similarity index 77% rename from src/DotTiled/Properties/TiledColor.cs rename to src/DotTiled/Color.cs index cebc1f6..78d0b80 100644 --- a/src/DotTiled/Properties/TiledColor.cs +++ b/src/DotTiled/Color.cs @@ -7,7 +7,7 @@ namespace DotTiled; /// /// Represents a Tiled color. /// -public class TiledColor : IParsable, IEquatable +public class Color : IParsable, IEquatable { /// /// The red component of the color. @@ -30,31 +30,31 @@ public class TiledColor : IParsable, IEquatable public byte A { get; set; } = 255; /// - /// Attempts to parse the specified string into a . Expects strings in the format #RRGGBB or #AARRGGBB. + /// Attempts to parse the specified string into a . Expects strings in the format #RRGGBB or #AARRGGBB. /// The leading # is optional. /// - /// A string value to parse into a + /// A string value to parse into a /// An object that supplies culture-specific information about the format of s. - /// The parsed + /// The parsed /// Thrown in case the provided string is not in a valid format. - public static TiledColor Parse(string s, IFormatProvider provider) + public static Color Parse(string s, IFormatProvider provider) { _ = TryParse(s, provider, out var result); return result ?? throw new FormatException($"Invalid format for TiledColor: {s}"); } /// - /// Attempts to parse the specified string into a . Expects strings in the format #RRGGBB or #AARRGGBB. + /// Attempts to parse the specified string into a . Expects strings in the format #RRGGBB or #AARRGGBB. /// The leading # is optional. /// - /// A string value to parse into a + /// A string value to parse into a /// An object that supplies culture-specific information about the format of s. - /// When this method returns, contains the parsed or null on failure. + /// When this method returns, contains the parsed or null on failure. /// true if was successfully parsed; otherwise, false. public static bool TryParse( [NotNullWhen(true)] string s, IFormatProvider provider, - [MaybeNullWhen(false)] out TiledColor result) + [MaybeNullWhen(false)] out Color result) { if (s is not null && !s.StartsWith('#')) return TryParse($"#{s}", provider, out result); @@ -68,7 +68,7 @@ public class TiledColor : IParsable, IEquatable if (s.Length == 7) { - result = new TiledColor + result = new Color { R = byte.Parse(s[1..3], NumberStyles.HexNumber, provider), G = byte.Parse(s[3..5], NumberStyles.HexNumber, provider), @@ -77,7 +77,7 @@ public class TiledColor : IParsable, IEquatable } else { - result = new TiledColor + result = new Color { A = byte.Parse(s[1..3], NumberStyles.HexNumber, provider), R = byte.Parse(s[3..5], NumberStyles.HexNumber, provider), @@ -90,7 +90,7 @@ public class TiledColor : IParsable, IEquatable } /// - public bool Equals(TiledColor other) + public bool Equals(Color other) { if (other is null) return false; @@ -99,7 +99,7 @@ public class TiledColor : IParsable, IEquatable } /// - public override bool Equals(object obj) => obj is TiledColor 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); diff --git a/src/DotTiled/DotTiled.csproj b/src/DotTiled/DotTiled.csproj index d8d83a5..6e8de2a 100644 --- a/src/DotTiled/DotTiled.csproj +++ b/src/DotTiled/DotTiled.csproj @@ -18,7 +18,7 @@ true Copyright © 2024 dcronqvist LICENSE - 0.4.0 + 0.3.0 diff --git a/src/DotTiled/Layers/BaseLayer.cs b/src/DotTiled/Layers/BaseLayer.cs index 4da3443..26a6416 100644 --- a/src/DotTiled/Layers/BaseLayer.cs +++ b/src/DotTiled/Layers/BaseLayer.cs @@ -37,7 +37,7 @@ public abstract class BaseLayer : HasPropertiesBase /// /// A tint color that is multiplied with any tiles drawn by this layer. /// - public Optional TintColor { get; set; } = Optional.Empty; + public Optional TintColor { get; set; } = Optional.Empty; /// /// Horizontal offset for this layer in pixels. diff --git a/src/DotTiled/Layers/Data.cs b/src/DotTiled/Layers/Data.cs index 958c2b3..16bf34e 100644 --- a/src/DotTiled/Layers/Data.cs +++ b/src/DotTiled/Layers/Data.cs @@ -90,12 +90,12 @@ public class Chunk /// /// The width of the chunk in tiles. /// - public required int Width { get; set; } + public required uint Width { get; set; } /// /// The height of the chunk in tiles. /// - public required int Height { get; set; } + public required uint Height { get; set; } /// /// The parsed chunk data, as a list of tile GIDs. diff --git a/src/DotTiled/Layers/ImageLayer.cs b/src/DotTiled/Layers/ImageLayer.cs index 6bd8ead..5d8de82 100644 --- a/src/DotTiled/Layers/ImageLayer.cs +++ b/src/DotTiled/Layers/ImageLayer.cs @@ -8,12 +8,12 @@ public class ImageLayer : BaseLayer /// /// The X position of the image layer in pixels. /// - public int X { get; set; } = 0; + public uint X { get; set; } = 0; /// /// The Y position of the image layer in pixels. /// - public int Y { get; set; } = 0; + public Optional Y { get; set; } = 0; /// /// Whether the image drawn by this layer is repeated along the X axis. diff --git a/src/DotTiled/Layers/ObjectLayer.cs b/src/DotTiled/Layers/ObjectLayer.cs index 1e825e1..77ecc02 100644 --- a/src/DotTiled/Layers/ObjectLayer.cs +++ b/src/DotTiled/Layers/ObjectLayer.cs @@ -26,27 +26,27 @@ public class ObjectLayer : BaseLayer /// /// The X coordinate of the object layer in tiles. /// - public int X { get; set; } = 0; + public uint X { get; set; } = 0; /// /// The Y coordinate of the object layer in tiles. /// - public int Y { get; set; } = 0; + public uint Y { get; set; } = 0; /// /// The width of the object layer in tiles. Meaningless. /// - public int Width { get; set; } = 0; + public uint Width { get; set; } = 0; /// /// The height of the object layer in tiles. Meaningless. /// - public int Height { get; set; } = 0; + public uint Height { get; set; } = 0; /// /// A color that is multiplied with any tile objects drawn by this layer. /// - public Optional Color { get; set; } = Optional.Empty; + public Optional Color { get; set; } = Optional.Empty; /// /// Whether the objects are drawn according to the order of appearance () or sorted by their Y coordinate (). diff --git a/src/DotTiled/Layers/Objects/TextObject.cs b/src/DotTiled/Layers/Objects/TextObject.cs index 42b07d0..48a095c 100644 --- a/src/DotTiled/Layers/Objects/TextObject.cs +++ b/src/DotTiled/Layers/Objects/TextObject.cs @@ -72,7 +72,7 @@ public class TextObject : Object /// /// The color of the text. /// - public TiledColor Color { get; set; } = TiledColor.Parse("#000000", CultureInfo.InvariantCulture); + public Color Color { get; set; } = Color.Parse("#000000", CultureInfo.InvariantCulture); /// /// Whether the text is bold. diff --git a/src/DotTiled/Layers/TileLayer.cs b/src/DotTiled/Layers/TileLayer.cs index 8d63180..631d205 100644 --- a/src/DotTiled/Layers/TileLayer.cs +++ b/src/DotTiled/Layers/TileLayer.cs @@ -8,22 +8,22 @@ public class TileLayer : BaseLayer /// /// The X coordinate of the layer in tiles. /// - public int X { get; set; } = 0; + public uint X { get; set; } = 0; /// /// The Y coordinate of the layer in tiles. /// - public int Y { get; set; } = 0; + public uint Y { get; set; } = 0; /// /// The width of the layer in tiles. Always the same as the map width for fixed-size maps. /// - public required int Width { get; set; } + public required uint Width { get; set; } /// /// The height of the layer in tiles. Always the same as the map height for fixed-size maps. /// - public required int Height { get; set; } + public required uint Height { get; set; } /// /// The tile layer data. diff --git a/src/DotTiled/Map.cs b/src/DotTiled/Map.cs index 92965f5..eb3f92e 100644 --- a/src/DotTiled/Map.cs +++ b/src/DotTiled/Map.cs @@ -126,27 +126,27 @@ public class Map : HasPropertiesBase /// /// The width of the map in tiles. /// - public required int Width { get; set; } + public required uint Width { get; set; } /// /// The height of the map in tiles. /// - public required int Height { get; set; } + public required uint Height { get; set; } /// /// The width of a tile. /// - public required int TileWidth { get; set; } + public required uint TileWidth { get; set; } /// /// The height of a tile. /// - public required int TileHeight { get; set; } + public required uint TileHeight { get; set; } /// /// Only for hexagonal maps. Determines the width or height (depending on the staggered axis) of the tile's edge, in pixels. /// - public Optional HexSideLength { get; set; } = Optional.Empty; + public Optional HexSideLength { get; set; } = Optional.Empty; /// /// For staggered and hexagonal maps, determines which axis (X or Y) is staggered. @@ -171,7 +171,7 @@ public class Map : HasPropertiesBase /// /// The background color of the map. /// - public TiledColor BackgroundColor { get; set; } = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture); + public Color BackgroundColor { get; set; } = Color.Parse("#00000000", CultureInfo.InvariantCulture); /// /// Stores the next available ID for new layers. This number is used to prevent reuse of the same ID after layers have been removed. diff --git a/src/DotTiled/Properties/ColorProperty.cs b/src/DotTiled/Properties/ColorProperty.cs index 9e5cc0d..295096e 100644 --- a/src/DotTiled/Properties/ColorProperty.cs +++ b/src/DotTiled/Properties/ColorProperty.cs @@ -3,7 +3,7 @@ namespace DotTiled; /// /// Represents a color property. /// -public class ColorProperty : IProperty> +public class ColorProperty : IProperty> { /// public required string Name { get; set; } @@ -14,7 +14,7 @@ public class ColorProperty : IProperty> /// /// The color value of the property. /// - public required Optional Value { get; set; } + public required Optional Value { get; set; } /// public IProperty Clone() => new ColorProperty diff --git a/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs b/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs index 7d799ca..37b8c6e 100644 --- a/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs +++ b/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs @@ -78,7 +78,7 @@ public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition /// /// The color of the custom class inside the Tiled editor. /// - public TiledColor Color { get; set; } + public Color Color { get; set; } /// /// Whether the custom class should be drawn with a fill color. @@ -155,8 +155,8 @@ public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition { case Type t when t == typeof(bool): return new BoolProperty { Name = propertyInfo.Name, Value = (bool)propertyInfo.GetValue(instance) }; - case Type t when t == typeof(TiledColor): - return new ColorProperty { Name = propertyInfo.Name, Value = (TiledColor)propertyInfo.GetValue(instance) }; + case Type t when t == typeof(Color): + return new ColorProperty { Name = propertyInfo.Name, Value = (Color)propertyInfo.GetValue(instance) }; case Type t when t == typeof(float): return new FloatProperty { Name = propertyInfo.Name, Value = (float)propertyInfo.GetValue(instance) }; case Type t when t == typeof(string): diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs index afd6734..47b9b75 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs @@ -23,8 +23,8 @@ public abstract partial class TmjReaderBase var x = element.GetRequiredProperty("x"); var y = element.GetRequiredProperty("y"); - var width = element.GetRequiredProperty("width"); - var height = element.GetRequiredProperty("height"); + var width = element.GetRequiredProperty("width"); + var height = element.GetRequiredProperty("height"); return new Chunk { diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Group.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Group.cs index 4c6ac38..0df3c10 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Group.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Group.cs @@ -12,7 +12,7 @@ public abstract partial class TmjReaderBase var @class = element.GetOptionalProperty("class").GetValueOr(""); var opacity = element.GetOptionalProperty("opacity").GetValueOr(1.0f); var visible = element.GetOptionalProperty("visible").GetValueOr(true); - var tintColor = element.GetOptionalPropertyParseable("tintcolor"); + var tintColor = element.GetOptionalPropertyParseable("tintcolor"); var offsetX = element.GetOptionalProperty("offsetx").GetValueOr(0.0f); var offsetY = element.GetOptionalProperty("offsety").GetValueOr(0.0f); var parallaxX = element.GetOptionalProperty("parallaxx").GetValueOr(1.0f); diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs index c0c2c5b..3d59779 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs @@ -11,7 +11,7 @@ public abstract partial class TmjReaderBase var @class = element.GetOptionalProperty("class").GetValueOr(""); var opacity = element.GetOptionalProperty("opacity").GetValueOr(1.0f); var visible = element.GetOptionalProperty("visible").GetValueOr(true); - var tintColor = element.GetOptionalPropertyParseable("tintcolor"); + var tintColor = element.GetOptionalPropertyParseable("tintcolor"); var offsetX = element.GetOptionalProperty("offsetx").GetValueOr(0.0f); var offsetY = element.GetOptionalProperty("offsety").GetValueOr(0.0f); var parallaxX = element.GetOptionalProperty("parallaxx").GetValueOr(1.0f); @@ -19,19 +19,17 @@ public abstract partial class TmjReaderBase var properties = ResolveAndMergeProperties(@class, element.GetOptionalPropertyCustom("properties", ReadProperties).GetValueOr([])); var image = element.GetRequiredProperty("image"); - var imageWidth = element.GetOptionalProperty("imagewidth").GetValueOr(0); - var imageHeight = element.GetOptionalProperty("imageheight").GetValueOr(0); var repeatX = element.GetOptionalProperty("repeatx").GetValueOr(false); var repeatY = element.GetOptionalProperty("repeaty").GetValueOr(false); - var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); - var x = element.GetOptionalProperty("x").GetValueOr(0); - var y = element.GetOptionalProperty("y").GetValueOr(0); + var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); + var x = element.GetOptionalProperty("x").GetValueOr(0); + var y = element.GetOptionalProperty("y").GetValueOr(0); var imgModel = new Image { Format = Helpers.ParseImageFormatFromSource(image), - Height = imageHeight, - Width = imageWidth, + Height = 0, + Width = 0, Source = image, TransparentColor = transparentColor }; diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Map.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Map.cs index dfe7eee..caecb7e 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Map.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Map.cs @@ -28,11 +28,11 @@ public abstract partial class TmjReaderBase _ => throw new JsonException($"Unknown render order '{s}'") }).GetValueOr(RenderOrder.RightDown); var compressionLevel = element.GetOptionalProperty("compressionlevel").GetValueOr(-1); - var width = element.GetRequiredProperty("width"); - var height = element.GetRequiredProperty("height"); - var tileWidth = element.GetRequiredProperty("tilewidth"); - var tileHeight = element.GetRequiredProperty("tileheight"); - var hexSideLength = element.GetOptionalProperty("hexsidelength"); + var width = element.GetRequiredProperty("width"); + var height = element.GetRequiredProperty("height"); + var tileWidth = element.GetRequiredProperty("tilewidth"); + var tileHeight = element.GetRequiredProperty("tileheight"); + var hexSideLength = element.GetOptionalProperty("hexsidelength"); var staggerAxis = element.GetOptionalPropertyParseable("staggeraxis", s => s switch { "x" => StaggerAxis.X, @@ -47,7 +47,7 @@ public abstract partial class TmjReaderBase }); var parallaxOriginX = element.GetOptionalProperty("parallaxoriginx").GetValueOr(0f); var parallaxOriginY = element.GetOptionalProperty("parallaxoriginy").GetValueOr(0f); - var backgroundColor = element.GetOptionalPropertyParseable("backgroundcolor").GetValueOr(TiledColor.Parse("#00000000", CultureInfo.InvariantCulture)); + var backgroundColor = element.GetOptionalPropertyParseable("backgroundcolor").GetValueOr(Color.Parse("#00000000", CultureInfo.InvariantCulture)); var nextLayerID = element.GetRequiredProperty("nextlayerid"); var nextObjectID = element.GetRequiredProperty("nextobjectid"); var infinite = element.GetOptionalProperty("infinite").GetValueOr(false); diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs index 132ceba..ced3f64 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs @@ -15,18 +15,18 @@ public abstract partial class TmjReaderBase var @class = element.GetOptionalProperty("class").GetValueOr(""); var opacity = element.GetOptionalProperty("opacity").GetValueOr(1.0f); var visible = element.GetOptionalProperty("visible").GetValueOr(true); - var tintColor = element.GetOptionalPropertyParseable("tintcolor"); + var tintColor = element.GetOptionalPropertyParseable("tintcolor"); var offsetX = element.GetOptionalProperty("offsetx").GetValueOr(0.0f); var offsetY = element.GetOptionalProperty("offsety").GetValueOr(0.0f); var parallaxX = element.GetOptionalProperty("parallaxx").GetValueOr(1.0f); var parallaxY = element.GetOptionalProperty("parallaxy").GetValueOr(1.0f); var properties = ResolveAndMergeProperties(@class, element.GetOptionalPropertyCustom("properties", ReadProperties).GetValueOr([])); - var x = element.GetOptionalProperty("x").GetValueOr(0); - var y = element.GetOptionalProperty("y").GetValueOr(0); - var width = element.GetOptionalProperty("width").GetValueOr(0); - var height = element.GetOptionalProperty("height").GetValueOr(0); - var color = element.GetOptionalPropertyParseable("color"); + var x = element.GetOptionalProperty("x").GetValueOr(0); + var y = element.GetOptionalProperty("y").GetValueOr(0); + var width = element.GetOptionalProperty("width").GetValueOr(0); + var height = element.GetOptionalProperty("height").GetValueOr(0); + var color = element.GetOptionalPropertyParseable("color"); var drawOrder = element.GetOptionalPropertyParseable("draworder", s => s switch { "topdown" => DrawOrder.TopDown, @@ -255,7 +255,7 @@ public abstract partial class TmjReaderBase internal static TextObject ReadText(JsonElement element) { var bold = element.GetOptionalProperty("bold").GetValueOr(false); - var color = element.GetOptionalPropertyParseable("color").GetValueOr(TiledColor.Parse("#00000000", CultureInfo.InvariantCulture)); + var color = element.GetOptionalPropertyParseable("color").GetValueOr(Color.Parse("#00000000", CultureInfo.InvariantCulture)); var fontfamily = element.GetOptionalProperty("fontfamily").GetValueOr("sans-serif"); var halign = element.GetOptionalPropertyParseable("halign", s => s switch { diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Properties.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Properties.cs index 1ad6e53..ae7ea1c 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Properties.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Properties.cs @@ -36,7 +36,7 @@ public abstract partial class TmjReaderBase PropertyType.Int => new IntProperty { Name = name, Value = e.GetRequiredProperty("value") }, PropertyType.Float => new FloatProperty { Name = name, Value = e.GetRequiredProperty("value") }, PropertyType.Bool => new BoolProperty { Name = name, Value = e.GetRequiredProperty("value") }, - PropertyType.Color => new ColorProperty { Name = name, Value = e.GetRequiredPropertyParseable("value", s => s == "" ? default : TiledColor.Parse(s, CultureInfo.InvariantCulture)) }, + PropertyType.Color => new ColorProperty { Name = name, Value = e.GetRequiredPropertyParseable("value", s => s == "" ? default : Color.Parse(s, CultureInfo.InvariantCulture)) }, PropertyType.File => new FileProperty { Name = name, Value = e.GetRequiredProperty("value") }, PropertyType.Object => new ObjectProperty { Name = name, Value = e.GetRequiredProperty("value") }, PropertyType.Class => throw new JsonException("Class property must have a property type"), @@ -163,7 +163,7 @@ public abstract partial class TmjReaderBase PropertyType.Int => new IntProperty { Name = prop.Name, Value = propElement.GetValueAs() }, PropertyType.Float => new FloatProperty { Name = prop.Name, Value = propElement.GetValueAs() }, PropertyType.Bool => new BoolProperty { Name = prop.Name, Value = propElement.GetValueAs() }, - PropertyType.Color => new ColorProperty { Name = prop.Name, Value = TiledColor.Parse(propElement.GetValueAs(), CultureInfo.InvariantCulture) }, + PropertyType.Color => new ColorProperty { Name = prop.Name, Value = Color.Parse(propElement.GetValueAs(), CultureInfo.InvariantCulture) }, PropertyType.File => new FileProperty { Name = prop.Name, Value = propElement.GetValueAs() }, PropertyType.Object => new ObjectProperty { Name = prop.Name, Value = propElement.GetValueAs() }, PropertyType.Enum => ReadEnumProperty(propElement), diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs index 287ef18..f33840d 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs @@ -22,7 +22,7 @@ public abstract partial class TmjReaderBase var chunks = element.GetOptionalPropertyCustom("chunks", e => ReadDataAsChunks(e, compression, encoding)); var @class = element.GetOptionalProperty("class").GetValueOr(""); var data = element.GetOptionalPropertyCustom("data", e => ReadDataWithoutChunks(e, compression, encoding)); - var height = element.GetRequiredProperty("height"); + var height = element.GetRequiredProperty("height"); var id = element.GetRequiredProperty("id"); var name = element.GetRequiredProperty("name"); var offsetX = element.GetOptionalProperty("offsetx").GetValueOr(0.0f); @@ -35,12 +35,12 @@ public abstract partial class TmjReaderBase var repeatY = element.GetOptionalProperty("repeaty").GetValueOr(false); var startX = element.GetOptionalProperty("startx").GetValueOr(0); var startY = element.GetOptionalProperty("starty").GetValueOr(0); - var tintColor = element.GetOptionalPropertyParseable("tintcolor"); - var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); + var tintColor = element.GetOptionalPropertyParseable("tintcolor"); + var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); var visible = element.GetOptionalProperty("visible").GetValueOr(true); - var width = element.GetRequiredProperty("width"); - var x = element.GetRequiredProperty("x"); - var y = element.GetRequiredProperty("y"); + var width = element.GetRequiredProperty("width"); + var x = element.GetRequiredProperty("x"); + var y = element.GetRequiredProperty("y"); if (!data.HasValue && !chunks.HasValue) throw new JsonException("Tile layer does not contain data."); diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Tileset.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Tileset.cs index fae87fe..9263fa9 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Tileset.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Tileset.cs @@ -10,9 +10,9 @@ public abstract partial class TmjReaderBase Optional parentVersion = null, Optional parentTiledVersion = null) { - var backgroundColor = element.GetOptionalPropertyParseable("backgroundcolor"); + var backgroundColor = element.GetOptionalPropertyParseable("backgroundcolor"); var @class = element.GetOptionalProperty("class").GetValueOr(""); - var columns = element.GetOptionalProperty("columns"); + var columns = element.GetOptionalProperty("columns"); var fillMode = element.GetOptionalPropertyParseable("fillmode", s => s switch { "stretch" => FillMode.Stretch, @@ -22,9 +22,9 @@ public abstract partial class TmjReaderBase var firstGID = element.GetOptionalProperty("firstgid"); var grid = element.GetOptionalPropertyCustom("grid", ReadGrid); var image = element.GetOptionalProperty("image"); - var imageHeight = element.GetOptionalProperty("imageheight"); - var imageWidth = element.GetOptionalProperty("imagewidth"); - var margin = element.GetOptionalProperty("margin"); + var imageHeight = element.GetOptionalProperty("imageheight"); + var imageWidth = element.GetOptionalProperty("imagewidth"); + var margin = element.GetOptionalProperty("margin"); var name = element.GetOptionalProperty("name"); var objectAlignment = element.GetOptionalPropertyParseable("objectalignment", s => s switch { @@ -42,10 +42,10 @@ public abstract partial class TmjReaderBase }).GetValueOr(ObjectAlignment.Unspecified); var properties = ResolveAndMergeProperties(@class, element.GetOptionalPropertyCustom("properties", ReadProperties).GetValueOr([])); var source = element.GetOptionalProperty("source"); - var spacing = element.GetOptionalProperty("spacing"); - var tileCount = element.GetOptionalProperty("tilecount"); + var spacing = element.GetOptionalProperty("spacing"); + var tileCount = element.GetOptionalProperty("tilecount"); var tiledVersion = element.GetOptionalProperty("tiledversion").GetValueOrOptional(parentTiledVersion); - var tileHeight = element.GetOptionalProperty("tileheight"); + var tileHeight = element.GetOptionalProperty("tileheight"); var tileOffset = element.GetOptionalPropertyCustom("tileoffset", ReadTileOffset); var tileRenderSize = element.GetOptionalPropertyParseable("tilerendersize", s => s switch { @@ -54,8 +54,9 @@ public abstract partial class TmjReaderBase _ => throw new JsonException($"Unknown tile render size '{s}'") }).GetValueOr(TileRenderSize.Tile); var tiles = element.GetOptionalPropertyCustom>("tiles", ReadTiles).GetValueOr([]); - var tileWidth = element.GetOptionalProperty("tilewidth"); - var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); + var tileWidth = element.GetOptionalProperty("tilewidth"); + var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); + var type = element.GetOptionalProperty("type"); var version = element.GetOptionalProperty("version").GetValueOrOptional(parentVersion); var transformations = element.GetOptionalPropertyCustom("transformations", ReadTransformations); var wangsets = element.GetOptionalPropertyCustom>("wangsets", el => el.GetValueAsList(e => ReadWangset(e))).GetValueOr([]); @@ -128,8 +129,8 @@ public abstract partial class TmjReaderBase "isometric" => GridOrientation.Isometric, _ => throw new JsonException($"Unknown grid orientation '{s}'") }).GetValueOr(GridOrientation.Orthogonal); - var height = element.GetRequiredProperty("height"); - var width = element.GetRequiredProperty("width"); + var height = element.GetRequiredProperty("height"); + var width = element.GetRequiredProperty("width"); return new Grid { @@ -157,12 +158,12 @@ public abstract partial class TmjReaderBase var animation = e.GetOptionalPropertyCustom>("animation", e => e.GetValueAsList(ReadFrame)).GetValueOr([]); var id = e.GetRequiredProperty("id"); var image = e.GetOptionalProperty("image"); - var imageHeight = e.GetOptionalProperty("imageheight"); - var imageWidth = e.GetOptionalProperty("imagewidth"); - var x = e.GetOptionalProperty("x").GetValueOr(0); - var y = e.GetOptionalProperty("y").GetValueOr(0); - var width = e.GetOptionalProperty("width").GetValueOr(imageWidth.GetValueOr(0)); - var height = e.GetOptionalProperty("height").GetValueOr(imageHeight.GetValueOr(0)); + var imageHeight = e.GetOptionalProperty("imageheight"); + var imageWidth = e.GetOptionalProperty("imagewidth"); + var x = e.GetOptionalProperty("x").GetValueOr(0); + var y = e.GetOptionalProperty("y").GetValueOr(0); + var width = e.GetOptionalProperty("width").GetValueOr(imageWidth.GetValueOr(0)); + var height = e.GetOptionalProperty("height").GetValueOr(imageHeight.GetValueOr(0)); var objectGroup = e.GetOptionalPropertyCustom("objectgroup", e => ReadObjectLayer(e)); var probability = e.GetOptionalProperty("probability").GetValueOr(0.0f); var type = e.GetOptionalProperty("type").GetValueOr(""); @@ -194,7 +195,7 @@ public abstract partial class TmjReaderBase internal static Frame ReadFrame(JsonElement element) { - var duration = element.GetRequiredProperty("duration"); + var duration = element.GetRequiredProperty("duration"); var tileID = element.GetRequiredProperty("tileid"); return new Frame @@ -228,7 +229,7 @@ public abstract partial class TmjReaderBase internal WangColor ReadWangColor(JsonElement element) { var @class = element.GetOptionalProperty("class").GetValueOr(""); - var color = element.GetRequiredPropertyParseable("color"); + var color = element.GetRequiredPropertyParseable("color"); var name = element.GetRequiredProperty("name"); var probability = element.GetOptionalProperty("probability").GetValueOr(1.0f); var properties = ResolveAndMergeProperties(@class, element.GetOptionalPropertyCustom("properties", ReadProperties).GetValueOr([])); diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Chunk.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Chunk.cs index 31a21f6..be10819 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Chunk.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Chunk.cs @@ -6,8 +6,8 @@ public abstract partial class TmxReaderBase { var x = _reader.GetRequiredAttributeParseable("x"); var y = _reader.GetRequiredAttributeParseable("y"); - var width = _reader.GetRequiredAttributeParseable("width"); - var height = _reader.GetRequiredAttributeParseable("height"); + var width = _reader.GetRequiredAttributeParseable("width"); + var height = _reader.GetRequiredAttributeParseable("height"); var usesTileChildrenInsteadOfRawData = !encoding.HasValue; if (usesTileChildrenInsteadOfRawData) diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Map.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Map.cs index 9f48633..ed3a492 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Map.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Map.cs @@ -32,11 +32,11 @@ public abstract partial class TmxReaderBase _ => throw new InvalidOperationException($"Unknown render order '{s}'") }).GetValueOr(RenderOrder.RightDown); var compressionLevel = _reader.GetOptionalAttributeParseable("compressionlevel").GetValueOr(-1); - var width = _reader.GetRequiredAttributeParseable("width"); - var height = _reader.GetRequiredAttributeParseable("height"); - var tileWidth = _reader.GetRequiredAttributeParseable("tilewidth"); - var tileHeight = _reader.GetRequiredAttributeParseable("tileheight"); - var hexSideLength = _reader.GetOptionalAttributeParseable("hexsidelength"); + var width = _reader.GetRequiredAttributeParseable("width"); + var height = _reader.GetRequiredAttributeParseable("height"); + var tileWidth = _reader.GetRequiredAttributeParseable("tilewidth"); + var tileHeight = _reader.GetRequiredAttributeParseable("tileheight"); + var hexSideLength = _reader.GetOptionalAttributeParseable("hexsidelength"); var staggerAxis = _reader.GetOptionalAttributeEnum("staggeraxis", s => s switch { "x" => StaggerAxis.X, @@ -51,7 +51,7 @@ public abstract partial class TmxReaderBase }); var parallaxOriginX = _reader.GetOptionalAttributeParseable("parallaxoriginx").GetValueOr(0.0f); var parallaxOriginY = _reader.GetOptionalAttributeParseable("parallaxoriginy").GetValueOr(0.0f); - var backgroundColor = _reader.GetOptionalAttributeClass("backgroundcolor").GetValueOr(TiledColor.Parse("#00000000", CultureInfo.InvariantCulture)); + var backgroundColor = _reader.GetOptionalAttributeClass("backgroundcolor").GetValueOr(Color.Parse("#00000000", CultureInfo.InvariantCulture)); var nextLayerID = _reader.GetRequiredAttributeParseable("nextlayerid"); var nextObjectID = _reader.GetRequiredAttributeParseable("nextobjectid"); var infinite = _reader.GetOptionalAttributeParseable("infinite").GetValueOr(0) == 1; diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs index 5e70f5e..b2e0c56 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs @@ -14,18 +14,18 @@ public abstract partial class TmxReaderBase var id = _reader.GetRequiredAttributeParseable("id"); var name = _reader.GetOptionalAttribute("name").GetValueOr(""); var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); - var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); - var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); - var width = _reader.GetOptionalAttributeParseable("width").GetValueOr(0); - var height = _reader.GetOptionalAttributeParseable("height").GetValueOr(0); + var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); + var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); + var width = _reader.GetOptionalAttributeParseable("width").GetValueOr(0); + var height = _reader.GetOptionalAttributeParseable("height").GetValueOr(0); var opacity = _reader.GetOptionalAttributeParseable("opacity").GetValueOr(1.0f); var visible = _reader.GetOptionalAttributeParseable("visible").GetValueOr(1) == 1; - var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); + var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); var offsetX = _reader.GetOptionalAttributeParseable("offsetx").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable("offsety").GetValueOr(0.0f); var parallaxX = _reader.GetOptionalAttributeParseable("parallaxx").GetValueOr(1.0f); var parallaxY = _reader.GetOptionalAttributeParseable("parallaxy").GetValueOr(1.0f); - var color = _reader.GetOptionalAttributeClass("color"); + var color = _reader.GetOptionalAttributeClass("color"); var drawOrder = _reader.GetOptionalAttributeEnum("draworder", s => s switch { "topdown" => DrawOrder.TopDown, @@ -245,7 +245,7 @@ public abstract partial class TmxReaderBase var fontFamily = _reader.GetOptionalAttribute("fontfamily") ?? "sans-serif"; var pixelSize = _reader.GetOptionalAttributeParseable("pixelsize") ?? 16; var wrap = _reader.GetOptionalAttributeParseable("wrap") ?? false; - var color = _reader.GetOptionalAttributeClass("color") ?? TiledColor.Parse("#000000", CultureInfo.InvariantCulture); + var color = _reader.GetOptionalAttributeClass("color") ?? Color.Parse("#000000", CultureInfo.InvariantCulture); var bold = _reader.GetOptionalAttributeParseable("bold") ?? false; var italic = _reader.GetOptionalAttributeParseable("italic") ?? false; var underline = _reader.GetOptionalAttributeParseable("underline") ?? false; diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Properties.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Properties.cs index 94b730b..5770056 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Properties.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Properties.cs @@ -45,7 +45,7 @@ public abstract partial class TmxReaderBase PropertyType.Int => new IntProperty { Name = name, Value = r.GetRequiredAttributeParseable("value") }, PropertyType.Float => new FloatProperty { Name = name, Value = r.GetRequiredAttributeParseable("value") }, PropertyType.Bool => new BoolProperty { Name = name, Value = r.GetRequiredAttributeParseable("value") }, - PropertyType.Color => new ColorProperty { Name = name, Value = r.GetRequiredAttributeParseable("value", s => s == "" ? default : TiledColor.Parse(s, CultureInfo.InvariantCulture)) }, + PropertyType.Color => new ColorProperty { Name = name, Value = r.GetRequiredAttributeParseable("value", s => s == "" ? default : Color.Parse(s, CultureInfo.InvariantCulture)) }, PropertyType.File => new FileProperty { Name = name, Value = r.GetRequiredAttribute("value") }, PropertyType.Object => new ObjectProperty { Name = name, Value = r.GetRequiredAttributeParseable("value") }, PropertyType.Class => throw new XmlException("Class property must have a property type"), diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.TileLayer.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.TileLayer.cs index 2df44b4..974215b 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.TileLayer.cs @@ -10,13 +10,13 @@ public abstract partial class TmxReaderBase var id = _reader.GetRequiredAttributeParseable("id"); var name = _reader.GetOptionalAttribute("name").GetValueOr(""); var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); - var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); - var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); - var width = _reader.GetRequiredAttributeParseable("width"); - var height = _reader.GetRequiredAttributeParseable("height"); + var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); + var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); + var width = _reader.GetRequiredAttributeParseable("width"); + var height = _reader.GetRequiredAttributeParseable("height"); var opacity = _reader.GetOptionalAttributeParseable("opacity").GetValueOr(1.0f); var visible = _reader.GetOptionalAttributeParseable("visible").GetValueOr(1) == 1; - var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); + var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); var offsetX = _reader.GetOptionalAttributeParseable("offsetx").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable("offsety").GetValueOr(0.0f); var parallaxX = _reader.GetOptionalAttributeParseable("parallaxx").GetValueOr(1.0f); @@ -59,11 +59,11 @@ public abstract partial class TmxReaderBase var id = _reader.GetRequiredAttributeParseable("id"); var name = _reader.GetOptionalAttribute("name").GetValueOr(""); var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); - var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); - var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); + var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); + var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); var opacity = _reader.GetOptionalAttributeParseable("opacity").GetValueOr(1f); var visible = _reader.GetOptionalAttributeParseable("visible").GetValueOr(true); - var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); + var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); var offsetX = _reader.GetOptionalAttributeParseable("offsetx").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable("offsety").GetValueOr(0.0f); var parallaxX = _reader.GetOptionalAttributeParseable("parallaxx").GetValueOr(1.0f); @@ -110,7 +110,7 @@ public abstract partial class TmxReaderBase var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); var opacity = _reader.GetOptionalAttributeParseable("opacity").GetValueOr(1.0f); var visible = _reader.GetOptionalAttributeParseable("visible").GetValueOr(1) == 1; - var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); + var tintColor = _reader.GetOptionalAttributeClass("tintcolor"); var offsetX = _reader.GetOptionalAttributeParseable("offsetx").GetValueOr(0f); var offsetY = _reader.GetOptionalAttributeParseable("offsety").GetValueOr(0f); var parallaxX = _reader.GetOptionalAttributeParseable("parallaxx").GetValueOr(1f); diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Tileset.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Tileset.cs index 4180bfe..bc7e0e8 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Tileset.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Tileset.cs @@ -31,12 +31,12 @@ public abstract partial class TmxReaderBase var tiledVersion = _reader.GetOptionalAttribute("tiledversion").GetValueOrOptional(parentTiledVersion); var name = _reader.GetRequiredAttribute("name"); var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); - var tileWidth = _reader.GetRequiredAttributeParseable("tilewidth"); - var tileHeight = _reader.GetRequiredAttributeParseable("tileheight"); - var spacing = _reader.GetOptionalAttributeParseable("spacing").GetValueOr(0); - var margin = _reader.GetOptionalAttributeParseable("margin").GetValueOr(0); - var tileCount = _reader.GetRequiredAttributeParseable("tilecount"); - var columns = _reader.GetRequiredAttributeParseable("columns"); + var tileWidth = _reader.GetRequiredAttributeParseable("tilewidth"); + var tileHeight = _reader.GetRequiredAttributeParseable("tileheight"); + var spacing = _reader.GetOptionalAttributeParseable("spacing").GetValueOr(0); + var margin = _reader.GetOptionalAttributeParseable("margin").GetValueOr(0); + var tileCount = _reader.GetRequiredAttributeParseable("tilecount"); + var columns = _reader.GetRequiredAttributeParseable("columns"); var objectAlignment = _reader.GetOptionalAttributeEnum("objectalignment", s => s switch { "unspecified" => ObjectAlignment.Unspecified, @@ -125,9 +125,9 @@ public abstract partial class TmxReaderBase _ => throw new InvalidOperationException($"Unknown image format '{s}'") }); var source = _reader.GetOptionalAttribute("source"); - var transparentColor = _reader.GetOptionalAttributeClass("trans"); - var width = _reader.GetOptionalAttributeParseable("width"); - var height = _reader.GetOptionalAttributeParseable("height"); + var transparentColor = _reader.GetOptionalAttributeClass("trans"); + var width = _reader.GetOptionalAttributeParseable("width"); + var height = _reader.GetOptionalAttributeParseable("height"); _reader.ProcessChildren("image", (r, elementName) => elementName switch { @@ -167,8 +167,8 @@ public abstract partial class TmxReaderBase "isometric" => GridOrientation.Isometric, _ => throw new InvalidOperationException($"Unknown orientation '{s}'") }).GetValueOr(GridOrientation.Orthogonal); - var width = _reader.GetRequiredAttributeParseable("width"); - var height = _reader.GetRequiredAttributeParseable("height"); + var width = _reader.GetRequiredAttributeParseable("width"); + var height = _reader.GetRequiredAttributeParseable("height"); _reader.ReadStartElement("grid"); return new Grid { Orientation = orientation, Width = width, Height = height }; @@ -192,10 +192,10 @@ public abstract partial class TmxReaderBase var id = _reader.GetRequiredAttributeParseable("id"); var type = _reader.GetOptionalAttribute("type").GetValueOr(""); var probability = _reader.GetOptionalAttributeParseable("probability").GetValueOr(0f); - var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); - var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); - var width = _reader.GetOptionalAttributeParseable("width"); - var height = _reader.GetOptionalAttributeParseable("height"); + var x = _reader.GetOptionalAttributeParseable("x").GetValueOr(0); + var y = _reader.GetOptionalAttributeParseable("y").GetValueOr(0); + var width = _reader.GetOptionalAttributeParseable("width"); + var height = _reader.GetOptionalAttributeParseable("height"); // Elements var propertiesCounter = 0; @@ -212,7 +212,7 @@ public abstract partial class TmxReaderBase "animation" => () => Helpers.SetAtMostOnce(ref animation, r.ReadList("animation", "frame", (ar) => { var tileID = ar.GetRequiredAttributeParseable("tileid"); - var duration = ar.GetRequiredAttributeParseable("duration"); + var duration = ar.GetRequiredAttributeParseable("duration"); return new Frame { TileID = tileID, Duration = duration }; }), "Animation"), _ => r.Skip @@ -277,7 +277,7 @@ public abstract partial class TmxReaderBase // Attributes var name = _reader.GetRequiredAttribute("name"); var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); - var color = _reader.GetRequiredAttributeParseable("color"); + var color = _reader.GetRequiredAttributeParseable("color"); var tile = _reader.GetRequiredAttributeParseable("tile"); var probability = _reader.GetOptionalAttributeParseable("probability").GetValueOr(0f); diff --git a/src/DotTiled/Tilesets/Frame.cs b/src/DotTiled/Tilesets/Frame.cs index fe76b22..ff37133 100644 --- a/src/DotTiled/Tilesets/Frame.cs +++ b/src/DotTiled/Tilesets/Frame.cs @@ -13,5 +13,5 @@ public class Frame /// /// How long (in milliseconds) this frame should be displayed before advancing to the next frame. /// - public required int Duration { get; set; } + public required uint Duration { get; set; } } diff --git a/src/DotTiled/Tilesets/Grid.cs b/src/DotTiled/Tilesets/Grid.cs index a50ed54..c063dd1 100644 --- a/src/DotTiled/Tilesets/Grid.cs +++ b/src/DotTiled/Tilesets/Grid.cs @@ -29,10 +29,10 @@ public class Grid /// /// Width of a grid cell. /// - public required int Width { get; set; } + public required uint Width { get; set; } /// /// Height of a grid cell. /// - public required int Height { get; set; } + public required uint Height { get; set; } } diff --git a/src/DotTiled/Tilesets/Image.cs b/src/DotTiled/Tilesets/Image.cs index 8685617..5a2e49c 100644 --- a/src/DotTiled/Tilesets/Image.cs +++ b/src/DotTiled/Tilesets/Image.cs @@ -44,15 +44,15 @@ public class Image /// /// Defines a specific color that is treated as transparent. /// - public Optional TransparentColor { get; set; } = Optional.Empty; + public Optional TransparentColor { get; set; } = Optional.Empty; /// /// The image width in pixels, used for tile index correction when the image changes. /// - public Optional Width { get; set; } = Optional.Empty; + public Optional Width { get; set; } = Optional.Empty; /// /// The image height in pixels, used for tile index correction when the image changes. /// - public Optional Height { get; set; } = Optional.Empty; + public Optional Height { get; set; } = Optional.Empty; } diff --git a/src/DotTiled/Tilesets/Tile.cs b/src/DotTiled/Tilesets/Tile.cs index 0f8addb..6b679e1 100644 --- a/src/DotTiled/Tilesets/Tile.cs +++ b/src/DotTiled/Tilesets/Tile.cs @@ -26,22 +26,22 @@ public class Tile : HasPropertiesBase /// /// The X position of the sub-rectangle representing this tile within the tileset image. /// - public int X { get; set; } = 0; + public uint X { get; set; } = 0; /// /// The Y position of the sub-rectangle representing this tile within the tileset image. /// - public int Y { get; set; } = 0; + public uint Y { get; set; } = 0; /// /// The width of the sub-rectangle representing this tile within the tileset image. /// - public required int Width { get; set; } + public required uint Width { get; set; } /// /// The height of the sub-rectangle representing this tile within the tileset image. /// - public required int Height { get; set; } + public required uint Height { get; set; } /// /// Tile properties. diff --git a/src/DotTiled/Tilesets/Tileset.cs b/src/DotTiled/Tilesets/Tileset.cs index b258705..65d66f6 100644 --- a/src/DotTiled/Tilesets/Tileset.cs +++ b/src/DotTiled/Tilesets/Tileset.cs @@ -128,32 +128,32 @@ public class Tileset : HasPropertiesBase /// /// The width of the tiles in this tileset, which should be at least 1 (non-zero) except in the case of image collection tilesets (in which case it stores the maximum tile width). /// - public required int TileWidth { get; set; } + public required uint TileWidth { get; set; } /// /// The height of the tiles in this tileset, which should be at least 1 (non-zero) except in the case of image collection tilesets (in which case it stores the maximum tile height). /// - public required int TileHeight { get; set; } + public required uint TileHeight { get; set; } /// /// The spacing in pixels between the tiles in this tileset (applies to the tileset image). Irrelevant for image collection tilesets. /// - public int Spacing { get; set; } = 0; + public uint Spacing { get; set; } = 0; /// /// The margin around the tiles in this tileset (applies to the tileset image). Irrelevant for image collection tilesets. /// - public int Margin { get; set; } = 0; + public uint Margin { get; set; } = 0; /// /// The number of tiles in this tileset. /// - public required int TileCount { get; set; } + public required uint TileCount { get; set; } /// /// The number of tile columns in the tileset. /// - public required int Columns { get; set; } + public required uint Columns { get; set; } /// /// Controls the aligntment for tile objects. diff --git a/src/DotTiled/Tilesets/WangColor.cs b/src/DotTiled/Tilesets/WangColor.cs index 58131bd..b5ef482 100644 --- a/src/DotTiled/Tilesets/WangColor.cs +++ b/src/DotTiled/Tilesets/WangColor.cs @@ -20,7 +20,7 @@ public class WangColor : HasPropertiesBase /// /// The color of the Wang color. /// - public required TiledColor Color { get; set; } + public required Color Color { get; set; } /// /// The tile ID of the tile representing this color.