mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 08:52:50 +02:00
More property changes
This commit is contained in:
parent
1c1ba326b2
commit
b46eed774a
29 changed files with 99 additions and 61 deletions
|
@ -32,14 +32,14 @@ public static partial class TestData
|
||||||
|
|
||||||
public static IEnumerable<object[]> MapTests =>
|
public static IEnumerable<object[]> MapTests =>
|
||||||
[
|
[
|
||||||
["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],
|
["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],
|
||||||
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => MapWithEmbeddedTileset(), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => MapWithEmbeddedTileset(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty<CustomTypeDefinition>()],
|
["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public partial class TestData
|
||||||
};
|
};
|
||||||
|
|
||||||
// This comes from map-with-custom-type-props/propertytypes.json
|
// This comes from map-with-custom-type-props/propertytypes.json
|
||||||
public static IReadOnlyCollection<CustomTypeDefinition> MapWithCustomTypePropsCustomTypeDefinitions() => [
|
public static IReadOnlyCollection<ICustomTypeDefinition> MapWithCustomTypePropsCustomTypeDefinitions() => [
|
||||||
new CustomClassDefinition
|
new CustomClassDefinition
|
||||||
{
|
{
|
||||||
Name = "CustomClass",
|
Name = "CustomClass",
|
||||||
|
|
|
@ -11,7 +11,7 @@ public partial class TmjMapReaderTests
|
||||||
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||||
string testDataFile,
|
string testDataFile,
|
||||||
Func<string, Map> expectedMap,
|
Func<string, Map> expectedMap,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
testDataFile += ".tmj";
|
testDataFile += ".tmj";
|
||||||
|
|
|
@ -11,7 +11,7 @@ public partial class TmxMapReaderTests
|
||||||
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
|
||||||
string testDataFile,
|
string testDataFile,
|
||||||
Func<string, Map> expectedMap,
|
Func<string, Map> expectedMap,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
testDataFile += ".tmx";
|
testDataFile += ".tmx";
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -38,7 +39,16 @@ public class ClassProperty : IHasProperties, IProperty<IList<IProperty>>
|
||||||
public IList<IProperty> GetProperties() => Value;
|
public IList<IProperty> GetProperties() => Value;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public T GetProperty<T>(string name) where T : IProperty => throw new System.NotImplementedException();
|
public T GetProperty<T>(string name) where T : IProperty
|
||||||
|
{
|
||||||
|
var property = Value.FirstOrDefault(_properties => _properties.Name == name) ?? throw new InvalidOperationException($"Property '{name}' not found.");
|
||||||
|
if (property is T prop)
|
||||||
|
{
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidOperationException($"Property '{name}' is not of type '{typeof(T).Name}'.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool TryGetProperty<T>(string name, [NotNullWhen(true)] out T? property) where T : IProperty
|
public bool TryGetProperty<T>(string name, [NotNullWhen(true)] out T? property) where T : IProperty
|
||||||
|
|
|
@ -65,8 +65,14 @@ public enum CustomClassUseAs
|
||||||
/// Represents a custom class definition in Tiled. Refer to the
|
/// Represents a custom class definition in Tiled. Refer to the
|
||||||
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomClassDefinition : CustomTypeDefinition
|
public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public uint ID { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The color of the custom class inside the Tiled editor.
|
/// The color of the custom class inside the Tiled editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -86,4 +92,7 @@ public class CustomClassDefinition : CustomTypeDefinition
|
||||||
/// The members of the custom class, with their names, types and default values.
|
/// The members of the custom class, with their names, types and default values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<IProperty> Members { get; set; } = [];
|
public List<IProperty> Members { get; set; } = [];
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override IList<IProperty> GetProperties() => Members;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,14 @@ public enum CustomEnumStorageType
|
||||||
/// Represents a custom enum definition in Tiled. Refer to the
|
/// Represents a custom enum definition in Tiled. Refer to the
|
||||||
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
/// <see href="https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types">documentation of custom types to understand how they work</see>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomEnumDefinition : CustomTypeDefinition
|
public class CustomEnumDefinition : ICustomTypeDefinition
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public uint ID { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The storage type of the custom enum.
|
/// The storage type of the custom enum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace DotTiled.Model;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for custom type definitions.
|
/// Base class for custom type definitions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class CustomTypeDefinition
|
public interface ICustomTypeDefinition
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the custom type.
|
/// The ID of the custom type.
|
||||||
|
@ -13,5 +13,5 @@ public abstract class CustomTypeDefinition
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the custom type.
|
/// The name of the custom type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; } = "";
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -33,7 +34,7 @@ public interface IHasProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for objects that have properties attached to them.
|
/// Interface for objects that have properties attached to them.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class HasPropertiesBase : IHasProperties
|
public abstract class HasPropertiesBase : IHasProperties
|
||||||
{
|
{
|
||||||
|
@ -41,7 +42,19 @@ public abstract class HasPropertiesBase : IHasProperties
|
||||||
public abstract IList<IProperty> GetProperties();
|
public abstract IList<IProperty> GetProperties();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public T GetProperty<T>(string name) where T : IProperty => throw new System.NotImplementedException();
|
/// <exception cref="KeyNotFoundException">Thrown when a property with the specified name is not found.</exception>
|
||||||
|
/// <exception cref="InvalidCastException">Thrown when a property with the specified name is not of the specified type.</exception>
|
||||||
|
public T GetProperty<T>(string name) where T : IProperty
|
||||||
|
{
|
||||||
|
var properties = GetProperties();
|
||||||
|
var property = properties.FirstOrDefault(_properties => _properties.Name == name) ?? throw new KeyNotFoundException($"Property '{name}' not found.");
|
||||||
|
if (property is T prop)
|
||||||
|
{
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidCastException($"Property '{name}' is not of type '{typeof(T).Name}'.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool TryGetProperty<T>(string name, [NotNullWhen(true)] out T? property) where T : IProperty
|
public bool TryGetProperty<T>(string name, [NotNullWhen(true)] out T? property) where T : IProperty
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class TjTemplateReader : ITemplateReader
|
||||||
private readonly string _jsonString;
|
private readonly string _jsonString;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TjTemplateReader"/>.
|
/// Constructs a new <see cref="TjTemplateReader"/>.
|
||||||
|
@ -30,7 +30,7 @@ public class TjTemplateReader : ITemplateReader
|
||||||
string jsonString,
|
string jsonString,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
||||||
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
||||||
|
|
|
@ -11,7 +11,7 @@ internal partial class Tmj
|
||||||
internal static Group ReadGroup(
|
internal static Group ReadGroup(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = element.GetRequiredProperty<uint>("id");
|
var id = element.GetRequiredProperty<uint>("id");
|
||||||
var name = element.GetRequiredProperty<string>("name");
|
var name = element.GetRequiredProperty<string>("name");
|
||||||
|
|
|
@ -9,7 +9,7 @@ internal partial class Tmj
|
||||||
{
|
{
|
||||||
internal static ImageLayer ReadImageLayer(
|
internal static ImageLayer ReadImageLayer(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = element.GetRequiredProperty<uint>("id");
|
var id = element.GetRequiredProperty<uint>("id");
|
||||||
var name = element.GetRequiredProperty<string>("name");
|
var name = element.GetRequiredProperty<string>("name");
|
||||||
|
|
|
@ -10,7 +10,7 @@ internal partial class Tmj
|
||||||
internal static BaseLayer ReadLayer(
|
internal static BaseLayer ReadLayer(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var type = element.GetRequiredProperty<string>("type");
|
var type = element.GetRequiredProperty<string>("type");
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ internal partial class Tmj
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Tileset>? externalTilesetResolver,
|
Func<string, Tileset>? externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var version = element.GetRequiredProperty<string>("version");
|
var version = element.GetRequiredProperty<string>("version");
|
||||||
var tiledVersion = element.GetRequiredProperty<string>("tiledversion");
|
var tiledVersion = element.GetRequiredProperty<string>("tiledversion");
|
||||||
|
|
|
@ -12,7 +12,7 @@ internal partial class Tmj
|
||||||
internal static ObjectLayer ReadObjectLayer(
|
internal static ObjectLayer ReadObjectLayer(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = element.GetRequiredProperty<uint>("id");
|
var id = element.GetRequiredProperty<uint>("id");
|
||||||
var name = element.GetRequiredProperty<string>("name");
|
var name = element.GetRequiredProperty<string>("name");
|
||||||
|
@ -66,7 +66,7 @@ internal partial class Tmj
|
||||||
internal static Model.Object ReadObject(
|
internal static Model.Object ReadObject(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
uint? idDefault = null;
|
uint? idDefault = null;
|
||||||
string nameDefault = "";
|
string nameDefault = "";
|
||||||
|
|
|
@ -10,7 +10,7 @@ internal partial class Tmj
|
||||||
{
|
{
|
||||||
internal static Dictionary<string, IProperty> ReadProperties(
|
internal static Dictionary<string, IProperty> ReadProperties(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions) =>
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions) =>
|
||||||
element.GetValueAsList<IProperty>(e =>
|
element.GetValueAsList<IProperty>(e =>
|
||||||
{
|
{
|
||||||
var name = e.GetRequiredProperty<string>("name");
|
var name = e.GetRequiredProperty<string>("name");
|
||||||
|
@ -45,7 +45,7 @@ internal partial class Tmj
|
||||||
|
|
||||||
internal static List<IProperty> ReadPropertiesList(
|
internal static List<IProperty> ReadPropertiesList(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions) =>
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions) =>
|
||||||
element.GetValueAsList<IProperty>(e =>
|
element.GetValueAsList<IProperty>(e =>
|
||||||
{
|
{
|
||||||
var name = e.GetRequiredProperty<string>("name");
|
var name = e.GetRequiredProperty<string>("name");
|
||||||
|
@ -80,7 +80,7 @@ internal partial class Tmj
|
||||||
|
|
||||||
internal static ClassProperty ReadClassProperty(
|
internal static ClassProperty ReadClassProperty(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var name = element.GetRequiredProperty<string>("name");
|
var name = element.GetRequiredProperty<string>("name");
|
||||||
var propertyType = element.GetRequiredProperty<string>("propertytype");
|
var propertyType = element.GetRequiredProperty<string>("propertytype");
|
||||||
|
@ -108,7 +108,7 @@ internal partial class Tmj
|
||||||
internal static List<IProperty> ReadCustomClassProperties(
|
internal static List<IProperty> ReadCustomClassProperties(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
CustomClassDefinition customClassDefinition,
|
CustomClassDefinition customClassDefinition,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
List<IProperty> resultingProps = Helpers.CreateInstanceOfCustomClass(customClassDefinition);
|
List<IProperty> resultingProps = Helpers.CreateInstanceOfCustomClass(customClassDefinition);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ internal partial class Tmj
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var type = element.GetRequiredProperty<string>("type");
|
var type = element.GetRequiredProperty<string>("type");
|
||||||
var tileset = element.GetOptionalPropertyCustom<Tileset?>("tileset", el => ReadTileset(el, externalTilesetResolver, externalTemplateResolver, customTypeDefinitions), null);
|
var tileset = element.GetOptionalPropertyCustom<Tileset?>("tileset", el => ReadTileset(el, externalTilesetResolver, externalTemplateResolver, customTypeDefinitions), null);
|
||||||
|
|
|
@ -9,7 +9,7 @@ internal partial class Tmj
|
||||||
{
|
{
|
||||||
internal static TileLayer ReadTileLayer(
|
internal static TileLayer ReadTileLayer(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var compression = element.GetOptionalPropertyParseable<DataCompression?>("compression", s => s switch
|
var compression = element.GetOptionalPropertyParseable<DataCompression?>("compression", s => s switch
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ internal partial class Tmj
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Tileset>? externalTilesetResolver,
|
Func<string, Tileset>? externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var backgroundColor = element.GetOptionalPropertyParseable<Color?>("backgroundcolor", s => Color.Parse(s, CultureInfo.InvariantCulture), null);
|
var backgroundColor = element.GetOptionalPropertyParseable<Color?>("backgroundcolor", s => Color.Parse(s, CultureInfo.InvariantCulture), null);
|
||||||
var @class = element.GetOptionalProperty<string>("class", "");
|
var @class = element.GetOptionalProperty<string>("class", "");
|
||||||
|
@ -162,7 +162,7 @@ internal partial class Tmj
|
||||||
internal static List<Tile> ReadTiles(
|
internal static List<Tile> ReadTiles(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions) =>
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions) =>
|
||||||
element.GetValueAsList<Tile>(e =>
|
element.GetValueAsList<Tile>(e =>
|
||||||
{
|
{
|
||||||
var animation = e.GetOptionalPropertyCustom<List<Frame>?>("animation", e => e.GetValueAsList<Frame>(ReadFrame), null);
|
var animation = e.GetOptionalPropertyCustom<List<Frame>?>("animation", e => e.GetValueAsList<Frame>(ReadFrame), null);
|
||||||
|
@ -218,7 +218,7 @@ internal partial class Tmj
|
||||||
|
|
||||||
internal static Wangset ReadWangset(
|
internal static Wangset ReadWangset(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var @clalss = element.GetOptionalProperty<string>("class", "");
|
var @clalss = element.GetOptionalProperty<string>("class", "");
|
||||||
var colors = element.GetOptionalPropertyCustom<List<WangColor>>("colors", e => e.GetValueAsList<WangColor>(el => ReadWangColor(el, customTypeDefinitions)), []);
|
var colors = element.GetOptionalPropertyCustom<List<WangColor>>("colors", e => e.GetValueAsList<WangColor>(el => ReadWangColor(el, customTypeDefinitions)), []);
|
||||||
|
@ -241,7 +241,7 @@ internal partial class Tmj
|
||||||
|
|
||||||
internal static WangColor ReadWangColor(
|
internal static WangColor ReadWangColor(
|
||||||
JsonElement element,
|
JsonElement element,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var @class = element.GetOptionalProperty<string>("class", "");
|
var @class = element.GetOptionalProperty<string>("class", "");
|
||||||
var color = element.GetRequiredPropertyParseable<Color>("color", s => Color.Parse(s, CultureInfo.InvariantCulture));
|
var color = element.GetRequiredPropertyParseable<Color>("color", s => Color.Parse(s, CultureInfo.InvariantCulture));
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class TmjMapReader : IMapReader
|
||||||
private readonly string _jsonString;
|
private readonly string _jsonString;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TmjMapReader"/>.
|
/// Constructs a new <see cref="TmjMapReader"/>.
|
||||||
|
@ -31,7 +31,7 @@ public class TmjMapReader : IMapReader
|
||||||
string jsonString,
|
string jsonString,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
||||||
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class TsjTilesetReader : ITilesetReader
|
||||||
private readonly string _jsonString;
|
private readonly string _jsonString;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TsjTilesetReader"/>.
|
/// Constructs a new <see cref="TsjTilesetReader"/>.
|
||||||
|
@ -27,7 +27,7 @@ public class TsjTilesetReader : ITilesetReader
|
||||||
public TsjTilesetReader(
|
public TsjTilesetReader(
|
||||||
string jsonString,
|
string jsonString,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
_jsonString = jsonString ?? throw new ArgumentNullException(nameof(jsonString));
|
||||||
_externalTemplateResolver = externalTemplateResolver ?? throw new ArgumentNullException(nameof(externalTemplateResolver));
|
_externalTemplateResolver = externalTemplateResolver ?? throw new ArgumentNullException(nameof(externalTemplateResolver));
|
||||||
|
|
|
@ -13,7 +13,7 @@ internal partial class Tmx
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var version = reader.GetRequiredAttribute("version");
|
var version = reader.GetRequiredAttribute("version");
|
||||||
|
|
|
@ -13,7 +13,7 @@ internal partial class Tmx
|
||||||
internal static ObjectLayer ReadObjectLayer(
|
internal static ObjectLayer ReadObjectLayer(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||||
|
@ -75,7 +75,7 @@ internal partial class Tmx
|
||||||
internal static Model.Object ReadObject(
|
internal static Model.Object ReadObject(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var template = reader.GetOptionalAttribute("template");
|
var template = reader.GetOptionalAttribute("template");
|
||||||
|
@ -308,7 +308,7 @@ internal partial class Tmx
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// No attributes
|
// No attributes
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ internal partial class Tmx
|
||||||
{
|
{
|
||||||
internal static Dictionary<string, IProperty> ReadProperties(
|
internal static Dictionary<string, IProperty> ReadProperties(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
return reader.ReadList("properties", "property", (r) =>
|
return reader.ReadList("properties", "property", (r) =>
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ internal partial class Tmx
|
||||||
|
|
||||||
internal static List<IProperty> ReadPropertiesList(
|
internal static List<IProperty> ReadPropertiesList(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
return reader.ReadList("properties", "property", (r) =>
|
return reader.ReadList("properties", "property", (r) =>
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ internal partial class Tmx
|
||||||
|
|
||||||
internal static ClassProperty ReadClassProperty(
|
internal static ClassProperty ReadClassProperty(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var name = reader.GetRequiredAttribute("name");
|
var name = reader.GetRequiredAttribute("name");
|
||||||
var propertyType = reader.GetRequiredAttribute("propertytype");
|
var propertyType = reader.GetRequiredAttribute("propertytype");
|
||||||
|
|
|
@ -11,7 +11,7 @@ internal partial class Tmx
|
||||||
internal static TileLayer ReadTileLayer(
|
internal static TileLayer ReadTileLayer(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
bool dataUsesChunks,
|
bool dataUsesChunks,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||||
var name = reader.GetOptionalAttribute("name") ?? "";
|
var name = reader.GetOptionalAttribute("name") ?? "";
|
||||||
|
@ -61,7 +61,7 @@ internal partial class Tmx
|
||||||
|
|
||||||
internal static ImageLayer ReadImageLayer(
|
internal static ImageLayer ReadImageLayer(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||||
var name = reader.GetOptionalAttribute("name") ?? "";
|
var name = reader.GetOptionalAttribute("name") ?? "";
|
||||||
|
@ -112,7 +112,7 @@ internal partial class Tmx
|
||||||
internal static Group ReadGroup(
|
internal static Group ReadGroup(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||||
var name = reader.GetOptionalAttribute("name") ?? "";
|
var name = reader.GetOptionalAttribute("name") ?? "";
|
||||||
|
|
|
@ -14,7 +14,7 @@ internal partial class Tmx
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Tileset>? externalTilesetResolver,
|
Func<string, Tileset>? externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var version = reader.GetOptionalAttribute("version");
|
var version = reader.GetOptionalAttribute("version");
|
||||||
|
@ -207,7 +207,7 @@ internal partial class Tmx
|
||||||
internal static Tile ReadTile(
|
internal static Tile ReadTile(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||||
|
@ -256,12 +256,12 @@ internal partial class Tmx
|
||||||
|
|
||||||
internal static List<Wangset> ReadWangsets(
|
internal static List<Wangset> ReadWangsets(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions) =>
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions) =>
|
||||||
reader.ReadList<Wangset>("wangsets", "wangset", r => ReadWangset(r, customTypeDefinitions));
|
reader.ReadList<Wangset>("wangsets", "wangset", r => ReadWangset(r, customTypeDefinitions));
|
||||||
|
|
||||||
internal static Wangset ReadWangset(
|
internal static Wangset ReadWangset(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var name = reader.GetRequiredAttribute("name");
|
var name = reader.GetRequiredAttribute("name");
|
||||||
|
@ -297,7 +297,7 @@ internal partial class Tmx
|
||||||
|
|
||||||
internal static WangColor ReadWangColor(
|
internal static WangColor ReadWangColor(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
var name = reader.GetRequiredAttribute("name");
|
var name = reader.GetRequiredAttribute("name");
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class TmxMapReader : IMapReader
|
||||||
private readonly XmlReader _reader;
|
private readonly XmlReader _reader;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TmxMapReader"/>.
|
/// Constructs a new <see cref="TmxMapReader"/>.
|
||||||
|
@ -31,7 +31,7 @@ public class TmxMapReader : IMapReader
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
||||||
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class TsxTilesetReader : ITilesetReader
|
||||||
private readonly XmlReader _reader;
|
private readonly XmlReader _reader;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TsxTilesetReader"/>.
|
/// Constructs a new <see cref="TsxTilesetReader"/>.
|
||||||
|
@ -28,7 +28,7 @@ public class TsxTilesetReader : ITilesetReader
|
||||||
public TsxTilesetReader(
|
public TsxTilesetReader(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
||||||
_externalTemplateResolver = externalTemplateResolver ?? throw new ArgumentNullException(nameof(externalTemplateResolver));
|
_externalTemplateResolver = externalTemplateResolver ?? throw new ArgumentNullException(nameof(externalTemplateResolver));
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class TxTemplateReader : ITemplateReader
|
||||||
private readonly XmlReader _reader;
|
private readonly XmlReader _reader;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<CustomTypeDefinition> _customTypeDefinitions;
|
private readonly IReadOnlyCollection<ICustomTypeDefinition> _customTypeDefinitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="TxTemplateReader"/>.
|
/// Constructs a new <see cref="TxTemplateReader"/>.
|
||||||
|
@ -31,7 +31,7 @@ public class TxTemplateReader : ITemplateReader
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Func<string, Tileset> externalTilesetResolver,
|
Func<string, Tileset> externalTilesetResolver,
|
||||||
Func<string, Template> externalTemplateResolver,
|
Func<string, Template> externalTemplateResolver,
|
||||||
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
|
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
|
||||||
{
|
{
|
||||||
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
|
||||||
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
_externalTilesetResolver = externalTilesetResolver ?? throw new ArgumentNullException(nameof(externalTilesetResolver));
|
||||||
|
|
Loading…
Add table
Reference in a new issue