mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-09 01:56:02 +03:00
Move source to src/
This commit is contained in:
parent
580e630148
commit
0a11cdd791
131 changed files with 0 additions and 0 deletions
20
src/DotTiled.Benchmark/DotTiled.Benchmark.csproj
Normal file
20
src/DotTiled.Benchmark/DotTiled.Benchmark.csproj
Normal file
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
|
||||
<PackageReference Include="TiledCSPlus" Version="4.2.0" />
|
||||
<PackageReference Include="TiledLib" Version="4.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotTiled\DotTiled.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
94
src/DotTiled.Benchmark/Program.cs
Normal file
94
src/DotTiled.Benchmark/Program.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Order;
|
||||
using BenchmarkDotNet.Reports;
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace MyBenchmarks
|
||||
{
|
||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
||||
[CategoriesColumn]
|
||||
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
|
||||
[HideColumns(["StdDev", "Error", "RatioSD"])]
|
||||
public class MapLoading
|
||||
{
|
||||
private string _tmxPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx";
|
||||
private string _tmxContents = "";
|
||||
|
||||
private string _tmjPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj";
|
||||
private string _tmjContents = "";
|
||||
|
||||
public MapLoading()
|
||||
{
|
||||
var basePath = Path.GetDirectoryName(WhereAmI())!;
|
||||
var tmxPath = Path.Combine(basePath, $"../{_tmxPath}");
|
||||
var tmjPath = Path.Combine(basePath, $"../{_tmjPath}");
|
||||
|
||||
_tmxContents = System.IO.File.ReadAllText(tmxPath);
|
||||
_tmjContents = System.IO.File.ReadAllText(tmjPath);
|
||||
}
|
||||
|
||||
static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath;
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryTmxString()
|
||||
{
|
||||
using var stringReader = new StringReader(_tmxContents);
|
||||
using var xmlReader = XmlReader.Create(stringReader);
|
||||
using var mapReader = new DotTiled.TmxMapReader(xmlReader, _ => throw new Exception(), _ => throw new Exception(), []);
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmjString")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryTmjString()
|
||||
{
|
||||
using var mapReader = new DotTiled.TmjMapReader(_tmjContents, _ => throw new Exception(), _ => throw new Exception(), []);
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Description = "TiledLib")]
|
||||
public TiledLib.Map LoadWithTiledLibFromInMemoryTmxString()
|
||||
{
|
||||
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmxContents));
|
||||
return TiledLib.Map.FromStream(memStream);
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmjString")]
|
||||
[Benchmark(Description = "TiledLib")]
|
||||
public TiledLib.Map LoadWithTiledLibFromInMemoryTmjString()
|
||||
{
|
||||
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmjContents));
|
||||
return TiledLib.Map.FromStream(memStream);
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Description = "TiledCSPlus")]
|
||||
public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromInMemoryTmxString()
|
||||
{
|
||||
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmxContents));
|
||||
return new TiledCSPlus.TiledMap(memStream);
|
||||
}
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var config = BenchmarkDotNet.Configs.DefaultConfig.Instance
|
||||
.WithArtifactsPath(args[0])
|
||||
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
|
||||
.AddDiagnoser(BenchmarkDotNet.Diagnosers.MemoryDiagnoser.Default);
|
||||
var summary = BenchmarkRunner.Run<MapLoading>(config);
|
||||
}
|
||||
}
|
||||
}
|
43
src/DotTiled.Tests/Assert/AssertData.cs
Normal file
43
src/DotTiled.Tests/Assert/AssertData.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertData(Data? expected, Data? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.Encoding, actual.Encoding, nameof(Data.Encoding));
|
||||
AssertEqual(expected.Compression, actual.Compression, nameof(Data.Compression));
|
||||
|
||||
// Data
|
||||
AssertEqual(expected.GlobalTileIDs, actual.GlobalTileIDs, nameof(Data.GlobalTileIDs));
|
||||
AssertEqual(expected.FlippingFlags, actual.FlippingFlags, nameof(Data.FlippingFlags));
|
||||
|
||||
if (expected.Chunks is not null)
|
||||
{
|
||||
Assert.NotNull(actual.Chunks);
|
||||
AssertEqual(expected.Chunks.Length, actual.Chunks.Length, "Chunks.Length");
|
||||
for (var i = 0; i < expected.Chunks.Length; i++)
|
||||
AssertChunk(expected.Chunks[i], actual.Chunks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertChunk(Chunk expected, Chunk actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.X, actual.X, nameof(Chunk.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(Chunk.Y));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Chunk.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Chunk.Height));
|
||||
|
||||
// Data
|
||||
AssertEqual(expected.GlobalTileIDs, actual.GlobalTileIDs, nameof(Chunk.GlobalTileIDs));
|
||||
AssertEqual(expected.FlippingFlags, actual.FlippingFlags, nameof(Chunk.FlippingFlags));
|
||||
}
|
||||
}
|
21
src/DotTiled.Tests/Assert/AssertImage.cs
Normal file
21
src/DotTiled.Tests/Assert/AssertImage.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertImage(Image? expected, Image? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.Format, actual.Format, nameof(Image.Format));
|
||||
AssertEqual(expected.Source, actual.Source, nameof(Image.Source));
|
||||
AssertEqual(expected.TransparentColor, actual.TransparentColor, nameof(Image.TransparentColor));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Image.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Image.Height));
|
||||
}
|
||||
}
|
75
src/DotTiled.Tests/Assert/AssertLayer.cs
Normal file
75
src/DotTiled.Tests/Assert/AssertLayer.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertLayer(BaseLayer? expected, BaseLayer? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.ID, actual.ID, nameof(BaseLayer.ID));
|
||||
AssertEqual(expected.Name, actual.Name, nameof(BaseLayer.Name));
|
||||
AssertEqual(expected.Class, actual.Class, nameof(BaseLayer.Class));
|
||||
AssertEqual(expected.Opacity, actual.Opacity, nameof(BaseLayer.Opacity));
|
||||
AssertEqual(expected.Visible, actual.Visible, nameof(BaseLayer.Visible));
|
||||
AssertEqual(expected.TintColor, actual.TintColor, nameof(BaseLayer.TintColor));
|
||||
AssertEqual(expected.OffsetX, actual.OffsetX, nameof(BaseLayer.OffsetX));
|
||||
AssertEqual(expected.OffsetY, actual.OffsetY, nameof(BaseLayer.OffsetY));
|
||||
AssertEqual(expected.ParallaxX, actual.ParallaxX, nameof(BaseLayer.ParallaxX));
|
||||
AssertEqual(expected.ParallaxY, actual.ParallaxY, nameof(BaseLayer.ParallaxY));
|
||||
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
AssertLayer((dynamic)expected, (dynamic)actual);
|
||||
}
|
||||
|
||||
private static void AssertLayer(TileLayer expected, TileLayer actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.Width, actual.Width, nameof(TileLayer.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(TileLayer.Height));
|
||||
AssertEqual(expected.X, actual.X, nameof(TileLayer.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(TileLayer.Y));
|
||||
|
||||
Assert.NotNull(actual.Data);
|
||||
AssertData(expected.Data, actual.Data);
|
||||
}
|
||||
|
||||
private static void AssertLayer(ObjectLayer expected, ObjectLayer actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.DrawOrder, actual.DrawOrder, nameof(ObjectLayer.DrawOrder));
|
||||
AssertEqual(expected.X, actual.X, nameof(ObjectLayer.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(ObjectLayer.Y));
|
||||
|
||||
Assert.NotNull(actual.Objects);
|
||||
AssertEqual(expected.Objects.Count, actual.Objects.Count, "Objects.Count");
|
||||
for (var i = 0; i < expected.Objects.Count; i++)
|
||||
AssertObject(expected.Objects[i], actual.Objects[i]);
|
||||
}
|
||||
|
||||
private static void AssertLayer(ImageLayer expected, ImageLayer actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.RepeatX, actual.RepeatX, nameof(ImageLayer.RepeatX));
|
||||
AssertEqual(expected.RepeatY, actual.RepeatY, nameof(ImageLayer.RepeatY));
|
||||
AssertEqual(expected.X, actual.X, nameof(ImageLayer.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(ImageLayer.Y));
|
||||
|
||||
Assert.NotNull(actual.Image);
|
||||
AssertImage(expected.Image, actual.Image);
|
||||
}
|
||||
|
||||
private static void AssertLayer(Group expected, Group actual)
|
||||
{
|
||||
// Attributes
|
||||
Assert.NotNull(actual.Layers);
|
||||
AssertEqual(expected.Layers.Count, actual.Layers.Count, "Layers.Count");
|
||||
for (var i = 0; i < expected.Layers.Count; i++)
|
||||
AssertLayer(expected.Layers[i], actual.Layers[i]);
|
||||
}
|
||||
}
|
105
src/DotTiled.Tests/Assert/AssertMap.cs
Normal file
105
src/DotTiled.Tests/Assert/AssertMap.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using System.Collections;
|
||||
using System.Numerics;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
private static void AssertEqual<T>(T expected, T actual, string nameof)
|
||||
{
|
||||
if (expected == null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(float))
|
||||
{
|
||||
var expectedFloat = (float)(object)expected;
|
||||
var actualFloat = (float)(object)actual!;
|
||||
|
||||
var expecRounded = MathF.Round(expectedFloat, 3);
|
||||
var actRounded = MathF.Round(actualFloat, 3);
|
||||
|
||||
Assert.True(expecRounded == actRounded, $"Expected {nameof} '{expecRounded}' but got '{actRounded}'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (expected is Vector2)
|
||||
{
|
||||
var expectedVector = (Vector2)(object)expected;
|
||||
var actualVector = (Vector2)(object)actual!;
|
||||
|
||||
AssertEqual(expectedVector.X, actualVector.X, $"{nameof}.X");
|
||||
AssertEqual(expectedVector.Y, actualVector.Y, $"{nameof}.Y");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof(T).IsArray)
|
||||
{
|
||||
var expectedArray = (Array)(object)expected;
|
||||
var actualArray = (Array)(object)actual!;
|
||||
|
||||
Assert.NotNull(actualArray);
|
||||
AssertEqual(expectedArray.Length, actualArray.Length, $"{nameof}.Length");
|
||||
|
||||
for (var i = 0; i < expectedArray.Length; i++)
|
||||
AssertEqual(expectedArray.GetValue(i), actualArray.GetValue(i), $"{nameof}[{i}]");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
var expectedList = (IList)(object)expected;
|
||||
var actualList = (IList)(object)actual!;
|
||||
|
||||
Assert.NotNull(actualList);
|
||||
AssertEqual(expectedList.Count, actualList.Count, $"{nameof}.Count");
|
||||
|
||||
for (var i = 0; i < expectedList.Count; i++)
|
||||
AssertEqual(expectedList[i], actualList[i], $"{nameof}[{i}]");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.True(expected.Equals(actual), $"Expected {nameof} '{expected}' but got '{actual}'");
|
||||
}
|
||||
|
||||
internal static void AssertMap(Map expected, Map actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.Version, actual.Version, nameof(Map.Version));
|
||||
AssertEqual(expected.TiledVersion, actual.TiledVersion, nameof(Map.TiledVersion));
|
||||
AssertEqual(expected.Class, actual.Class, nameof(Map.Class));
|
||||
AssertEqual(expected.Orientation, actual.Orientation, nameof(Map.Orientation));
|
||||
AssertEqual(expected.RenderOrder, actual.RenderOrder, nameof(Map.RenderOrder));
|
||||
AssertEqual(expected.CompressionLevel, actual.CompressionLevel, nameof(Map.CompressionLevel));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Map.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Map.Height));
|
||||
AssertEqual(expected.TileWidth, actual.TileWidth, nameof(Map.TileWidth));
|
||||
AssertEqual(expected.TileHeight, actual.TileHeight, nameof(Map.TileHeight));
|
||||
AssertEqual(expected.HexSideLength, actual.HexSideLength, nameof(Map.HexSideLength));
|
||||
AssertEqual(expected.StaggerAxis, actual.StaggerAxis, nameof(Map.StaggerAxis));
|
||||
AssertEqual(expected.StaggerIndex, actual.StaggerIndex, nameof(Map.StaggerIndex));
|
||||
AssertEqual(expected.ParallaxOriginX, actual.ParallaxOriginX, nameof(Map.ParallaxOriginX));
|
||||
AssertEqual(expected.ParallaxOriginY, actual.ParallaxOriginY, nameof(Map.ParallaxOriginY));
|
||||
AssertEqual(expected.BackgroundColor, actual.BackgroundColor, nameof(Map.BackgroundColor));
|
||||
AssertEqual(expected.NextLayerID, actual.NextLayerID, nameof(Map.NextLayerID));
|
||||
AssertEqual(expected.NextObjectID, actual.NextObjectID, nameof(Map.NextObjectID));
|
||||
AssertEqual(expected.Infinite, actual.Infinite, nameof(Map.Infinite));
|
||||
|
||||
AssertProperties(actual.Properties, expected.Properties);
|
||||
|
||||
Assert.NotNull(actual.Tilesets);
|
||||
AssertEqual(expected.Tilesets.Count, actual.Tilesets.Count, "Tilesets.Count");
|
||||
for (var i = 0; i < expected.Tilesets.Count; i++)
|
||||
AssertTileset(expected.Tilesets[i], actual.Tilesets[i]);
|
||||
|
||||
Assert.NotNull(actual.Layers);
|
||||
AssertEqual(expected.Layers.Count, actual.Layers.Count, "Layers.Count");
|
||||
for (var i = 0; i < expected.Layers.Count; i++)
|
||||
AssertLayer(expected.Layers[i], actual.Layers[i]);
|
||||
}
|
||||
}
|
73
src/DotTiled.Tests/Assert/AssertObject.cs
Normal file
73
src/DotTiled.Tests/Assert/AssertObject.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertObject(Object expected, Object actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.ID, actual.ID, nameof(Object.ID));
|
||||
AssertEqual(expected.Name, actual.Name, nameof(Object.Name));
|
||||
AssertEqual(expected.Type, actual.Type, nameof(Object.Type));
|
||||
AssertEqual(expected.X, actual.X, nameof(Object.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(Object.Y));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Object.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Object.Height));
|
||||
AssertEqual(expected.Rotation, actual.Rotation, nameof(Object.Rotation));
|
||||
AssertEqual(expected.Visible, actual.Visible, nameof(Object.Visible));
|
||||
AssertEqual(expected.Template, actual.Template, nameof(Object.Template));
|
||||
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
|
||||
Assert.True(expected.GetType() == actual.GetType(), $"Expected object type {expected.GetType()} but got {actual.GetType()}");
|
||||
AssertObject((dynamic)expected, (dynamic)actual);
|
||||
}
|
||||
|
||||
private static void AssertObject(RectangleObject expected, RectangleObject actual)
|
||||
{
|
||||
Assert.True(true); // A rectangle object is the same as the abstract Object
|
||||
}
|
||||
|
||||
private static void AssertObject(EllipseObject expected, EllipseObject actual)
|
||||
{
|
||||
Assert.True(true); // An ellipse object is the same as the abstract Object
|
||||
}
|
||||
|
||||
private static void AssertObject(PointObject expected, PointObject actual)
|
||||
{
|
||||
Assert.True(true); // A point object is the same as the abstract Object
|
||||
}
|
||||
|
||||
private static void AssertObject(PolygonObject expected, PolygonObject actual)
|
||||
{
|
||||
AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points));
|
||||
}
|
||||
|
||||
private static void AssertObject(PolylineObject expected, PolylineObject actual)
|
||||
{
|
||||
AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points));
|
||||
}
|
||||
|
||||
private static void AssertObject(TextObject expected, TextObject actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.FontFamily, actual.FontFamily, nameof(TextObject.FontFamily));
|
||||
AssertEqual(expected.PixelSize, actual.PixelSize, nameof(TextObject.PixelSize));
|
||||
AssertEqual(expected.Wrap, actual.Wrap, nameof(TextObject.Wrap));
|
||||
AssertEqual(expected.Color, actual.Color, nameof(TextObject.Color));
|
||||
AssertEqual(expected.Bold, actual.Bold, nameof(TextObject.Bold));
|
||||
AssertEqual(expected.Italic, actual.Italic, nameof(TextObject.Italic));
|
||||
AssertEqual(expected.Underline, actual.Underline, nameof(TextObject.Underline));
|
||||
AssertEqual(expected.Strikeout, actual.Strikeout, nameof(TextObject.Strikeout));
|
||||
AssertEqual(expected.Kerning, actual.Kerning, nameof(TextObject.Kerning));
|
||||
AssertEqual(expected.HorizontalAlignment, actual.HorizontalAlignment, nameof(TextObject.HorizontalAlignment));
|
||||
AssertEqual(expected.VerticalAlignment, actual.VerticalAlignment, nameof(TextObject.VerticalAlignment));
|
||||
|
||||
AssertEqual(expected.Text, actual.Text, nameof(TextObject.Text));
|
||||
}
|
||||
|
||||
private static void AssertObject(TileObject expected, TileObject actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID));
|
||||
}
|
||||
}
|
69
src/DotTiled.Tests/Assert/AssertProperties.cs
Normal file
69
src/DotTiled.Tests/Assert/AssertProperties.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertProperties(Dictionary<string, IProperty>? expected, Dictionary<string, IProperty>? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.Count, actual.Count, "Properties.Count");
|
||||
foreach (var kvp in expected)
|
||||
{
|
||||
Assert.Contains(kvp.Key, actual.Keys);
|
||||
AssertProperty((dynamic)kvp.Value, (dynamic)actual[kvp.Key]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertProperty(IProperty expected, IProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Type, actual.Type, "Property.Type");
|
||||
AssertEqual(expected.Name, actual.Name, "Property.Name");
|
||||
AssertProperties((dynamic)actual, (dynamic)expected);
|
||||
}
|
||||
|
||||
private static void AssertProperty(StringProperty expected, StringProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "StringProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(IntProperty expected, IntProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "IntProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(FloatProperty expected, FloatProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "FloatProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(BoolProperty expected, BoolProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "BoolProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(ColorProperty expected, ColorProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "ColorProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(FileProperty expected, FileProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "FileProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(ObjectProperty expected, ObjectProperty actual)
|
||||
{
|
||||
AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value");
|
||||
}
|
||||
|
||||
private static void AssertProperty(ClassProperty expected, ClassProperty actual)
|
||||
{
|
||||
AssertEqual(expected.PropertyType, actual.PropertyType, "ClassProperty.PropertyType");
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
}
|
||||
}
|
160
src/DotTiled.Tests/Assert/AssertTileset.cs
Normal file
160
src/DotTiled.Tests/Assert/AssertTileset.cs
Normal file
|
@ -0,0 +1,160 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class DotTiledAssert
|
||||
{
|
||||
internal static void AssertTileset(Tileset expected, Tileset actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.Version, actual.Version, nameof(Tileset.Version));
|
||||
AssertEqual(expected.TiledVersion, actual.TiledVersion, nameof(Tileset.TiledVersion));
|
||||
AssertEqual(expected.FirstGID, actual.FirstGID, nameof(Tileset.FirstGID));
|
||||
AssertEqual(expected.Source, actual.Source, nameof(Tileset.Source));
|
||||
AssertEqual(expected.Name, actual.Name, nameof(Tileset.Name));
|
||||
AssertEqual(expected.Class, actual.Class, nameof(Tileset.Class));
|
||||
AssertEqual(expected.TileWidth, actual.TileWidth, nameof(Tileset.TileWidth));
|
||||
AssertEqual(expected.TileHeight, actual.TileHeight, nameof(Tileset.TileHeight));
|
||||
AssertEqual(expected.Spacing, actual.Spacing, nameof(Tileset.Spacing));
|
||||
AssertEqual(expected.Margin, actual.Margin, nameof(Tileset.Margin));
|
||||
AssertEqual(expected.TileCount, actual.TileCount, nameof(Tileset.TileCount));
|
||||
AssertEqual(expected.Columns, actual.Columns, nameof(Tileset.Columns));
|
||||
AssertEqual(expected.ObjectAlignment, actual.ObjectAlignment, nameof(Tileset.ObjectAlignment));
|
||||
AssertEqual(expected.RenderSize, actual.RenderSize, nameof(Tileset.RenderSize));
|
||||
AssertEqual(expected.FillMode, actual.FillMode, nameof(Tileset.FillMode));
|
||||
|
||||
// At most one of
|
||||
AssertImage(expected.Image, actual.Image);
|
||||
AssertTileOffset(expected.TileOffset, actual.TileOffset);
|
||||
AssertGrid(expected.Grid, actual.Grid);
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
// TODO: AssertTerrainTypes(actual.TerrainTypes, expected.TerrainTypes);
|
||||
if (expected.Wangsets is not null)
|
||||
{
|
||||
Assert.NotNull(actual.Wangsets);
|
||||
AssertEqual(expected.Wangsets.Count, actual.Wangsets.Count, "Wangsets.Count");
|
||||
for (var i = 0; i < expected.Wangsets.Count; i++)
|
||||
AssertWangset(expected.Wangsets[i], actual.Wangsets[i]);
|
||||
}
|
||||
AssertTransformations(expected.Transformations, actual.Transformations);
|
||||
|
||||
// Any number of
|
||||
Assert.NotNull(actual.Tiles);
|
||||
AssertEqual(expected.Tiles.Count, actual.Tiles.Count, "Tiles.Count");
|
||||
for (var i = 0; i < expected.Tiles.Count; i++)
|
||||
AssertTile(expected.Tiles[i], actual.Tiles[i]);
|
||||
}
|
||||
|
||||
private static void AssertTileOffset(TileOffset? expected, TileOffset? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.X, actual.X, nameof(TileOffset.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(TileOffset.Y));
|
||||
}
|
||||
|
||||
private static void AssertGrid(Grid? expected, Grid? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.Orientation, actual.Orientation, nameof(Grid.Orientation));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Grid.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Grid.Height));
|
||||
}
|
||||
|
||||
private static void AssertWangset(Wangset expected, Wangset actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.Name, actual.Name, nameof(Wangset.Name));
|
||||
AssertEqual(expected.Class, actual.Class, nameof(Wangset.Class));
|
||||
AssertEqual(expected.Tile, actual.Tile, nameof(Wangset.Tile));
|
||||
|
||||
// At most one of
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
if (expected.WangColors is not null)
|
||||
{
|
||||
Assert.NotNull(actual.WangColors);
|
||||
AssertEqual(expected.WangColors.Count, actual.WangColors.Count, "WangColors.Count");
|
||||
for (var i = 0; i < expected.WangColors.Count; i++)
|
||||
AssertWangColor(expected.WangColors[i], actual.WangColors[i]);
|
||||
}
|
||||
for (var i = 0; i < expected.WangTiles.Count; i++)
|
||||
AssertWangTile(expected.WangTiles[i], actual.WangTiles[i]);
|
||||
}
|
||||
|
||||
private static void AssertWangColor(WangColor expected, WangColor actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.Name, actual.Name, nameof(WangColor.Name));
|
||||
AssertEqual(expected.Class, actual.Class, nameof(WangColor.Class));
|
||||
AssertEqual(expected.Color, actual.Color, nameof(WangColor.Color));
|
||||
AssertEqual(expected.Tile, actual.Tile, nameof(WangColor.Tile));
|
||||
AssertEqual(expected.Probability, actual.Probability, nameof(WangColor.Probability));
|
||||
|
||||
AssertProperties(expected.Properties, actual.Properties);
|
||||
}
|
||||
|
||||
private static void AssertWangTile(WangTile expected, WangTile actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.TileID, actual.TileID, nameof(WangTile.TileID));
|
||||
AssertEqual(expected.WangID, actual.WangID, nameof(WangTile.WangID));
|
||||
}
|
||||
|
||||
private static void AssertTransformations(Transformations? expected, Transformations? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
Assert.NotNull(actual);
|
||||
AssertEqual(expected.HFlip, actual.HFlip, nameof(Transformations.HFlip));
|
||||
AssertEqual(expected.VFlip, actual.VFlip, nameof(Transformations.VFlip));
|
||||
AssertEqual(expected.Rotate, actual.Rotate, nameof(Transformations.Rotate));
|
||||
AssertEqual(expected.PreferUntransformed, actual.PreferUntransformed, nameof(Transformations.PreferUntransformed));
|
||||
}
|
||||
|
||||
private static void AssertTile(Tile expected, Tile actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.ID, actual.ID, nameof(Tile.ID));
|
||||
AssertEqual(expected.Type, actual.Type, nameof(Tile.Type));
|
||||
AssertEqual(expected.Probability, actual.Probability, nameof(Tile.Probability));
|
||||
AssertEqual(expected.X, actual.X, nameof(Tile.X));
|
||||
AssertEqual(expected.Y, actual.Y, nameof(Tile.Y));
|
||||
AssertEqual(expected.Width, actual.Width, nameof(Tile.Width));
|
||||
AssertEqual(expected.Height, actual.Height, nameof(Tile.Height));
|
||||
|
||||
// Elements
|
||||
AssertProperties(actual.Properties, expected.Properties);
|
||||
AssertImage(actual.Image, expected.Image);
|
||||
AssertLayer((BaseLayer?)actual.ObjectLayer, (BaseLayer?)expected.ObjectLayer);
|
||||
if (expected.Animation is not null)
|
||||
{
|
||||
Assert.NotNull(actual.Animation);
|
||||
AssertEqual(expected.Animation.Count, actual.Animation.Count, "Animation.Count");
|
||||
for (var i = 0; i < expected.Animation.Count; i++)
|
||||
AssertFrame(expected.Animation[i], actual.Animation[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertFrame(Frame expected, Frame actual)
|
||||
{
|
||||
// Attributes
|
||||
AssertEqual(expected.TileID, actual.TileID, nameof(Frame.TileID));
|
||||
AssertEqual(expected.Duration, actual.Duration, nameof(Frame.Duration));
|
||||
}
|
||||
}
|
32
src/DotTiled.Tests/DotTiled.Tests.csproj
Normal file
32
src/DotTiled.Tests/DotTiled.Tests.csproj
Normal file
|
@ -0,0 +1,32 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotTiled\DotTiled.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Test data -->
|
||||
<EmbeddedResource Include="Serialization/TestData/**/*" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
79
src/DotTiled.Tests/Serialization/TestData.cs
Normal file
79
src/DotTiled.Tests/Serialization/TestData.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System.Xml;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public static partial class TestData
|
||||
{
|
||||
public static XmlReader GetXmlReaderFor(string testDataFile)
|
||||
{
|
||||
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
||||
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
||||
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
||||
|
||||
using var stringReader = new StreamReader(stream);
|
||||
var xml = stringReader.ReadToEnd();
|
||||
var xmlStringReader = new StringReader(xml);
|
||||
return XmlReader.Create(xmlStringReader);
|
||||
}
|
||||
|
||||
public static string GetRawStringFor(string testDataFile)
|
||||
{
|
||||
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
||||
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
||||
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
||||
|
||||
using var stringReader = new StreamReader(stream);
|
||||
return stringReader.ReadToEnd();
|
||||
}
|
||||
|
||||
private static string ConvertPathToAssemblyResourcePath(string path) =>
|
||||
path.Replace("/", ".").Replace("\\", ".").Replace(" ", "_");
|
||||
|
||||
public static IEnumerable<object[]> MapTests =>
|
||||
[
|
||||
["Serialization/TestData/Map/default_map/default-map", (string f) => TestData.DefaultMap(), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => TestData.MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => TestData.MapWithCustomTypeProps(), TestData.MapWithCustomTypePropsCustomTypeDefinitions()],
|
||||
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => TestData.MapWithEmbeddedTileset(), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => TestData.MapWithExternalTileset(f), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => TestData.MapWithFlippingFlags(f), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => TestData.MapExternalTilesetMulti(f), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => TestData.MapExternalTilesetWangset(f), Array.Empty<CustomTypeDefinition>()],
|
||||
["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => TestData.MapWithManyLayers(f), Array.Empty<CustomTypeDefinition>()],
|
||||
];
|
||||
|
||||
private static CustomTypeDefinition[] typedefs = [
|
||||
new CustomClassDefinition
|
||||
{
|
||||
Name = "TestClass",
|
||||
ID = 1,
|
||||
UseAs = CustomClassUseAs.Property,
|
||||
Members = [
|
||||
new StringProperty
|
||||
{
|
||||
Name = "Name",
|
||||
Value = ""
|
||||
},
|
||||
new FloatProperty
|
||||
{
|
||||
Name = "Amount",
|
||||
Value = 0f
|
||||
}
|
||||
]
|
||||
},
|
||||
new CustomClassDefinition
|
||||
{
|
||||
Name = "Test",
|
||||
ID = 2,
|
||||
UseAs = CustomClassUseAs.All,
|
||||
Members = [
|
||||
new ClassProperty
|
||||
{
|
||||
Name = "Yep",
|
||||
PropertyType = "TestClass",
|
||||
Properties = []
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map DefaultMap() => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 },
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
|
@ -0,0 +1,121 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapExternalTilesetMulti(string fileExt) => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
TileOffset = new TileOffset
|
||||
{
|
||||
X = 1,
|
||||
Y = 5
|
||||
},
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
FirstGID = 1,
|
||||
Name = "multi-tileset",
|
||||
TileWidth = 256,
|
||||
TileHeight = 96,
|
||||
TileCount = 2,
|
||||
Columns = 0,
|
||||
Source = $"multi-tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
|
||||
Grid = new Grid
|
||||
{
|
||||
Orientation = GridOrientation.Orthogonal,
|
||||
Width = 1,
|
||||
Height = 1
|
||||
},
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["tilesetbool"] = new BoolProperty { Name = "tilesetbool", Value = true },
|
||||
["tilesetcolor"] = new ColorProperty { Name = "tilesetcolor", Value = Color.Parse("#ffff0000", CultureInfo.InvariantCulture) },
|
||||
["tilesetfile"] = new FileProperty { Name = "tilesetfile", Value = "" },
|
||||
["tilesetfloat"] = new FloatProperty { Name = "tilesetfloat", Value = 5.2f },
|
||||
["tilesetint"] = new IntProperty { Name = "tilesetint", Value = 9 },
|
||||
["tilesetobject"] = new ObjectProperty { Name = "tilesetobject", Value = 0 },
|
||||
["tilesetstring"] = new StringProperty { Name = "tilesetstring", Value = "hello world!" }
|
||||
},
|
||||
Tiles = [
|
||||
new Tile
|
||||
{
|
||||
ID = 0,
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96
|
||||
}
|
||||
},
|
||||
new Tile
|
||||
{
|
||||
ID = 1,
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 2, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 2, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"multi-tileset.tsj"
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="multi-tileset.tsx"/>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
1,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,2,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
|
@ -0,0 +1,71 @@
|
|||
{ "columns":0,
|
||||
"grid":
|
||||
{
|
||||
"height":1,
|
||||
"orientation":"orthogonal",
|
||||
"width":1
|
||||
},
|
||||
"margin":0,
|
||||
"name":"multi-tileset",
|
||||
"properties":[
|
||||
{
|
||||
"name":"tilesetbool",
|
||||
"type":"bool",
|
||||
"value":true
|
||||
},
|
||||
{
|
||||
"name":"tilesetcolor",
|
||||
"type":"color",
|
||||
"value":"#ffff0000"
|
||||
},
|
||||
{
|
||||
"name":"tilesetfile",
|
||||
"type":"file",
|
||||
"value":""
|
||||
},
|
||||
{
|
||||
"name":"tilesetfloat",
|
||||
"type":"float",
|
||||
"value":5.2
|
||||
},
|
||||
{
|
||||
"name":"tilesetint",
|
||||
"type":"int",
|
||||
"value":9
|
||||
},
|
||||
{
|
||||
"name":"tilesetobject",
|
||||
"type":"object",
|
||||
"value":0
|
||||
},
|
||||
{
|
||||
"name":"tilesetstring",
|
||||
"type":"string",
|
||||
"value":"hello world!"
|
||||
}],
|
||||
"spacing":0,
|
||||
"tilecount":2,
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":96,
|
||||
"tileoffset":
|
||||
{
|
||||
"x":1,
|
||||
"y":5
|
||||
},
|
||||
"tiles":[
|
||||
{
|
||||
"id":0,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256
|
||||
},
|
||||
{
|
||||
"id":1,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256
|
||||
}],
|
||||
"tilewidth":256,
|
||||
"type":"tileset",
|
||||
"version":"1.10"
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.10" tiledversion="1.11.0" name="multi-tileset" tilewidth="256" tileheight="96" tilecount="2" columns="0">
|
||||
<tileoffset x="1" y="5"/>
|
||||
<grid orientation="orthogonal" width="1" height="1"/>
|
||||
<properties>
|
||||
<property name="tilesetbool" type="bool" value="true"/>
|
||||
<property name="tilesetcolor" type="color" value="#ffff0000"/>
|
||||
<property name="tilesetfile" type="file" value=""/>
|
||||
<property name="tilesetfloat" type="float" value="5.2"/>
|
||||
<property name="tilesetint" type="int" value="9"/>
|
||||
<property name="tilesetobject" type="object" value="0"/>
|
||||
<property name="tilesetstring" value="hello world!"/>
|
||||
</properties>
|
||||
<tile id="0">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tile>
|
||||
<tile id="1">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tile>
|
||||
</tileset>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,92 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapExternalTilesetWangset(string fileExt) => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 24,
|
||||
TileHeight = 24,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
FirstGID = 1,
|
||||
Name = "tileset",
|
||||
TileWidth = 24,
|
||||
TileHeight = 24,
|
||||
TileCount = 48,
|
||||
Columns = 10,
|
||||
Source = $"wangset-tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
|
||||
Transformations = new Transformations
|
||||
{
|
||||
HFlip = true,
|
||||
VFlip = true,
|
||||
Rotate = false,
|
||||
PreferUntransformed = false
|
||||
},
|
||||
Grid = new Grid
|
||||
{
|
||||
Orientation = GridOrientation.Orthogonal,
|
||||
Width = 32,
|
||||
Height = 32
|
||||
},
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
}
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
2, 2, 12, 11, 0,
|
||||
1, 12, 1, 11, 0,
|
||||
2, 1, 0, 1, 0,
|
||||
12, 11, 12, 2, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.FlippedHorizontally, FlippingFlags.None, FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.None,
|
||||
FlippingFlags.FlippedVertically, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically | FlippingFlags.FlippedHorizontally, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically | FlippingFlags.FlippedHorizontally, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedHorizontally, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[2147483650, 2, 2147483660, 2147483659, 0,
|
||||
1073741825, 12, 1, 3221225483, 0,
|
||||
2, 1, 0, 3221225473, 0,
|
||||
12, 11, 12, 2147483650, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":24,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"wangset-tileset.tsj"
|
||||
}],
|
||||
"tilewidth":24,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="24" tileheight="24" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="wangset-tileset.tsx"/>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
2147483650,2,2147483660,2147483659,0,
|
||||
1073741825,12,1,3221225483,0,
|
||||
2,1,0,3221225473,0,
|
||||
12,11,12,2147483650,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,69 @@
|
|||
{ "columns":10,
|
||||
"grid":
|
||||
{
|
||||
"height":32,
|
||||
"orientation":"orthogonal",
|
||||
"width":32
|
||||
},
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"tileset",
|
||||
"spacing":0,
|
||||
"tilecount":48,
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":24,
|
||||
"tilewidth":24,
|
||||
"transformations":
|
||||
{
|
||||
"hflip":true,
|
||||
"preferuntransformed":false,
|
||||
"rotate":false,
|
||||
"vflip":true
|
||||
},
|
||||
"type":"tileset",
|
||||
"version":"1.10",
|
||||
"wangsets":[
|
||||
{
|
||||
"colors":[
|
||||
{
|
||||
"color":"#ff0000",
|
||||
"name":"Water",
|
||||
"probability":1,
|
||||
"tile":0
|
||||
},
|
||||
{
|
||||
"color":"#00ff00",
|
||||
"name":"Grass",
|
||||
"probability":1,
|
||||
"tile":-1
|
||||
},
|
||||
{
|
||||
"color":"#0000ff",
|
||||
"name":"Stone",
|
||||
"probability":1,
|
||||
"tile":29
|
||||
}],
|
||||
"name":"test-terrain",
|
||||
"tile":-1,
|
||||
"type":"mixed",
|
||||
"wangtiles":[
|
||||
{
|
||||
"tileid":0,
|
||||
"wangid":[1, 1, 0, 0, 0, 1, 1, 1]
|
||||
},
|
||||
{
|
||||
"tileid":1,
|
||||
"wangid":[1, 1, 1, 1, 0, 0, 0, 1]
|
||||
},
|
||||
{
|
||||
"tileid":10,
|
||||
"wangid":[0, 0, 0, 1, 1, 1, 1, 1]
|
||||
},
|
||||
{
|
||||
"tileid":11,
|
||||
"wangid":[0, 1, 1, 1, 1, 1, 0, 0]
|
||||
}]
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.10" tiledversion="1.11.0" name="tileset" tilewidth="24" tileheight="24" tilecount="48" columns="10">
|
||||
<grid orientation="orthogonal" width="32" height="32"/>
|
||||
<transformations hflip="1" vflip="1" rotate="0" preferuntransformed="0"/>
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
<wangsets>
|
||||
<wangset name="test-terrain" type="mixed" tile="-1">
|
||||
<wangcolor name="Water" color="#ff0000" tile="0" probability="1"/>
|
||||
<wangcolor name="Grass" color="#00ff00" tile="-1" probability="1"/>
|
||||
<wangcolor name="Stone" color="#0000ff" tile="29" probability="1"/>
|
||||
<wangtile tileid="0" wangid="1,1,0,0,0,1,1,1"/>
|
||||
<wangtile tileid="1" wangid="1,1,1,1,0,0,0,1"/>
|
||||
<wangtile tileid="10" wangid="0,0,0,1,1,1,1,1"/>
|
||||
<wangtile tileid="11" wangid="0,1,1,1,1,1,0,0"/>
|
||||
</wangset>
|
||||
</wangsets>
|
||||
</tileset>
|
|
@ -0,0 +1,68 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithCommonProps() => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Isometric,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 16,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00ff00", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["boolprop"] = new BoolProperty { Name = "boolprop", Value = true },
|
||||
["colorprop"] = new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) },
|
||||
["fileprop"] = new FileProperty { Name = "fileprop", Value = "file.txt" },
|
||||
["floatprop"] = new FloatProperty { Name = "floatprop", Value = 4.2f },
|
||||
["intprop"] = new IntProperty { Name = "intprop", Value = 8 },
|
||||
["objectprop"] = new ObjectProperty { Name = "objectprop", Value = 5 },
|
||||
["stringprop"] = new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
{ "backgroundcolor":"#00ff00",
|
||||
"compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"isometric",
|
||||
"properties":[
|
||||
{
|
||||
"name":"boolprop",
|
||||
"type":"bool",
|
||||
"value":true
|
||||
},
|
||||
{
|
||||
"name":"colorprop",
|
||||
"type":"color",
|
||||
"value":"#ff55ffff"
|
||||
},
|
||||
{
|
||||
"name":"fileprop",
|
||||
"type":"file",
|
||||
"value":"file.txt"
|
||||
},
|
||||
{
|
||||
"name":"floatprop",
|
||||
"type":"float",
|
||||
"value":4.2
|
||||
},
|
||||
{
|
||||
"name":"intprop",
|
||||
"type":"int",
|
||||
"value":8
|
||||
},
|
||||
|
||||
{
|
||||
"name":"objectprop",
|
||||
"type":"object",
|
||||
"value":5
|
||||
},
|
||||
{
|
||||
"name":"stringprop",
|
||||
"type":"string",
|
||||
"value":"This is a string, hello world!"
|
||||
}],
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":16,
|
||||
"tilesets":[],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="isometric" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="16" infinite="0" backgroundcolor="#00ff00" nextlayerid="2" nextobjectid="1">
|
||||
<properties>
|
||||
<property name="boolprop" type="bool" value="true"/>
|
||||
<property name="colorprop" type="color" value="#ff55ffff"/>
|
||||
<property name="fileprop" type="file" value="file.txt"/>
|
||||
<property name="floatprop" type="float" value="4.2"/>
|
||||
<property name="intprop" type="int" value="8"/>
|
||||
<property name="objectprop" type="object" value="5"/>
|
||||
<property name="stringprop" value="This is a string, hello world!"/>
|
||||
</properties>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
|
@ -0,0 +1,122 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithCustomTypeProps() => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["customclassprop"] = new ClassProperty
|
||||
{
|
||||
Name = "customclassprop",
|
||||
PropertyType = "CustomClass",
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["boolinclass"] = new BoolProperty { Name = "boolinclass", Value = true },
|
||||
["colorinclass"] = new ColorProperty { Name = "colorinclass", Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture) },
|
||||
["fileinclass"] = new FileProperty { Name = "fileinclass", Value = "" },
|
||||
["floatinclass"] = new FloatProperty { Name = "floatinclass", Value = 13.37f },
|
||||
["intinclass"] = new IntProperty { Name = "intinclass", Value = 0 },
|
||||
["objectinclass"] = new ObjectProperty { Name = "objectinclass", Value = 0 },
|
||||
["stringinclass"] = new StringProperty { Name = "stringinclass", Value = "This is a set string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// This comes from map-with-custom-type-props/propertytypes.json
|
||||
public static IReadOnlyCollection<CustomTypeDefinition> MapWithCustomTypePropsCustomTypeDefinitions() => [
|
||||
new CustomClassDefinition
|
||||
{
|
||||
Name = "CustomClass",
|
||||
UseAs = CustomClassUseAs.Property,
|
||||
Members = [
|
||||
new BoolProperty
|
||||
{
|
||||
Name = "boolinclass",
|
||||
Value = false
|
||||
},
|
||||
new ColorProperty
|
||||
{
|
||||
Name = "colorinclass",
|
||||
Value = Color.Parse("#000000ff", CultureInfo.InvariantCulture)
|
||||
},
|
||||
new FileProperty
|
||||
{
|
||||
Name = "fileinclass",
|
||||
Value = ""
|
||||
},
|
||||
new FloatProperty
|
||||
{
|
||||
Name = "floatinclass",
|
||||
Value = 0f
|
||||
},
|
||||
new IntProperty
|
||||
{
|
||||
Name = "intinclass",
|
||||
Value = 0
|
||||
},
|
||||
new ObjectProperty
|
||||
{
|
||||
Name = "objectinclass",
|
||||
Value = 0
|
||||
},
|
||||
new StringProperty
|
||||
{
|
||||
Name = "stringinclass",
|
||||
Value = ""
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"properties":[
|
||||
{
|
||||
"name":"customclassprop",
|
||||
"propertytype":"CustomClass",
|
||||
"type":"class",
|
||||
"value":
|
||||
{
|
||||
"boolinclass":true,
|
||||
"floatinclass":13.37,
|
||||
"stringinclass":"This is a set string"
|
||||
}
|
||||
}],
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<properties>
|
||||
<property name="customclassprop" type="class" propertytype="CustomClass">
|
||||
<properties>
|
||||
<property name="boolinclass" type="bool" value="true"/>
|
||||
<property name="floatinclass" type="float" value="13.37"/>
|
||||
<property name="stringinclass" value="This is a set string"/>
|
||||
</properties>
|
||||
</property>
|
||||
</properties>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
|
@ -0,0 +1,49 @@
|
|||
[
|
||||
{
|
||||
"color": "#ffa0a0a4",
|
||||
"drawFill": true,
|
||||
"id": 8,
|
||||
"members": [
|
||||
{
|
||||
"name": "boolinclass",
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "colorinclass",
|
||||
"type": "color",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "fileinclass",
|
||||
"type": "file",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "floatinclass",
|
||||
"type": "float",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"name": "intinclass",
|
||||
"type": "int",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"name": "objectinclass",
|
||||
"type": "object",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"name": "stringinclass",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"name": "CustomClass",
|
||||
"type": "class",
|
||||
"useAs": [
|
||||
"property"
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,76 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithEmbeddedTileset() => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
FirstGID = 1,
|
||||
Name = "tileset",
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
TileCount = 24,
|
||||
Columns = 8,
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
}
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
1, 1, 0, 0, 7,
|
||||
1, 1, 0, 0, 7,
|
||||
0, 0, 0, 0, 7,
|
||||
9, 10, 0, 0, 7,
|
||||
17, 18, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[1, 1, 0, 0, 7,
|
||||
1, 1, 0, 0, 7,
|
||||
0, 0, 0, 0, 7,
|
||||
9, 10, 0, 0, 7,
|
||||
17, 18, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"columns":8,
|
||||
"firstgid":1,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"tileset",
|
||||
"spacing":0,
|
||||
"tilecount":24,
|
||||
"tileheight":32,
|
||||
"tilewidth":32
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" name="tileset" tilewidth="32" tileheight="32" tilecount="24" columns="8">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tileset>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
1,1,0,0,7,
|
||||
1,1,0,0,7,
|
||||
0,0,0,0,7,
|
||||
9,10,0,0,7,
|
||||
17,18,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,79 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithExternalTileset(string fileExt) => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
FirstGID = 1,
|
||||
Name = "tileset",
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
TileCount = 24,
|
||||
Columns = 8,
|
||||
Source = $"tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
}
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
1, 1, 0, 0, 7,
|
||||
1, 1, 0, 0, 7,
|
||||
0, 0, 1, 0, 7,
|
||||
0, 0, 0, 1, 7,
|
||||
21, 21, 21, 21, 1
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[1, 1, 0, 0, 7,
|
||||
1, 1, 0, 0, 7,
|
||||
0, 0, 1, 0, 7,
|
||||
0, 0, 0, 1, 7,
|
||||
21, 21, 21, 21, 1],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"tileset.tsj"
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
1,1,0,0,7,
|
||||
1,1,0,0,7,
|
||||
0,0,1,0,7,
|
||||
0,0,0,1,7,
|
||||
21,21,21,21,1
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,14 @@
|
|||
{ "columns":8,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"tileset",
|
||||
"spacing":0,
|
||||
"tilecount":24,
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilewidth":32,
|
||||
"type":"tileset",
|
||||
"version":"1.10"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.10" tiledversion="1.11.0" name="tileset" tilewidth="32" tileheight="32" tilecount="24" columns="8">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tileset>
|
|
@ -0,0 +1,79 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithFlippingFlags(string fileExt) => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture),
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 2,
|
||||
NextObjectID = 1,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
FirstGID = 1,
|
||||
Name = "tileset",
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
TileCount = 24,
|
||||
Columns = 8,
|
||||
Source = $"tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
}
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
1, 1, 0, 0, 7,
|
||||
1, 1, 0, 0, 7,
|
||||
0, 0, 1, 0, 7,
|
||||
0, 0, 0, 1, 7,
|
||||
21, 21, 21, 21, 1
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.FlippedDiagonally | FlippingFlags.FlippedHorizontally, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically,
|
||||
FlippingFlags.FlippedDiagonally | FlippingFlags.FlippedVertically, FlippingFlags.FlippedVertically | FlippingFlags.FlippedHorizontally, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.FlippedVertically,
|
||||
FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[1, 2684354561, 0, 0, 1073741831,
|
||||
1610612737, 3221225473, 0, 0, 1073741831,
|
||||
0, 0, 1, 0, 1073741831,
|
||||
0, 0, 0, 1, 1073741831,
|
||||
2147483669, 2147483669, 2147483669, 2147483669, 1],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"tileset.tsj"
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
1,2684354561,0,0,1073741831,
|
||||
1610612737,3221225473,0,0,1073741831,
|
||||
0,0,1,0,1073741831,
|
||||
0,0,0,1,1073741831,
|
||||
2147483669,2147483669,2147483669,2147483669,1
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,14 @@
|
|||
{ "columns":8,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"tileset",
|
||||
"spacing":0,
|
||||
"tilecount":24,
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilewidth":32,
|
||||
"type":"tileset",
|
||||
"version":"1.10"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.10" tiledversion="1.11.0" name="tileset" tilewidth="32" tileheight="32" tilecount="24" columns="8">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tileset>
|
|
@ -0,0 +1,219 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TestData
|
||||
{
|
||||
public static Map MapWithManyLayers(string fileExt) => new Map
|
||||
{
|
||||
Class = "",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
HexSideLength = null,
|
||||
StaggerAxis = null,
|
||||
StaggerIndex = null,
|
||||
ParallaxOriginX = 0,
|
||||
ParallaxOriginY = 0,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
CompressionLevel = -1,
|
||||
BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 },
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
NextLayerID = 8,
|
||||
NextObjectID = 7,
|
||||
Tilesets = [
|
||||
new Tileset
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
FirstGID = 1,
|
||||
Name = "tileset",
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
TileCount = 24,
|
||||
Columns = 8,
|
||||
Source = $"tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = 256,
|
||||
Height = 96,
|
||||
}
|
||||
}
|
||||
],
|
||||
Layers = [
|
||||
new Group
|
||||
{
|
||||
ID = 2,
|
||||
Name = "Root",
|
||||
Layers = [
|
||||
new ObjectLayer
|
||||
{
|
||||
ID = 3,
|
||||
Name = "Objects",
|
||||
Objects = [
|
||||
new RectangleObject
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Object 1",
|
||||
X = 25.6667f,
|
||||
Y = 28.6667f,
|
||||
Width = 31.3333f,
|
||||
Height = 31.3333f
|
||||
},
|
||||
new PointObject
|
||||
{
|
||||
ID = 3,
|
||||
Name = "P1",
|
||||
X = 117.667f,
|
||||
Y = 48.6667f
|
||||
},
|
||||
new EllipseObject
|
||||
{
|
||||
ID = 4,
|
||||
Name = "Circle1",
|
||||
X = 77f,
|
||||
Y = 72.3333f,
|
||||
Width = 34.6667f,
|
||||
Height = 34.6667f
|
||||
},
|
||||
new PolygonObject
|
||||
{
|
||||
ID = 5,
|
||||
Name = "Poly",
|
||||
X = 20.6667f,
|
||||
Y = 114.667f,
|
||||
Points = [
|
||||
new Vector2(0, 0),
|
||||
new Vector2(104,20),
|
||||
new Vector2(35.6667f, 32.3333f)
|
||||
],
|
||||
Template = fileExt == "tmx" ? "poly.tx" : "poly.tj",
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["templateprop"] = new StringProperty { Name = "templateprop", Value = "helo there" }
|
||||
}
|
||||
},
|
||||
new TileObject
|
||||
{
|
||||
ID = 6,
|
||||
Name = "TileObj",
|
||||
GID = 7,
|
||||
X = -35,
|
||||
Y = 110.333f,
|
||||
Width = 64,
|
||||
Height = 146
|
||||
}
|
||||
]
|
||||
},
|
||||
new Group
|
||||
{
|
||||
ID = 5,
|
||||
Name = "Sub",
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 7,
|
||||
Name = "Tile 3",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
},
|
||||
new TileLayer
|
||||
{
|
||||
ID = 6,
|
||||
Name = "Tile 2",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
0, 15, 15, 0, 0,
|
||||
0, 15, 15, 0, 0,
|
||||
0, 15, 15, 15, 0,
|
||||
15, 15, 15, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
new ImageLayer
|
||||
{
|
||||
ID = 4,
|
||||
Name = "ImageLayer",
|
||||
Image = new Image
|
||||
{
|
||||
Format = ImageFormat.Png,
|
||||
Source = "tileset.png",
|
||||
Width = fileExt == "tmx" ? 256u : 0, // Currently, json format does not
|
||||
Height = fileExt == "tmx" ? 96u : 0 // include image dimensions in image layer https://github.com/mapeditor/tiled/issues/4028
|
||||
},
|
||||
RepeatX = true
|
||||
},
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
Chunks = null,
|
||||
Compression = null,
|
||||
GlobalTileIDs = [
|
||||
1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
FlippingFlags = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
{ "compressionlevel":-1,
|
||||
"height":5,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"id":2,
|
||||
"layers":[
|
||||
{
|
||||
"draworder":"topdown",
|
||||
"id":3,
|
||||
"name":"Objects",
|
||||
"objects":[
|
||||
{
|
||||
"height":31.3333,
|
||||
"id":1,
|
||||
"name":"Object 1",
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":31.3333,
|
||||
"x":25.6667,
|
||||
"y":28.6667
|
||||
},
|
||||
{
|
||||
"height":0,
|
||||
"id":3,
|
||||
"name":"P1",
|
||||
"point":true,
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":117.667,
|
||||
"y":48.6667
|
||||
},
|
||||
{
|
||||
"ellipse":true,
|
||||
"height":34.6667,
|
||||
"id":4,
|
||||
"name":"Circle1",
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":34.6667,
|
||||
"x":77,
|
||||
"y":72.3333
|
||||
},
|
||||
{
|
||||
"id":5,
|
||||
"template":"poly.tj",
|
||||
"x":20.6667,
|
||||
"y":114.667
|
||||
},
|
||||
{
|
||||
"gid":7,
|
||||
"height":146,
|
||||
"id":6,
|
||||
"name":"TileObj",
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":64,
|
||||
"x":-35,
|
||||
"y":110.333
|
||||
}],
|
||||
"opacity":1,
|
||||
"type":"objectgroup",
|
||||
"visible":true,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"id":5,
|
||||
"layers":[
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":7,
|
||||
"name":"Tile 3",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"data":[0, 15, 15, 0, 0,
|
||||
0, 15, 15, 0, 0,
|
||||
0, 15, 15, 15, 0,
|
||||
15, 15, 15, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":6,
|
||||
"name":"Tile 2",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"name":"Sub",
|
||||
"opacity":1,
|
||||
"type":"group",
|
||||
"visible":true,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"id":4,
|
||||
"image":"tileset.png",
|
||||
"name":"ImageLayer",
|
||||
"opacity":1,
|
||||
"repeatx":true,
|
||||
"type":"imagelayer",
|
||||
"visible":true,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"data":[1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0],
|
||||
"height":5,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":5,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"name":"Root",
|
||||
"opacity":1,
|
||||
"type":"group",
|
||||
"visible":true,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":8,
|
||||
"nextobjectid":7,
|
||||
"orientation":"orthogonal",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"tileset.tsj"
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.10",
|
||||
"width":5
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="8" nextobjectid="7">
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<group id="2" name="Root">
|
||||
<objectgroup id="3" name="Objects">
|
||||
<object id="1" name="Object 1" x="25.6667" y="28.6667" width="31.3333" height="31.3333"/>
|
||||
<object id="3" name="P1" x="117.667" y="48.6667">
|
||||
<point/>
|
||||
</object>
|
||||
<object id="4" name="Circle1" x="77" y="72.3333" width="34.6667" height="34.6667">
|
||||
<ellipse/>
|
||||
</object>
|
||||
<object id="5" template="poly.tx" x="20.6667" y="114.667"/>
|
||||
<object id="6" name="TileObj" gid="7" x="-35" y="110.333" width="64" height="146"/>
|
||||
</objectgroup>
|
||||
<group id="5" name="Sub">
|
||||
<layer id="7" name="Tile 3" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
<layer id="6" name="Tile 2" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
0,15,15,0,0,
|
||||
0,15,15,0,0,
|
||||
0,15,15,15,0,
|
||||
15,15,15,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</group>
|
||||
<imagelayer id="4" name="ImageLayer" repeatx="1">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</imagelayer>
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
1,1,1,1,1,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
</group>
|
||||
</map>
|
|
@ -0,0 +1,31 @@
|
|||
{ "object":
|
||||
{
|
||||
"height":0,
|
||||
"id":5,
|
||||
"name":"Poly",
|
||||
"polygon":[
|
||||
{
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"x":104,
|
||||
"y":20
|
||||
},
|
||||
{
|
||||
"x":35.6667,
|
||||
"y":32.3333
|
||||
}],
|
||||
"properties":[
|
||||
{
|
||||
"name":"templateprop",
|
||||
"type":"string",
|
||||
"value":"helo there"
|
||||
}],
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":0
|
||||
},
|
||||
"type":"template"
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<object name="Poly">
|
||||
<properties>
|
||||
<property name="templateprop" value="helo there"/>
|
||||
</properties>
|
||||
<polygon points="0,0 104,20 35.6667,32.3333"/>
|
||||
</object>
|
||||
</template>
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,14 @@
|
|||
{ "columns":8,
|
||||
"image":"tileset.png",
|
||||
"imageheight":96,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"tileset",
|
||||
"spacing":0,
|
||||
"tilecount":24,
|
||||
"tiledversion":"1.11.0",
|
||||
"tileheight":32,
|
||||
"tilewidth":32,
|
||||
"type":"tileset",
|
||||
"version":"1.10"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.10" tiledversion="1.11.0" name="tileset" tilewidth="32" tileheight="32" tilecount="24" columns="8">
|
||||
<image source="tileset.png" width="256" height="96"/>
|
||||
</tileset>
|
38
src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs
Normal file
38
src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TmjMapReaderTests
|
||||
{
|
||||
public static IEnumerable<object[]> Maps => TestData.MapTests;
|
||||
[Theory]
|
||||
[MemberData(nameof(Maps))]
|
||||
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||
string testDataFile,
|
||||
Func<string, Map> expectedMap,
|
||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
||||
{
|
||||
// Arrange
|
||||
testDataFile += ".tmj";
|
||||
var fileDir = Path.GetDirectoryName(testDataFile);
|
||||
var json = TestData.GetRawStringFor(testDataFile);
|
||||
Template ResolveTemplate(string source)
|
||||
{
|
||||
var templateJson = TestData.GetRawStringFor($"{fileDir}/{source}");
|
||||
using var templateReader = new TjTemplateReader(templateJson, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
return templateReader.ReadTemplate();
|
||||
}
|
||||
Tileset ResolveTileset(string source)
|
||||
{
|
||||
var tilesetJson = TestData.GetRawStringFor($"{fileDir}/{source}");
|
||||
using var tilesetReader = new TsjTilesetReader(tilesetJson, ResolveTemplate, customTypeDefinitions);
|
||||
return tilesetReader.ReadTileset();
|
||||
}
|
||||
using var mapReader = new TmjMapReader(json, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
|
||||
// Act
|
||||
var map = mapReader.ReadMap();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(map);
|
||||
DotTiledAssert.AssertMap(expectedMap("tmj"), map);
|
||||
}
|
||||
}
|
40
src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs
Normal file
40
src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Xml;
|
||||
|
||||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TmxMapReaderTests
|
||||
{
|
||||
public static IEnumerable<object[]> Maps => TestData.MapTests;
|
||||
[Theory]
|
||||
[MemberData(nameof(Maps))]
|
||||
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||
string testDataFile,
|
||||
Func<string, Map> expectedMap,
|
||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
||||
{
|
||||
// Arrange
|
||||
testDataFile += ".tmx";
|
||||
var fileDir = Path.GetDirectoryName(testDataFile);
|
||||
using var reader = TestData.GetXmlReaderFor(testDataFile);
|
||||
Template ResolveTemplate(string source)
|
||||
{
|
||||
using var xmlTemplateReader = TestData.GetXmlReaderFor($"{fileDir}/{source}");
|
||||
using var templateReader = new TxTemplateReader(xmlTemplateReader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
return templateReader.ReadTemplate();
|
||||
}
|
||||
Tileset ResolveTileset(string source)
|
||||
{
|
||||
using var xmlTilesetReader = TestData.GetXmlReaderFor($"{fileDir}/{source}");
|
||||
using var tilesetReader = new TsxTilesetReader(xmlTilesetReader, ResolveTemplate, customTypeDefinitions);
|
||||
return tilesetReader.ReadTileset();
|
||||
}
|
||||
using var mapReader = new TmxMapReader(reader, ResolveTileset, ResolveTemplate, customTypeDefinitions);
|
||||
|
||||
// Act
|
||||
var map = mapReader.ReadMap();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(map);
|
||||
DotTiledAssert.AssertMap(expectedMap("tmx"), map);
|
||||
}
|
||||
}
|
34
src/DotTiled.sln
Normal file
34
src/DotTiled.sln
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotTiled", "DotTiled\DotTiled.csproj", "{80A60DE7-D6AE-4CC7-825F-75308D83F36D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotTiled.Tests", "DotTiled.Tests\DotTiled.Tests.csproj", "{C1311A5A-5206-467C-B323-B131CA11FDB8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotTiled.Benchmark", "DotTiled.Benchmark\DotTiled.Benchmark.csproj", "{510F3077-8EA4-47D1-8D01-E2D538F1B899}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{80A60DE7-D6AE-4CC7-825F-75308D83F36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{80A60DE7-D6AE-4CC7-825F-75308D83F36D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{80A60DE7-D6AE-4CC7-825F-75308D83F36D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{80A60DE7-D6AE-4CC7-825F-75308D83F36D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C1311A5A-5206-467C-B323-B131CA11FDB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C1311A5A-5206-467C-B323-B131CA11FDB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C1311A5A-5206-467C-B323-B131CA11FDB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C1311A5A-5206-467C-B323-B131CA11FDB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{510F3077-8EA4-47D1-8D01-E2D538F1B899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{510F3077-8EA4-47D1-8D01-E2D538F1B899}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{510F3077-8EA4-47D1-8D01-E2D538F1B899}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{510F3077-8EA4-47D1-8D01-E2D538F1B899}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
8
src/DotTiled/DotTiled.csproj
Normal file
8
src/DotTiled/DotTiled.csproj
Normal file
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
71
src/DotTiled/Model/Color.cs
Normal file
71
src/DotTiled/Model/Color.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class Color : IParsable<Color>, IEquatable<Color>
|
||||
{
|
||||
public required byte R { get; set; }
|
||||
public required byte G { get; set; }
|
||||
public required byte B { get; set; }
|
||||
public byte A { get; set; } = 255;
|
||||
|
||||
public static Color Parse(string s, IFormatProvider? provider)
|
||||
{
|
||||
TryParse(s, provider, out var result);
|
||||
return result ?? throw new FormatException($"Invalid format for TiledColor: {s}");
|
||||
}
|
||||
|
||||
public static bool TryParse(
|
||||
[NotNullWhen(true)] string? s,
|
||||
IFormatProvider? provider,
|
||||
[MaybeNullWhen(false)] out Color result)
|
||||
{
|
||||
if (s is not null && !s.StartsWith('#'))
|
||||
return TryParse($"#{s}", provider, out result);
|
||||
|
||||
// Format: #RRGGBB or #AARRGGBB
|
||||
if (s is null || s.Length != 7 && s.Length != 9 || s[0] != '#')
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (s.Length == 7)
|
||||
{
|
||||
result = new Color
|
||||
{
|
||||
R = byte.Parse(s[1..3], NumberStyles.HexNumber, provider),
|
||||
G = byte.Parse(s[3..5], NumberStyles.HexNumber, provider),
|
||||
B = byte.Parse(s[5..7], NumberStyles.HexNumber, provider)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new Color
|
||||
{
|
||||
A = byte.Parse(s[1..3], NumberStyles.HexNumber, provider),
|
||||
R = byte.Parse(s[3..5], NumberStyles.HexNumber, provider),
|
||||
G = byte.Parse(s[5..7], NumberStyles.HexNumber, provider),
|
||||
B = byte.Parse(s[7..9], NumberStyles.HexNumber, provider)
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Equals(Color? other)
|
||||
{
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
return R == other.R && G == other.G && B == other.B && A == other.A;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => obj is Color other && Equals(other);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(R, G, B, A);
|
||||
|
||||
public override string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}";
|
||||
}
|
21
src/DotTiled/Model/Layers/BaseLayer.cs
Normal file
21
src/DotTiled/Model/Layers/BaseLayer.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public abstract class BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public required uint ID { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Class { get; set; } = "";
|
||||
public float Opacity { get; set; } = 1.0f;
|
||||
public bool Visible { get; set; } = true;
|
||||
public Color? TintColor { get; set; }
|
||||
public float OffsetX { get; set; } = 0.0f;
|
||||
public float OffsetY { get; set; } = 0.0f;
|
||||
public float ParallaxX { get; set; } = 1.0f;
|
||||
public float ParallaxY { get; set; } = 1.0f;
|
||||
|
||||
// At most one of
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
51
src/DotTiled/Model/Layers/Data.cs
Normal file
51
src/DotTiled/Model/Layers/Data.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public enum DataEncoding
|
||||
{
|
||||
Csv,
|
||||
Base64
|
||||
}
|
||||
|
||||
public enum DataCompression
|
||||
{
|
||||
GZip,
|
||||
ZLib,
|
||||
ZStd
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FlippingFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
FlippedHorizontally = 0x80000000u,
|
||||
FlippedVertically = 0x40000000u,
|
||||
FlippedDiagonally = 0x20000000u,
|
||||
RotatedHexagonal120 = 0x10000000u
|
||||
}
|
||||
|
||||
public class Chunk
|
||||
{
|
||||
// Attributes
|
||||
public required int X { get; set; }
|
||||
public required int Y { get; set; }
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// Data
|
||||
public required uint[] GlobalTileIDs { get; set; }
|
||||
public required FlippingFlags[] FlippingFlags { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
// Attributes
|
||||
public DataEncoding? Encoding { get; set; }
|
||||
public DataCompression? Compression { get; set; }
|
||||
|
||||
// Data
|
||||
public uint[]? GlobalTileIDs { get; set; }
|
||||
public FlippingFlags[]? FlippingFlags { get; set; }
|
||||
public Chunk[]? Chunks { get; set; }
|
||||
}
|
11
src/DotTiled/Model/Layers/Group.cs
Normal file
11
src/DotTiled/Model/Layers/Group.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class Group : BaseLayer
|
||||
{
|
||||
// Uses same attributes as BaseLayer
|
||||
|
||||
// Any number of
|
||||
public List<BaseLayer> Layers { get; set; } = [];
|
||||
}
|
13
src/DotTiled/Model/Layers/ImageLayer.cs
Normal file
13
src/DotTiled/Model/Layers/ImageLayer.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class ImageLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public bool RepeatX { get; set; } = false;
|
||||
public bool RepeatY { get; set; } = false;
|
||||
|
||||
// At most one of
|
||||
public Image? Image { get; set; }
|
||||
}
|
23
src/DotTiled/Model/Layers/ObjectLayer.cs
Normal file
23
src/DotTiled/Model/Layers/ObjectLayer.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public enum DrawOrder
|
||||
{
|
||||
TopDown,
|
||||
Index
|
||||
}
|
||||
|
||||
public class ObjectLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public uint? Width { get; set; }
|
||||
public uint? Height { get; set; }
|
||||
public Color? Color { get; set; }
|
||||
public DrawOrder DrawOrder { get; set; } = DrawOrder.TopDown;
|
||||
|
||||
// Elements
|
||||
public required List<Object> Objects { get; set; }
|
||||
}
|
3
src/DotTiled/Model/Layers/Objects/EllipseObject.cs
Normal file
3
src/DotTiled/Model/Layers/Objects/EllipseObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class EllipseObject : Object { }
|
21
src/DotTiled/Model/Layers/Objects/Object.cs
Normal file
21
src/DotTiled/Model/Layers/Objects/Object.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public abstract class Object
|
||||
{
|
||||
// Attributes
|
||||
public uint? ID { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Type { get; set; } = "";
|
||||
public float X { get; set; } = 0f;
|
||||
public float Y { get; set; } = 0f;
|
||||
public float Width { get; set; } = 0f;
|
||||
public float Height { get; set; } = 0f;
|
||||
public float Rotation { get; set; } = 0f;
|
||||
public bool Visible { get; set; } = true;
|
||||
public string? Template { get; set; }
|
||||
|
||||
// Elements
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
3
src/DotTiled/Model/Layers/Objects/PointObject.cs
Normal file
3
src/DotTiled/Model/Layers/Objects/PointObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class PointObject : Object { }
|
10
src/DotTiled/Model/Layers/Objects/PolygonObject.cs
Normal file
10
src/DotTiled/Model/Layers/Objects/PolygonObject.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class PolygonObject : Object
|
||||
{
|
||||
// Attributes
|
||||
public required List<Vector2> Points { get; set; }
|
||||
}
|
10
src/DotTiled/Model/Layers/Objects/PolylineObject.cs
Normal file
10
src/DotTiled/Model/Layers/Objects/PolylineObject.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class PolylineObject : Object
|
||||
{
|
||||
// Attributes
|
||||
public required List<Vector2> Points { get; set; }
|
||||
}
|
3
src/DotTiled/Model/Layers/Objects/RectangleObject.cs
Normal file
3
src/DotTiled/Model/Layers/Objects/RectangleObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class RectangleObject : Object { }
|
38
src/DotTiled/Model/Layers/Objects/TextObject.cs
Normal file
38
src/DotTiled/Model/Layers/Objects/TextObject.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
|
||||
public enum TextHorizontalAlignment
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
Justify
|
||||
}
|
||||
|
||||
public enum TextVerticalAlignment
|
||||
{
|
||||
Top,
|
||||
Center,
|
||||
Bottom
|
||||
}
|
||||
|
||||
public class TextObject : Object
|
||||
{
|
||||
// Attributes
|
||||
public string FontFamily { get; set; } = "sans-serif";
|
||||
public int PixelSize { get; set; } = 16;
|
||||
public bool Wrap { get; set; } = false;
|
||||
public Color Color { get; set; } = Color.Parse("#000000", CultureInfo.InvariantCulture);
|
||||
public bool Bold { get; set; } = false;
|
||||
public bool Italic { get; set; } = false;
|
||||
public bool Underline { get; set; } = false;
|
||||
public bool Strikeout { get; set; } = false;
|
||||
public bool Kerning { get; set; } = true;
|
||||
public TextHorizontalAlignment HorizontalAlignment { get; set; } = TextHorizontalAlignment.Left;
|
||||
public TextVerticalAlignment VerticalAlignment { get; set; } = TextVerticalAlignment.Top;
|
||||
|
||||
// Elements
|
||||
public string Text { get; set; } = "";
|
||||
}
|
6
src/DotTiled/Model/Layers/Objects/TileObject.cs
Normal file
6
src/DotTiled/Model/Layers/Objects/TileObject.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class TileObject : Object
|
||||
{
|
||||
public uint GID { get; set; }
|
||||
}
|
13
src/DotTiled/Model/Layers/TileLayer.cs
Normal file
13
src/DotTiled/Model/Layers/TileLayer.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class TileLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// At most one of
|
||||
public Data? Data { get; set; }
|
||||
}
|
63
src/DotTiled/Model/Map.cs
Normal file
63
src/DotTiled/Model/Map.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public enum MapOrientation
|
||||
{
|
||||
Orthogonal,
|
||||
Isometric,
|
||||
Staggered,
|
||||
Hexagonal
|
||||
}
|
||||
|
||||
public enum RenderOrder
|
||||
{
|
||||
RightDown,
|
||||
RightUp,
|
||||
LeftDown,
|
||||
LeftUp
|
||||
}
|
||||
|
||||
public enum StaggerAxis
|
||||
{
|
||||
X,
|
||||
Y
|
||||
}
|
||||
|
||||
public enum StaggerIndex
|
||||
{
|
||||
Odd,
|
||||
Even
|
||||
}
|
||||
|
||||
public class Map
|
||||
{
|
||||
// Attributes
|
||||
public required string Version { get; set; }
|
||||
public required string TiledVersion { get; set; }
|
||||
public string Class { get; set; } = "";
|
||||
public required MapOrientation Orientation { get; set; }
|
||||
public RenderOrder RenderOrder { get; set; } = RenderOrder.RightDown;
|
||||
public int CompressionLevel { get; set; } = -1;
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
public required uint TileWidth { get; set; }
|
||||
public required uint TileHeight { get; set; }
|
||||
public uint? HexSideLength { get; set; }
|
||||
public StaggerAxis? StaggerAxis { get; set; }
|
||||
public StaggerIndex? StaggerIndex { get; set; }
|
||||
public float ParallaxOriginX { get; set; } = 0.0f;
|
||||
public float ParallaxOriginY { get; set; } = 0.0f;
|
||||
public Color BackgroundColor { get; set; } = Color.Parse("#00000000", CultureInfo.InvariantCulture);
|
||||
public required uint NextLayerID { get; set; }
|
||||
public required uint NextObjectID { get; set; }
|
||||
public bool Infinite { get; set; } = false;
|
||||
|
||||
// At most one of
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
|
||||
// Any number of
|
||||
public List<Tileset> Tilesets { get; set; } = [];
|
||||
public List<BaseLayer> Layers { get; set; } = [];
|
||||
}
|
14
src/DotTiled/Model/Properties/BoolProperty.cs
Normal file
14
src/DotTiled/Model/Properties/BoolProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class BoolProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.Bool;
|
||||
public required bool Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new BoolProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
19
src/DotTiled/Model/Properties/ClassProperty.cs
Normal file
19
src/DotTiled/Model/Properties/ClassProperty.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class ClassProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => DotTiled.PropertyType.Class;
|
||||
public required string PropertyType { get; set; }
|
||||
public required Dictionary<string, IProperty> Properties { get; set; }
|
||||
|
||||
public IProperty Clone() => new ClassProperty
|
||||
{
|
||||
Name = Name,
|
||||
PropertyType = PropertyType,
|
||||
Properties = Properties.ToDictionary(p => p.Key, p => p.Value.Clone())
|
||||
};
|
||||
}
|
14
src/DotTiled/Model/Properties/ColorProperty.cs
Normal file
14
src/DotTiled/Model/Properties/ColorProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class ColorProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.Color;
|
||||
public required Color Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new ColorProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
[Flags]
|
||||
public enum CustomClassUseAs
|
||||
{
|
||||
Property,
|
||||
Map,
|
||||
Layer,
|
||||
Object,
|
||||
Tile,
|
||||
Tileset,
|
||||
WangColor,
|
||||
Wangset,
|
||||
Project,
|
||||
All = Property | Map | Layer | Object | Tile | Tileset | WangColor | Wangset | Project
|
||||
}
|
||||
|
||||
public class CustomClassDefinition : CustomTypeDefinition
|
||||
{
|
||||
public Color? Color { get; set; }
|
||||
public bool DrawFill { get; set; }
|
||||
public CustomClassUseAs UseAs { get; set; }
|
||||
public List<IProperty> Members { get; set; } = [];
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public enum CustomEnumStorageType
|
||||
{
|
||||
Int,
|
||||
String
|
||||
}
|
||||
|
||||
public class CustomEnumDefinition : CustomTypeDefinition
|
||||
{
|
||||
public CustomEnumStorageType StorageType { get; set; }
|
||||
public List<string> Values { get; set; } = [];
|
||||
public bool ValueAsFlags { get; set; }
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public abstract class CustomTypeDefinition
|
||||
{
|
||||
public uint ID { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
}
|
14
src/DotTiled/Model/Properties/FileProperty.cs
Normal file
14
src/DotTiled/Model/Properties/FileProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class FileProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.File;
|
||||
public required string Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new FileProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
14
src/DotTiled/Model/Properties/FloatProperty.cs
Normal file
14
src/DotTiled/Model/Properties/FloatProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class FloatProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.Float;
|
||||
public required float Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new FloatProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
9
src/DotTiled/Model/Properties/IProperty.cs
Normal file
9
src/DotTiled/Model/Properties/IProperty.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public interface IProperty
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public PropertyType Type { get; }
|
||||
|
||||
IProperty Clone();
|
||||
}
|
14
src/DotTiled/Model/Properties/IntProperty.cs
Normal file
14
src/DotTiled/Model/Properties/IntProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class IntProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.Int;
|
||||
public required int Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new IntProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
14
src/DotTiled/Model/Properties/ObjectProperty.cs
Normal file
14
src/DotTiled/Model/Properties/ObjectProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class ObjectProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.Object;
|
||||
public required uint Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new ObjectProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
13
src/DotTiled/Model/Properties/PropertyType.cs
Normal file
13
src/DotTiled/Model/Properties/PropertyType.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public enum PropertyType
|
||||
{
|
||||
String,
|
||||
Int,
|
||||
Float,
|
||||
Bool,
|
||||
Color,
|
||||
File,
|
||||
Object,
|
||||
Class
|
||||
}
|
14
src/DotTiled/Model/Properties/StringProperty.cs
Normal file
14
src/DotTiled/Model/Properties/StringProperty.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class StringProperty : IProperty
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public PropertyType Type => PropertyType.String;
|
||||
public required string Value { get; set; }
|
||||
|
||||
public IProperty Clone() => new StringProperty
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value
|
||||
};
|
||||
}
|
8
src/DotTiled/Model/Template.cs
Normal file
8
src/DotTiled/Model/Template.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class Template
|
||||
{
|
||||
// At most one of (if the template is a tile object)
|
||||
public Tileset? Tileset { get; set; }
|
||||
public required Object Object { get; set; }
|
||||
}
|
8
src/DotTiled/Model/Tileset/Frame.cs
Normal file
8
src/DotTiled/Model/Tileset/Frame.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class Frame
|
||||
{
|
||||
// Attributes
|
||||
public required uint TileID { get; set; }
|
||||
public required uint Duration { get; set; }
|
||||
}
|
15
src/DotTiled/Model/Tileset/Grid.cs
Normal file
15
src/DotTiled/Model/Tileset/Grid.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public enum GridOrientation
|
||||
{
|
||||
Orthogonal,
|
||||
Isometric
|
||||
}
|
||||
|
||||
public class Grid
|
||||
{
|
||||
// Attributes
|
||||
public GridOrientation Orientation { get; set; } = GridOrientation.Orthogonal;
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
}
|
19
src/DotTiled/Model/Tileset/Image.cs
Normal file
19
src/DotTiled/Model/Tileset/Image.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public enum ImageFormat
|
||||
{
|
||||
Png,
|
||||
Gif,
|
||||
Jpg,
|
||||
Bmp
|
||||
}
|
||||
|
||||
public class Image
|
||||
{
|
||||
// Attributes
|
||||
public ImageFormat? Format { get; set; }
|
||||
public string? Source { get; set; }
|
||||
public Color? TransparentColor { get; set; }
|
||||
public uint? Width { get; set; }
|
||||
public uint? Height { get; set; }
|
||||
}
|
21
src/DotTiled/Model/Tileset/Tile.cs
Normal file
21
src/DotTiled/Model/Tileset/Tile.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class Tile
|
||||
{
|
||||
// Attributes
|
||||
public required uint ID { get; set; }
|
||||
public string Type { get; set; } = "";
|
||||
public float Probability { get; set; } = 0f;
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
|
||||
// Elements
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
public Image? Image { get; set; }
|
||||
public ObjectLayer? ObjectLayer { get; set; }
|
||||
public List<Frame>? Animation { get; set; }
|
||||
}
|
8
src/DotTiled/Model/Tileset/TileOffset.cs
Normal file
8
src/DotTiled/Model/Tileset/TileOffset.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class TileOffset
|
||||
{
|
||||
// Attributes
|
||||
public float X { get; set; } = 0f;
|
||||
public float Y { get; set; } = 0f;
|
||||
}
|
61
src/DotTiled/Model/Tileset/Tileset.cs
Normal file
61
src/DotTiled/Model/Tileset/Tileset.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public enum ObjectAlignment
|
||||
{
|
||||
Unspecified,
|
||||
TopLeft,
|
||||
Top,
|
||||
TopRight,
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
BottomLeft,
|
||||
Bottom,
|
||||
BottomRight
|
||||
}
|
||||
|
||||
public enum TileRenderSize
|
||||
{
|
||||
Tile,
|
||||
Grid
|
||||
}
|
||||
|
||||
public enum FillMode
|
||||
{
|
||||
Stretch,
|
||||
PreserveAspectFit
|
||||
}
|
||||
|
||||
public class Tileset
|
||||
{
|
||||
// Attributes
|
||||
public string? Version { get; set; }
|
||||
public string? TiledVersion { get; set; }
|
||||
public uint? FirstGID { get; set; }
|
||||
public string? Source { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string Class { get; set; } = "";
|
||||
public uint? TileWidth { get; set; }
|
||||
public uint? TileHeight { get; set; }
|
||||
public float? Spacing { get; set; } = 0f;
|
||||
public float? Margin { get; set; } = 0f;
|
||||
public uint? TileCount { get; set; }
|
||||
public uint? Columns { get; set; }
|
||||
public ObjectAlignment ObjectAlignment { get; set; } = ObjectAlignment.Unspecified;
|
||||
public TileRenderSize RenderSize { get; set; } = TileRenderSize.Tile;
|
||||
public FillMode FillMode { get; set; } = FillMode.Stretch;
|
||||
|
||||
// At most one of
|
||||
public Image? Image { get; set; }
|
||||
public TileOffset? TileOffset { get; set; }
|
||||
public Grid? Grid { get; set; }
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
// public List<Terrain>? TerrainTypes { get; set; } TODO: Implement Terrain -> Wangset conversion during deserialization
|
||||
public List<Wangset>? Wangsets { get; set; }
|
||||
public Transformations? Transformations { get; set; }
|
||||
|
||||
// Any number of
|
||||
public List<Tile> Tiles { get; set; } = [];
|
||||
}
|
10
src/DotTiled/Model/Tileset/Transformations.cs
Normal file
10
src/DotTiled/Model/Tileset/Transformations.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class Transformations
|
||||
{
|
||||
// Attributes
|
||||
public bool HFlip { get; set; } = false;
|
||||
public bool VFlip { get; set; } = false;
|
||||
public bool Rotate { get; set; } = false;
|
||||
public bool PreferUntransformed { get; set; } = false;
|
||||
}
|
16
src/DotTiled/Model/Tileset/WangColor.cs
Normal file
16
src/DotTiled/Model/Tileset/WangColor.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class WangColor
|
||||
{
|
||||
// Attributes
|
||||
public required string Name { get; set; }
|
||||
public string Class { get; set; } = "";
|
||||
public required Color Color { get; set; }
|
||||
public required int Tile { get; set; }
|
||||
public float Probability { get; set; } = 0f;
|
||||
|
||||
// Elements
|
||||
public Dictionary<string, IProperty>? Properties { get; set; }
|
||||
}
|
8
src/DotTiled/Model/Tileset/WangTile.cs
Normal file
8
src/DotTiled/Model/Tileset/WangTile.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace DotTiled;
|
||||
|
||||
public class WangTile
|
||||
{
|
||||
// Attributes
|
||||
public required uint TileID { get; set; }
|
||||
public required byte[] WangID { get; set; }
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue