diff --git a/Makefile b/Makefile index 66cf561..5e6402f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,18 @@ -test: - dotnet test src/DotTiled.sln - -docs-serve: docs-build - docfx docs/docfx.json --serve - -docs-build: - cp README.md docs/index.md - docfx docs/docfx.json - -BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj -BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts -.PHONY: benchmark -benchmark: $(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md - -$(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md: $(BENCHMARK_SOURCES) +test: + dotnet build src/DotTiled.sln + dotnet test src/DotTiled.sln + +docs-serve: + docfx docs/docfx.json --serve + +docs-build: + cp README.md docs/index.md + docfx docs/docfx.json + +BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj +BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts +.PHONY: benchmark +benchmark: $(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md + +$(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md: $(BENCHMARK_SOURCES) dotnet run --project DotTiled.Benchmark/DotTiled.Benchmark.csproj -c Release -- $(BENCHMARK_OUTPUTDIR) \ No newline at end of file diff --git a/docs/docfx.json b/docs/docfx.json index fa6feed..4c955cb 100644 --- a/docs/docfx.json +++ b/docs/docfx.json @@ -9,7 +9,8 @@ ] } ], - "dest": "api" + "dest": "api", + "enumSortOrder": "declaringOrder" } ], "build": { diff --git a/src/DotTiled.Tests/Assert/AssertData.cs b/src/DotTiled.Tests/Assert/AssertData.cs index 3c18ef9..3ddcf4a 100644 --- a/src/DotTiled.Tests/Assert/AssertData.cs +++ b/src/DotTiled.Tests/Assert/AssertData.cs @@ -1,4 +1,4 @@ -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Assert/AssertImage.cs b/src/DotTiled.Tests/Assert/AssertImage.cs index 613318b..51a9b82 100644 --- a/src/DotTiled.Tests/Assert/AssertImage.cs +++ b/src/DotTiled.Tests/Assert/AssertImage.cs @@ -1,4 +1,4 @@ -using DotTiled.Model.Tilesets; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Assert/AssertLayer.cs b/src/DotTiled.Tests/Assert/AssertLayer.cs index 1cb9e36..89886cc 100644 --- a/src/DotTiled.Tests/Assert/AssertLayer.cs +++ b/src/DotTiled.Tests/Assert/AssertLayer.cs @@ -1,4 +1,4 @@ -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Assert/AssertObject.cs b/src/DotTiled.Tests/Assert/AssertObject.cs index f234ed2..d982ebd 100644 --- a/src/DotTiled.Tests/Assert/AssertObject.cs +++ b/src/DotTiled.Tests/Assert/AssertObject.cs @@ -1,22 +1,22 @@ -using DotTiled.Model.Layers.Objects; +using DotTiled.Model; namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertObject(Model.Layers.Objects.Object expected, Model.Layers.Objects.Object actual) + internal static void AssertObject(Model.Object expected, Model.Object actual) { // Attributes - AssertEqual(expected.ID, actual.ID, nameof(Model.Layers.Objects.Object.ID)); - AssertEqual(expected.Name, actual.Name, nameof(Model.Layers.Objects.Object.Name)); - AssertEqual(expected.Type, actual.Type, nameof(Model.Layers.Objects.Object.Type)); - AssertEqual(expected.X, actual.X, nameof(Model.Layers.Objects.Object.X)); - AssertEqual(expected.Y, actual.Y, nameof(Model.Layers.Objects.Object.Y)); - AssertEqual(expected.Width, actual.Width, nameof(Model.Layers.Objects.Object.Width)); - AssertEqual(expected.Height, actual.Height, nameof(Model.Layers.Objects.Object.Height)); - AssertEqual(expected.Rotation, actual.Rotation, nameof(Model.Layers.Objects.Object.Rotation)); - AssertEqual(expected.Visible, actual.Visible, nameof(Model.Layers.Objects.Object.Visible)); - AssertEqual(expected.Template, actual.Template, nameof(Model.Layers.Objects.Object.Template)); + AssertEqual(expected.ID, actual.ID, nameof(Model.Object.ID)); + AssertEqual(expected.Name, actual.Name, nameof(Model.Object.Name)); + AssertEqual(expected.Type, actual.Type, nameof(Model.Object.Type)); + AssertEqual(expected.X, actual.X, nameof(Model.Object.X)); + AssertEqual(expected.Y, actual.Y, nameof(Model.Object.Y)); + AssertEqual(expected.Width, actual.Width, nameof(Model.Object.Width)); + AssertEqual(expected.Height, actual.Height, nameof(Model.Object.Height)); + AssertEqual(expected.Rotation, actual.Rotation, nameof(Model.Object.Rotation)); + AssertEqual(expected.Visible, actual.Visible, nameof(Model.Object.Visible)); + AssertEqual(expected.Template, actual.Template, nameof(Model.Object.Template)); AssertProperties(expected.Properties, actual.Properties); diff --git a/src/DotTiled.Tests/Assert/AssertProperties.cs b/src/DotTiled.Tests/Assert/AssertProperties.cs index ddd0e69..16d9cdb 100644 --- a/src/DotTiled.Tests/Assert/AssertProperties.cs +++ b/src/DotTiled.Tests/Assert/AssertProperties.cs @@ -1,4 +1,4 @@ -using DotTiled.Model.Properties; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Assert/AssertTileset.cs b/src/DotTiled.Tests/Assert/AssertTileset.cs index c0e5e8e..3e4ab28 100644 --- a/src/DotTiled.Tests/Assert/AssertTileset.cs +++ b/src/DotTiled.Tests/Assert/AssertTileset.cs @@ -1,5 +1,5 @@ -using DotTiled.Model.Layers; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData.cs b/src/DotTiled.Tests/Serialization/TestData.cs index 467e1df..30c4b9f 100644 --- a/src/DotTiled.Tests/Serialization/TestData.cs +++ b/src/DotTiled.Tests/Serialization/TestData.cs @@ -1,6 +1,6 @@ using System.Xml; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs index c445069..4eef6de 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs @@ -1,5 +1,5 @@ using DotTiled.Model; -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs index e1aecda..04c425a 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs @@ -1,8 +1,8 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs index 7e21c54..a894a53 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs @@ -1,7 +1,7 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs index 7b4de68..14f95ac 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs @@ -1,7 +1,7 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs index 47a6b6b..e7d135c 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs @@ -1,8 +1,8 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; +using DotTiled.Model; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs index 0673cf6..e9c4e73 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs @@ -1,7 +1,7 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs index efea5c0..055a0c9 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs @@ -1,7 +1,7 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs index d2f1813..96995d7 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs @@ -1,7 +1,7 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs index 2b09178..320fa48 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs @@ -1,9 +1,9 @@ using System.Numerics; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Layers.Objects; -using DotTiled.Model.Properties; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs index c862203..a856f68 100644 --- a/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs @@ -1,6 +1,6 @@ using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; using DotTiled.Serialization.Tmj; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs index ab48769..6a26b62 100644 --- a/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs @@ -1,7 +1,7 @@ using System.Xml; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; using DotTiled.Serialization.Tmx; namespace DotTiled.Tests; diff --git a/src/DotTiled/DotTiled.csproj b/src/DotTiled/DotTiled.csproj index 0102e6e..0a2dfe8 100644 --- a/src/DotTiled/DotTiled.csproj +++ b/src/DotTiled/DotTiled.csproj @@ -3,6 +3,7 @@ net8.0 enable + true diff --git a/src/DotTiled/Model/Color.cs b/src/DotTiled/Model/Color.cs index 4700e0c..24cf8e5 100644 --- a/src/DotTiled/Model/Color.cs +++ b/src/DotTiled/Model/Color.cs @@ -1,22 +1,57 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Threading; namespace DotTiled.Model; +/// +/// Represents a Tiled color. +/// public class Color : IParsable, IEquatable { + /// + /// The red component of the color. + /// public required byte R { get; set; } + + /// + /// The green component of the color. + /// public required byte G { get; set; } + + /// + /// The blue component of the color. + /// public required byte B { get; set; } + + /// + /// The alpha component of the color. + /// public byte A { get; set; } = 255; + /// + /// 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 + /// An object that supplies culture-specific information about the format of s. + /// The parsed + /// Thrown in case the provided string is not in a valid format. 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. + /// The leading # is optional. + /// + /// 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. + /// true if was successfully parsed; otherwise, false. public static bool TryParse( [NotNullWhen(true)] string? s, IFormatProvider? provider, @@ -55,6 +90,7 @@ public class Color : IParsable, IEquatable return true; } + /// public bool Equals(Color? other) { if (other is null) @@ -63,9 +99,12 @@ public class Color : IParsable, IEquatable return R == other.R && G == other.G && B == other.B && A == other.A; } + /// public override bool Equals(object? obj) => obj is Color other && Equals(other); + /// public override int GetHashCode() => HashCode.Combine(R, G, B, A); + /// public override string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}"; } diff --git a/src/DotTiled/Model/Layers/BaseLayer.cs b/src/DotTiled/Model/Layers/BaseLayer.cs index adeee69..aa78191 100644 --- a/src/DotTiled/Model/Layers/BaseLayer.cs +++ b/src/DotTiled/Model/Layers/BaseLayer.cs @@ -1,22 +1,66 @@ using System.Collections.Generic; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Base class for all layer types in a map. +/// To check the type of a layer, use C# pattern matching, +/// or some other mechanism to determine the type of the layer at runtime. +/// public abstract class BaseLayer { - // Attributes + /// + /// Unique ID of the layer. Each layer that is added to a map gets a unique ID. Even if a layer is deleted, no layer ever gets the same ID. + /// public required uint ID { get; set; } + + /// + /// The name of the layer. + /// public string Name { get; set; } = ""; + + /// + /// The class of the layer. + /// public string Class { get; set; } = ""; + + /// + /// The opacity of the layer as a value from 0 (fully transparent) to 1 (fully opaque). + /// public float Opacity { get; set; } = 1.0f; + + /// + /// Whether the layer is shown (true) or hidden (false). + /// public bool Visible { get; set; } = true; + + /// + /// A tint color that is multiplied with any tiles drawn by this layer. + /// public Color? TintColor { get; set; } + + /// + /// Horizontal offset for this layer in pixels. + /// public float OffsetX { get; set; } = 0.0f; + + /// + /// Vertical offset for this layer in pixels. + /// public float OffsetY { get; set; } = 0.0f; + + /// + /// Horizontal parallax factor for this layer. + /// public float ParallaxX { get; set; } = 1.0f; + + /// + /// Vertical parallax factor for this layer. + /// public float ParallaxY { get; set; } = 1.0f; - // At most one of + /// + /// Layer properties. + /// public Dictionary? Properties { get; set; } } diff --git a/src/DotTiled/Model/Layers/Data.cs b/src/DotTiled/Model/Layers/Data.cs index 2d54020..d2a9686 100644 --- a/src/DotTiled/Model/Layers/Data.cs +++ b/src/DotTiled/Model/Layers/Data.cs @@ -1,51 +1,144 @@ using System; -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Specifies the encoding used to encode the tile layer data. +/// public enum DataEncoding { + /// + /// The data is stored as comma-separated values. + /// Csv, + + /// + /// The data is stored as base64-encoded binary data. + /// Base64 } +/// +/// Specifies the compression algorithm used to compress the tile layer data. +/// public enum DataCompression { + /// + /// GZip compression. + /// GZip, + + /// + /// ZLib compression. + /// ZLib, + + /// + /// ZStandard compression. Currently not supported by DotTiled and will throw an exception if encountered. + /// ZStd } +/// +/// The flipping flags for a tile. These can be used to check how a tile is flipped or rotated. Uses the +/// FlagsAttribute, for which there is plenty of documentation. +/// [Flags] public enum FlippingFlags : uint { + /// + /// No flipping. + /// None = 0, + + /// + /// The tile is flipped horizontally. + /// FlippedHorizontally = 0x80000000u, + + /// + /// The tile is flipped vertically. + /// FlippedVertically = 0x40000000u, + + /// + /// The tile is flipped diagonally. + /// FlippedDiagonally = 0x20000000u, + + /// + /// In hexagonal maps, the tile is rotated 120 degrees clockwise. + /// RotatedHexagonal120 = 0x10000000u } +/// +/// Represents part of a tile layer of a map that is infinite. +/// public class Chunk { - // Attributes + /// + /// The X coordinate of the chunk in tiles. + /// public required int X { get; set; } + + /// + /// The Y coordinate of the chunk in tiles. + /// public required int Y { get; set; } + + /// + /// The width of the chunk in tiles. + /// public required uint Width { get; set; } + + /// + /// The height of the chunk in tiles. + /// public required uint Height { get; set; } - // Data + /// + /// The parsed chunk data, as a list of tile GIDs. + /// To get an actual tile ID, you map it to a local tile ID using the correct tileset. Please refer to + /// the documentation on how to do this. + /// public required uint[] GlobalTileIDs { get; set; } + + /// + /// The parsed flipping flags for each tile in the chunk. Appear in the same order as the tiles in the layer in . + /// public required FlippingFlags[] FlippingFlags { get; set; } } +/// +/// Represents the data of a tile layer. +/// public class Data { - // Attributes + /// + /// The encoding used to encode the tile layer data. + /// public DataEncoding? Encoding { get; set; } + + /// + /// The compression method used to compress the tile layer data. + /// public DataCompression? Compression { get; set; } - // Data + /// + /// The parsed tile layer data, as a list of tile GIDs. + /// To get an actual tile ID, you map it to a local tile ID using the correct tileset. Please refer to + /// the documentation on how to do this. + /// public uint[]? GlobalTileIDs { get; set; } + + /// + /// The parsed flipping flags for each tile in the layer. Appear in the same order as the tiles in the layer in . + /// public FlippingFlags[]? FlippingFlags { get; set; } + + /// + /// If the map is infinite, it will instead contain a list of chunks. + /// public Chunk[]? Chunks { get; set; } } diff --git a/src/DotTiled/Model/Layers/Group.cs b/src/DotTiled/Model/Layers/Group.cs index fd89f61..f770c63 100644 --- a/src/DotTiled/Model/Layers/Group.cs +++ b/src/DotTiled/Model/Layers/Group.cs @@ -1,11 +1,14 @@ using System.Collections.Generic; -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Represents a group of layers, to form a hierarchy. +/// public class Group : BaseLayer { - // Uses same attributes as BaseLayer - - // Any number of + /// + /// The contained sub-layers in the group. + /// public List Layers { get; set; } = []; } diff --git a/src/DotTiled/Model/Layers/ImageLayer.cs b/src/DotTiled/Model/Layers/ImageLayer.cs index cd35a41..e0bb110 100644 --- a/src/DotTiled/Model/Layers/ImageLayer.cs +++ b/src/DotTiled/Model/Layers/ImageLayer.cs @@ -1,15 +1,32 @@ -using DotTiled.Model.Tilesets; - -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Represents an image layer in a map. +/// public class ImageLayer : BaseLayer { - // Attributes + /// + /// The X position of the image layer in pixels. + /// public uint X { get; set; } = 0; + + /// + /// The Y position of the image layer in pixels. + /// public uint Y { get; set; } = 0; + + /// + /// Whether the image drawn by this layer is repeated along the X axis. + /// public bool RepeatX { get; set; } = false; + + /// + /// Whether the image drawn by this layer is repeated along the Y axis. + /// public bool RepeatY { get; set; } = false; - // At most one of + /// + /// The image to be drawn by this image layer. + /// public Image? Image { get; set; } } diff --git a/src/DotTiled/Model/Layers/ObjectLayer.cs b/src/DotTiled/Model/Layers/ObjectLayer.cs index 817e95e..60acc13 100644 --- a/src/DotTiled/Model/Layers/ObjectLayer.cs +++ b/src/DotTiled/Model/Layers/ObjectLayer.cs @@ -1,24 +1,60 @@ using System.Collections.Generic; -using DotTiled.Model.Layers.Objects; -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Represents the order in which objects can be drawn. +/// public enum DrawOrder { + /// + /// Objects are drawn sorted by their Y coordinate. + /// TopDown, + + /// + /// Objects are drawn in the order of appearance in the object layer. + /// Index } +/// +/// Represents an object layer in a map. In Tiled documentation, it is often called an "object group". +/// public class ObjectLayer : BaseLayer { - // Attributes + /// + /// The X coordinate of the object layer in tiles. + /// public uint X { get; set; } = 0; + + /// + /// The Y coordinate of the object layer in tiles. + /// public uint Y { get; set; } = 0; + + /// + /// The width of the object layer in tiles. Meaningless. + /// public uint? Width { get; set; } + + /// + /// The height of the object layer in tiles. Meaningless. + /// public uint? Height { get; set; } + + /// + /// A color that is multiplied with any tile objects drawn by this layer. + /// public Color? Color { get; set; } + + /// + /// Whether the objects are drawn according to the order of appearance () or sorted by their Y coordinate (). + /// public DrawOrder DrawOrder { get; set; } = DrawOrder.TopDown; - // Elements + /// + /// The objects in the object layer. + /// public required List Objects { get; set; } } diff --git a/src/DotTiled/Model/Layers/Objects/EllipseObject.cs b/src/DotTiled/Model/Layers/Objects/EllipseObject.cs index fe57573..7e777de 100644 --- a/src/DotTiled/Model/Layers/Objects/EllipseObject.cs +++ b/src/DotTiled/Model/Layers/Objects/EllipseObject.cs @@ -1,3 +1,7 @@ -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// An ellipse object in a map. The existing , , , +/// and properties are used to determine the size of the ellipse. +/// public class EllipseObject : Object { } diff --git a/src/DotTiled/Model/Layers/Objects/Object.cs b/src/DotTiled/Model/Layers/Objects/Object.cs index 82254e5..fad05db 100644 --- a/src/DotTiled/Model/Layers/Objects/Object.cs +++ b/src/DotTiled/Model/Layers/Objects/Object.cs @@ -1,22 +1,64 @@ using System.Collections.Generic; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// Base class for objects in object layers. +/// public abstract class Object { - // Attributes + /// + /// Unique ID of the objects. Each object that is placed on a map gets a unique ID. Even if an object was deleted, no object gets the same ID. + /// public uint? ID { get; set; } + + /// + /// The name of the object. An arbitrary string. + /// public string Name { get; set; } = ""; + + /// + /// The class of the object. An arbitrary string. + /// public string Type { get; set; } = ""; + + /// + /// The X coordinate of the object in pixels. + /// public float X { get; set; } = 0f; + + /// + /// The Y coordinate of the object in pixels. + /// public float Y { get; set; } = 0f; + + /// + /// The width of the object in pixels. + /// public float Width { get; set; } = 0f; + + /// + /// The height of the object in pixels. + /// public float Height { get; set; } = 0f; + + /// + /// The rotation of the object in degrees clockwise around (X, Y). + /// public float Rotation { get; set; } = 0f; + + /// + /// Whether the object is shown (true) or hidden (false). + /// public bool Visible { get; set; } = true; + + /// + /// A reference to a template file. + /// public string? Template { get; set; } - // Elements + /// + /// Object properties. + /// public Dictionary? Properties { get; set; } } diff --git a/src/DotTiled/Model/Layers/Objects/PointObject.cs b/src/DotTiled/Model/Layers/Objects/PointObject.cs index f2949a2..44eada8 100644 --- a/src/DotTiled/Model/Layers/Objects/PointObject.cs +++ b/src/DotTiled/Model/Layers/Objects/PointObject.cs @@ -1,3 +1,7 @@ -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// A point object in a map. The existing and properties are used to +/// determine the position of the point. +/// public class PointObject : Object { } diff --git a/src/DotTiled/Model/Layers/Objects/PolygonObject.cs b/src/DotTiled/Model/Layers/Objects/PolygonObject.cs index 57e3f06..09805d8 100644 --- a/src/DotTiled/Model/Layers/Objects/PolygonObject.cs +++ b/src/DotTiled/Model/Layers/Objects/PolygonObject.cs @@ -1,10 +1,17 @@ using System.Collections.Generic; using System.Numerics; -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// A polygon object in a map. The existing and properties are used as +/// the origin of the polygon. +/// public class PolygonObject : Object { - // Attributes + /// + /// The points that make up the polygon. + /// and are used as the origin of the polygon. + /// public required List Points { get; set; } } diff --git a/src/DotTiled/Model/Layers/Objects/PolylineObject.cs b/src/DotTiled/Model/Layers/Objects/PolylineObject.cs index 03cd6b4..d267c07 100644 --- a/src/DotTiled/Model/Layers/Objects/PolylineObject.cs +++ b/src/DotTiled/Model/Layers/Objects/PolylineObject.cs @@ -1,10 +1,16 @@ using System.Collections.Generic; using System.Numerics; -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// A polyline object in a map. The existing and properties are used as +/// the origin of the polyline. +/// public class PolylineObject : Object { - // Attributes + /// + /// The points that make up the polyline. and are used as the origin of the polyline. + /// public required List Points { get; set; } } diff --git a/src/DotTiled/Model/Layers/Objects/RectangleObject.cs b/src/DotTiled/Model/Layers/Objects/RectangleObject.cs index ff64a76..99c6cff 100644 --- a/src/DotTiled/Model/Layers/Objects/RectangleObject.cs +++ b/src/DotTiled/Model/Layers/Objects/RectangleObject.cs @@ -1,3 +1,7 @@ -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// A rectangle object in a map. The existing , , , +/// and properties are used to determine the size of the rectangle. +/// public class RectangleObject : Object { } diff --git a/src/DotTiled/Model/Layers/Objects/TextObject.cs b/src/DotTiled/Model/Layers/Objects/TextObject.cs index f39f84a..9c5ed2d 100644 --- a/src/DotTiled/Model/Layers/Objects/TextObject.cs +++ b/src/DotTiled/Model/Layers/Objects/TextObject.cs @@ -1,38 +1,116 @@ using System.Globalization; -namespace DotTiled.Model.Layers.Objects; - +namespace DotTiled.Model; +/// +/// The horizontal alignment of text. +/// public enum TextHorizontalAlignment { + /// + /// The text is aligned to the left. + /// Left, + + /// + /// The text is aligned to the center. + /// Center, + + /// + /// The text is aligned to the right. + /// Right, + + /// + /// The text is justified. + /// Justify } +/// +/// The vertical alignment of text. +/// public enum TextVerticalAlignment { + /// + /// The text is aligned to the top. + /// Top, + + /// + /// The text is aligned to the center. + /// Center, + + /// + /// The text is aligned to the bottom. + /// Bottom } +/// +/// A text object in a map. +/// public class TextObject : Object { - // Attributes + /// + /// The font family used for the text. + /// public string FontFamily { get; set; } = "sans-serif"; + + /// + /// The size of the font in pixels. + /// public int PixelSize { get; set; } = 16; + + /// + /// Whether word wrapping is enabled. + /// public bool Wrap { get; set; } = false; + + /// + /// The color of the text. + /// public Color Color { get; set; } = Color.Parse("#000000", CultureInfo.InvariantCulture); + + /// + /// Whether the text is bold. + /// public bool Bold { get; set; } = false; + + /// + /// Whether the text is italic. + /// public bool Italic { get; set; } = false; + + /// + /// Whether a line should be drawn below the text. + /// public bool Underline { get; set; } = false; + + /// + /// Whether a line should be drawn through the text. + /// public bool Strikeout { get; set; } = false; + + /// + /// Whether kerning should be used while rendering the text. + /// public bool Kerning { get; set; } = true; + + /// + /// The horizontal alignment of the text. + /// public TextHorizontalAlignment HorizontalAlignment { get; set; } = TextHorizontalAlignment.Left; + + /// + /// The vertical alignment of the text. + /// public TextVerticalAlignment VerticalAlignment { get; set; } = TextVerticalAlignment.Top; - // Elements + /// + /// The text to be displayed. + /// public string Text { get; set; } = ""; } diff --git a/src/DotTiled/Model/Layers/Objects/TileObject.cs b/src/DotTiled/Model/Layers/Objects/TileObject.cs index 992ac3c..fe44c50 100644 --- a/src/DotTiled/Model/Layers/Objects/TileObject.cs +++ b/src/DotTiled/Model/Layers/Objects/TileObject.cs @@ -1,6 +1,12 @@ -namespace DotTiled.Model.Layers.Objects; +namespace DotTiled.Model; +/// +/// A tile object in a map. +/// public class TileObject : Object { + /// + /// A reference to a tile. + /// public uint GID { get; set; } } diff --git a/src/DotTiled/Model/Layers/TileLayer.cs b/src/DotTiled/Model/Layers/TileLayer.cs index 9002397..600f7c0 100644 --- a/src/DotTiled/Model/Layers/TileLayer.cs +++ b/src/DotTiled/Model/Layers/TileLayer.cs @@ -1,13 +1,32 @@ -namespace DotTiled.Model.Layers; +namespace DotTiled.Model; +/// +/// Represents a tile layer in a map. +/// public class TileLayer : BaseLayer { - // Attributes + /// + /// The X coordinate of the layer in tiles. + /// public uint X { get; set; } = 0; + + /// + /// The Y coordinate of the layer in tiles. + /// 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 uint Width { get; set; } + + /// + /// The height of the layer in tiles. Always the same as the map height for fixed-size maps. + /// public required uint Height { get; set; } - // At most one of + /// + /// The tile layer data. + /// public Data? Data { get; set; } } diff --git a/src/DotTiled/Model/Map.cs b/src/DotTiled/Model/Map.cs index 3102567..c9c72dc 100644 --- a/src/DotTiled/Model/Map.cs +++ b/src/DotTiled/Model/Map.cs @@ -1,66 +1,205 @@ using System.Collections.Generic; using System.Globalization; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Tilesets; namespace DotTiled.Model; +/// +/// Map orientation enumeration. The map orientation determines the alignment of the tiles in the map. +/// public enum MapOrientation { + /// + /// Orthogonal orientation. This is the typical top-down grid-based layout. + /// Orthogonal, + + /// + /// Isometric orientation. This is a type of axonometric projection where the tiles are shown as rhombuses, as seen from a side-on view. + /// Isometric, + + /// + /// Staggered orientation. This is an isometric projection with a side-on view where the tiles are arranged in a staggered grid. + /// Staggered, + + /// + /// Hexagonal orientation. This is a type of axial projection where the tiles are shown as hexagons, as seen from a top-down view. + /// Hexagonal } +/// +/// Render order enumeration. The order in which tiles on tile layers are rendered. +/// public enum RenderOrder { + /// + /// Right-down render order. Starts at top-left and proceeds right then down. + /// RightDown, + + /// + /// Right-up render order. Starts at bottom-left and proceeds right then up. + /// RightUp, + + /// + /// Left-down render order. Starts at top-right and proceeds left then down. + /// LeftDown, + + /// + /// Left-up render order. Starts at bottom-right and proceeds left then up. + /// LeftUp } +/// +/// Stagger axis enumeration. For staggered and hexagonal maps, determines which axis (X or Y) is staggered. +/// public enum StaggerAxis { + /// + /// X stagger axis. + /// X, + + /// + /// Y stagger axis. + /// Y } +/// +/// Stagger index enumeration. For staggered and hexagonal maps, determines whether the "even" or "odd" indexes along the staggered axis are shifted. +/// public enum StaggerIndex { + /// + /// Even stagger index. + /// Odd, + + /// + /// Odd stagger index. + /// Even } +/// +/// Represents a Tiled map. +/// public class Map { - // Attributes + /// + /// The TMX format version. Is incremented to match minor Tiled releases. + /// public required string Version { get; set; } + + /// + /// The Tiled version used to save the file. + /// public required string TiledVersion { get; set; } + + /// + /// The class of this map. + /// public string Class { get; set; } = ""; + + /// + /// Map orientation. + /// public required MapOrientation Orientation { get; set; } + + /// + /// The order in which tiles on tile layers are rendered. + /// public RenderOrder RenderOrder { get; set; } = RenderOrder.RightDown; + + /// + /// The compression level to use for tile layer data (defaults to -1, which means to use the algorithm default). + /// Typically only useful for parsing, but may be interesting for certain use cases. + /// public int CompressionLevel { get; set; } = -1; + + /// + /// The width of the map in tiles. + /// public required uint Width { get; set; } + + /// + /// The height of the map in tiles. + /// public required uint Height { get; set; } + + /// + /// The width of a tile. + /// public required uint TileWidth { get; set; } + + /// + /// The height of a tile. + /// 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 uint? HexSideLength { get; set; } + + /// + /// For staggered and hexagonal maps, determines which axis (X or Y) is staggered. + /// public StaggerAxis? StaggerAxis { get; set; } + + /// + /// For staggered and hexagonal maps, determines whether the "even" or "odd" indexes along the staggered axis are shifted. + /// public StaggerIndex? StaggerIndex { get; set; } + + /// + /// X coordinate of the parallax origin in pixels. + /// public float ParallaxOriginX { get; set; } = 0.0f; + + /// + /// Y coordinate of the parallax origin in pixels. + /// public float ParallaxOriginY { get; set; } = 0.0f; + + /// + /// The background color of the map. + /// 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. + /// public required uint NextLayerID { get; set; } + + /// + /// Stores the next available ID for new objects. This number is used to prevent reuse of the same ID after objects have been removed. + /// public required uint NextObjectID { get; set; } + + /// + /// Whether this map is infinite. An infinite map has no fixed size and can grow in all directions. Its layer data is stored in chunks. + /// public bool Infinite { get; set; } = false; - // At most one of + /// + /// Map properties. + /// public Dictionary? Properties { get; set; } - // Any number of + /// + /// List of tilesets used by the map. + /// public List Tilesets { get; set; } = []; + + /// + /// Hierarchical list of layers. is a layer type which can contain sub-layers to create a hierarchy. + /// public List Layers { get; set; } = []; } diff --git a/src/DotTiled/Model/Properties/BoolProperty.cs b/src/DotTiled/Model/Properties/BoolProperty.cs index 6360a3a..bc60a87 100644 --- a/src/DotTiled/Model/Properties/BoolProperty.cs +++ b/src/DotTiled/Model/Properties/BoolProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a boolean property. +/// public class BoolProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.Bool; + + /// + /// The boolean value of the property. + /// public required bool Value { get; set; } + /// public IProperty Clone() => new BoolProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/ClassProperty.cs b/src/DotTiled/Model/Properties/ClassProperty.cs index e46389f..50d65ba 100644 --- a/src/DotTiled/Model/Properties/ClassProperty.cs +++ b/src/DotTiled/Model/Properties/ClassProperty.cs @@ -1,15 +1,31 @@ using System.Collections.Generic; using System.Linq; -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a class property. +/// public class ClassProperty : IProperty { + /// public required string Name { get; set; } - public PropertyType Type => Model.Properties.PropertyType.Class; + + /// + public PropertyType Type => Model.PropertyType.Class; + + /// + /// The type of the class property. This will be the name of a custom defined + /// type in Tiled. + /// public required string PropertyType { get; set; } + + /// + /// The properties of the class property. + /// public required Dictionary Properties { get; set; } + /// public IProperty Clone() => new ClassProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/ColorProperty.cs b/src/DotTiled/Model/Properties/ColorProperty.cs index 06d8fc1..aec43f6 100644 --- a/src/DotTiled/Model/Properties/ColorProperty.cs +++ b/src/DotTiled/Model/Properties/ColorProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a color property. +/// public class ColorProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.Color; + + /// + /// The color value of the property. + /// public required Color Value { get; set; } + /// public IProperty Clone() => new ColorProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs b/src/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs index c080e2a..b5aa0ec 100644 --- a/src/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs +++ b/src/DotTiled/Model/Properties/CustomTypes/CustomClassDefinition.cs @@ -1,27 +1,89 @@ using System; using System.Collections.Generic; -namespace DotTiled.Model.Properties.CustomTypes; +namespace DotTiled.Model; +/// +/// Represents the types of objects that can use a custom class. +/// Uses the FlagsAttribute, for which there is plenty of documentation. +/// [Flags] public enum CustomClassUseAs { + /// + /// Any property on any kind of object. + /// Property, + + /// + /// A map. + /// Map, + + /// + /// A layer. + /// Layer, + + /// + /// An object. + /// Object, + + /// + /// A tile. + /// Tile, + + /// + /// A tileset. + /// Tileset, + + /// + /// A Wang color. + /// WangColor, + + /// + /// A Wangset. + /// Wangset, + + /// + /// A project. + /// Project, + + /// + /// All types. + /// All = Property | Map | Layer | Object | Tile | Tileset | WangColor | Wangset | Project } +/// +/// Represents a custom class definition in Tiled. Refer to the +/// documentation of custom types to understand how they work. +/// public class CustomClassDefinition : CustomTypeDefinition { + /// + /// The color of the custom class inside the Tiled editor. + /// public Color? Color { get; set; } + + /// + /// Whether the custom class should be drawn with a fill color. + /// public bool DrawFill { get; set; } + + /// + /// What the custom class can be used as, or rather, what types of objects can use it. + /// public CustomClassUseAs UseAs { get; set; } + + /// + /// The members of the custom class, with their names, types and default values. + /// public List Members { get; set; } = []; } diff --git a/src/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs b/src/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs index 9d15b7d..ee40be0 100644 --- a/src/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs +++ b/src/DotTiled/Model/Properties/CustomTypes/CustomEnumDefinition.cs @@ -1,16 +1,41 @@ using System.Collections.Generic; -namespace DotTiled.Model.Properties.CustomTypes; +namespace DotTiled.Model; +/// +/// Represents the storage type of a custom enum. +/// public enum CustomEnumStorageType { + /// + /// The backing value is an integer. + /// Int, + + /// + /// The backing value is a string. + /// String } +/// +/// Represents a custom enum definition in Tiled. Refer to the +/// documentation of custom types to understand how they work. +/// public class CustomEnumDefinition : CustomTypeDefinition { + /// + /// The storage type of the custom enum. + /// public CustomEnumStorageType StorageType { get; set; } + + /// + /// The values of the custom enum. + /// public List Values { get; set; } = []; + + /// + /// Whether the value should be treated as flags. + /// public bool ValueAsFlags { get; set; } } diff --git a/src/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs b/src/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs index f535215..3a91b0a 100644 --- a/src/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs +++ b/src/DotTiled/Model/Properties/CustomTypes/CustomTypeDefinition.cs @@ -1,7 +1,17 @@ -namespace DotTiled.Model.Properties.CustomTypes; +namespace DotTiled.Model; +/// +/// Base class for custom type definitions. +/// public abstract class CustomTypeDefinition { + /// + /// The ID of the custom type. + /// public uint ID { get; set; } + + /// + /// The name of the custom type. + /// public string Name { get; set; } = ""; } diff --git a/src/DotTiled/Model/Properties/FileProperty.cs b/src/DotTiled/Model/Properties/FileProperty.cs index 42b9d15..4ed8642 100644 --- a/src/DotTiled/Model/Properties/FileProperty.cs +++ b/src/DotTiled/Model/Properties/FileProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a file property. +/// public class FileProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.File; + + /// + /// The value of the property. + /// public required string Value { get; set; } + /// public IProperty Clone() => new FileProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/FloatProperty.cs b/src/DotTiled/Model/Properties/FloatProperty.cs index ccb18ae..4c6b51f 100644 --- a/src/DotTiled/Model/Properties/FloatProperty.cs +++ b/src/DotTiled/Model/Properties/FloatProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a float property. +/// public class FloatProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.Float; + + /// + /// The float value of the property. + /// public required float Value { get; set; } + /// public IProperty Clone() => new FloatProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/IProperty.cs b/src/DotTiled/Model/Properties/IProperty.cs index 0414c3c..262ee09 100644 --- a/src/DotTiled/Model/Properties/IProperty.cs +++ b/src/DotTiled/Model/Properties/IProperty.cs @@ -1,9 +1,24 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Interface for properties that can be attached to objects, tiles, tilesets, maps etc. +/// public interface IProperty { + /// + /// The name of the property. + /// public string Name { get; set; } + + /// + /// The type of the property. + /// public PropertyType Type { get; } + /// + /// Clones the property, only used for copying properties when performing overriding + /// with templates. + /// + /// An identical, but non-reference-equal, instance of the same property. IProperty Clone(); } diff --git a/src/DotTiled/Model/Properties/IntProperty.cs b/src/DotTiled/Model/Properties/IntProperty.cs index cfaf7d0..29f7a1d 100644 --- a/src/DotTiled/Model/Properties/IntProperty.cs +++ b/src/DotTiled/Model/Properties/IntProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents an integer property. +/// public class IntProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.Int; + + /// + /// The integer value of the property. + /// public required int Value { get; set; } + /// public IProperty Clone() => new IntProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/ObjectProperty.cs b/src/DotTiled/Model/Properties/ObjectProperty.cs index 5f37607..04b15ba 100644 --- a/src/DotTiled/Model/Properties/ObjectProperty.cs +++ b/src/DotTiled/Model/Properties/ObjectProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents an object property. +/// public class ObjectProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.Object; + + /// + /// The object identifier referenced by the property. + /// public required uint Value { get; set; } + /// public IProperty Clone() => new ObjectProperty { Name = Name, diff --git a/src/DotTiled/Model/Properties/PropertyType.cs b/src/DotTiled/Model/Properties/PropertyType.cs index bb01960..d6057cc 100644 --- a/src/DotTiled/Model/Properties/PropertyType.cs +++ b/src/DotTiled/Model/Properties/PropertyType.cs @@ -1,13 +1,47 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents the type of a property. +/// public enum PropertyType { + /// + /// A string property. + /// String, + + /// + /// An integer property. + /// Int, + + /// + /// A float property. + /// Float, + + /// + /// A boolean property. + /// Bool, + + /// + /// A color property. + /// Color, + + /// + /// A file property. + /// File, + + /// + /// An object property. + /// Object, + + /// + /// A class property. + /// Class } diff --git a/src/DotTiled/Model/Properties/StringProperty.cs b/src/DotTiled/Model/Properties/StringProperty.cs index 9842ca4..49d7aec 100644 --- a/src/DotTiled/Model/Properties/StringProperty.cs +++ b/src/DotTiled/Model/Properties/StringProperty.cs @@ -1,11 +1,22 @@ -namespace DotTiled.Model.Properties; +namespace DotTiled.Model; +/// +/// Represents a string property. +/// public class StringProperty : IProperty { + /// public required string Name { get; set; } + + /// public PropertyType Type => PropertyType.String; + + /// + /// The string value of the property. + /// public required string Value { get; set; } + /// public IProperty Clone() => new StringProperty { Name = Name, diff --git a/src/DotTiled/Model/Template.cs b/src/DotTiled/Model/Template.cs index 834f8d8..d8cee95 100644 --- a/src/DotTiled/Model/Template.cs +++ b/src/DotTiled/Model/Template.cs @@ -1,11 +1,17 @@ -using DotTiled.Model.Layers.Objects; -using DotTiled.Model.Tilesets; - namespace DotTiled.Model; +/// +/// Represents a Tiled template. A template is a reusable object that can be placed in an inside the Tiled editor. +/// public class Template { - // At most one of (if the template is a tile object) + /// + /// If the template represents a tile object, this property will contain the tileset that the tile belongs to. + /// public Tileset? Tileset { get; set; } + + /// + /// The object that this template represents. + /// public required Object Object { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/Frame.cs b/src/DotTiled/Model/Tilesets/Frame.cs index 8762423..7e48aa0 100644 --- a/src/DotTiled/Model/Tilesets/Frame.cs +++ b/src/DotTiled/Model/Tilesets/Frame.cs @@ -1,8 +1,17 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// A single frame of an animated tile. +/// public class Frame { - // Attributes + /// + /// The local tile ID within the parent tileset. + /// public required uint TileID { get; set; } + + /// + /// How long (in milliseconds) this frame should be displayed before advancing to the next frame. + /// public required uint Duration { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/Grid.cs b/src/DotTiled/Model/Tilesets/Grid.cs index 81d5e06..e8acfac 100644 --- a/src/DotTiled/Model/Tilesets/Grid.cs +++ b/src/DotTiled/Model/Tilesets/Grid.cs @@ -1,15 +1,38 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Orientation of the grid for the tiles in this tileset. +/// public enum GridOrientation { + /// + /// The grid is orthogonal. + /// Orthogonal, + + /// + /// The grid is isometric. + /// Isometric } +/// +/// Used to specify how tile overlays for terrain and collision information are rendered in isometric maps. +/// public class Grid { - // Attributes + /// + /// Orientation of the grid for the tiles in this tileset. + /// public GridOrientation Orientation { get; set; } = GridOrientation.Orthogonal; + + /// + /// Width of a grid cell. + /// public required uint Width { get; set; } + + /// + /// Height of a grid cell. + /// public required uint Height { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/Image.cs b/src/DotTiled/Model/Tilesets/Image.cs index e5ea154..418d5f4 100644 --- a/src/DotTiled/Model/Tilesets/Image.cs +++ b/src/DotTiled/Model/Tilesets/Image.cs @@ -1,19 +1,58 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// The format of an image. +/// public enum ImageFormat { + /// + /// Portable Network Graphics. + /// Png, + + /// + /// Graphics Interchange Format. + /// Gif, + + /// + /// Joint Photographic Experts Group. + /// Jpg, + + /// + /// Windows Bitmap. + /// Bmp } +/// +/// Represents an image that is used by a tileset. +/// public class Image { - // Attributes + /// + /// The format of the image. + /// public ImageFormat? Format { get; set; } + + /// + /// The reference to the image file. + /// public string? Source { get; set; } + + /// + /// Defines a specific color that is treated as transparent. + /// public Color? TransparentColor { get; set; } + + /// + /// The image width in pixels, used for tile index correction when the image changes. + /// public uint? Width { get; set; } + + /// + /// The image height in pixels, used for tile index correction when the image changes. + /// public uint? Height { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/Tile.cs b/src/DotTiled/Model/Tilesets/Tile.cs index 55669ee..c6b964d 100644 --- a/src/DotTiled/Model/Tilesets/Tile.cs +++ b/src/DotTiled/Model/Tilesets/Tile.cs @@ -1,23 +1,65 @@ using System.Collections.Generic; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Represents a single tile in a tileset, when using a collection of images to represent the tileset. +/// Tiled documentation for Tileset tiles +/// public class Tile { - // Attributes + /// + /// The local tile ID within its tileset. + /// public required uint ID { get; set; } + + /// + /// The class of the tile. Is inherited by tile objects + /// public string Type { get; set; } = ""; + + /// + /// A percentage indicating the probability that this tile is chosen when it competes with others while editing with the terrain tool. + /// public float Probability { get; set; } = 0f; + + /// + /// The X position of the sub-rectangle representing this tile within the tileset image. + /// public uint X { get; set; } = 0; + + /// + /// The Y position of the sub-rectangle representing this tile within the tileset image. + /// public uint Y { get; set; } = 0; + + /// + /// The width of the sub-rectangle representing this tile within the tileset image. + /// public required uint Width { get; set; } + + /// + /// The height of the sub-rectangle representing this tile within the tileset image. + /// public required uint Height { get; set; } - // Elements + /// + /// Tile properties. + /// public Dictionary? Properties { get; set; } + + /// + /// The image representing this tile. Only used for tilesets that composed of a collection of images. + /// public Image? Image { get; set; } + + /// + /// Unclear what this is for. + /// public ObjectLayer? ObjectLayer { get; set; } + + /// + /// The animation frames for this tile. + /// public List? Animation { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/TileOffset.cs b/src/DotTiled/Model/Tilesets/TileOffset.cs index cbe9111..6030f39 100644 --- a/src/DotTiled/Model/Tilesets/TileOffset.cs +++ b/src/DotTiled/Model/Tilesets/TileOffset.cs @@ -1,8 +1,17 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Is used to specify an offset in pixels in tilesets, to be applied when drawing a tile from the related tileset. +/// public class TileOffset { - // Attributes + /// + /// The horizontal offset in pixels. + /// public float X { get; set; } = 0f; + + /// + /// The vertical offset in pixels. + /// public float Y { get; set; } = 0f; } diff --git a/src/DotTiled/Model/Tilesets/Tileset.cs b/src/DotTiled/Model/Tilesets/Tileset.cs index 15bd56b..147f3d2 100644 --- a/src/DotTiled/Model/Tilesets/Tileset.cs +++ b/src/DotTiled/Model/Tilesets/Tileset.cs @@ -1,62 +1,209 @@ using System.Collections.Generic; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// The alignment of tile objects. +/// public enum ObjectAlignment { + /// + /// The alignment is unspecified. Tile objects will use in orthogonal maps, and in isometric maps. + /// Unspecified, + + /// + /// The tile object is aligned to the top left of the tile. + /// TopLeft, + + /// + /// The tile object is aligned to the top of the tile. + /// Top, + + /// + /// The tile object is aligned to the top right of the tile. + /// TopRight, + + /// + /// The tile object is aligned to the left of the tile. + /// Left, + + /// + /// The tile object is aligned to the center of the tile. + /// Center, + + /// + /// The tile object is aligned to the right of the tile. + /// Right, + + /// + /// The tile object is aligned to the bottom left of the tile. + /// BottomLeft, + + /// + /// The tile object is aligned to the bottom of the tile. + /// Bottom, + + /// + /// The tile object is aligned to the bottom right of the tile. + /// BottomRight } +/// +/// The size to use when rendering tiles from a tileset on a tile layer. +/// public enum TileRenderSize { + /// + /// The tile is drawn at the size of the tile in the tileset. + /// Tile, + + /// + /// The tile is drawn at the tile grid size of the map. + /// Grid } +/// +/// Determines how a tile is rendered in a tile set. +/// public enum FillMode { + /// + /// The tile is stretched to fill the tile size, possibly distorting the tile. + /// Stretch, + + /// + /// The tile's aspect ratio is preserved, and it is scaled to fit within the tile size. + /// PreserveAspectFit } +/// +/// A tileset is a collection of tiles that can be used in a tile layer, or by tile objects. +/// public class Tileset { - // Attributes + /// + /// The TMX format version. Is incremented to match minor Tiled releases. + /// public string? Version { get; set; } + + /// + /// The Tiled version used to save the file in case it was loaded from an external tileset file. + /// public string? TiledVersion { get; set; } + + /// + /// The first global tile ID of this tileset (this global ID maps to the first tile in this tileset). + /// public uint? FirstGID { get; set; } + + /// + /// If this tileset is stored in an external TSX (Tile Set XML) file, this attribute refers to that file. + /// public string? Source { get; set; } + + /// + /// The name of this tileset. + /// public string? Name { get; set; } + + /// + /// The class of this tileset. + /// public string Class { get; set; } = ""; + + /// + /// 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 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 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 float? Spacing { get; set; } = 0f; + + /// + /// The margin around the tiles in this tileset (applies to the tileset image). Irrelevant for image collection tilesets. + /// public float? Margin { get; set; } = 0f; + + /// + /// The number of tiles in this tileset. + /// public uint? TileCount { get; set; } + + /// + /// The number of tile columns in the tileset. + /// public uint? Columns { get; set; } + + /// + /// Controls the aligntment for tile objects. + /// public ObjectAlignment ObjectAlignment { get; set; } = ObjectAlignment.Unspecified; + + /// + /// The size to use when rendering tiles from thie tileset on a tile layer. When set to , the tile is drawn at the tile grid size of the map. + /// public TileRenderSize RenderSize { get; set; } = TileRenderSize.Tile; + + /// + /// The fill mode to use when rendering tiles from this tileset. + /// public FillMode FillMode { get; set; } = FillMode.Stretch; - // At most one of + /// + /// If the tileset is based on a single image, which is cut into tiles based on the given attributes of the tileset, then this is that image. + /// public Image? Image { get; set; } + + /// + /// This is used to specify an offset in pixels, to be applied when drawing a tile from the related tileset. When not present, no offset is applied. + /// public TileOffset? TileOffset { get; set; } + + /// + /// Ths is only used in case of isometric orientation, and determines how tile overlays for terrain and collision information are rendered. + /// public Grid? Grid { get; set; } + + /// + /// Tileset properties. + /// public Dictionary? Properties { get; set; } + // public List? TerrainTypes { get; set; } TODO: Implement Terrain -> Wangset conversion during deserialization + + /// + /// Contains the list of Wang sets defined for this tileset. + /// public List? Wangsets { get; set; } + + /// + /// Used to describe which transformations can be applied to the tiles (e.g. to extend a Wang set by transforming existing tiles). + /// public Transformations? Transformations { get; set; } - // Any number of + /// + /// If this tileset is based on a collection of images, then this list of tiles will contain the individual images that make up the tileset. + /// public List Tiles { get; set; } = []; } diff --git a/src/DotTiled/Model/Tilesets/Transformations.cs b/src/DotTiled/Model/Tilesets/Transformations.cs index 83187a7..b6cf6bf 100644 --- a/src/DotTiled/Model/Tilesets/Transformations.cs +++ b/src/DotTiled/Model/Tilesets/Transformations.cs @@ -1,10 +1,27 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Represents which transformations can be applied to a tile in a tileset. +/// public class Transformations { - // Attributes + /// + /// Whether the file in this can set be flipped horizontally. + /// public bool HFlip { get; set; } = false; + + /// + /// Whether the file in this can set be flipped vertically. + /// public bool VFlip { get; set; } = false; + + /// + /// Whether the file in this set can be rotated in 90 degree increments. + /// public bool Rotate { get; set; } = false; + + /// + /// Whether untransformed tiles remain preferred, otherwise transformed tiles are used to produce more vartiations. + /// public bool PreferUntransformed { get; set; } = false; } diff --git a/src/DotTiled/Model/Tilesets/WangColor.cs b/src/DotTiled/Model/Tilesets/WangColor.cs index c13b0da..20678cb 100644 --- a/src/DotTiled/Model/Tilesets/WangColor.cs +++ b/src/DotTiled/Model/Tilesets/WangColor.cs @@ -1,17 +1,39 @@ using System.Collections.Generic; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Represents a Wang color in a Wang set. +/// public class WangColor { - // Attributes + /// + /// The name of this color. + /// public required string Name { get; set; } + + /// + /// The class of the Wang color. + /// public string Class { get; set; } = ""; + + /// + /// The color of the Wang color. + /// public required Color Color { get; set; } + + /// + /// The tile ID of the tile representing this color. + /// public required int Tile { get; set; } + + /// + /// The relative probability that this color is chosen over others in case of multiple options. + /// public float Probability { get; set; } = 0f; - // Elements + /// + /// The Wang color properties. + /// public Dictionary? Properties { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/WangTile.cs b/src/DotTiled/Model/Tilesets/WangTile.cs index 488a12a..2347b91 100644 --- a/src/DotTiled/Model/Tilesets/WangTile.cs +++ b/src/DotTiled/Model/Tilesets/WangTile.cs @@ -1,8 +1,17 @@ -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Represents a Wang tile in a Wang set. +/// public class WangTile { - // Attributes + /// + /// The tile ID associated with this Wang tile. + /// public required uint TileID { get; set; } + + /// + /// The Wang ID of this Wang tile. + /// public required byte[] WangID { get; set; } } diff --git a/src/DotTiled/Model/Tilesets/Wangset.cs b/src/DotTiled/Model/Tilesets/Wangset.cs index 6101347..1a6f7c3 100644 --- a/src/DotTiled/Model/Tilesets/Wangset.cs +++ b/src/DotTiled/Model/Tilesets/Wangset.cs @@ -1,22 +1,40 @@ using System.Collections.Generic; -using DotTiled.Model.Properties; -namespace DotTiled.Model.Tilesets; +namespace DotTiled.Model; +/// +/// Defines a list of colors and any number of Wang tiles using these colors. +/// public class Wangset { - // Attributes + /// + /// The name of the Wang set. + /// public required string Name { get; set; } + + /// + /// The class of the Wang set. + /// public string Class { get; set; } = ""; + + /// + /// The tile ID of the tile representing the Wang set. + /// public required int Tile { get; set; } - // Elements - // At most one of + /// + /// The Wang set properties. + /// public Dictionary? Properties { get; set; } // Up to 254 Wang colors + /// + /// The Wang colors in the Wang set. + /// public List? WangColors { get; set; } = []; - // Any number of + /// + /// The Wang tiles in the Wang set. + /// public List WangTiles { get; set; } = []; } diff --git a/src/DotTiled/Serialization/Helpers.cs b/src/DotTiled/Serialization/Helpers.cs index abfba09..fe401ba 100644 --- a/src/DotTiled/Serialization/Helpers.cs +++ b/src/DotTiled/Serialization/Helpers.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Tilesets; +using DotTiled.Model; +using DotTiled.Model; +using DotTiled.Model; namespace DotTiled.Serialization; diff --git a/src/DotTiled/Serialization/IMapReader.cs b/src/DotTiled/Serialization/IMapReader.cs index a1e8b05..d96def5 100644 --- a/src/DotTiled/Serialization/IMapReader.cs +++ b/src/DotTiled/Serialization/IMapReader.cs @@ -3,7 +3,14 @@ using DotTiled.Model; namespace DotTiled.Serialization; +/// +/// Interface for reading a map from some source. Used by the different file format parsers to read a map. +/// public interface IMapReader : IDisposable { + /// + /// Reads a map from the source. + /// + /// The parsed map. Map ReadMap(); } diff --git a/src/DotTiled/Serialization/ITemplateReader.cs b/src/DotTiled/Serialization/ITemplateReader.cs index 45832fa..9497e26 100644 --- a/src/DotTiled/Serialization/ITemplateReader.cs +++ b/src/DotTiled/Serialization/ITemplateReader.cs @@ -3,7 +3,14 @@ using DotTiled.Model; namespace DotTiled.Serialization; +/// +/// Interface for reading a template from some source. Used by the different file format parsers to read a template. +/// public interface ITemplateReader : IDisposable { + /// + /// Reads a template from the source. + /// + /// The parsed template. Template ReadTemplate(); } diff --git a/src/DotTiled/Serialization/ITilesetReader.cs b/src/DotTiled/Serialization/ITilesetReader.cs index fa4a94c..e798bcf 100644 --- a/src/DotTiled/Serialization/ITilesetReader.cs +++ b/src/DotTiled/Serialization/ITilesetReader.cs @@ -1,9 +1,16 @@ using System; -using DotTiled.Model.Tilesets; +using DotTiled.Model; namespace DotTiled.Serialization; +/// +/// Interface for reading a tileset from some source. Used by the different file format parsers to read a tileset. +/// public interface ITilesetReader : IDisposable { + /// + /// Reads a tileset from the source. + /// + /// The parsed tileset. Tileset ReadTileset(); } diff --git a/src/DotTiled/Serialization/Tmj/TjTemplateReader.cs b/src/DotTiled/Serialization/Tmj/TjTemplateReader.cs index 69747bb..3a66f1b 100644 --- a/src/DotTiled/Serialization/Tmj/TjTemplateReader.cs +++ b/src/DotTiled/Serialization/Tmj/TjTemplateReader.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; +/// +/// A template reader for reading Tiled JSON templates. +/// public class TjTemplateReader : ITemplateReader { // External resolvers @@ -17,6 +18,14 @@ public class TjTemplateReader : ITemplateReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// A string containing a Tiled template in the Tiled JSON format. + /// A function that resolves external tilesets given their source. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TjTemplateReader( string jsonString, Func externalTilesetResolver, @@ -29,6 +38,7 @@ public class TjTemplateReader : ITemplateReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); } + /// public Template ReadTemplate() { var jsonDoc = System.Text.Json.JsonDocument.Parse(_jsonString); @@ -36,6 +46,7 @@ public class TjTemplateReader : ITemplateReader return Tmj.ReadTemplate(rootElement, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); } + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -58,6 +69,7 @@ public class TjTemplateReader : ITemplateReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Data.cs b/src/DotTiled/Serialization/Tmj/Tmj.Data.cs index ac3d30b..2edb93f 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Data.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Data.cs @@ -5,7 +5,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Text.Json; -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Group.cs b/src/DotTiled/Serialization/Tmj/Tmj.Group.cs index 159d892..796458b 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Group.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Group.cs @@ -4,9 +4,6 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs index e3d6112..70d9ce4 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs @@ -4,10 +4,7 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; +using DotTiled.Model; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs b/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs index d81ce17..fb02fe5 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs @@ -4,8 +4,6 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Map.cs b/src/DotTiled/Serialization/Tmj/Tmj.Map.cs index e27dfed..642d8f4 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Map.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Map.cs @@ -5,10 +5,6 @@ using System.IO; using System.Linq; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs index 0662fc9..ba01791 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs @@ -4,10 +4,6 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Layers.Objects; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmj; @@ -42,7 +38,7 @@ internal partial class Tmj _ => throw new JsonException($"Unknown draw order '{s}'.") }, DrawOrder.TopDown); - var objects = element.GetOptionalPropertyCustom>("objects", e => e.GetValueAsList(el => ReadObject(el, externalTemplateResolver, customTypeDefinitions)), []); + var objects = element.GetOptionalPropertyCustom>("objects", e => e.GetValueAsList(el => ReadObject(el, externalTemplateResolver, customTypeDefinitions)), []); return new ObjectLayer { @@ -67,7 +63,7 @@ internal partial class Tmj }; } - internal static Model.Layers.Objects.Object ReadObject( + internal static Model.Object ReadObject( JsonElement element, Func externalTemplateResolver, IReadOnlyCollection customTypeDefinitions) diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs b/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs index 1ef4944..28aad66 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs @@ -4,8 +4,6 @@ using System.IO; using System.Linq; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Template.cs b/src/DotTiled/Serialization/Tmj/Tmj.Template.cs index 65d6f87..100aaa2 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Template.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Template.cs @@ -4,8 +4,6 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; @@ -19,7 +17,7 @@ internal partial class Tmj { var type = element.GetRequiredProperty("type"); var tileset = element.GetOptionalPropertyCustom("tileset", el => ReadTileset(el, externalTilesetResolver, externalTemplateResolver, customTypeDefinitions), null); - var @object = element.GetRequiredPropertyCustom("object", el => ReadObject(el, externalTemplateResolver, customTypeDefinitions)); + var @object = element.GetRequiredPropertyCustom("object", el => ReadObject(el, externalTemplateResolver, customTypeDefinitions)); return new Template { diff --git a/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs index d2fd53d..3711eb2 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs @@ -4,9 +4,6 @@ using System.Globalization; using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs b/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs index 8b206c9..0d6dfc7 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs @@ -6,10 +6,6 @@ using System.IO.Compression; using System.Linq; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/TmjMapReader.cs b/src/DotTiled/Serialization/Tmj/TmjMapReader.cs index 3eb1df0..8e5ddd4 100644 --- a/src/DotTiled/Serialization/Tmj/TmjMapReader.cs +++ b/src/DotTiled/Serialization/Tmj/TmjMapReader.cs @@ -4,11 +4,12 @@ using System.IO; using System.Text; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; +/// +/// A map reader for reading Tiled JSON maps. +/// public class TmjMapReader : IMapReader { // External resolvers @@ -20,6 +21,14 @@ public class TmjMapReader : IMapReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// A string containing a Tiled map in the Tiled JSON format. + /// A function that resolves external tilesets given their source. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TmjMapReader( string jsonString, Func externalTilesetResolver, @@ -32,6 +41,7 @@ public class TmjMapReader : IMapReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); } + /// public Map ReadMap() { var jsonDoc = JsonDocument.Parse(_jsonString); @@ -39,6 +49,7 @@ public class TmjMapReader : IMapReader return Tmj.ReadMap(rootElement, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); } + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -61,6 +72,7 @@ public class TmjMapReader : IMapReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method diff --git a/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs b/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs index a41adfe..84ec60e 100644 --- a/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs +++ b/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmj; +/// +/// A tileset reader for the Tiled JSON format. +/// public class TsjTilesetReader : ITilesetReader { // External resolvers @@ -16,6 +17,13 @@ public class TsjTilesetReader : ITilesetReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// A string containing a Tiled tileset in the Tiled JSON format. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TsjTilesetReader( string jsonString, Func externalTemplateResolver, @@ -26,6 +34,7 @@ public class TsjTilesetReader : ITilesetReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); } + /// public Tileset ReadTileset() { var jsonDoc = System.Text.Json.JsonDocument.Parse(_jsonString); @@ -37,6 +46,7 @@ public class TsjTilesetReader : ITilesetReader _customTypeDefinitions); } + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -59,6 +69,7 @@ public class TsjTilesetReader : ITilesetReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Chunk.cs b/src/DotTiled/Serialization/Tmx/Tmx.Chunk.cs index d0db01f..b42ebb0 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Chunk.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Chunk.cs @@ -1,5 +1,5 @@ using System.Xml; -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Data.cs b/src/DotTiled/Serialization/Tmx/Tmx.Data.cs index 5d55ba4..77f7d6a 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Data.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Data.cs @@ -4,7 +4,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Xml; -using DotTiled.Model.Layers; +using DotTiled.Model; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Map.cs b/src/DotTiled/Serialization/Tmx/Tmx.Map.cs index 2152852..e7a5e35 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Map.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Map.cs @@ -4,10 +4,6 @@ using System.Globalization; using System.Linq; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs b/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs index 5f5bda0..7c04edf 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs @@ -5,11 +5,6 @@ using System.Linq; using System.Numerics; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Layers.Objects; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; @@ -45,7 +40,7 @@ internal partial class Tmx // Elements Dictionary? properties = null; - List objects = []; + List objects = []; reader.ProcessChildren("objectgroup", (r, elementName) => elementName switch { @@ -77,14 +72,14 @@ internal partial class Tmx }; } - internal static Model.Layers.Objects.Object ReadObject( + internal static Model.Object ReadObject( XmlReader reader, Func externalTemplateResolver, IReadOnlyCollection customTypeDefinitions) { // Attributes var template = reader.GetOptionalAttribute("template"); - Model.Layers.Objects.Object? obj = null; + Model.Object? obj = null; if (template is not null) obj = externalTemplateResolver(template).Object; @@ -112,7 +107,7 @@ internal partial class Tmx var visible = reader.GetOptionalAttributeParseable("visible") ?? visibleDefault; // Elements - Model.Layers.Objects.Object? foundObject = null; + Model.Object? foundObject = null; int propertiesCounter = 0; Dictionary? properties = propertiesDefault; @@ -150,7 +145,7 @@ internal partial class Tmx return OverrideObject(obj, foundObject); } - internal static Model.Layers.Objects.Object OverrideObject(Model.Layers.Objects.Object? obj, Model.Layers.Objects.Object foundObject) + internal static Model.Object OverrideObject(Model.Object? obj, Model.Object foundObject) { if (obj is null) return foundObject; @@ -321,7 +316,7 @@ internal partial class Tmx Tileset? tileset = null; // Should contain exactly one of - Model.Layers.Objects.Object? obj = null; + Model.Object? obj = null; reader.ProcessChildren("template", (r, elementName) => elementName switch { diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs b/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs index 7f62358..3d5b6c4 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.TileLayer.cs b/src/DotTiled/Serialization/Tmx/Tmx.TileLayer.cs index 41e720b..8b972a3 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.TileLayer.cs @@ -3,10 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs b/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs index 5d8aac6..6e43455 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs @@ -4,10 +4,6 @@ using System.IO; using System.Linq; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Layers; -using DotTiled.Model.Properties; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Serialization/Tmx/TmxMapReader.cs b/src/DotTiled/Serialization/Tmx/TmxMapReader.cs index f9228b4..be21580 100644 --- a/src/DotTiled/Serialization/Tmx/TmxMapReader.cs +++ b/src/DotTiled/Serialization/Tmx/TmxMapReader.cs @@ -2,11 +2,12 @@ using System; using System.Collections.Generic; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; +/// +/// A map reader for the Tiled XML format. +/// public class TmxMapReader : IMapReader { // External resolvers @@ -18,6 +19,14 @@ public class TmxMapReader : IMapReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// An XML reader for reading a Tiled map in the Tiled XML format. + /// A function that resolves external tilesets given their source. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TmxMapReader( XmlReader reader, Func externalTilesetResolver, @@ -33,11 +42,13 @@ public class TmxMapReader : IMapReader _reader.MoveToContent(); } + /// public Map ReadMap() { return Tmx.ReadMap(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); } + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -61,6 +72,7 @@ public class TmxMapReader : IMapReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method diff --git a/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs b/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs index f7a1565..374a0d1 100644 --- a/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs +++ b/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs @@ -2,11 +2,12 @@ using System; using System.Collections.Generic; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; +/// +/// A tileset reader for the Tiled XML format. +/// public class TsxTilesetReader : ITilesetReader { // External resolvers @@ -17,6 +18,13 @@ public class TsxTilesetReader : ITilesetReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// An XML reader for reading a Tiled tileset in the Tiled XML format. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TsxTilesetReader( XmlReader reader, Func externalTemplateResolver, @@ -30,8 +38,10 @@ public class TsxTilesetReader : ITilesetReader _reader.MoveToContent(); } + /// public Tileset ReadTileset() => Tmx.ReadTileset(_reader, null, _externalTemplateResolver, _customTypeDefinitions); + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -54,6 +64,7 @@ public class TsxTilesetReader : ITilesetReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method diff --git a/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs b/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs index 3fa6c69..fe93244 100644 --- a/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs +++ b/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs @@ -2,11 +2,12 @@ using System; using System.Collections.Generic; using System.Xml; using DotTiled.Model; -using DotTiled.Model.Properties.CustomTypes; -using DotTiled.Model.Tilesets; namespace DotTiled.Serialization.Tmx; +/// +/// A template reader for the Tiled XML format. +/// public class TxTemplateReader : ITemplateReader { // Resolvers @@ -18,6 +19,14 @@ public class TxTemplateReader : ITemplateReader private readonly IReadOnlyCollection _customTypeDefinitions; + /// + /// Constructs a new . + /// + /// An XML reader for reading a Tiled template in the Tiled XML format. + /// A function that resolves external tilesets given their source. + /// A function that resolves external templates given their source. + /// A collection of custom type definitions that can be used to resolve custom types when encountering . + /// Thrown when any of the arguments are null. public TxTemplateReader( XmlReader reader, Func externalTilesetResolver, @@ -33,8 +42,10 @@ public class TxTemplateReader : ITemplateReader _reader.MoveToContent(); } + /// public Template ReadTemplate() => Tmx.ReadTemplate(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); + /// protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -57,6 +68,7 @@ public class TxTemplateReader : ITemplateReader // Dispose(disposing: false); // } + /// public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method