mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 08:52:50 +02:00
Merge pull request #12 from dcronqvist/xml-docs
Add XML docs to public API
This commit is contained in:
commit
399c52d8ff
88 changed files with 1403 additions and 234 deletions
33
Makefile
33
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)
|
|
@ -9,7 +9,8 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"dest": "api"
|
||||
"dest": "api",
|
||||
"enumSortOrder": "declaringOrder"
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using DotTiled.Model.Tilesets;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using DotTiled.Model.Properties;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model.Tilesets;
|
||||
using DotTiled.Model;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using DotTiled.Model;
|
||||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,22 +1,57 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Tiled color.
|
||||
/// </summary>
|
||||
public class Color : IParsable<Color>, IEquatable<Color>
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component of the color.
|
||||
/// </summary>
|
||||
public required byte R { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The green component of the color.
|
||||
/// </summary>
|
||||
public required byte G { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The blue component of the color.
|
||||
/// </summary>
|
||||
public required byte B { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component of the color.
|
||||
/// </summary>
|
||||
public byte A { get; set; } = 255;
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to parse the specified string into a <see cref="Color"/>. Expects strings in the format <c>#RRGGBB</c> or <c>#AARRGGBB</c>.
|
||||
/// The leading <c>#</c> is optional.
|
||||
/// </summary>
|
||||
/// <param name="s">A string value to parse into a <see cref="Color"/></param>
|
||||
/// <param name="provider">An object that supplies culture-specific information about the format of s.</param>
|
||||
/// <returns>The parsed <see cref="Color"/></returns>
|
||||
/// <exception cref="FormatException">Thrown in case the provided string <paramref name="s"/> is not in a valid format.</exception>
|
||||
public static Color Parse(string s, IFormatProvider? provider)
|
||||
{
|
||||
TryParse(s, provider, out var result);
|
||||
return result ?? throw new FormatException($"Invalid format for TiledColor: {s}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to parse the specified string into a <see cref="Color"/>. Expects strings in the format <c>#RRGGBB</c> or <c>#AARRGGBB</c>.
|
||||
/// The leading <c>#</c> is optional.
|
||||
/// </summary>
|
||||
/// <param name="s">A string value to parse into a <see cref="Color"/></param>
|
||||
/// <param name="provider">An object that supplies culture-specific information about the format of s.</param>
|
||||
/// <param name="result">When this method returns, contains the parsed <see cref="Color"/> or <c>null</c> on failure.</param>
|
||||
/// <returns><c>true</c> if <paramref name="s"/> was successfully parsed; otherwise, <c>false</c>.</returns>
|
||||
public static bool TryParse(
|
||||
[NotNullWhen(true)] string? s,
|
||||
IFormatProvider? provider,
|
||||
|
@ -55,6 +90,7 @@ public class Color : IParsable<Color>, IEquatable<Color>
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Color? other)
|
||||
{
|
||||
if (other is null)
|
||||
|
@ -63,9 +99,12 @@ public class Color : IParsable<Color>, IEquatable<Color>
|
|||
return R == other.R && G == other.G && B == other.B && A == other.A;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj) => obj is Color other && Equals(other);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => HashCode.Combine(R, G, B, A);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}";
|
||||
}
|
||||
|
|
|
@ -1,22 +1,66 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all layer types in a map.
|
||||
/// To check the type of a layer, <see href="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching">use C# pattern matching</see>,
|
||||
/// or some other mechanism to determine the type of the layer at runtime.
|
||||
/// </summary>
|
||||
public abstract class BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public required uint ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the layer.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The class of the layer.
|
||||
/// </summary>
|
||||
public string Class { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The opacity of the layer as a value from 0 (fully transparent) to 1 (fully opaque).
|
||||
/// </summary>
|
||||
public float Opacity { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the layer is shown (true) or hidden (false).
|
||||
/// </summary>
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// A tint color that is multiplied with any tiles drawn by this layer.
|
||||
/// </summary>
|
||||
public Color? TintColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal offset for this layer in pixels.
|
||||
/// </summary>
|
||||
public float OffsetX { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical offset for this layer in pixels.
|
||||
/// </summary>
|
||||
public float OffsetY { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal parallax factor for this layer.
|
||||
/// </summary>
|
||||
public float ParallaxX { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical parallax factor for this layer.
|
||||
/// </summary>
|
||||
public float ParallaxY { get; set; } = 1.0f;
|
||||
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// Layer properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,51 +1,144 @@
|
|||
using System;
|
||||
|
||||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the encoding used to encode the tile layer data.
|
||||
/// </summary>
|
||||
public enum DataEncoding
|
||||
{
|
||||
/// <summary>
|
||||
/// The data is stored as comma-separated values.
|
||||
/// </summary>
|
||||
Csv,
|
||||
|
||||
/// <summary>
|
||||
/// The data is stored as base64-encoded binary data.
|
||||
/// </summary>
|
||||
Base64
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the compression algorithm used to compress the tile layer data.
|
||||
/// </summary>
|
||||
public enum DataCompression
|
||||
{
|
||||
/// <summary>
|
||||
/// GZip compression.
|
||||
/// </summary>
|
||||
GZip,
|
||||
|
||||
/// <summary>
|
||||
/// ZLib compression.
|
||||
/// </summary>
|
||||
ZLib,
|
||||
|
||||
/// <summary>
|
||||
/// ZStandard compression. Currently not supported by DotTiled and will throw an exception if encountered.
|
||||
/// </summary>
|
||||
ZStd
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The flipping flags for a tile. These can be used to check how a tile is flipped or rotated. Uses the
|
||||
/// <see href="https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-flagsattribute">FlagsAttribute, for which there is plenty of documentation.</see>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum FlippingFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// No flipping.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The tile is flipped horizontally.
|
||||
/// </summary>
|
||||
FlippedHorizontally = 0x80000000u,
|
||||
|
||||
/// <summary>
|
||||
/// The tile is flipped vertically.
|
||||
/// </summary>
|
||||
FlippedVertically = 0x40000000u,
|
||||
|
||||
/// <summary>
|
||||
/// The tile is flipped diagonally.
|
||||
/// </summary>
|
||||
FlippedDiagonally = 0x20000000u,
|
||||
|
||||
/// <summary>
|
||||
/// In hexagonal maps, the tile is rotated 120 degrees clockwise.
|
||||
/// </summary>
|
||||
RotatedHexagonal120 = 0x10000000u
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents part of a tile layer of a map that is infinite.
|
||||
/// </summary>
|
||||
public class Chunk
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The X coordinate of the chunk in tiles.
|
||||
/// </summary>
|
||||
public required int X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Y coordinate of the chunk in tiles.
|
||||
/// </summary>
|
||||
public required int Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width of the chunk in tiles.
|
||||
/// </summary>
|
||||
public required uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the chunk in tiles.
|
||||
/// </summary>
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// Data
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <see href="https://doc.mapeditor.org/en/stable/reference/global-tile-ids/#mapping-a-gid-to-a-local-tile-id">the documentation on how to do this</see>.
|
||||
/// </summary>
|
||||
public required uint[] GlobalTileIDs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parsed flipping flags for each tile in the chunk. Appear in the same order as the tiles in the layer in <see cref="GlobalTileIDs"/>.
|
||||
/// </summary>
|
||||
public required FlippingFlags[] FlippingFlags { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the data of a tile layer.
|
||||
/// </summary>
|
||||
public class Data
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The encoding used to encode the tile layer data.
|
||||
/// </summary>
|
||||
public DataEncoding? Encoding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The compression method used to compress the tile layer data.
|
||||
/// </summary>
|
||||
public DataCompression? Compression { get; set; }
|
||||
|
||||
// Data
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <see href="https://doc.mapeditor.org/en/stable/reference/global-tile-ids/#mapping-a-gid-to-a-local-tile-id">the documentation on how to do this</see>.
|
||||
/// </summary>
|
||||
public uint[]? GlobalTileIDs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parsed flipping flags for each tile in the layer. Appear in the same order as the tiles in the layer in <see cref="GlobalTileIDs"/>.
|
||||
/// </summary>
|
||||
public FlippingFlags[]? FlippingFlags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the map is infinite, it will instead contain a list of chunks.
|
||||
/// </summary>
|
||||
public Chunk[]? Chunks { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a group of layers, to form a hierarchy.
|
||||
/// </summary>
|
||||
public class Group : BaseLayer
|
||||
{
|
||||
// Uses same attributes as BaseLayer
|
||||
|
||||
// Any number of
|
||||
/// <summary>
|
||||
/// The contained sub-layers in the group.
|
||||
/// </summary>
|
||||
public List<BaseLayer> Layers { get; set; } = [];
|
||||
}
|
||||
|
|
|
@ -1,15 +1,32 @@
|
|||
using DotTiled.Model.Tilesets;
|
||||
|
||||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an image layer in a map.
|
||||
/// </summary>
|
||||
public class ImageLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The X position of the image layer in pixels.
|
||||
/// </summary>
|
||||
public uint X { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The Y position of the image layer in pixels.
|
||||
/// </summary>
|
||||
public uint Y { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the image drawn by this layer is repeated along the X axis.
|
||||
/// </summary>
|
||||
public bool RepeatX { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the image drawn by this layer is repeated along the Y axis.
|
||||
/// </summary>
|
||||
public bool RepeatY { get; set; } = false;
|
||||
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// The image to be drawn by this image layer.
|
||||
/// </summary>
|
||||
public Image? Image { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,24 +1,60 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Layers.Objects;
|
||||
|
||||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the order in which objects can be drawn.
|
||||
/// </summary>
|
||||
public enum DrawOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Objects are drawn sorted by their Y coordinate.
|
||||
/// </summary>
|
||||
TopDown,
|
||||
|
||||
/// <summary>
|
||||
/// Objects are drawn in the order of appearance in the object layer.
|
||||
/// </summary>
|
||||
Index
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an object layer in a map. In Tiled documentation, it is often called an "object group".
|
||||
/// </summary>
|
||||
public class ObjectLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The X coordinate of the object layer in tiles.
|
||||
/// </summary>
|
||||
public uint X { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The Y coordinate of the object layer in tiles.
|
||||
/// </summary>
|
||||
public uint Y { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the object layer in tiles. Meaningless.
|
||||
/// </summary>
|
||||
public uint? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the object layer in tiles. Meaningless.
|
||||
/// </summary>
|
||||
public uint? Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A color that is multiplied with any tile objects drawn by this layer.
|
||||
/// </summary>
|
||||
public Color? Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the objects are drawn according to the order of appearance (<see cref="DrawOrder.Index"/>) or sorted by their Y coordinate (<see cref="DrawOrder.TopDown"/>).
|
||||
/// </summary>
|
||||
public DrawOrder DrawOrder { get; set; } = DrawOrder.TopDown;
|
||||
|
||||
// Elements
|
||||
/// <summary>
|
||||
/// The objects in the object layer.
|
||||
/// </summary>
|
||||
public required List<Object> Objects { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// An ellipse object in a map. The existing <see cref="Object.X"/>, <see cref="Object.Y"/>, <see cref="Object.Width"/>,
|
||||
/// and <see cref="Object.Height"/> properties are used to determine the size of the ellipse.
|
||||
/// </summary>
|
||||
public class EllipseObject : Object { }
|
||||
|
|
|
@ -1,22 +1,64 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for objects in object layers.
|
||||
/// </summary>
|
||||
public abstract class Object
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public uint? ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the object. An arbitrary string.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The class of the object. An arbitrary string.
|
||||
/// </summary>
|
||||
public string Type { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The X coordinate of the object in pixels.
|
||||
/// </summary>
|
||||
public float X { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The Y coordinate of the object in pixels.
|
||||
/// </summary>
|
||||
public float Y { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the object in pixels.
|
||||
/// </summary>
|
||||
public float Width { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The height of the object in pixels.
|
||||
/// </summary>
|
||||
public float Height { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The rotation of the object in degrees clockwise around (X, Y).
|
||||
/// </summary>
|
||||
public float Rotation { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the object is shown (true) or hidden (false).
|
||||
/// </summary>
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// A reference to a template file.
|
||||
/// </summary>
|
||||
public string? Template { get; set; }
|
||||
|
||||
// Elements
|
||||
/// <summary>
|
||||
/// Object properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A point object in a map. The existing <see cref="Object.X"/> and <see cref="Object.Y"/> properties are used to
|
||||
/// determine the position of the point.
|
||||
/// </summary>
|
||||
public class PointObject : Object { }
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A polygon object in a map. The existing <see cref="Object.X"/> and <see cref="Object.Y"/> properties are used as
|
||||
/// the origin of the polygon.
|
||||
/// </summary>
|
||||
public class PolygonObject : Object
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The points that make up the polygon.
|
||||
/// <see cref="Object.X"/> and <see cref="Object.Y"/> are used as the origin of the polygon.
|
||||
/// </summary>
|
||||
public required List<Vector2> Points { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A polyline object in a map. The existing <see cref="Object.X"/> and <see cref="Object.Y"/> properties are used as
|
||||
/// the origin of the polyline.
|
||||
/// </summary>
|
||||
public class PolylineObject : Object
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The points that make up the polyline. <see cref="Object.X"/> and <see cref="Object.Y"/> are used as the origin of the polyline.
|
||||
/// </summary>
|
||||
public required List<Vector2> Points { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A rectangle object in a map. The existing <see cref="Object.X"/>, <see cref="Object.Y"/>, <see cref="Object.Width"/>,
|
||||
/// and <see cref="Object.Height"/> properties are used to determine the size of the rectangle.
|
||||
/// </summary>
|
||||
public class RectangleObject : Object { }
|
||||
|
|
|
@ -1,38 +1,116 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Model.Layers.Objects;
|
||||
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// The horizontal alignment of text.
|
||||
/// </summary>
|
||||
public enum TextHorizontalAlignment
|
||||
{
|
||||
/// <summary>
|
||||
/// The text is aligned to the left.
|
||||
/// </summary>
|
||||
Left,
|
||||
|
||||
/// <summary>
|
||||
/// The text is aligned to the center.
|
||||
/// </summary>
|
||||
Center,
|
||||
|
||||
/// <summary>
|
||||
/// The text is aligned to the right.
|
||||
/// </summary>
|
||||
Right,
|
||||
|
||||
/// <summary>
|
||||
/// The text is justified.
|
||||
/// </summary>
|
||||
Justify
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vertical alignment of text.
|
||||
/// </summary>
|
||||
public enum TextVerticalAlignment
|
||||
{
|
||||
/// <summary>
|
||||
/// The text is aligned to the top.
|
||||
/// </summary>
|
||||
Top,
|
||||
|
||||
/// <summary>
|
||||
/// The text is aligned to the center.
|
||||
/// </summary>
|
||||
Center,
|
||||
|
||||
/// <summary>
|
||||
/// The text is aligned to the bottom.
|
||||
/// </summary>
|
||||
Bottom
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A text object in a map.
|
||||
/// </summary>
|
||||
public class TextObject : Object
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The font family used for the text.
|
||||
/// </summary>
|
||||
public string FontFamily { get; set; } = "sans-serif";
|
||||
|
||||
/// <summary>
|
||||
/// The size of the font in pixels.
|
||||
/// </summary>
|
||||
public int PixelSize { get; set; } = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Whether word wrapping is enabled.
|
||||
/// </summary>
|
||||
public bool Wrap { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The color of the text.
|
||||
/// </summary>
|
||||
public Color Color { get; set; } = Color.Parse("#000000", CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the text is bold.
|
||||
/// </summary>
|
||||
public bool Bold { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the text is italic.
|
||||
/// </summary>
|
||||
public bool Italic { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a line should be drawn below the text.
|
||||
/// </summary>
|
||||
public bool Underline { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a line should be drawn through the text.
|
||||
/// </summary>
|
||||
public bool Strikeout { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether kerning should be used while rendering the text.
|
||||
/// </summary>
|
||||
public bool Kerning { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The horizontal alignment of the text.
|
||||
/// </summary>
|
||||
public TextHorizontalAlignment HorizontalAlignment { get; set; } = TextHorizontalAlignment.Left;
|
||||
|
||||
/// <summary>
|
||||
/// The vertical alignment of the text.
|
||||
/// </summary>
|
||||
public TextVerticalAlignment VerticalAlignment { get; set; } = TextVerticalAlignment.Top;
|
||||
|
||||
// Elements
|
||||
/// <summary>
|
||||
/// The text to be displayed.
|
||||
/// </summary>
|
||||
public string Text { get; set; } = "";
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
namespace DotTiled.Model.Layers.Objects;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A tile object in a map.
|
||||
/// </summary>
|
||||
public class TileObject : Object
|
||||
{
|
||||
/// <summary>
|
||||
/// A reference to a tile.
|
||||
/// </summary>
|
||||
public uint GID { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,13 +1,32 @@
|
|||
namespace DotTiled.Model.Layers;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a tile layer in a map.
|
||||
/// </summary>
|
||||
public class TileLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The X coordinate of the layer in tiles.
|
||||
/// </summary>
|
||||
public uint X { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The Y coordinate of the layer in tiles.
|
||||
/// </summary>
|
||||
public uint Y { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the layer in tiles. Always the same as the map width for fixed-size maps.
|
||||
/// </summary>
|
||||
public required uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the layer in tiles. Always the same as the map height for fixed-size maps.
|
||||
/// </summary>
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// The tile layer data.
|
||||
/// </summary>
|
||||
public Data? Data { get; set; }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Map orientation enumeration. The map orientation determines the alignment of the tiles in the map.
|
||||
/// </summary>
|
||||
public enum MapOrientation
|
||||
{
|
||||
/// <summary>
|
||||
/// Orthogonal orientation. This is the typical top-down grid-based layout.
|
||||
/// </summary>
|
||||
Orthogonal,
|
||||
|
||||
/// <summary>
|
||||
/// Isometric orientation. This is a type of axonometric projection where the tiles are shown as rhombuses, as seen from a side-on view.
|
||||
/// </summary>
|
||||
Isometric,
|
||||
|
||||
/// <summary>
|
||||
/// Staggered orientation. This is an isometric projection with a side-on view where the tiles are arranged in a staggered grid.
|
||||
/// </summary>
|
||||
Staggered,
|
||||
|
||||
/// <summary>
|
||||
/// Hexagonal orientation. This is a type of axial projection where the tiles are shown as hexagons, as seen from a top-down view.
|
||||
/// </summary>
|
||||
Hexagonal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Render order enumeration. The order in which tiles on tile layers are rendered.
|
||||
/// </summary>
|
||||
public enum RenderOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Right-down render order. Starts at top-left and proceeds right then down.
|
||||
/// </summary>
|
||||
RightDown,
|
||||
|
||||
/// <summary>
|
||||
/// Right-up render order. Starts at bottom-left and proceeds right then up.
|
||||
/// </summary>
|
||||
RightUp,
|
||||
|
||||
/// <summary>
|
||||
/// Left-down render order. Starts at top-right and proceeds left then down.
|
||||
/// </summary>
|
||||
LeftDown,
|
||||
|
||||
/// <summary>
|
||||
/// Left-up render order. Starts at bottom-right and proceeds left then up.
|
||||
/// </summary>
|
||||
LeftUp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stagger axis enumeration. For staggered and hexagonal maps, determines which axis (X or Y) is staggered.
|
||||
/// </summary>
|
||||
public enum StaggerAxis
|
||||
{
|
||||
/// <summary>
|
||||
/// X stagger axis.
|
||||
/// </summary>
|
||||
X,
|
||||
|
||||
/// <summary>
|
||||
/// Y stagger axis.
|
||||
/// </summary>
|
||||
Y
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stagger index enumeration. For staggered and hexagonal maps, determines whether the "even" or "odd" indexes along the staggered axis are shifted.
|
||||
/// </summary>
|
||||
public enum StaggerIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// Even stagger index.
|
||||
/// </summary>
|
||||
Odd,
|
||||
|
||||
/// <summary>
|
||||
/// Odd stagger index.
|
||||
/// </summary>
|
||||
Even
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Tiled map.
|
||||
/// </summary>
|
||||
public class Map
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The TMX format version. Is incremented to match minor Tiled releases.
|
||||
/// </summary>
|
||||
public required string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Tiled version used to save the file.
|
||||
/// </summary>
|
||||
public required string TiledVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The class of this map.
|
||||
/// </summary>
|
||||
public string Class { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Map orientation.
|
||||
/// </summary>
|
||||
public required MapOrientation Orientation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order in which tiles on tile layers are rendered.
|
||||
/// </summary>
|
||||
public RenderOrder RenderOrder { get; set; } = RenderOrder.RightDown;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public int CompressionLevel { get; set; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the map in tiles.
|
||||
/// </summary>
|
||||
public required uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the map in tiles.
|
||||
/// </summary>
|
||||
public required uint Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width of a tile.
|
||||
/// </summary>
|
||||
public required uint TileWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of a tile.
|
||||
/// </summary>
|
||||
public required uint TileHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only for hexagonal maps. Determines the width or height (depending on the staggered axis) of the tile's edge, in pixels.
|
||||
/// </summary>
|
||||
public uint? HexSideLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// For staggered and hexagonal maps, determines which axis (X or Y) is staggered.
|
||||
/// </summary>
|
||||
public StaggerAxis? StaggerAxis { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// For staggered and hexagonal maps, determines whether the "even" or "odd" indexes along the staggered axis are shifted.
|
||||
/// </summary>
|
||||
public StaggerIndex? StaggerIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// X coordinate of the parallax origin in pixels.
|
||||
/// </summary>
|
||||
public float ParallaxOriginX { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Y coordinate of the parallax origin in pixels.
|
||||
/// </summary>
|
||||
public float ParallaxOriginY { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The background color of the map.
|
||||
/// </summary>
|
||||
public Color BackgroundColor { get; set; } = Color.Parse("#00000000", CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// Stores the next available ID for new layers. This number is used to prevent reuse of the same ID after layers have been removed.
|
||||
/// </summary>
|
||||
public required uint NextLayerID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stores the next available ID for new objects. This number is used to prevent reuse of the same ID after objects have been removed.
|
||||
/// </summary>
|
||||
public required uint NextObjectID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool Infinite { get; set; } = false;
|
||||
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// Map properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
|
||||
// Any number of
|
||||
/// <summary>
|
||||
/// List of tilesets used by the map.
|
||||
/// </summary>
|
||||
public List<Tileset> Tilesets { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Hierarchical list of layers. <see cref="Group"/> is a layer type which can contain sub-layers to create a hierarchy.
|
||||
/// </summary>
|
||||
public List<BaseLayer> Layers { get; set; } = [];
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a boolean property.
|
||||
/// </summary>
|
||||
public class BoolProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.Bool;
|
||||
|
||||
/// <summary>
|
||||
/// The boolean value of the property.
|
||||
/// </summary>
|
||||
public required bool Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new BoolProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a class property.
|
||||
/// </summary>
|
||||
public class ClassProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => Model.Properties.PropertyType.Class;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => Model.PropertyType.Class;
|
||||
|
||||
/// <summary>
|
||||
/// The type of the class property. This will be the name of a custom defined
|
||||
/// type in Tiled.
|
||||
/// </summary>
|
||||
public required string PropertyType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The properties of the class property.
|
||||
/// </summary>
|
||||
public required Dictionary<string, IProperty> Properties { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ClassProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a color property.
|
||||
/// </summary>
|
||||
public class ColorProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.Color;
|
||||
|
||||
/// <summary>
|
||||
/// The color value of the property.
|
||||
/// </summary>
|
||||
public required Color Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ColorProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,27 +1,89 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled.Model.Properties.CustomTypes;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the types of objects that can use a custom class.
|
||||
/// Uses the <see href="https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-flagsattribute">FlagsAttribute, for which there is plenty of documentation.</see>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum CustomClassUseAs
|
||||
{
|
||||
/// <summary>
|
||||
/// Any property on any kind of object.
|
||||
/// </summary>
|
||||
Property,
|
||||
|
||||
/// <summary>
|
||||
/// A map.
|
||||
/// </summary>
|
||||
Map,
|
||||
|
||||
/// <summary>
|
||||
/// A layer.
|
||||
/// </summary>
|
||||
Layer,
|
||||
|
||||
/// <summary>
|
||||
/// An object.
|
||||
/// </summary>
|
||||
Object,
|
||||
|
||||
/// <summary>
|
||||
/// A tile.
|
||||
/// </summary>
|
||||
Tile,
|
||||
|
||||
/// <summary>
|
||||
/// A tileset.
|
||||
/// </summary>
|
||||
Tileset,
|
||||
|
||||
/// <summary>
|
||||
/// A Wang color.
|
||||
/// </summary>
|
||||
WangColor,
|
||||
|
||||
/// <summary>
|
||||
/// A Wangset.
|
||||
/// </summary>
|
||||
Wangset,
|
||||
|
||||
/// <summary>
|
||||
/// A project.
|
||||
/// </summary>
|
||||
Project,
|
||||
|
||||
/// <summary>
|
||||
/// All types.
|
||||
/// </summary>
|
||||
All = Property | Map | Layer | Object | Tile | Tileset | WangColor | Wangset | Project
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a custom class definition in Tiled. Refer to the
|
||||
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
||||
/// </summary>
|
||||
public class CustomClassDefinition : CustomTypeDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// The color of the custom class inside the Tiled editor.
|
||||
/// </summary>
|
||||
public Color? Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the custom class should be drawn with a fill color.
|
||||
/// </summary>
|
||||
public bool DrawFill { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What the custom class can be used as, or rather, what types of objects can use it.
|
||||
/// </summary>
|
||||
public CustomClassUseAs UseAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The members of the custom class, with their names, types and default values.
|
||||
/// </summary>
|
||||
public List<IProperty> Members { get; set; } = [];
|
||||
}
|
||||
|
|
|
@ -1,16 +1,41 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled.Model.Properties.CustomTypes;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the storage type of a custom enum.
|
||||
/// </summary>
|
||||
public enum CustomEnumStorageType
|
||||
{
|
||||
/// <summary>
|
||||
/// The backing value is an integer.
|
||||
/// </summary>
|
||||
Int,
|
||||
|
||||
/// <summary>
|
||||
/// The backing value is a string.
|
||||
/// </summary>
|
||||
String
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a custom enum definition in Tiled. Refer to the
|
||||
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
||||
/// </summary>
|
||||
public class CustomEnumDefinition : CustomTypeDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// The storage type of the custom enum.
|
||||
/// </summary>
|
||||
public CustomEnumStorageType StorageType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The values of the custom enum.
|
||||
/// </summary>
|
||||
public List<string> Values { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Whether the value should be treated as flags.
|
||||
/// </summary>
|
||||
public bool ValueAsFlags { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
namespace DotTiled.Model.Properties.CustomTypes;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for custom type definitions.
|
||||
/// </summary>
|
||||
public abstract class CustomTypeDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the custom type.
|
||||
/// </summary>
|
||||
public uint ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the custom type.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = "";
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a file property.
|
||||
/// </summary>
|
||||
public class FileProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.File;
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property.
|
||||
/// </summary>
|
||||
public required string Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new FileProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a float property.
|
||||
/// </summary>
|
||||
public class FloatProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.Float;
|
||||
|
||||
/// <summary>
|
||||
/// The float value of the property.
|
||||
/// </summary>
|
||||
public required float Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new FloatProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for properties that can be attached to objects, tiles, tilesets, maps etc.
|
||||
/// </summary>
|
||||
public interface IProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the property.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of the property.
|
||||
/// </summary>
|
||||
public PropertyType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Clones the property, only used for copying properties when performing overriding
|
||||
/// with templates.
|
||||
/// </summary>
|
||||
/// <returns>An identical, but non-reference-equal, instance of the same property.</returns>
|
||||
IProperty Clone();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an integer property.
|
||||
/// </summary>
|
||||
public class IntProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.Int;
|
||||
|
||||
/// <summary>
|
||||
/// The integer value of the property.
|
||||
/// </summary>
|
||||
public required int Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new IntProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an object property.
|
||||
/// </summary>
|
||||
public class ObjectProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.Object;
|
||||
|
||||
/// <summary>
|
||||
/// The object identifier referenced by the property.
|
||||
/// </summary>
|
||||
public required uint Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ObjectProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,13 +1,47 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type of a property.
|
||||
/// </summary>
|
||||
public enum PropertyType
|
||||
{
|
||||
/// <summary>
|
||||
/// A string property.
|
||||
/// </summary>
|
||||
String,
|
||||
|
||||
/// <summary>
|
||||
/// An integer property.
|
||||
/// </summary>
|
||||
Int,
|
||||
|
||||
/// <summary>
|
||||
/// A float property.
|
||||
/// </summary>
|
||||
Float,
|
||||
|
||||
/// <summary>
|
||||
/// A boolean property.
|
||||
/// </summary>
|
||||
Bool,
|
||||
|
||||
/// <summary>
|
||||
/// A color property.
|
||||
/// </summary>
|
||||
Color,
|
||||
|
||||
/// <summary>
|
||||
/// A file property.
|
||||
/// </summary>
|
||||
File,
|
||||
|
||||
/// <summary>
|
||||
/// An object property.
|
||||
/// </summary>
|
||||
Object,
|
||||
|
||||
/// <summary>
|
||||
/// A class property.
|
||||
/// </summary>
|
||||
Class
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
namespace DotTiled.Model.Properties;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a string property.
|
||||
/// </summary>
|
||||
public class StringProperty : IProperty
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertyType Type => PropertyType.String;
|
||||
|
||||
/// <summary>
|
||||
/// The string value of the property.
|
||||
/// </summary>
|
||||
public required string Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new StringProperty
|
||||
{
|
||||
Name = Name,
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
using DotTiled.Model.Layers.Objects;
|
||||
using DotTiled.Model.Tilesets;
|
||||
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Tiled template. A template is a reusable object that can be placed in an <see cref="DotTiled.Model"/> inside the Tiled editor.
|
||||
/// </summary>
|
||||
public class Template
|
||||
{
|
||||
// At most one of (if the template is a tile object)
|
||||
/// <summary>
|
||||
/// If the template represents a tile object, this property will contain the tileset that the tile belongs to.
|
||||
/// </summary>
|
||||
public Tileset? Tileset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The object that this template represents.
|
||||
/// </summary>
|
||||
public required Object Object { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// A single frame of an animated tile.
|
||||
/// </summary>
|
||||
public class Frame
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The local tile ID within the parent tileset.
|
||||
/// </summary>
|
||||
public required uint TileID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How long (in milliseconds) this frame should be displayed before advancing to the next frame.
|
||||
/// </summary>
|
||||
public required uint Duration { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,15 +1,38 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Orientation of the grid for the tiles in this tileset.
|
||||
/// </summary>
|
||||
public enum GridOrientation
|
||||
{
|
||||
/// <summary>
|
||||
/// The grid is orthogonal.
|
||||
/// </summary>
|
||||
Orthogonal,
|
||||
|
||||
/// <summary>
|
||||
/// The grid is isometric.
|
||||
/// </summary>
|
||||
Isometric
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to specify how tile overlays for terrain and collision information are rendered in isometric maps.
|
||||
/// </summary>
|
||||
public class Grid
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// Orientation of the grid for the tiles in this tileset.
|
||||
/// </summary>
|
||||
public GridOrientation Orientation { get; set; } = GridOrientation.Orthogonal;
|
||||
|
||||
/// <summary>
|
||||
/// Width of a grid cell.
|
||||
/// </summary>
|
||||
public required uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Height of a grid cell.
|
||||
/// </summary>
|
||||
public required uint Height { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,19 +1,58 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// The format of an image.
|
||||
/// </summary>
|
||||
public enum ImageFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// Portable Network Graphics.
|
||||
/// </summary>
|
||||
Png,
|
||||
|
||||
/// <summary>
|
||||
/// Graphics Interchange Format.
|
||||
/// </summary>
|
||||
Gif,
|
||||
|
||||
/// <summary>
|
||||
/// Joint Photographic Experts Group.
|
||||
/// </summary>
|
||||
Jpg,
|
||||
|
||||
/// <summary>
|
||||
/// Windows Bitmap.
|
||||
/// </summary>
|
||||
Bmp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an image that is used by a tileset.
|
||||
/// </summary>
|
||||
public class Image
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The format of the image.
|
||||
/// </summary>
|
||||
public ImageFormat? Format { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The reference to the image file.
|
||||
/// </summary>
|
||||
public string? Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a specific color that is treated as transparent.
|
||||
/// </summary>
|
||||
public Color? TransparentColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The image width in pixels, used for tile index correction when the image changes.
|
||||
/// </summary>
|
||||
public uint? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The image height in pixels, used for tile index correction when the image changes.
|
||||
/// </summary>
|
||||
public uint? Height { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,23 +1,65 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single tile in a tileset, when using a collection of images to represent the tileset.
|
||||
/// <see href="https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tile">Tiled documentation for Tileset tiles</see>
|
||||
/// </summary>
|
||||
public class Tile
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The local tile ID within its tileset.
|
||||
/// </summary>
|
||||
public required uint ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The class of the tile. Is inherited by tile objects
|
||||
/// </summary>
|
||||
public string Type { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// A percentage indicating the probability that this tile is chosen when it competes with others while editing with the terrain tool.
|
||||
/// </summary>
|
||||
public float Probability { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The X position of the sub-rectangle representing this tile within the tileset image.
|
||||
/// </summary>
|
||||
public uint X { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The Y position of the sub-rectangle representing this tile within the tileset image.
|
||||
/// </summary>
|
||||
public uint Y { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the sub-rectangle representing this tile within the tileset image.
|
||||
/// </summary>
|
||||
public required uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the sub-rectangle representing this tile within the tileset image.
|
||||
/// </summary>
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// Elements
|
||||
/// <summary>
|
||||
/// Tile properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The image representing this tile. Only used for tilesets that composed of a collection of images.
|
||||
/// </summary>
|
||||
public Image? Image { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unclear what this is for.
|
||||
/// </summary>
|
||||
public ObjectLayer? ObjectLayer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The animation frames for this tile.
|
||||
/// </summary>
|
||||
public List<Frame>? Animation { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Is used to specify an offset in pixels in tilesets, to be applied when drawing a tile from the related tileset.
|
||||
/// </summary>
|
||||
public class TileOffset
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The horizontal offset in pixels.
|
||||
/// </summary>
|
||||
public float X { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The vertical offset in pixels.
|
||||
/// </summary>
|
||||
public float Y { get; set; } = 0f;
|
||||
}
|
||||
|
|
|
@ -1,62 +1,209 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// The alignment of tile objects.
|
||||
/// </summary>
|
||||
public enum ObjectAlignment
|
||||
{
|
||||
/// <summary>
|
||||
/// The alignment is unspecified. Tile objects will use <see cref="BottomLeft"/> in orthogonal maps, and <see cref="Bottom"/> in isometric maps.
|
||||
/// </summary>
|
||||
Unspecified,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the top left of the tile.
|
||||
/// </summary>
|
||||
TopLeft,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the top of the tile.
|
||||
/// </summary>
|
||||
Top,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the top right of the tile.
|
||||
/// </summary>
|
||||
TopRight,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the left of the tile.
|
||||
/// </summary>
|
||||
Left,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the center of the tile.
|
||||
/// </summary>
|
||||
Center,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the right of the tile.
|
||||
/// </summary>
|
||||
Right,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the bottom left of the tile.
|
||||
/// </summary>
|
||||
BottomLeft,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the bottom of the tile.
|
||||
/// </summary>
|
||||
Bottom,
|
||||
|
||||
/// <summary>
|
||||
/// The tile object is aligned to the bottom right of the tile.
|
||||
/// </summary>
|
||||
BottomRight
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The size to use when rendering tiles from a tileset on a tile layer.
|
||||
/// </summary>
|
||||
public enum TileRenderSize
|
||||
{
|
||||
/// <summary>
|
||||
/// The tile is drawn at the size of the tile in the tileset.
|
||||
/// </summary>
|
||||
Tile,
|
||||
|
||||
/// <summary>
|
||||
/// The tile is drawn at the tile grid size of the map.
|
||||
/// </summary>
|
||||
Grid
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines how a tile is rendered in a tile set.
|
||||
/// </summary>
|
||||
public enum FillMode
|
||||
{
|
||||
/// <summary>
|
||||
/// The tile is stretched to fill the tile size, possibly distorting the tile.
|
||||
/// </summary>
|
||||
Stretch,
|
||||
|
||||
/// <summary>
|
||||
/// The tile's aspect ratio is preserved, and it is scaled to fit within the tile size.
|
||||
/// </summary>
|
||||
PreserveAspectFit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A tileset is a collection of tiles that can be used in a tile layer, or by tile objects.
|
||||
/// </summary>
|
||||
public class Tileset
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The TMX format version. Is incremented to match minor Tiled releases.
|
||||
/// </summary>
|
||||
public string? Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Tiled version used to save the file in case it was loaded from an external tileset file.
|
||||
/// </summary>
|
||||
public string? TiledVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The first global tile ID of this tileset (this global ID maps to the first tile in this tileset).
|
||||
/// </summary>
|
||||
public uint? FirstGID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this tileset is stored in an external TSX (Tile Set XML) file, this attribute refers to that file.
|
||||
/// </summary>
|
||||
public string? Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of this tileset.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The class of this tileset.
|
||||
/// </summary>
|
||||
public string Class { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
public uint? TileWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
public uint? TileHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The spacing in pixels between the tiles in this tileset (applies to the tileset image). Irrelevant for image collection tilesets.
|
||||
/// </summary>
|
||||
public float? Spacing { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The margin around the tiles in this tileset (applies to the tileset image). Irrelevant for image collection tilesets.
|
||||
/// </summary>
|
||||
public float? Margin { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The number of tiles in this tileset.
|
||||
/// </summary>
|
||||
public uint? TileCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of tile columns in the tileset.
|
||||
/// </summary>
|
||||
public uint? Columns { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls the aligntment for tile objects.
|
||||
/// </summary>
|
||||
public ObjectAlignment ObjectAlignment { get; set; } = ObjectAlignment.Unspecified;
|
||||
|
||||
/// <summary>
|
||||
/// The size to use when rendering tiles from thie tileset on a tile layer. When set to <see cref="TileRenderSize.Grid"/>, the tile is drawn at the tile grid size of the map.
|
||||
/// </summary>
|
||||
public TileRenderSize RenderSize { get; set; } = TileRenderSize.Tile;
|
||||
|
||||
/// <summary>
|
||||
/// The fill mode to use when rendering tiles from this tileset.
|
||||
/// </summary>
|
||||
public FillMode FillMode { get; set; } = FillMode.Stretch;
|
||||
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public Image? Image { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public TileOffset? TileOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ths is only used in case of isometric orientation, and determines how tile overlays for terrain and collision information are rendered.
|
||||
/// </summary>
|
||||
public Grid? Grid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tileset properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
|
||||
// public List<Terrain>? TerrainTypes { get; set; } TODO: Implement Terrain -> Wangset conversion during deserialization
|
||||
|
||||
/// <summary>
|
||||
/// Contains the list of Wang sets defined for this tileset.
|
||||
/// </summary>
|
||||
public List<Wangset>? Wangsets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to describe which transformations can be applied to the tiles (e.g. to extend a Wang set by transforming existing tiles).
|
||||
/// </summary>
|
||||
public Transformations? Transformations { get; set; }
|
||||
|
||||
// Any number of
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public List<Tile> Tiles { get; set; } = [];
|
||||
}
|
||||
|
|
|
@ -1,10 +1,27 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents which transformations can be applied to a tile in a tileset.
|
||||
/// </summary>
|
||||
public class Transformations
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// Whether the file in this can set be flipped horizontally.
|
||||
/// </summary>
|
||||
public bool HFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the file in this can set be flipped vertically.
|
||||
/// </summary>
|
||||
public bool VFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the file in this set can be rotated in 90 degree increments.
|
||||
/// </summary>
|
||||
public bool Rotate { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether untransformed tiles remain preferred, otherwise transformed tiles are used to produce more vartiations.
|
||||
/// </summary>
|
||||
public bool PreferUntransformed { get; set; } = false;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,39 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Wang color in a Wang set.
|
||||
/// </summary>
|
||||
public class WangColor
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The name of this color.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The class of the Wang color.
|
||||
/// </summary>
|
||||
public string Class { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The color of the Wang color.
|
||||
/// </summary>
|
||||
public required Color Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The tile ID of the tile representing this color.
|
||||
/// </summary>
|
||||
public required int Tile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The relative probability that this color is chosen over others in case of multiple options.
|
||||
/// </summary>
|
||||
public float Probability { get; set; } = 0f;
|
||||
|
||||
// Elements
|
||||
/// <summary>
|
||||
/// The Wang color properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Wang tile in a Wang set.
|
||||
/// </summary>
|
||||
public class WangTile
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The tile ID associated with this Wang tile.
|
||||
/// </summary>
|
||||
public required uint TileID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Wang ID of this Wang tile.
|
||||
/// </summary>
|
||||
public required byte[] WangID { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,22 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using DotTiled.Model.Properties;
|
||||
|
||||
namespace DotTiled.Model.Tilesets;
|
||||
namespace DotTiled.Model;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list of colors and any number of Wang tiles using these colors.
|
||||
/// </summary>
|
||||
public class Wangset
|
||||
{
|
||||
// Attributes
|
||||
/// <summary>
|
||||
/// The name of the Wang set.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The class of the Wang set.
|
||||
/// </summary>
|
||||
public string Class { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// The tile ID of the tile representing the Wang set.
|
||||
/// </summary>
|
||||
public required int Tile { get; set; }
|
||||
|
||||
// Elements
|
||||
// At most one of
|
||||
/// <summary>
|
||||
/// The Wang set properties.
|
||||
/// </summary>
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
|
||||
// Up to 254 Wang colors
|
||||
/// <summary>
|
||||
/// The Wang colors in the Wang set.
|
||||
/// </summary>
|
||||
public List<WangColor>? WangColors { get; set; } = [];
|
||||
|
||||
// Any number of
|
||||
/// <summary>
|
||||
/// The Wang tiles in the Wang set.
|
||||
/// </summary>
|
||||
public List<WangTile> WangTiles { get; set; } = [];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -3,7 +3,14 @@ using DotTiled.Model;
|
|||
|
||||
namespace DotTiled.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for reading a map from some source. Used by the different file format parsers to read a map.
|
||||
/// </summary>
|
||||
public interface IMapReader : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a map from the source.
|
||||
/// </summary>
|
||||
/// <returns>The parsed map.</returns>
|
||||
Map ReadMap();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,14 @@ using DotTiled.Model;
|
|||
|
||||
namespace DotTiled.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for reading a template from some source. Used by the different file format parsers to read a template.
|
||||
/// </summary>
|
||||
public interface ITemplateReader : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a template from the source.
|
||||
/// </summary>
|
||||
/// <returns>The parsed template.</returns>
|
||||
Template ReadTemplate();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
using System;
|
||||
using DotTiled.Model.Tilesets;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for reading a tileset from some source. Used by the different file format parsers to read a tileset.
|
||||
/// </summary>
|
||||
public interface ITilesetReader : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a tileset from the source.
|
||||
/// </summary>
|
||||
/// <returns>The parsed tileset.</returns>
|
||||
Tileset ReadTileset();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A template reader for reading Tiled JSON templates.
|
||||
/// </summary>
|
||||
public class TjTemplateReader : ITemplateReader
|
||||
{
|
||||
// External resolvers
|
||||
|
@ -17,6 +18,14 @@ public class TjTemplateReader : ITemplateReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TjTemplateReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonString">A string containing a Tiled template in the Tiled JSON format.</param>
|
||||
/// <param name="externalTilesetResolver">A function that resolves external tilesets given their source.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TjTemplateReader(
|
||||
string jsonString,
|
||||
Func<string, Tileset> externalTilesetResolver,
|
||||
|
@ -29,6 +38,7 @@ public class TjTemplateReader : ITemplateReader
|
|||
_customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -58,6 +69,7 @@ public class TjTemplateReader : ITemplateReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<List<Model.Layers.Objects.Object>>("objects", e => e.GetValueAsList<Model.Layers.Objects.Object>(el => ReadObject(el, externalTemplateResolver, customTypeDefinitions)), []);
|
||||
var objects = element.GetOptionalPropertyCustom<List<Model.Object>>("objects", e => e.GetValueAsList<Model.Object>(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<string, Template> externalTemplateResolver,
|
||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<string>("type");
|
||||
var tileset = element.GetOptionalPropertyCustom<Tileset?>("tileset", el => ReadTileset(el, externalTilesetResolver, externalTemplateResolver, customTypeDefinitions), null);
|
||||
var @object = element.GetRequiredPropertyCustom<Model.Layers.Objects.Object>("object", el => ReadObject(el, externalTemplateResolver, customTypeDefinitions));
|
||||
var @object = element.GetRequiredPropertyCustom<Model.Object>("object", el => ReadObject(el, externalTemplateResolver, customTypeDefinitions));
|
||||
|
||||
return new Template
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A map reader for reading Tiled JSON maps.
|
||||
/// </summary>
|
||||
public class TmjMapReader : IMapReader
|
||||
{
|
||||
// External resolvers
|
||||
|
@ -20,6 +21,14 @@ public class TmjMapReader : IMapReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TmjMapReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonString">A string containing a Tiled map in the Tiled JSON format.</param>
|
||||
/// <param name="externalTilesetResolver">A function that resolves external tilesets given their source.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TmjMapReader(
|
||||
string jsonString,
|
||||
Func<string, Tileset> externalTilesetResolver,
|
||||
|
@ -32,6 +41,7 @@ public class TmjMapReader : IMapReader
|
|||
_customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Map ReadMap()
|
||||
{
|
||||
var jsonDoc = JsonDocument.Parse(_jsonString);
|
||||
|
@ -39,6 +49,7 @@ public class TmjMapReader : IMapReader
|
|||
return Tmj.ReadMap(rootElement, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -61,6 +72,7 @@ public class TmjMapReader : IMapReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A tileset reader for the Tiled JSON format.
|
||||
/// </summary>
|
||||
public class TsjTilesetReader : ITilesetReader
|
||||
{
|
||||
// External resolvers
|
||||
|
@ -16,6 +17,13 @@ public class TsjTilesetReader : ITilesetReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TsjTilesetReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonString">A string containing a Tiled tileset in the Tiled JSON format.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TsjTilesetReader(
|
||||
string jsonString,
|
||||
Func<string, Template> externalTemplateResolver,
|
||||
|
@ -26,6 +34,7 @@ public class TsjTilesetReader : ITilesetReader
|
|||
_customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Tileset ReadTileset()
|
||||
{
|
||||
var jsonDoc = System.Text.Json.JsonDocument.Parse(_jsonString);
|
||||
|
@ -37,6 +46,7 @@ public class TsjTilesetReader : ITilesetReader
|
|||
_customTypeDefinitions);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -59,6 +69,7 @@ public class TsjTilesetReader : ITilesetReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System.Xml;
|
||||
using DotTiled.Model.Layers;
|
||||
using DotTiled.Model;
|
||||
|
||||
namespace DotTiled.Serialization.Tmx;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<string, IProperty>? properties = null;
|
||||
List<Model.Layers.Objects.Object> objects = [];
|
||||
List<Model.Object> 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<string, Template> externalTemplateResolver,
|
||||
IReadOnlyCollection<CustomTypeDefinition> 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<bool>("visible") ?? visibleDefault;
|
||||
|
||||
// Elements
|
||||
Model.Layers.Objects.Object? foundObject = null;
|
||||
Model.Object? foundObject = null;
|
||||
int propertiesCounter = 0;
|
||||
Dictionary<string, IProperty>? 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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A map reader for the Tiled XML format.
|
||||
/// </summary>
|
||||
public class TmxMapReader : IMapReader
|
||||
{
|
||||
// External resolvers
|
||||
|
@ -18,6 +19,14 @@ public class TmxMapReader : IMapReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TmxMapReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">An XML reader for reading a Tiled map in the Tiled XML format.</param>
|
||||
/// <param name="externalTilesetResolver">A function that resolves external tilesets given their source.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TmxMapReader(
|
||||
XmlReader reader,
|
||||
Func<string, Tileset> externalTilesetResolver,
|
||||
|
@ -33,11 +42,13 @@ public class TmxMapReader : IMapReader
|
|||
_reader.MoveToContent();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Map ReadMap()
|
||||
{
|
||||
return Tmx.ReadMap(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -61,6 +72,7 @@ public class TmxMapReader : IMapReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A tileset reader for the Tiled XML format.
|
||||
/// </summary>
|
||||
public class TsxTilesetReader : ITilesetReader
|
||||
{
|
||||
// External resolvers
|
||||
|
@ -17,6 +18,13 @@ public class TsxTilesetReader : ITilesetReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TsxTilesetReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">An XML reader for reading a Tiled tileset in the Tiled XML format.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TsxTilesetReader(
|
||||
XmlReader reader,
|
||||
Func<string, Template> externalTemplateResolver,
|
||||
|
@ -30,8 +38,10 @@ public class TsxTilesetReader : ITilesetReader
|
|||
_reader.MoveToContent();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Tileset ReadTileset() => Tmx.ReadTileset(_reader, null, _externalTemplateResolver, _customTypeDefinitions);
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -54,6 +64,7 @@ public class TsxTilesetReader : ITilesetReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A template reader for the Tiled XML format.
|
||||
/// </summary>
|
||||
public class TxTemplateReader : ITemplateReader
|
||||
{
|
||||
// Resolvers
|
||||
|
@ -18,6 +19,14 @@ public class TxTemplateReader : ITemplateReader
|
|||
|
||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="TxTemplateReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">An XML reader for reading a Tiled template in the Tiled XML format.</param>
|
||||
/// <param name="externalTilesetResolver">A function that resolves external tilesets given their source.</param>
|
||||
/// <param name="externalTemplateResolver">A function that resolves external templates given their source.</param>
|
||||
/// <param name="customTypeDefinitions">A collection of custom type definitions that can be used to resolve custom types when encountering <see cref="ClassProperty"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when any of the arguments are null.</exception>
|
||||
public TxTemplateReader(
|
||||
XmlReader reader,
|
||||
Func<string, Tileset> externalTilesetResolver,
|
||||
|
@ -33,8 +42,10 @@ public class TxTemplateReader : ITemplateReader
|
|||
_reader.MoveToContent();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Template ReadTemplate() => Tmx.ReadTemplate(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions);
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -57,6 +68,7 @@ public class TxTemplateReader : ITemplateReader
|
|||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
|
|
Loading…
Add table
Reference in a new issue