diff --git a/.editorconfig b/.editorconfig index a784f75..71746d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -235,9 +235,7 @@ dotnet_diagnostic.IDE0004.severity = silent dotnet_diagnostic.IDE0005.severity = error dotnet_diagnostic.IDE0008.severity = silent dotnet_diagnostic.IDE0055.severity = silent -dotnet_diagnostic.IDE0058.severity = silent dotnet_diagnostic.IDE0160.severity = none -dotnet_diagnostic.IDE0210.severity = none dotnet_diagnostic.CA1707.severity = silent dotnet_diagnostic.CA1852.severity = none dotnet_diagnostic.CA1805.severity = none @@ -245,7 +243,7 @@ dotnet_diagnostic.CA1720.severity = silent dotnet_diagnostic.CA1711.severity = silent dotnet_diagnostic.CA1716.severity = silent -[*.(yml|json|js)] +[.github/**/*.yml] charset = utf-8 end_of_line = lf indent_size = 2 diff --git a/.github/PULL_REQUEST_TEMPLATE/dev_template.md b/.github/PULL_REQUEST_TEMPLATE/dev_template.md deleted file mode 100644 index 128b591..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/dev_template.md +++ /dev/null @@ -1,15 +0,0 @@ -## Description - - -### Type of Change - -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) -- [ ] Documentation update - -## Checklist - -- [ ] Tests have been added/updated to cover new functionality. -- [ ] Documentation has been updated for all new changes (e.g., usage examples, API documentation). - diff --git a/.github/PULL_REQUEST_TEMPLATE/master_template.md b/.github/PULL_REQUEST_TEMPLATE/master_template.md deleted file mode 100644 index 28ba2d5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/master_template.md +++ /dev/null @@ -1,10 +0,0 @@ -# Release vX.Y.Z - - - -## Checklist for a release PR - -- [ ] Version compatibility matrix has been updated. -- [ ] Tests have been added/updated to cover new functionality. -- [ ] Documentation has been updated for all new changes (e.g., usage examples, API documentation). - diff --git a/.gitignore b/.gitignore index 1b33c6c..a2b8d83 100644 --- a/.gitignore +++ b/.gitignore @@ -402,4 +402,3 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml -.idea diff --git a/Makefile b/Makefile index c83c9fa..601eda2 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,13 @@ test: dotnet build src/DotTiled.sln dotnet test src/DotTiled.sln - dotnet run --project src/DotTiled.Examples/DotTiled.Example.Console/DotTiled.Example.Console.csproj -- src/DotTiled.Examples/DotTiled.Example.Console -docs-serve: docs/index.md +docs-serve: docfx docs/docfx.json --serve -docs-build: docs/index.md - docfx docs/docfx.json - -docs/index.md: README.md +docs-build: cp README.md docs/index.md + docfx docs/docfx.json lint: dotnet format style --verify-no-changes src/DotTiled.sln diff --git a/README.md b/README.md index 66e4d04..8739d03 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -DotTiled is a simple and easy-to-use library for loading [Tiled maps and tilesets](https://mapeditor.org) in your .NET projects. After [TiledCS](https://github.com/TheBoneJarmer/TiledCS) unfortunately became unmaintained (since 2022), I aimed to create a new library that could fill its shoes. DotTiled is the result of that effort. +DotTiled is a simple and easy-to-use library for loading, saving, and managing [Tiled maps and tilesets](https://mapeditor.org) in your .NET projects. After [TiledCS](https://github.com/TheBoneJarmer/TiledCS) unfortunately became unmaintained (since 2022), I aimed to create a new library that could fill its shoes. DotTiled is the result of that effort. DotTiled is designed to be a lightweight and efficient library that provides a simple API for loading and managing Tiled maps and tilesets. It is built with performance in mind and aims to be as fast and memory-efficient as possible. @@ -16,17 +16,17 @@ Other similar libraries exist, and you may want to consider them for your projec |**Comparison**|**DotTiled**|[TiledLib](https://github.com/Ragath/TiledLib.Net)|[TiledCSPlus](https://github.com/nolemretaWxd/TiledCSPlus)|[TiledSharp](https://github.com/marshallward/TiledSharp)|[TiledCS](https://github.com/TheBoneJarmer/TiledCS)|[TiledNet](https://github.com/napen123/Tiled.Net)| |---------------------------------|:-----------------------:|:--------:|:-----------:|:----------:|:-------:|:------:| -| Actively maintained | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | -| Benchmark (time)* | 1.00 | 1.78 | 2.11 | - | - | - | -| Benchmark (memory)* | 1.00 | 1.32 | 1.88 | - | - | - | -| .NET Targets | `net8.0` | `net8.0` |`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`| +| Actively maintained | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | +| Benchmark (time)* | 1.00 | 1.83 | 2.16 | - | - | - | +| Benchmark (memory)* | 1.00 | 1.43 | 2.03 | - | - | - | +| .NET Targets | `net8.0` |`net6.0`
`net7.0`|`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`| | Docs |Usage, API,
XML Docs|Usage|Usage, API,
XML Docs|Usage, API|Usage, XML Docs|Usage, XML Docs| | License | MIT | MIT | MIT | Apache-2.0 | MIT | BSD 3-Clause | > [!NOTE] > *Both benchmark time and memory ratios are relative to DotTiled. Lower is better. Benchmark (time) refers to the execution time of loading the same map from an in-memory string that contains XML data in the `.tmx` format. Benchmark (memory) refers to the memory allocated during that loading process. For further details on the benchmark results, see the collapsible section below. -[MonoGame](https://www.monogame.net) users may also want to consider using [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended) for loading Tiled maps and tilesets. The feature coverage by MonoGame.Extended is less than that of DotTiled, so you may want to consider using DotTiled if you need access to more Tiled features and flexibility. +[MonoGame](https://www.monogame.net) users may also want to consider using [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended) for loading Tiled maps and tilesets. Like MonoGame.Extended, DotTiled also provides a way to properly import Tiled maps and tilesets with the MonoGame content pipeline (with the DotTiled.MonoGame.Pipeline NuGet). However, unlike MonoGame.Extended, DotTiled does *not* include any kind of rendering capabilities, and it is up to you as a developer to implement any kind of rendering for your maps when using DotTiled. The feature coverage by MonoGame.Extended is less than that of DotTiled, so you may want to consider using DotTiled if you need access to more Tiled features and flexibility.
@@ -36,7 +36,7 @@ Benchmark details The following benchmark results were gathered using the `DotTiled.Benchmark` project which uses [BenchmarkDotNet](https://benchmarkdotnet.org/) to compare the performance of DotTiled with other similar libraries. The benchmark results are grouped by category and show the mean execution time, memory consumption metrics, and ratio to DotTiled. ``` -BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.5131/22H2/2022Update) +BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4651/22H2/2022Update) 12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores .NET SDK 8.0.202 [Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2 @@ -44,12 +44,12 @@ BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.5131/22H2/2022Update) ``` | Method | Categories | Mean | Ratio | Gen0 | Gen1 | Allocated | Alloc Ratio | |------------ |------------------------- |---------:|------:|-------:|-------:|----------:|------------:| -| DotTiled | MapFromInMemoryTmjString | 4.602 μs | 1.00 | 0.5417 | - | 7 KB | 1.00 | -| TiledLib | MapFromInMemoryTmjString | 6.385 μs | 1.39 | 0.7019 | 0.0153 | 9.01 KB | 1.29 | +| DotTiled | MapFromInMemoryTmjString | 4.431 μs | 1.00 | 0.4349 | - | 5.58 KB | 1.00 | +| TiledLib | MapFromInMemoryTmjString | 6.369 μs | 1.44 | 0.7019 | 0.0153 | 9.01 KB | 1.61 | | | | | | | | | | -| DotTiled | MapFromInMemoryTmxString | 3.216 μs | 1.00 | 1.3733 | 0.0610 | 17.68 KB | 1.00 | -| TiledLib | MapFromInMemoryTmxString | 5.721 μs | 1.78 | 1.8005 | 0.0916 | 23.32 KB | 1.32 | -| TiledCSPlus | MapFromInMemoryTmxString | 6.696 μs | 2.11 | 2.5940 | 0.1831 | 33.23 KB | 1.88 | +| DotTiled | MapFromInMemoryTmxString | 3.125 μs | 1.00 | 1.2817 | 0.0610 | 16.36 KB | 1.00 | +| TiledLib | MapFromInMemoryTmxString | 5.709 μs | 1.83 | 1.8005 | 0.0916 | 23.32 KB | 1.43 | +| TiledCSPlus | MapFromInMemoryTmxString | 6.757 μs | 2.16 | 2.5940 | 0.1831 | 33.16 KB | 2.03 | It is important to note that the above benchmark results come from loading a very small map with a single tile layer as I had to find a common denominator between the libraries so that they all could load the same map. The results aim to be indicative of the performance of the libraries, but should be taken with a grain of salt. Only the actively maintained libraries are included in the benchmark results. TiledCSPlus does not support the `.tmj` format, so it was not included for that benchmark category. diff --git a/docs/docfx.json b/docs/docfx.json index 744755c..4c955cb 100644 --- a/docs/docfx.json +++ b/docs/docfx.json @@ -41,10 +41,7 @@ "_appName": "DotTiled", "_appTitle": "DotTiled", "_enableSearch": true, - "pdf": false - }, - "xref": [ - "https://learn.microsoft.com/en-us/dotnet/.xrefmap.json" - ] + "pdf": true + } } } \ No newline at end of file diff --git a/docs/docs/essentials/custom-properties.md b/docs/docs/essentials/custom-properties.md index 3fd1bcc..b18ba7f 100644 --- a/docs/docs/essentials/custom-properties.md +++ b/docs/docs/essentials/custom-properties.md @@ -66,17 +66,11 @@ Tiled supports a variety of property types, which are represented in the DotTile - `object` - - `string` - -In addition to these primitive property types, [Tiled also supports more complex property types](https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types). These custom property types are defined in Tiled according to the linked documentation, and to work with them in DotTiled, you *must* define their equivalences as a . This is because of how Tiled handles default values for custom property types, and DotTiled needs to know these defaults to be able to populate the properties correctly. +In addition to these primitive property types, [Tiled also supports more complex property types](https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types). These custom property types are defined in Tiled according to the linked documentation, and to work with them in DotTiled, you *must* define their equivalences as a . You must then provide a resolving function to a defined type given a custom type name, as it is defined in Tiled. ## Custom types -Tiled allows you to define custom property types that can be used in your maps. These custom property types can be of type `class` or `enum`. DotTiled supports custom property types by allowing you to define the equivalent in C#. This section will guide you through how to define custom property types in DotTiled and how to map properties in loaded maps to C# classes or enums. - -> [!NOTE] -> While custom types are powerful, they will incur a bit of overhead as you attempt to sync them between Tiled and DotTiled. Defining custom types is recommended, but not necessary for simple use cases as Tiled supports arbitrary strings as classes. - -> [!IMPORTANT] -> If you choose to use custom types in your maps, but don't define them properly in DotTiled, you may get inconsistencies between the map in Tiled and the loaded map with DotTiled. If you still want to use custom types in Tiled without having to define them in DotTiled, it is recommended to set the `Resolve object types and properties` setting in Tiled to `true`. This will make Tiled resolve the custom types for you, but it will still require you to define the custom types in DotTiled if you want to access the properties in a type-safe manner. +Tiled allows you to define custom property types that can be used in your maps. These custom property types can be of type `class` or `enum`. DotTiled supports custom property types by allowing you to define the equivalent in C# and then providing a custom type resolver function that will return the equivalent definition given a custom type name. ### Class properties @@ -94,39 +88,14 @@ var monsterSpawnerDefinition = new CustomClassDefinition Name = "MonsterSpawner", UseAs = CustomClassUseAs.All, // Not really validated by DotTiled Members = [ // Make sure that the default values match the Tiled UI - new BoolProperty { Name = "Enabled", Value = true }, - new IntProperty { Name = "MaxSpawnAmount", Value = 10 }, - new IntProperty { Name = "MinSpawnAmount", Value = 0 }, - new StringProperty { Name = "MonsterNames", Value = "" } + new BoolProperty { Name = "enabled", Value = true }, + new IntProperty { Name = "maxSpawnAmount", Value = 10 }, + new IntProperty { Name = "minSpawnAmount", Value = 0 }, + new StringProperty { Name = "monsterNames", Value = "" } ] }; ``` -Luckily, you don't have to manually define these custom class definitions, even though you most definitively can for scenarios that require it. DotTiled provides a way to automatically generate these definitions for you from a C# class. This is done by using the method, or one of its overloads. This method will generate a from a given C# class, and you can then use this definition when loading your maps. - -```csharp -class MonsterSpawner -{ - public bool Enabled { get; set; } = true; - public int MaxSpawnAmount { get; set; } = 10; - public int MinSpawnAmount { get; set; } = 0; - public string MonsterNames { get; set; } = ""; -} - -// ... - -// These are all valid ways to create your custom class definitions from a C# class -// The first two require the class to have a default, parameterless constructor -var monsterSpawnerDefinition1 = CustomClassDefinition.FromClass(); -var monsterSpawnerDefinition2 = CustomClassDefinition.FromClass(typeof(MonsterSpawner)); -var monsterSpawnerDefinition3 = CustomClassDefinition.FromClass(() => new MonsterSpawner -{ - Enabled = false // This will use the property values in the instance created by a factory method as the default values -}); -``` - -The last one is especially useful if you have classes that may not have parameterless constructors, or if you want to provide custom default values for the properties. Finally, the generated custom class definition will be identical to the one defined manually in the first example. - ### Enum properties Tiled also allows you to define custom property types that work as enums. Similarly to `class` properties, you must define the equivalent in DotTiled as a . You can then return the corresponding definition in the resolving function. @@ -152,9 +121,23 @@ var entityTypeDefinition = new CustomEnumDefinition }; ``` -Similarly to custom class definitions, you can also automatically generate custom enum definitions from C# enums. This is done by using the method, or one of its overloads. This method will generate a from a given C# enum, and you can then use this definition when loading your maps. +### [Future] Automatically map custom property `class` types to C# classes + +In the future, DotTiled will support automatically mapping custom property `class` types to C# classes. This will allow you to define a C# class that matches the structure of the `class` property in Tiled, and DotTiled will automatically map the properties of the `class` property to the properties of the C# class. This will make working with `class` properties much easier and more intuitive. + +The idea is to expand on the interface with a method like `GetMappedProperty(string propertyName)`, where `T` is a class that matches the structure of the `class` property in Tiled. + +This functionality would be accompanied by a way to automatically create a matching given a C# class or enum. Something like this would then be possible: ```csharp +class MonsterSpawner +{ + public bool Enabled { get; set; } = true; + public int MaxSpawnAmount { get; set; } = 10; + public int MinSpawnAmount { get; set; } = 0; + public string MonsterNames { get; set; } = ""; +} + enum EntityType { Bomb, @@ -163,98 +146,16 @@ enum EntityType Chair } +var monsterSpawnerDefinition = CustomClassDefinition.FromClass(); +var entityTypeDefinition = CustomEnumDefinition.FromEnum(); + // ... -// These are both valid ways to create your custom enum definitions from a C# enum -var entityTypeDefinition1 = CustomEnumDefinition.FromEnum(); -var entityTypeDefinition2 = CustomEnumDefinition.FromEnum(typeof(EntityType)); +var map = LoadMap(); +var monsterSpawner = map.GetMappedProperty("monsterSpawnerPropertyInMap"); +var entityType = map.GetMappedProperty("entityTypePropertyInMap"); ``` -The generated custom enum definition will be identical to the one defined manually in the first example. +Finally, it might be possible to also make some kind of exporting functionality for . Given a collection of custom type definitions, DotTiled could generate a corresponding `propertytypes.json` file that you then can import into Tiled. This would make it so that you only have to define your custom property types once (in C#) and then import them into Tiled to use them in your maps. -For enum definitions, the can be used to indicate that the enum should be treated as a flags enum. This will make it so the enum definition will have `ValueAsFlags = true` and the enum values will be treated as flags when working with them in DotTiled. - -> [!NOTE] -> Tiled supports enums which can store their values as either strings or integers, and depending on the storage type you have specified in Tiled, you must make sure to have the same storage type in your . This can be done by setting the `StorageType` property to either `CustomEnumStorageType.String` or `CustomEnumStorageType.Int` when creating the definition, or by passing the storage type as an argument to the method. To be consistent with Tiled, will default to `CustomEnumStorageType.String` for the storage type parameter. - -> [!WARNING] -> If you have a custom enum type in Tiled, but do not define it in DotTiled, you must be aware that the type of the parsed property will be either or . It is not possible to determine the correct way to parse the enum property without the custom enum definition, which is why you will instead be given a property of type `string` or `int` when accessing the property in DotTiled. This can lead to inconsistencies between the map in Tiled and the loaded map with DotTiled. It is therefore recommended to define your custom enum types in DotTiled if you want to access the properties as instances. - -## Mapping properties to C# classes or enums - -So far, we have only discussed how to define custom property types in DotTiled, and why they are needed. However, the most important part is how you can map properties inside your maps to their corresponding C# classes or enums. - -The interface has two overloads of the method. These methods allow you to map a collection of properties to a given C# class. Let's look at an example: - -```csharp -// Define a few Tiled compatible custom types -enum EntityType -{ - Player, - Enemy, - Collectible, - Explosive -} - -class EntityData -{ - public EntityType Type { get; set; } = EntityType.Player; - public int Health { get; set; } = 100; - public string Name { get; set; } = "Unnamed Entity"; -} - -var entityTypeDef = CustomEnumDefinition.FromEnum(); -var entityDataDef = CustomClassDefinition.FromClass(); -``` - -The above gives us two custom type definitions that we can supply to our map loader. Given a map that looks like this: - -> [!WARNING] -> For classes that you call `FromClass` on, which also contain enum properties (at some level of depth) that you want to map to a C# enum, you must also supply the custom enum definitions to the map loader. This is so that the map loader can resolve the enum values correctly. - -```xml - - - - - - 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 - - - - - - - - - - - - - -``` - -We can see that there is an ellipse object in the map that has the type `EntityData` and it has set the three properties to some value other than their defaults. After having loaded this map, we can map the properties of the object to the `EntityData` class like this: - -```csharp -var map = LoadMap([entityTypeDef, entityDataDef]); // Load the map somehow, using DotTiled.Loader or similar - -// Retrieve the object layer from the map in some way -var objectLayer = map.Layers.Skip(1).First() as ObjectLayer; - -// Retrieve the object from the object layer -var entityObject = objectLayer.Objects.First(); - -// Map the properties of the object to the EntityData class -var entityData = entityObject.MapPropertiesTo(); -``` - -The above snippet will map the properties of the object to the `EntityData` class using reflection based on the property names. The `entityData` object will now have the properties set to the values found in the object in the map. If a property is not found in the object, the default value of the property in the `EntityData` class will be used. It will even map the nested enum to its corresponding value in C#. This will work for several levels of depth as it performs this kind of mapping recursively. only supports mapping to classes that have a default, parameterless constructor. - -### [Future] Exporting custom types - -It might be possible to also make some kind of exporting functionality for . Given a collection of custom type definitions, DotTiled could generate a corresponding `propertytypes.json` file that you then can import into Tiled. This would make it so that you only have to define your custom property types once (in C#) and then import them into Tiled to use them in your maps. \ No newline at end of file +Depending on implementation this might become something that can inhibit native AOT compilation due to potential reflection usage. Source generators could be used to mitigate this, but it is not yet clear how this will be implemented. \ No newline at end of file diff --git a/docs/docs/essentials/loading-maps.md b/docs/docs/essentials/loading-maps.md index d262ec9..b34b964 100644 --- a/docs/docs/essentials/loading-maps.md +++ b/docs/docs/essentials/loading-maps.md @@ -1,92 +1,15 @@ # Loading maps -Loading maps with DotTiled is very flexible and allows you as a developer to freely choose how you want to load your maps and tilesets. This guide will show you how to customize the loading process to fit your needs. As the tip below suggests, you can also use the quickstart guide if you just want to load maps from the filesystem without any particular customization. +Loading maps with DotTiled is straightforward and easy. The class is a representation of a Tiled map, mimicking the structure of a Tiled map file. Map files can either be in the [`.tmx`/XML](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) or [`.tmj`/json](https://doc.mapeditor.org/en/stable/reference/json-map-format/) format. DotTiled supports **both** formats fully. -> [!TIP] -> For a quick and easy way to load maps from the filesystem, please refer to the [quickstart guide](../quickstart.md). +> [!NOTE] +> Using the `.tmj` file format will result in not having the same amount of information as for the `.tmx` format. This is due to the fact that the `.tmj` format does not include the full information that the `.tmx` format does. This is not a problem with DotTiled, but rather a limitation of the `.tmj` format. -## File format caveats +## External resolution -The class is a representation of a Tiled map, mimicking the structure of a Tiled XML map file. Map files can either be in the [`.tmx`/XML](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) or [`.tmj`/json](https://doc.mapeditor.org/en/stable/reference/json-map-format/) format. DotTiled supports **both** formats fully. +Tiled maps may consist of several external files, such as tilesets or object templates. In Tiled map files, they are typically referenced by their path relative to the map file. It would be annoying to have to first load all these external resources before loading a map (which is how some other similar libraries work), so loading a map with DotTiled is designed in a way that you only have to provide a function that resolves these external resources. This way, DotTiled will figure out which external resources are needed and will invoke the corresponding resolver function to load them. -> [!WARNING] -> Using the `.tmj` file format will result in (the source image for image layers) not having the same amount of information as for the `.tmx` format. This is due to the fact that the `.tmj` format does not include the full information that the `.tmx` format does. This is not a problem with DotTiled, but rather a limitation of the `.tmj` format. - -## The process of loading a map - -Loading a map with DotTiled is not a complex process, but one that at least demands a basic understanding of how Tiled maps are structured. The process can be broken down into the following flow(-ish) chart: - -```mermaid -flowchart LR - Z{{Loading a map - with DotTiled}} --> A - - subgraph Parsing map - A[(Read map)] --> B(Parse map) - end - - subgraph Parsing tileset - B -.->|References - external tileset| C[(Read tileset)] - C --> D(Parse tileset) --o|Store in map| B - end - - subgraph Parsing template - B -.->|References external - template in object| E[(Read template)] - E --> F(Parse template) --o|Use as template - for object| B - end - - F -.-> |References - external tileset| C - F -.-> |References - external template| E -``` - -As you can see, the process is quite simple. You read the map, parse it, and then read and parse any external tilesets or templates that are referenced in the map. The tilesets and templates are then stored in the map object that is returned to you. - -However, because DotTiled works in the way that it does, you will need to provide a way to resolve these external resources. We'll go through how to do that in the next section. - -## Loading a map with - -When using , external resources like tilesets and templates will be resolved by the loader itself. Since Tiled saves the external resource paths relative to the map file, the loader will automatically resolve these paths and use the provided to read the external resources. Therefore, as long as the external resources are accessible in a "relative path" way using the provided , you don't have to worry about resolving them yourself. - -```xml - - - - - -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 - - - -``` - -A map like the one above that is loaded by the following code will result in the loader calling `IResourceReader.Read("path/to/tileset.tsx")` to read the external tileset, since it will use the path relative to the map file to resolve the tileset. - -```csharp -var loader = Loader.Default(); -var map = loader.LoadMap("path/to/map.tmx"); -``` - -Additionally, the loader will use an in-memory cache to avoid loading the same tileset or template multiple times. This is done using the that is provided to the loader. If you don't provide a cache, the loader will use the by default. - -## Loading a map manually with - -While it is recommended to use the class to perform the loading of maps and tilesets, you may have certain requirements that necessitate you to load maps in a more manual way. This section will guide you through how to load a map manually without the use of the provided loader. - -### , , and - -are the three classes that you will use to read the map, tileset, and template, respectively. They are designed to be used in a way that you can provide your own resolver functions to load external resources. - -> [!IMPORTANT] -> The resolving functions will get the source path of the external resource as a parameter, *in the exact way it is written in the map file*. You will have to perform your own path resolution to load the external resources. +Loading a map, tileset, or template will require you to specify **three** resolver functions. We'll go through each of them below. ### `Func` - Tileset resolver @@ -115,17 +38,17 @@ Tileset ResolveTileset(string source) ### `Func` - Template resolver -This function is used to resolve external object templates by their source path. The function should return a instance given the source path of the template. If you just want to load templates from the file system, you can use something very similar to the example tileset resolver by replacing with . +This function is used to resolve external object templates by their source path. The function should return a instance given the source path of the template. If you just want to load templates from the file system, you can use something very similar to the tileset resolver by replacing with . -### `Func` - Custom type resolver +### `Func` - Custom type resolver -This function is used to resolve custom types that are defined in your Tiled maps. Please refer to the [custom properties](custom-properties.md) documentation for more information on custom types. The function should return a instance given the custom type's name. +This function is used to resolve custom types that are defined in Tiled maps. Please refer to the [custom properties](custom-properties.md) documentation for more information on custom types. The function should return a instance given the custom type's name. ## Putting it all together The following classes are the readers that you will need to use to read the map, tileset, and template: , , and . -Here is an example of how you can load a map with DotTiled, and is very similar to how the class works: +Here is an example of how you can load a map with DotTiled: ```csharp string mapPath = "path/to/map.tmx"; diff --git a/docs/docs/essentials/representation-model.md b/docs/docs/essentials/representation-model.md deleted file mode 100644 index b1b6ef7..0000000 --- a/docs/docs/essentials/representation-model.md +++ /dev/null @@ -1,17 +0,0 @@ -# Representation model - -Tiled map files contain various types of data, such as tilesets, layers, and object groups. The representation model is a way to represent this data in a structured way. By using the `.tmx` file format as inspiration, the representation model is a collection of classes which mimic the structure of a Tiled map file. - -Certain properties throughout the representation model are marked as *optional* by being either wrapped in a or by having a set default value. - -- Properties that make use of the [required](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required) keyword must be present in the file, otherwise an error will be raised. -- Properties that have default values will use the default value if the property is not present in the file, and are not marked as required or optional since you must not provide a value for them. -- Properties that are wrapped in may or may not be present in the file, and have no default value. - -## Version compatibility - -The representation model is designed to be compatible with the latest version of Tiled. This means that it may not be able to read files from older versions of Tiled, or files that use features that are not yet supported by the representation model. However, here is a table of which versions of Tiled are supported by which versions of DotTiled. - -| Tiled version | Compatible DotTiled version(s) | -|---------------|--------------------------------| -| 1.11 | 0.1.0, 0.2.0, 0.2.1, 0.3.0 | \ No newline at end of file diff --git a/docs/docs/quickstart.md b/docs/docs/quickstart.md index c43031b..8d067eb 100644 --- a/docs/docs/quickstart.md +++ b/docs/docs/quickstart.md @@ -6,64 +6,41 @@ Install DotTiled from NuGet: dotnet add package DotTiled ``` -Use the `DotTiled` namespace (if you want). +Load a map from file system: ```csharp -using DotTiled; -``` +string mapPath = "path/to/map.tmx"; +string mapDirectory = Path.GetDirectoryName(mapPath); -Or fully qualify all `DotTiled` types e.g. `DotTiled.Loader`. - -## Loading a map from the file system - -This will create a loader that will load files from the underlying file system using . It will also be configured to use an in-memory cache to avoid loading the same tileset or template multiple times using . - -```csharp -var loader = Loader.Default(); -var map = loader.LoadMap("path/to/map.tmx"); -``` - -## Loading a map from a different source - -If you want to load resources (maps, tilesets, templates) from a different source than the underlying file system, you can override the that is being used with your own implementation of . - -```csharp -var loader = Loader.DefaultWith( - resourceReader: new MyCustomResourceReader()); -var map = loader.LoadMap("path/to/map.tmx"); -``` - -## Caching resources - -Similarly, you can override the that is being used with your own implementation of . - -```csharp -var loader = Loader.DefaultWith( - resourceReader: new MyCustomResourceReader(), - resourceCache: new MyCustomResourceCache()); -var map = loader.LoadMap("path/to/map.tmx"); -``` - -## Custom types - -If you have custom types in your map, you can provide any `IEnumerable` to the loader. This will allow the loader to deserialize the custom types in your map. - -```csharp -var monsterSpawnerDef = new CustomClassDefinition { ... }; -var chestDef = new CustomClassDefinition +Tileset ResolveTileset(string source) { - Name = "Chest", - UseAs = CustomClassUseAs.All, - Members = [ - new IntProperty { Name = "coins", Value = 0 }, - new BoolProperty { Name = "locked", Value = true } - ] -}; + string tilesetPath = Path.Combine(mapDirectory, source); + using var tilesetFileReader = new StreamReader(tilesetPath); + var tilesetString = tilesetReader.ReadToEnd(); + using var tilesetReader = new TilesetReader(tilesetString, ResolveTileset, ResolveTemplate, ResolveCustomType); + return tilesetReader.ReadTileset(); +} -var loader = Loader.DefaultWith( - customTypeDefinitions: [monsterSpawnerDef, chestDef]); -var map = loader.LoadMap("path/to/map.tmx"); +Template ResolveTemplate(string source) +{ + string templatePath = Path.Combine(mapDirectory, source); + using var templateFileReader = new StreamReader(templatePath); + var templateString = templateReader.ReadToEnd(); + using var templateReader = new TemplateReader(templateString, ResolveTileset, ResolveTemplate, ResolveCustomType); + return templateReader.ReadTemplate(); +} -var chest = map.GetProperty("chest").Value; -var coinsToSpawn = chest.GetProperty("coins").Value; -``` \ No newline at end of file +ICustomTypeDefinition ResolveCustomType(string name) +{ + var allDefinedTypes = [ ... ]; + return allDefinedTypes.FirstOrDefault(type => type.Name == name); +} + +using var mapFileReader = new StreamReader(mapPath); +var mapString = mapFileReader.ReadToEnd(); +using var mapReader = new MapReader(mapString, ResolveTileset, ResolveTemplate, ResolveCustomType); + +var map = mapReader.ReadMap(); +``` + +If the above looks intimidating, don't worry! DotTiled is designed to be flexible and allow you to load maps from any source, such as a database or a custom file format. The above example is just one way to load a map from a file system. Please look at [Loading Maps](essentials/loading-maps.md) for more information on how to load maps from different sources. \ No newline at end of file diff --git a/docs/docs/toc.yml b/docs/docs/toc.yml index 5b190b8..6a04547 100644 --- a/docs/docs/toc.yml +++ b/docs/docs/toc.yml @@ -4,5 +4,4 @@ - name: Essentials - href: essentials/loading-maps.md -- href: essentials/representation-model.md - href: essentials/custom-properties.md \ No newline at end of file diff --git a/docs/template/public/main.js b/docs/template/public/main.js deleted file mode 100644 index 7ab60f9..0000000 --- a/docs/template/public/main.js +++ /dev/null @@ -1,9 +0,0 @@ -export default { - iconLinks: [ - { - icon: 'github', - href: 'https://github.com/dcronqvist/DotTiled', - title: 'GitHub' - } - ] -} \ No newline at end of file diff --git a/src/DotTiled.Benchmark/Program.cs b/src/DotTiled.Benchmark/Program.cs index 5378abc..40e695b 100644 --- a/src/DotTiled.Benchmark/Program.cs +++ b/src/DotTiled.Benchmark/Program.cs @@ -15,10 +15,10 @@ namespace DotTiled.Benchmark [HideColumns(["StdDev", "Error", "RatioSD"])] public class MapLoading { - private readonly string _tmxPath = @"DotTiled.Tests/TestData/Maps/default-map/default-map.tmx"; + private readonly string _tmxPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx"; private readonly string _tmxContents = ""; - private readonly string _tmjPath = @"DotTiled.Tests/TestData/Maps/default-map/default-map.tmj"; + private readonly string _tmjPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj"; private readonly string _tmjContents = ""; public MapLoading() diff --git a/src/DotTiled.Examples/DotTiled.Example.Console/DotTiled.Example.Console.csproj b/src/DotTiled.Examples/DotTiled.Example.Console/DotTiled.Example.Console.csproj deleted file mode 100644 index 0dbaba2..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Console/DotTiled.Example.Console.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - - - - - - diff --git a/src/DotTiled.Examples/DotTiled.Example.Console/Program.cs b/src/DotTiled.Examples/DotTiled.Example.Console/Program.cs deleted file mode 100644 index baf36ea..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Console/Program.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Reflection; -using DotTiled.Serialization; - -namespace DotTiled.Example; - -public class Program -{ - private static void Main(string[] args) - { - Quick(args[0]); - Manual(); - } - - // QUICK START - // Automatic and easy way to load tilemaps. - private static void Quick(string basePath) - { - var tilemapPath = Path.Combine(basePath, "tilemap.tmx"); - - var loader = Loader.Default(); - var map = loader.LoadMap(tilemapPath); - - // You can do stuff with it like... - Console.WriteLine($"Tile width and height: {map.TileWidth}x{map.TileHeight}"); - TileLayer layer0 = (TileLayer)map.Layers[0]; // Get a layer - Console.WriteLine($"Tile in layer 0 at 0, 0: {layer0.Data.Value.GlobalTileIDs.Value[0]}"); - } - - // MANUAL - // Manually load a map, if you need to load from a custom source - private static void Manual() - { - using Stream? tilemapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.tilemap.tmx") - ?? throw new FileLoadException($"DotTiled.Example.Console.tilemap.tmx not found in assembly."); - string tileMapString = new StreamReader(tilemapStream).ReadToEnd(); - using var mapReader = new MapReader(tileMapString, ResolveTileset, ResolveTemplate, ResolveCustomType); - var map = mapReader.ReadMap(); - - // Now do some other stuff with it... - StringProperty hello = map.GetProperty("hello"); - Console.WriteLine($"Layer 1 name: {map.Layers[0].Name}"); - Console.WriteLine($"Property 'hello': {hello.Value}"); - - // Now with tileset - Tileset tileset = map.Tilesets[0]; - Console.WriteLine($"Tileset 0 source: {tileset.Source.Value}"); - Console.WriteLine($"Tileset 0 image 0 source: {tileset.Image.Value.Source.Value}"); - } - - // This function is responsible for loading all tilesets required by a tilemap, if you - // want to use a custom source. - private static Tileset ResolveTileset(string source) - { - // Read a file from assembly - // You can use any other source for files, eg. compressed archive, or even file from internet. - using Stream? tilesetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.{source}") - ?? throw new FileLoadException($"{source} not found in assembly."); - string tilesetString = new StreamReader(tilesetStream).ReadToEnd(); - - using TilesetReader tilesetReader = new TilesetReader(tilesetString, ResolveTileset, ResolveTemplate, ResolveCustomType); // Parse loaded tileset. - - return tilesetReader.ReadTileset(); // Return loaded tileset - } - - // This is pretty similar to above, but instead it loads templates, not tilesets. - private static Template ResolveTemplate(string source) - { - using Stream? templateStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.{source}") - ?? throw new FileLoadException($"{source} not found in assembly."); - string templateString = new StreamReader(templateStream).ReadToEnd(); - - using TemplateReader templateReader = new TemplateReader(templateString, ResolveTileset, ResolveTemplate, ResolveCustomType); - return templateReader.ReadTemplate(); - } - - private static Optional ResolveCustomType(string name) - { - ICustomTypeDefinition[] allDefinedTypes = - [ - new CustomClassDefinition() { Name = "a" }, - ]; - return allDefinedTypes.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd ? new Optional(ctd) : Optional.Empty; - } -} diff --git a/src/DotTiled.Examples/DotTiled.Example.Console/tilemap.tmx b/src/DotTiled.Examples/DotTiled.Example.Console/tilemap.tmx deleted file mode 100644 index 7a9a294..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Console/tilemap.tmx +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAA== - - - diff --git a/src/DotTiled.Examples/DotTiled.Example.Console/tileset.png b/src/DotTiled.Examples/DotTiled.Example.Console/tileset.png deleted file mode 100644 index 67b9eee..0000000 Binary files a/src/DotTiled.Examples/DotTiled.Example.Console/tileset.png and /dev/null differ diff --git a/src/DotTiled.Examples/DotTiled.Example.Console/tileset.tsx b/src/DotTiled.Examples/DotTiled.Example.Console/tileset.tsx deleted file mode 100644 index 9fc1b9b..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Console/tileset.tsx +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/.gitattributes b/src/DotTiled.Examples/DotTiled.Example.Godot/.gitattributes deleted file mode 100644 index 8ad74f7..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Normalize EOL for all files that Git considers text files. -* text=auto eol=lf diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/.gitignore b/src/DotTiled.Examples/DotTiled.Example.Godot/.gitignore deleted file mode 100644 index 4709183..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Godot 4+ specific ignores -.godot/ diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.csproj b/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.csproj deleted file mode 100644 index 99e4b77..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - net8.0 - net7.0 - net8.0 - true - - - - - \ No newline at end of file diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.sln b/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.sln deleted file mode 100644 index c707fa2..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/DotTiled.Example.Godot.sln +++ /dev/null @@ -1,19 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotTiled.Example.Godot", "DotTiled.Example.Godot.csproj", "{61468FCF-ACC1-4E3B-B4B4-270279E45BF5}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - ExportDebug|Any CPU = ExportDebug|Any CPU - ExportRelease|Any CPU = ExportRelease|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU - {61468FCF-ACC1-4E3B-B4B4-270279E45BF5}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU - EndGlobalSection -EndGlobal diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/MapParser.cs b/src/DotTiled.Examples/DotTiled.Example.Godot/MapParser.cs deleted file mode 100644 index 8319d00..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/MapParser.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Globalization; -using System.Linq; -using DotTiled.Serialization; -using Godot; - -namespace DotTiled.Example.Godot; -public partial class MapParser : Node2D -{ - public override void _Ready() - { - // Load map - var mapString = FileAccess.Open("res://tilemap.tmx", FileAccess.ModeFlags.Read).GetAsText(); //Get file from Godot filesystem - using var mapReader = new MapReader(mapString, ResolveTileset, ResolveTemplate, ResolveCustomType); - var map = mapReader.ReadMap(); - - TileLayer layer0 = (TileLayer)map.Layers[0]; - - for (int y = 0; y < layer0.Height; y++) - { - for (int x = 0; x < layer0.Width; x++) - { - uint tile = layer0.Data.Value.GlobalTileIDs.Value[(y * layer0.Width) + x]; - if (tile == 0) continue; // If block is 0, i.e. air, then continue - - // Load actual block from Godot resources - Node2D block = (Node2D)GD.Load($"res://blocks/{tile}.tscn").Instantiate(); - - // Calculate where block should be - Vector2I scale = (Vector2I)block.GetNode(tile.ToString(CultureInfo.CurrentCulture)).Scale; - int blockX = (block.GetNode(tile.ToString(CultureInfo.CurrentCulture)).Texture.GetWidth() * scale.X / 2) + - (x * block.GetNode(tile.ToString(CultureInfo.CurrentCulture)).Texture.GetWidth() * scale.X); - int blockY = (block.GetNode(tile.ToString(CultureInfo.CurrentCulture)).Texture.GetHeight() * scale.Y / 2) + - (y * block.GetNode(tile.ToString(CultureInfo.CurrentCulture)).Texture.GetHeight() * scale.Y); - block.Position = new Vector2(blockX, blockY); - - // Add block to current scene - AddChild(block); - GD.Print($"{blockX}, {blockY}: {tile}"); - } - } - } - - private Tileset ResolveTileset(string source) - { - string tilesetString = FileAccess.Open($"res://{source}", FileAccess.ModeFlags.Read).GetAsText(); - using TilesetReader tilesetReader = - new TilesetReader(tilesetString, ResolveTileset, ResolveTemplate, ResolveCustomType); - return tilesetReader.ReadTileset(); - } - - private Template ResolveTemplate(string source) - { - string templateString = FileAccess.Open($"res://{source}", FileAccess.ModeFlags.Read).GetAsText(); - using TemplateReader templateReader = - new TemplateReader(templateString, ResolveTileset, ResolveTemplate, ResolveCustomType); - return templateReader.ReadTemplate(); - } - - private static Optional ResolveCustomType(string name) - { - ICustomTypeDefinition[] allDefinedTypes = - [ - new CustomClassDefinition() { Name = "a" }, - ]; - return allDefinedTypes.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd ? new Optional(ctd) : Optional.Empty; - } -} diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/blocks/1.tscn b/src/DotTiled.Examples/DotTiled.Example.Godot/blocks/1.tscn deleted file mode 100644 index 8c10a13..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/blocks/1.tscn +++ /dev/null @@ -1,9 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://ce10iald4cb3f"] - -[ext_resource type="Texture2D" uid="uid://da08vay832u8c" path="res://tileset.png" id="1_c5fs4"] - -[node name="1" type="Node2D"] - -[node name="1" type="Sprite2D" parent="."] -scale = Vector2(2, 2) -texture = ExtResource("1_c5fs4") diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg b/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg deleted file mode 100644 index 3fe4f4a..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg.import b/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg.import deleted file mode 100644 index 164e9de..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/icon.svg.import +++ /dev/null @@ -1,37 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://0kywmrvvqqyr" -path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://icon.svg" -dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 -svg/scale=1.0 -editor/scale_with_editor_scale=false -editor/convert_colors_with_editor_theme=false diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/main.tscn b/src/DotTiled.Examples/DotTiled.Example.Godot/main.tscn deleted file mode 100644 index 4fdfc60..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/main.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://p4rpwsvyslew"] - -[ext_resource type="Script" path="res://MapParser.cs" id="1_xjmxv"] - -[node name="Node2D" type="Node2D"] -script = ExtResource("1_xjmxv") diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/project.godot b/src/DotTiled.Examples/DotTiled.Example.Godot/project.godot deleted file mode 100644 index 539b623..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/project.godot +++ /dev/null @@ -1,20 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=5 - -[application] - -config/name="DotTiled.Example.Godot" -run/main_scene="res://main.tscn" -config/features=PackedStringArray("4.3", "C#", "Forward Plus") -config/icon="res://icon.svg" - -[dotnet] - -project/assembly_name="DotTiled.Example.Godot" diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/tilemap.tmx b/src/DotTiled.Examples/DotTiled.Example.Godot/tilemap.tmx deleted file mode 100644 index 7a9a294..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/tilemap.tmx +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAA== - - - diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png b/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png deleted file mode 100644 index 67b9eee..0000000 Binary files a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png and /dev/null differ diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png.import b/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png.import deleted file mode 100644 index 440f099..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://da08vay832u8c" -path="res://.godot/imported/tileset.png-a39e944f25b35d62f55d4f98a36e2b5e.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://tileset.png" -dest_files=["res://.godot/imported/tileset.png-a39e944f25b35d62f55d4f98a36e2b5e.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.tsx b/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.tsx deleted file mode 100644 index 9fc1b9b..0000000 --- a/src/DotTiled.Examples/DotTiled.Example.Godot/tileset.tsx +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/DotTiled.Tests/Assert/AssertCustomTypes.cs b/src/DotTiled.Tests/Assert/AssertCustomTypes.cs deleted file mode 100644 index 19eae5b..0000000 --- a/src/DotTiled.Tests/Assert/AssertCustomTypes.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace DotTiled.Tests; - -public static partial class DotTiledAssert -{ - internal static void AssertCustomClassDefinitionEqual(CustomClassDefinition expected, CustomClassDefinition actual) - { - AssertEqual(expected.ID, actual.ID, nameof(CustomClassDefinition.ID)); - AssertEqual(expected.Name, actual.Name, nameof(CustomClassDefinition.Name)); - AssertEqual(expected.Color, actual.Color, nameof(CustomClassDefinition.Color)); - AssertEqual(expected.DrawFill, actual.DrawFill, nameof(CustomClassDefinition.DrawFill)); - AssertEqual(expected.UseAs, actual.UseAs, nameof(CustomClassDefinition.UseAs)); - AssertProperties(expected.Members, actual.Members); - } - - internal static void AssertCustomEnumDefinitionEqual(CustomEnumDefinition expected, CustomEnumDefinition actual) - { - AssertEqual(expected.ID, actual.ID, nameof(CustomEnumDefinition.ID)); - AssertEqual(expected.Name, actual.Name, nameof(CustomEnumDefinition.Name)); - AssertEqual(expected.StorageType, actual.StorageType, nameof(CustomEnumDefinition.StorageType)); - AssertEqual(expected.ValueAsFlags, actual.ValueAsFlags, nameof(CustomEnumDefinition.ValueAsFlags)); - AssertListOrdered(expected.Values, actual.Values, nameof(CustomEnumDefinition.Values)); - } -} diff --git a/src/DotTiled.Tests/Assert/AssertData.cs b/src/DotTiled.Tests/Assert/AssertData.cs index 6e8aaa2..31ffff2 100644 --- a/src/DotTiled.Tests/Assert/AssertData.cs +++ b/src/DotTiled.Tests/Assert/AssertData.cs @@ -2,7 +2,7 @@ namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertData(Data expected, Data actual) + internal static void AssertData(Data? expected, Data? actual) { if (expected is null) { @@ -18,7 +18,14 @@ public static partial class DotTiledAssert // Data AssertEqual(expected.GlobalTileIDs, actual.GlobalTileIDs, nameof(Data.GlobalTileIDs)); AssertEqual(expected.FlippingFlags, actual.FlippingFlags, nameof(Data.FlippingFlags)); - AssertOptionalsEqual(expected.Chunks, actual.Chunks, nameof(Data.Chunks), (a, b) => AssertListOrdered(a, b, nameof(Chunk), AssertChunk)); + + 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) diff --git a/src/DotTiled.Tests/Assert/AssertImage.cs b/src/DotTiled.Tests/Assert/AssertImage.cs index 6bb5f4e..a674faa 100644 --- a/src/DotTiled.Tests/Assert/AssertImage.cs +++ b/src/DotTiled.Tests/Assert/AssertImage.cs @@ -2,7 +2,7 @@ namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertImage(Image expected, Image actual) + internal static void AssertImage(Image? expected, Image? actual) { if (expected is null) { diff --git a/src/DotTiled.Tests/Assert/AssertLayer.cs b/src/DotTiled.Tests/Assert/AssertLayer.cs index 7dc8011..5432d62 100644 --- a/src/DotTiled.Tests/Assert/AssertLayer.cs +++ b/src/DotTiled.Tests/Assert/AssertLayer.cs @@ -2,7 +2,7 @@ namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertLayer(BaseLayer expected, BaseLayer actual) + internal static void AssertLayer(BaseLayer? expected, BaseLayer? actual) { if (expected is null) { diff --git a/src/DotTiled.Tests/Assert/AssertMap.cs b/src/DotTiled.Tests/Assert/AssertMap.cs index bc87002..0110f51 100644 --- a/src/DotTiled.Tests/Assert/AssertMap.cs +++ b/src/DotTiled.Tests/Assert/AssertMap.cs @@ -5,69 +5,7 @@ namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertListOrdered(IList expected, IList actual, string nameof, Action assertEqual = null) - { - if (expected is null) - { - Assert.Null(actual); - return; - } - - Assert.NotNull(actual); - AssertEqual(expected.Count, actual.Count, $"{nameof}.Count"); - - for (var i = 0; i < expected.Count; i++) - { - if (assertEqual is not null) - { - assertEqual(expected[i], actual[i]); - continue; - } - AssertEqual(expected[i], actual[i], $"{nameof}[{i}]"); - } - } - - internal static void AssertOptionalsEqual( - Optional expected, - Optional actual, - string nameof, - Action assertEqual) - { - if (expected is null) - { - Assert.Null(actual); - return; - } - - if (expected.HasValue) - { - Assert.True(actual.HasValue, $"Expected {nameof} to have a value"); - assertEqual(expected.Value, actual.Value); - return; - } - - Assert.False(actual.HasValue, $"Expected {nameof} to not have a value"); - } - - internal static void AssertEqual(Optional expected, Optional actual, string nameof) - { - if (expected is null) - { - Assert.Null(actual); - return; - } - - if (expected.HasValue) - { - Assert.True(actual.HasValue, $"Expected {nameof} to have a value"); - AssertEqual(expected.Value, actual.Value, nameof); - return; - } - - Assert.False(actual.HasValue, $"Expected {nameof} to not have a value"); - } - - internal static void AssertEqual(T expected, T actual, string nameof) + private static void AssertEqual(T expected, T actual, string nameof) { if (expected == null) { diff --git a/src/DotTiled.Tests/Assert/AssertProperties.cs b/src/DotTiled.Tests/Assert/AssertProperties.cs index 9454486..843d8d0 100644 --- a/src/DotTiled.Tests/Assert/AssertProperties.cs +++ b/src/DotTiled.Tests/Assert/AssertProperties.cs @@ -2,7 +2,7 @@ namespace DotTiled.Tests; public static partial class DotTiledAssert { - internal static void AssertProperties(IList expected, IList actual) + internal static void AssertProperties(IList? expected, IList? actual) { if (expected is null) { diff --git a/src/DotTiled.Tests/Assert/AssertTileset.cs b/src/DotTiled.Tests/Assert/AssertTileset.cs index 607b542..4646a85 100644 --- a/src/DotTiled.Tests/Assert/AssertTileset.cs +++ b/src/DotTiled.Tests/Assert/AssertTileset.cs @@ -4,6 +4,7 @@ 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)); @@ -20,16 +21,29 @@ public static partial class DotTiledAssert AssertEqual(expected.RenderSize, actual.RenderSize, nameof(Tileset.RenderSize)); AssertEqual(expected.FillMode, actual.FillMode, nameof(Tileset.FillMode)); - AssertOptionalsEqual(expected.Image, actual.Image, nameof(Tileset.Image), AssertImage); - AssertOptionalsEqual(expected.TileOffset, actual.TileOffset, nameof(Tileset.TileOffset), AssertTileOffset); - AssertOptionalsEqual(expected.Grid, actual.Grid, nameof(Tileset.Grid), AssertGrid); + // At most one of + AssertImage(expected.Image, actual.Image); + AssertTileOffset(expected.TileOffset, actual.TileOffset); + AssertGrid(expected.Grid, actual.Grid); AssertProperties(expected.Properties, actual.Properties); - AssertListOrdered(expected.Wangsets, actual.Wangsets, nameof(Tileset.Wangsets), AssertWangset); - AssertOptionalsEqual(expected.Transformations, actual.Transformations, nameof(Tileset.Transformations), AssertTransformations); - AssertListOrdered(expected.Tiles, actual.Tiles, nameof(Tileset.Tiles), AssertTile); + // 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) + private static void AssertTileOffset(TileOffset? expected, TileOffset? actual) { if (expected is null) { @@ -43,7 +57,7 @@ public static partial class DotTiledAssert AssertEqual(expected.Y, actual.Y, nameof(TileOffset.Y)); } - private static void AssertGrid(Grid expected, Grid actual) + private static void AssertGrid(Grid? expected, Grid? actual) { if (expected is null) { @@ -60,17 +74,27 @@ public static partial class DotTiledAssert 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); - AssertListOrdered(expected.WangColors, actual.WangColors, nameof(Wangset.WangColors), AssertWangColor); - AssertListOrdered(expected.WangTiles, actual.WangTiles, nameof(Wangset.WangTiles), AssertWangTile); + 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)); @@ -82,11 +106,12 @@ public static partial class DotTiledAssert 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) + private static void AssertTransformations(Transformations? expected, Transformations? actual) { if (expected is null) { @@ -94,6 +119,7 @@ public static partial class DotTiledAssert return; } + // Attributes Assert.NotNull(actual); AssertEqual(expected.HFlip, actual.HFlip, nameof(Transformations.HFlip)); AssertEqual(expected.VFlip, actual.VFlip, nameof(Transformations.VFlip)); @@ -103,6 +129,7 @@ public static partial class DotTiledAssert 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)); @@ -111,14 +138,22 @@ public static partial class DotTiledAssert AssertEqual(expected.Width, actual.Width, nameof(Tile.Width)); AssertEqual(expected.Height, actual.Height, nameof(Tile.Height)); + // Elements AssertProperties(expected.Properties, actual.Properties); - AssertOptionalsEqual(expected.Image, actual.Image, nameof(Tile.Image), AssertImage); - AssertOptionalsEqual(expected.ObjectLayer, actual.ObjectLayer, nameof(Tile.ObjectLayer), (a, b) => AssertLayer((BaseLayer)a, (BaseLayer)b)); - AssertListOrdered(expected.Animation, actual.Animation, nameof(Tile.Animation), AssertFrame); + AssertImage(expected.Image, actual.Image); + AssertLayer((BaseLayer?)expected.ObjectLayer, (BaseLayer?)actual.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)); } diff --git a/src/DotTiled.Tests/DotTiled.Tests.csproj b/src/DotTiled.Tests/DotTiled.Tests.csproj index 552a423..faa22d4 100644 --- a/src/DotTiled.Tests/DotTiled.Tests.csproj +++ b/src/DotTiled.Tests/DotTiled.Tests.csproj @@ -3,6 +3,7 @@ net8.0 enable + enable false true @@ -11,7 +12,6 @@ - @@ -26,12 +26,7 @@ - - - - - - + diff --git a/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs b/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs deleted file mode 100644 index c0d580f..0000000 --- a/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs +++ /dev/null @@ -1,272 +0,0 @@ -using DotTiled.Serialization; -using NSubstitute; - -namespace DotTiled.Tests; - -public class FromTypeUsedInLoaderTests -{ - private sealed class TestClass - { - public string Name { get; set; } = "John Doe"; - public int Age { get; set; } = 42; - } - - [Fact] - public void LoadMap_MapHasClassAndClassIsDefined_ReturnsCorrectMap() - { - // Arrange - var resourceReader = Substitute.For(); - resourceReader.Read("map.tmx").Returns( - """ - - - - - 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 - - - - """); - var classDefinition = CustomClassDefinition.FromClass(); - var loader = Loader.DefaultWith( - resourceReader: resourceReader, - customTypeDefinitions: [classDefinition]); - var expectedMap = new Map - { - Class = "TestClass", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 StringProperty { Name = "Name", Value = "John Doe" }, - new IntProperty { Name = "Age", Value = 42 } - ] - }; - - // Act - var result = loader.LoadMap("map.tmx"); - - // Assert - DotTiledAssert.AssertMap(expectedMap, result); - } - - [Fact] - public void LoadMap_MapHasClassAndClassIsDefinedAndFieldIsOverridenFromDefault_ReturnsCorrectMap() - { - // Arrange - var resourceReader = Substitute.For(); - resourceReader.Read("map.tmx").Returns( - """ - - - - - - - - 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 - - - - """); - var classDefinition = CustomClassDefinition.FromClass(); - var loader = Loader.DefaultWith( - resourceReader: resourceReader, - customTypeDefinitions: [classDefinition]); - var expectedMap = new Map - { - Class = "TestClass", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 StringProperty { Name = "Name", Value = "John Doe" }, - new IntProperty { Name = "Age", Value = 42 } - ] - }; - - // Act - var result = loader.LoadMap("map.tmx"); - - // Assert - DotTiledAssert.AssertMap(expectedMap, result); - } - - private enum TestEnum - { - Value1, - Value2 - } - - private sealed class TestClassWithEnum - { - public TestEnum Enum { get; set; } = TestEnum.Value1; - } - - [Fact] - public void LoadMap_MapHasClassWithEnumAndClassIsDefined_ReturnsCorrectMap() - { - // Arrange - var resourceReader = Substitute.For(); - resourceReader.Read("map.tmx").Returns( - """ - - - - - 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 - - - - """); - var classDefinition = CustomClassDefinition.FromClass(); - var loader = Loader.DefaultWith( - resourceReader: resourceReader, - customTypeDefinitions: [classDefinition]); - var expectedMap = new Map - { - Class = "TestClassWithEnum", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 EnumProperty { Name = "Enum", PropertyType = "TestEnum", Value = new HashSet { "Value1" } } - ] - }; - - // Act - var result = loader.LoadMap("map.tmx"); - - // Assert - DotTiledAssert.AssertMap(expectedMap, result); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Serialization/MapReaderTests.cs b/src/DotTiled.Tests/Serialization/MapReaderTests.cs similarity index 84% rename from src/DotTiled.Tests/UnitTests/Serialization/MapReaderTests.cs rename to src/DotTiled.Tests/Serialization/MapReaderTests.cs index dd6bcca..885f57e 100644 --- a/src/DotTiled.Tests/UnitTests/Serialization/MapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/MapReaderTests.cs @@ -32,14 +32,9 @@ public partial class MapReaderTests using var tilesetReader = new TilesetReader(tilesetString, ResolveTileset, ResolveTemplate, ResolveCustomType); return tilesetReader.ReadTileset(); } - Optional ResolveCustomType(string name) + ICustomTypeDefinition ResolveCustomType(string name) { - if (customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd) - { - return new Optional(ctd); - } - - return Optional.Empty; + return customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name)!; } using var mapReader = new MapReader(mapString, ResolveTileset, ResolveTemplate, ResolveCustomType); diff --git a/src/DotTiled.Tests/Serialization/TestData.cs b/src/DotTiled.Tests/Serialization/TestData.cs new file mode 100644 index 0000000..7f68c9e --- /dev/null +++ b/src/DotTiled.Tests/Serialization/TestData.cs @@ -0,0 +1,45 @@ +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 MapTests => + [ + ["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty()], + ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty()], + ["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()], + ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_deep_props/map-with-deep-props", (string f) => MapWithDeepProps(), MapWithDeepPropsCustomTypeDefinitions()], + ]; +} diff --git a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs similarity index 87% rename from src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs index 8aeae0d..eff73d9 100644 --- a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs @@ -11,6 +11,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -30,20 +33,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/default-map/default-map.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/default-map/default-map.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/default-map/default-map.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs similarity index 93% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs index 2500a4d..28d6272 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -94,20 +97,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/map-external-tileset-multi.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/multi-tileset.tsj b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/multi-tileset.tsj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/multi-tileset.tsj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/multi-tileset.tsj diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/multi-tileset.tsx b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/multi-tileset.tsx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/multi-tileset.tsx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/multi-tileset.tsx diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-multi/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs similarity index 61% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs index 756c59f..9aaa7d7 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 24, TileHeight = 24, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -53,59 +56,7 @@ public partial class TestData Source = "tileset.png", Width = 256, Height = 96, - }, - Wangsets = [ - new Wangset - { - Name = "test-terrain", - Tile = -1, - WangColors = [ - new WangColor - { - Name = "Water", - Color = Color.Parse("#ff0000", CultureInfo.InvariantCulture), - Tile = 0, - Probability = 1 - }, - new WangColor - { - Name = "Grass", - Color = Color.Parse("#00ff00", CultureInfo.InvariantCulture), - Tile = -1, - Probability = 1 - }, - new WangColor - { - Name = "Stone", - Color = Color.Parse("#0000ff", CultureInfo.InvariantCulture), - Tile = 29, - Probability = 1 - } - ], - WangTiles = [ - new WangTile - { - TileID = 0, - WangID = [1,1,0,0,0,1,1,1] - }, - new WangTile - { - TileID = 1, - WangID = [1,1,1,1,0,0,0,1] - }, - new WangTile - { - TileID = 10, - WangID = [0,0,0,1,1,1,1,1] - }, - new WangTile - { - TileID = 11, - WangID = [0,1,1,1,1,1,0,0] - } - ] - } - ] + } } ], Layers = [ @@ -118,20 +69,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/map-external-tileset-wangset.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/wangset-tileset.tsj b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/wangset-tileset.tsj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/wangset-tileset.tsj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/wangset-tileset.tsj diff --git a/src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/wangset-tileset.tsx b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/wangset-tileset.tsx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-external-tileset-wangset/wangset-tileset.tsx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/wangset-tileset.tsx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs similarity index 89% rename from src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs index 2437d0b..fdedbf8 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 16, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -32,20 +35,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ], @@ -57,8 +62,7 @@ public partial class TestData new FloatProperty { Name = "floatprop", Value = 4.2f }, new IntProperty { Name = "intprop", Value = 8 }, new ObjectProperty { Name = "objectprop", Value = 5 }, - new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }, - new ColorProperty { Name = "unsetcolorprop", Value = Optional.Empty } + new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" } ] }; } diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmj similarity index 88% rename from src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmj index 4fbc980..c7182ef 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmj +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmj @@ -58,11 +58,6 @@ "name":"stringprop", "type":"string", "value":"This is a string, hello world!" - }, - { - "name":"unsetcolorprop", - "type":"color", - "value":"" }], "renderorder":"right-down", "tiledversion":"1.11.0", diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmx similarity index 91% rename from src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmx index 1aeacd7..b4b36cd 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-common-props/map-with-common-props.tmx +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.tmx @@ -8,7 +8,6 @@ - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs similarity index 96% rename from src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs index f77638b..56759d4 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -32,20 +35,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ], diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/map-with-custom-type-props.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/propertytypes.json b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/propertytypes.json similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props/propertytypes.json rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/propertytypes.json diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.cs similarity index 95% rename from src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.cs index b67548a..90aac6c 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -32,20 +35,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ], diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-deep-props/map-with-deep-props.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-deep-props/map-with-deep-props.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs similarity index 89% rename from src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs index 0056fd1..fb3c95f 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -25,8 +28,6 @@ public partial class TestData Tilesets = [ new Tileset { - Version = "1.10", - TiledVersion = "1.11.0", FirstGID = 1, Name = "tileset", TileWidth = 32, @@ -52,20 +53,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/map-with-embedded-tileset.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs similarity index 90% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs index 15b9873..10c4d67 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -53,20 +56,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/map-with-external-tileset.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-embedded-tileset/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.tsj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.tsj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.tsj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.tsj diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.tsx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.tsx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-override-object-bug/tileset.tsx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/tileset.tsx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs similarity index 72% rename from src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs index aef25d3..4e181c4 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -20,8 +23,8 @@ public partial class TestData BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", - NextLayerID = 3, - NextObjectID = 3, + NextLayerID = 2, + NextObjectID = 1, Tilesets = [ new Tileset { @@ -53,48 +56,23 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } - }, - new ObjectLayer - { - ID = 2, - Name = "Object Layer 1", - Objects = [ - new TileObject - { - ID = 1, - GID = 21, - X = 80.0555f, - Y = 48.3887f, - Width = 32, - Height = 32, - FlippingFlags = FlippingFlags.FlippedHorizontally - }, - new TileObject - { - ID = 2, - GID = 21, - X = 15.833f, - Y = 112.056f, - Width = 32, - Height = 32, - FlippingFlags = FlippingFlags.FlippedHorizontally | FlippingFlags.FlippedVertically - } - ] } ] }; diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmj similarity index 56% rename from src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmj index d60afe3..3b74128 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmj +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmj @@ -1,14 +1,13 @@ -{ "class":"TestClass", - "compressionlevel":-1, +{ "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], + "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", @@ -22,16 +21,14 @@ "nextlayerid":2, "nextobjectid":1, "orientation":"orthogonal", - "properties":[ - { - "name":"classstring", - "type":"string", - "value":"I am not default value" - }], "renderorder":"right-down", "tiledversion":"1.11.0", "tileheight":32, - "tilesets":[], + "tilesets":[ + { + "firstgid":1, + "source":"tileset.tsj" + }], "tilewidth":32, "type":"map", "version":"1.10", diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmx similarity index 60% rename from src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmx index ca0130d..a72cd1a 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.tmx @@ -1,5 +1,5 @@ - + @@ -10,8 +10,4 @@ 2147483669,2147483669,2147483669,2147483669,1 - - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.tsj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.tsj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.tsj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.tsj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.tsx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.tsx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-external-tileset/tileset.tsx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/tileset.tsx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs similarity index 91% rename from src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs index 1b06285..64974bc 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs @@ -13,6 +13,9 @@ public partial class TestData TileWidth = 32, TileHeight = 32, Infinite = false, + HexSideLength = null, + StaggerAxis = null, + StaggerIndex = null, ParallaxOriginX = 0, ParallaxOriginY = 0, RenderOrder = RenderOrder.RightDown, @@ -121,20 +124,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 @@ -146,20 +151,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] @@ -186,20 +193,22 @@ public partial class TestData Data = new Data { Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ + 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 = new Optional([ + ], + 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 - ]) + ] } } ] diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.tmj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.tmj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.tmx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.tmx diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/poly.tj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/poly.tj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-override-object-bug/poly.tj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/poly.tj diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/poly.tx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/poly.tx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-override-object-bug/poly.tx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/poly.tx diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.png b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.png similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.png rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.png diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.tsj b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.tsj similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.tsj rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.tsj diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.tsx b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.tsx similarity index 100% rename from src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/tileset.tsx rename to src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/tileset.tsx diff --git a/src/DotTiled.Tests/UnitTests/Serialization/Tmj/TmjMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs similarity index 83% rename from src/DotTiled.Tests/UnitTests/Serialization/Tmj/TmjMapReaderTests.cs rename to src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs index aa289f6..a896a48 100644 --- a/src/DotTiled.Tests/UnitTests/Serialization/Tmj/TmjMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs @@ -28,14 +28,9 @@ public partial class TmjMapReaderTests using var tilesetReader = new TsjTilesetReader(tilesetJson, ResolveTileset, ResolveTemplate, ResolveCustomType); return tilesetReader.ReadTileset(); } - Optional ResolveCustomType(string name) + ICustomTypeDefinition ResolveCustomType(string name) { - if (customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd) - { - return new Optional(ctd); - } - - return Optional.Empty; + return customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name)!; } using var mapReader = new TmjMapReader(json, ResolveTileset, ResolveTemplate, ResolveCustomType); diff --git a/src/DotTiled.Tests/UnitTests/Serialization/Tmx/TmxMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs similarity index 83% rename from src/DotTiled.Tests/UnitTests/Serialization/Tmx/TmxMapReaderTests.cs rename to src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs index 82dba07..b6e5813 100644 --- a/src/DotTiled.Tests/UnitTests/Serialization/Tmx/TmxMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs @@ -28,14 +28,9 @@ public partial class TmxMapReaderTests using var tilesetReader = new TsxTilesetReader(xmlTilesetReader, ResolveTileset, ResolveTemplate, ResolveCustomType); return tilesetReader.ReadTileset(); } - Optional ResolveCustomType(string name) + ICustomTypeDefinition ResolveCustomType(string name) { - if (customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd) - { - return new Optional(ctd); - } - - return Optional.Empty; + return customTypeDefinitions.FirstOrDefault(ctd => ctd.Name == name)!; } using var mapReader = new TmxMapReader(reader, ResolveTileset, ResolveTemplate, ResolveCustomType); diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs deleted file mode 100644 index 82dfd29..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.cs +++ /dev/null @@ -1,242 +0,0 @@ -using System.Numerics; - -namespace DotTiled.Tests; - -public partial class TestData -{ - public static Map MapOverrideObjectBug(string fileExt) => new Map - { - Class = "", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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 = 8, - 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 StringProperty { Name = "templateprop", Value = "helo there" } - ] - }, - new TileObject - { - ID = 6, - Name = "TileObj", - GID = 7, - X = -35, - Y = 110.333f, - Width = 64, - Height = 146 - }, - new RectangleObject - { - ID = 7, - Name = "", - Template = fileExt == "tmx" ? "random.tx" : "random.tj", - Type = "randomclass", - X = 134.552f, - Y = 113.638f - } - ] - }, - new Group - { - ID = 5, - Name = "Sub", - Layers = [ - new TileLayer - { - ID = 7, - Name = "Tile 3", - Width = 5, - Height = 5, - Data = new Data - { - Encoding = DataEncoding.Csv, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 - ]) - } - } - ] - } - ] - }; - - public static IReadOnlyCollection MapOverrideObjectBugCustomTypeDefinitions() => [ - new CustomClassDefinition - { - Name = "TestClass", - UseAs = CustomClassUseAs.Map, - Members = [ - new BoolProperty - { - Name = "classbool", - Value = true - }, - new StringProperty - { - Name = "classstring", - Value = "Hello there default value" - } - ] - }, - new CustomClassDefinition - { - Name = "randomclass" - } - ]; -} diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmj b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmj deleted file mode 100644 index ba67083..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmj +++ /dev/null @@ -1,171 +0,0 @@ -{ "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 - }, - - { - "id":7, - "template":"random.tj", - "type":"randomclass", - "x":134.551764025448, - "y":113.637941006362 - }], - "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":8, - "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 -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmx b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmx deleted file mode 100644 index 08f2657..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/map-override-object-bug.tmx +++ /dev/null @@ -1,50 +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,0,0 - - - - -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 - - - - - - - - -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 - - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tj b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tj deleted file mode 100644 index 09b8393..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tj +++ /dev/null @@ -1,12 +0,0 @@ -{ "object": - { - "height":0, - "id":7, - "name":"", - "rotation":0, - "type":"randomclass", - "visible":true, - "width":0 - }, - "type":"template" -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tx b/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tx deleted file mode 100644 index d6b44ee..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-override-object-bug/random.tx +++ /dev/null @@ -1,4 +0,0 @@ - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs b/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs deleted file mode 100644 index 8cbd6bd..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.cs +++ /dev/null @@ -1,83 +0,0 @@ -namespace DotTiled.Tests; - -public partial class TestData -{ - public static Map MapWithClassAndProps() => new Map - { - Class = "TestClass", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 BoolProperty - { - Name = "classbool", - Value = true - }, - new StringProperty - { - Name = "classstring", - Value = "I am not default value" - } - ] - }; - - public static IReadOnlyCollection MapWithClassAndPropsCustomTypeDefinitions() => [ - new CustomClassDefinition - { - Name = "TestClass", - UseAs = CustomClassUseAs.Map, - Members = [ - new BoolProperty - { - Name = "classbool", - Value = true - }, - new StringProperty - { - Name = "classstring", - Value = "Hello there default value" - } - ] - }, - ]; -} diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmx deleted file mode 100644 index 4da805d..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class-and-props/map-with-class-and-props.tmx +++ /dev/null @@ -1,15 +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,0,0 - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs b/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs deleted file mode 100644 index ef98d02..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.cs +++ /dev/null @@ -1,83 +0,0 @@ -namespace DotTiled.Tests; - -public partial class TestData -{ - public static Map MapWithClass() => new Map - { - Class = "TestClass", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 BoolProperty - { - Name = "classbool", - Value = true - }, - new StringProperty - { - Name = "classstring", - Value = "Hello there default value" - } - ] - }; - - public static IReadOnlyCollection MapWithClassCustomTypeDefinitions() => [ - new CustomClassDefinition - { - Name = "TestClass", - UseAs = CustomClassUseAs.Map, - Members = [ - new BoolProperty - { - Name = "classbool", - Value = true - }, - new StringProperty - { - Name = "classstring", - Value = "Hello there default value" - } - ] - }, - ]; -} diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmj deleted file mode 100644 index 480e3bb..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmj +++ /dev/null @@ -1,33 +0,0 @@ -{ "class":"TestClass", - "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 -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmx deleted file mode 100644 index b3382eb..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-class/map-with-class.tmx +++ /dev/null @@ -1,12 +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,0,0 - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs deleted file mode 100644 index 4134dac..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Globalization; - -namespace DotTiled.Tests; - -public partial class TestData -{ - public static Map MapWithCustomTypePropsWithoutDefs() => new Map - { - Class = "", - Orientation = MapOrientation.Orthogonal, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 32, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 ClassProperty - { - Name = "customclassprop", - PropertyType = "CustomClass", - Value = [ - new BoolProperty { Name = "boolinclass", Value = true }, - new FloatProperty { Name = "floatinclass", Value = 13.37f }, - new StringProperty { Name = "stringinclass", Value = "This is a set string" } - ] - }, - new IntProperty - { - Name = "customenumintflagsprop", - Value = 6 - }, - new IntProperty - { - Name = "customenumintprop", - Value = 3 - }, - new StringProperty - { - Name = "customenumstringprop", - Value = "CustomEnumString_2" - }, - new StringProperty - { - Name = "customenumstringflagsprop", - Value = "CustomEnumStringFlags_1,CustomEnumStringFlags_2" - } - ] - }; -} diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmj deleted file mode 100644 index 74f892b..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmj +++ /dev/null @@ -1,68 +0,0 @@ -{ "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" - } - }, - { - "name":"customenumintflagsprop", - "propertytype":"CustomEnumIntFlags", - "type":"int", - "value":6 - }, - { - "name":"customenumintprop", - "propertytype":"CustomEnumInt", - "type":"int", - "value":3 - }, - { - "name":"customenumstringflagsprop", - "propertytype":"CustomEnumStringFlags", - "type":"string", - "value":"CustomEnumStringFlags_1,CustomEnumStringFlags_2" - }, - { - "name":"customenumstringprop", - "propertytype":"CustomEnumString", - "type":"string", - "value":"CustomEnumString_2" - }], - "renderorder":"right-down", - "tiledversion":"1.11.0", - "tileheight":32, - "tilesets":[], - "tilewidth":32, - "type":"map", - "version":"1.10", - "width":5 -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmx deleted file mode 100644 index cadc2fa..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-custom-type-props-without-defs/map-with-custom-type-props-without-defs.tmx +++ /dev/null @@ -1,25 +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,0,0 - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj deleted file mode 100644 index 43a18fe..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj +++ /dev/null @@ -1,71 +0,0 @@ -{ "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 - }, - { - "draworder":"topdown", - "id":2, - "name":"Object Layer 1", - "objects":[ - { - "gid":2147483669, - "height":32, - "id":1, - "name":"", - "rotation":0, - "type":"", - "visible":true, - "width":32, - "x":80.0555234239445, - "y":48.3886639676113 - }, - { - "gid":1073741845, - "height":32, - "id":2, - "name":"", - "rotation":0, - "type":"", - "visible":true, - "width":32, - "x":15.8334297281666, - "y":112.055523423944 - }], - "opacity":1, - "type":"objectgroup", - "visible":true, - "x":0, - "y":0 - }], - "nextlayerid":3, - "nextobjectid":3, - "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 -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tj b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tj deleted file mode 100644 index f23c7d9..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tj +++ /dev/null @@ -1,31 +0,0 @@ -{ "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" -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tx b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tx deleted file mode 100644 index a0a2457..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/poly.tx +++ /dev/null @@ -1,9 +0,0 @@ - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.png b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.png deleted file mode 100644 index 97c1fb3..0000000 Binary files a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.png and /dev/null differ diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsj b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsj deleted file mode 100644 index 820e88f..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsj +++ /dev/null @@ -1,14 +0,0 @@ -{ "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" -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsx b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsx deleted file mode 100644 index d730182..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/tileset.tsx +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs b/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs deleted file mode 100644 index 06fc07f..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Globalization; - -namespace DotTiled.Tests; - -public partial class TestData -{ - public static Map MapWithMultilineStringProp() => new Map - { - Class = "", - Orientation = MapOrientation.Isometric, - Width = 5, - Height = 5, - TileWidth = 32, - TileHeight = 16, - Infinite = false, - 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, - GlobalTileIDs = new Optional([ - 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 = new Optional([ - 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 BoolProperty { Name = "boolprop", Value = true }, - new ColorProperty { Name = "colorprop", Value = Color.Parse("#ff55ffff", CultureInfo.InvariantCulture) }, - new FileProperty { Name = "fileprop", Value = "file.txt" }, - new FloatProperty { Name = "floatprop", Value = 4.2f }, - new IntProperty { Name = "intprop", Value = 8 }, - new ObjectProperty { Name = "objectprop", Value = 5 }, - new StringProperty { Name = "stringmultiline", Value = "hello there\n\ni am a multiline\nstring property" }, - new StringProperty { Name = "stringprop", Value = "This is a string, hello world!" }, - new StringProperty { Name = "unsetstringprop", Value = "" } - ] - }; -} diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmj deleted file mode 100644 index 44465f2..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmj +++ /dev/null @@ -1,80 +0,0 @@ -{ "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":"stringmultiline", - "type":"string", - "value":"hello there\n\ni am a multiline\nstring property" - }, - { - "name":"stringprop", - "type":"string", - "value":"This is a string, hello world!" - }, - { - "name":"unsetstringprop", - "type":"string", - "value":"" - }], - "renderorder":"right-down", - "tiledversion":"1.11.0", - "tileheight":16, - "tilesets":[], - "tilewidth":32, - "type":"map", - "version":"1.10", - "width":5 -} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmx deleted file mode 100644 index de55ee1..0000000 --- a/src/DotTiled.Tests/TestData/Maps/map-with-multiline-string-prop/map-with-multiline-string-prop.tmx +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - hello there - -i am a multiline -string property - - - - - -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 - - - diff --git a/src/DotTiled.Tests/UnitTests/OptionalTests.cs b/src/DotTiled.Tests/UnitTests/OptionalTests.cs deleted file mode 100644 index 5390a64..0000000 --- a/src/DotTiled.Tests/UnitTests/OptionalTests.cs +++ /dev/null @@ -1,317 +0,0 @@ -namespace DotTiled.Tests; - -public class OptionalTests -{ - // Constructor Tests - - [Fact] - public void Constructor_WithNonNullValue_ShouldSetHasValueToTrue() - { - // Arrange - string expectedValue = "test"; - - // Act - var optional = new Optional(expectedValue); - - // Assert - Assert.True(optional.HasValue); - Assert.Equal(expectedValue, optional.Value); - } - - [Fact] - public void Constructor_WithNullValue_ShouldSetHasValueToTrue() - { - // Arrange - string expectedValue = null; - - // Act - var optional = new Optional(expectedValue); - - // Assert - Assert.True(optional.HasValue); - Assert.Null(optional.Value); - } - - [Fact] - public void DefaultConstructor_ShouldSetHasValueToFalse() - { - // Arrange & Act - var optional = new Optional(); - - // Assert - Assert.False(optional.HasValue); - _ = Assert.Throws(() => optional.Value); - } - - // Implicit Conversion Tests - - [Fact] - public void ImplicitConversion_FromValueToOptional_ShouldSetHasValueToTrue() - { - // Arrange - int expectedValue = 5; - - // Act - Optional optional = expectedValue; - - // Assert - Assert.True(optional.HasValue); - Assert.Equal(expectedValue, optional.Value); - } - - [Fact] - public void ImplicitConversion_FromOptionalToValue_ShouldReturnValue_WhenHasValueIsTrue() - { - // Arrange - int expectedValue = 10; - var optional = new Optional(expectedValue); - - // Act - int value = optional; - - // Assert - Assert.Equal(expectedValue, value); - } - - [Fact] - public void ImplicitConversion_FromOptionalToValue_ShouldThrowException_WhenHasValueIsFalse() - { - // Arrange - var optional = new Optional(); - - // Act & Assert - _ = Assert.Throws(() => { int value = optional; }); - } - - // ToString Method Tests - - [Fact] - public void ToString_WithValue_ShouldReturnValueToString() - { - // Arrange - int expectedValue = 42; - var optional = new Optional(expectedValue); - - // Act - string result = optional.ToString(); - - // Assert -#pragma warning disable CA1305 // Specify IFormatProvider - Assert.Equal(expectedValue.ToString(), result); -#pragma warning restore CA1305 // Specify IFormatProvider - } - - [Fact] - public void ToString_WithoutValue_ShouldReturnEmpty() - { - // Arrange & Act - var optional = new Optional(); - string result = optional.ToString(); - - // Assert - Assert.Equal("Empty", result); - } - - // Equality Tests - - [Fact] - public void Equals_WithSameValue_ShouldReturnTrue() - { - // Arrange - var optional1 = new Optional(10); - var optional2 = new Optional(10); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.True(areEqual); - } - - [Fact] - public void Equals_WithDifferentValues_ShouldReturnFalse() - { - // Arrange - var optional1 = new Optional(10); - var optional2 = new Optional(20); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.False(areEqual); - } - - [Fact] - public void Equals_WithNull_ShouldReturnFalse() - { - // Arrange - var optional = new Optional("test"); - - // Act - bool areEqual = optional.Equals(null); - - // Assert - Assert.False(areEqual); - } - - [Fact] - public void Equals_WithEmptyOptional_ShouldReturnTrue() - { - // Arrange - var optional1 = new Optional(); - var optional2 = new Optional(); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.True(areEqual); - } - - [Fact] - public void Equals_WithSameReferenceTypeValue_ShouldReturnTrue() - { - // Arrange - var value = new object(); - var optional1 = new Optional(value); - var optional2 = new Optional(value); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.True(areEqual); - } - - [Fact] - public void Equals_WithDifferentReferenceTypeValues_ShouldReturnFalse() - { - // Arrange - var optional1 = new Optional(new object()); - var optional2 = new Optional(new object()); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.False(areEqual); - } - - // GetHashCode Method Tests - - [Fact] - public void GetHashCode_WithValue_ShouldReturnValueHashCode() - { - // Arrange - int value = 42; - var optional = new Optional(value); - - // Act - int hashCode = optional.GetHashCode(); - - // Assert - Assert.Equal(value.GetHashCode(), hashCode); - } - - [Fact] - public void GetHashCode_WithoutValue_ShouldReturnZero() - { - // Arrange & Act - var optional = new Optional(); - int hashCode = optional.GetHashCode(); - - // Assert - Assert.Equal(0, hashCode); - } - - // Exception Tests - - [Fact] - public void Value_WhenHasValueIsFalse_ShouldThrowInvalidOperationException() - { - // Arrange - var optional = new Optional(); - - // Act & Assert - _ = Assert.Throws(() => optional.Value); - } - - [Fact] - public void ImplicitConversion_WhenHasValueIsFalse_ShouldThrowInvalidOperationException() - { - // Arrange - var optional = new Optional(); - - // Act & Assert - _ = Assert.Throws(() => { int value = optional; }); - } - - // Edge Cases - - [Fact] - public void EmptyOptionalEquality_ShouldReturnTrue() - { - // Arrange - var optional1 = new Optional(); - var optional2 = new Optional(); - - // Act - bool areEqual = optional1.Equals(optional2); - - // Assert - Assert.True(areEqual); - } - - // Special Scenarios - - public struct CustomStruct - { - public int X { get; set; } - } - - [Fact] - public void OptionalWithCustomStruct_ShouldBehaveCorrectly() - { - // Arrange - var structValue = new CustomStruct { X = 10 }; - var optional = new Optional(structValue); - - // Act - CustomStruct value = optional.Value; - - // Assert - Assert.True(optional.HasValue); - Assert.Equal(structValue, value); - } - - [Fact] - public void OptionalWithNullableInt_ShouldBehaveCorrectly() - { - // Arrange - int? nullableValue = 5; - var optional = new Optional(nullableValue); - - // Act - int? value = optional.Value; - - // Assert - Assert.True(optional.HasValue); - Assert.Equal(nullableValue, value); - } - - [Fact] - public void OptionalWithNullNullableInt_ShouldBehaveCorrectly() - { - // Arrange - int? nullableValue = null; - var optional = new Optional(nullableValue); - - // Act - int? value = optional.Value; - - // Assert - Assert.True(optional.HasValue); - Assert.Null(value); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomClassDefinitionTests.cs b/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomClassDefinitionTests.cs deleted file mode 100644 index 74e716c..0000000 --- a/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomClassDefinitionTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -namespace DotTiled.Tests; - -public class CustomClassDefinitionTests -{ - private sealed class TestClass1 - { - public string Name { get; set; } = "John Doe"; - public int Age { get; set; } = 42; - } - - private static CustomClassDefinition ExpectedTestClass1Definition => new CustomClassDefinition - { - Name = "TestClass1", - UseAs = CustomClassUseAs.All, - Members = new List - { - new StringProperty { Name = "Name", Value = "John Doe" }, - new IntProperty { Name = "Age", Value = 42 } - } - }; - - private sealed class TestClass2WithNestedClass - { - public string Name { get; set; } = "John Doe"; - public int Age { get; set; } = 42; - public TestClass1 Nested { get; set; } = new TestClass1(); - } - - private static CustomClassDefinition ExpectedTestClass2WithNestedClassDefinition => new CustomClassDefinition - { - Name = "TestClass2WithNestedClass", - UseAs = CustomClassUseAs.All, - Members = [ - new StringProperty { Name = "Name", Value = "John Doe" }, - new IntProperty { Name = "Age", Value = 42 }, - new ClassProperty - { - Name = "Nested", - PropertyType = "TestClass1", - Value = [] - } - ] - }; - - private sealed class TestClass3WithOverridenNestedClass - { - public string Name { get; set; } = "John Doe"; - public int Age { get; set; } = 42; - public TestClass1 Nested { get; set; } = new TestClass1 - { - Name = "Jane Doe" - }; - } - - private static CustomClassDefinition ExpectedTestClass3WithOverridenNestedClassDefinition => new CustomClassDefinition - { - Name = "TestClass3WithOverridenNestedClass", - UseAs = CustomClassUseAs.All, - Members = [ - new StringProperty { Name = "Name", Value = "John Doe" }, - new IntProperty { Name = "Age", Value = 42 }, - new ClassProperty - { - Name = "Nested", - PropertyType = "TestClass1", - Value = [ - new StringProperty { Name = "Name", Value = "Jane Doe" }, - ] - } - ] - }; - - private enum TestEnum1 - { - Value1, - Value2 - } - - [Flags] - private enum TestFlags1 - { - Value1 = 0b001, - Value2 = 0b010, - Value3 = 0b100 - } - - private sealed class TestClass4WithEnums - { - public TestEnum1 Enum { get; set; } = TestEnum1.Value2; - public TestFlags1 Flags { get; set; } = TestFlags1.Value1 | TestFlags1.Value2; - } - - private static CustomClassDefinition ExpectedTestClass4WithEnumsDefinition => new CustomClassDefinition - { - Name = "TestClass4WithEnums", - UseAs = CustomClassUseAs.All, - Members = [ - new EnumProperty { Name = "Enum", PropertyType = "TestEnum1", Value = new HashSet { "Value2" } }, - new EnumProperty { Name = "Flags", PropertyType = "TestFlags1", Value = new HashSet { "Value1", "Value2" } } - ] - }; - - private static IEnumerable<(Type, CustomClassDefinition)> GetCustomClassDefinitionTestData() - { - yield return (typeof(TestClass1), ExpectedTestClass1Definition); - yield return (typeof(TestClass2WithNestedClass), ExpectedTestClass2WithNestedClassDefinition); - yield return (typeof(TestClass3WithOverridenNestedClass), ExpectedTestClass3WithOverridenNestedClassDefinition); - yield return (typeof(TestClass4WithEnums), ExpectedTestClass4WithEnumsDefinition); - } - - public static IEnumerable CustomClassDefinitionTestData => - GetCustomClassDefinitionTestData().Select(data => new object[] { data.Item1, data.Item2 }); - [Theory] - [MemberData(nameof(CustomClassDefinitionTestData))] - public void FromClass_Type_WhenTypeIsCustomClass_ReturnsCustomClassDefinition(Type type, CustomClassDefinition expected) - { - // Arrange & Act - var result = CustomClassDefinition.FromClass(type); - - // Assert - DotTiledAssert.AssertCustomClassDefinitionEqual(expected, result); - } - - [Fact] - public void FromClass_Type_WhenTypeIsNull_ThrowsArgumentNullException() - { - // Arrange - Type type = null; - - // Act & Assert - Assert.Throws(() => CustomClassDefinition.FromClass(type)); - } - - [Fact] - public void FromClass_Type_WhenTypeIsString_ThrowsArgumentException() - { - // Arrange - Type type = typeof(string); - - // Act & Assert - Assert.Throws(() => CustomClassDefinition.FromClass(type)); - } - - [Fact] - public void FromClass_Type_WhenTypeIsNotClass_ThrowsArgumentException() - { - // Arrange - Type type = typeof(int); - - // Act & Assert - Assert.Throws(() => CustomClassDefinition.FromClass(type)); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomEnumDefinitionTests.cs b/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomEnumDefinitionTests.cs deleted file mode 100644 index 02b16d2..0000000 --- a/src/DotTiled.Tests/UnitTests/Properties/CustomTypes/CustomEnumDefinitionTests.cs +++ /dev/null @@ -1,109 +0,0 @@ -namespace DotTiled.Tests; - -public class CustomEnumDefinitionTests -{ - [Fact] - public void FromEnum_Type_WhenTypeIsNotEnum_ThrowsArgumentException() - { - // Arrange - var type = typeof(string); - - // Act & Assert - Assert.Throws(() => CustomEnumDefinition.FromEnum(type)); - } - - private enum TestEnum1 { Value1, Value2, Value3 } - - [Theory] - [InlineData(CustomEnumStorageType.String)] - [InlineData(CustomEnumStorageType.Int)] - public void FromEnum_Type_WhenTypeIsEnum_ReturnsCustomEnumDefinition(CustomEnumStorageType storageType) - { - // Arrange - var type = typeof(TestEnum1); - var expected = new CustomEnumDefinition - { - ID = 0, - Name = "TestEnum1", - StorageType = storageType, - Values = ["Value1", "Value2", "Value3"], - ValueAsFlags = false - }; - - // Act - var result = CustomEnumDefinition.FromEnum(type, storageType); - - // Assert - DotTiledAssert.AssertCustomEnumDefinitionEqual(expected, result); - } - - [Flags] - private enum TestEnum2 { Value1, Value2, Value3 } - - [Theory] - [InlineData(CustomEnumStorageType.String)] - [InlineData(CustomEnumStorageType.Int)] - public void FromEnum_Type_WhenEnumIsFlags_ReturnsCustomEnumDefinition(CustomEnumStorageType storageType) - { - // Arrange - var type = typeof(TestEnum2); - var expected = new CustomEnumDefinition - { - ID = 0, - Name = "TestEnum2", - StorageType = storageType, - Values = ["Value1", "Value2", "Value3"], - ValueAsFlags = true - }; - - // Act - var result = CustomEnumDefinition.FromEnum(type, storageType); - - // Assert - DotTiledAssert.AssertCustomEnumDefinitionEqual(expected, result); - } - - [Theory] - [InlineData(CustomEnumStorageType.String)] - [InlineData(CustomEnumStorageType.Int)] - public void FromEnum_T_WhenTypeIsEnum_ReturnsCustomEnumDefinition(CustomEnumStorageType storageType) - { - // Arrange - var expected = new CustomEnumDefinition - { - ID = 0, - Name = "TestEnum1", - StorageType = storageType, - Values = ["Value1", "Value2", "Value3"], - ValueAsFlags = false - }; - - // Act - var result = CustomEnumDefinition.FromEnum(storageType); - - // Assert - DotTiledAssert.AssertCustomEnumDefinitionEqual(expected, result); - } - - [Theory] - [InlineData(CustomEnumStorageType.String)] - [InlineData(CustomEnumStorageType.Int)] - public void FromEnum_T_WhenEnumIsFlags_ReturnsCustomEnumDefinition(CustomEnumStorageType storageType) - { - // Arrange - var expected = new CustomEnumDefinition - { - ID = 0, - Name = "TestEnum2", - StorageType = storageType, - Values = ["Value1", "Value2", "Value3"], - ValueAsFlags = true - }; - - // Act - var result = CustomEnumDefinition.FromEnum(storageType); - - // Assert - DotTiledAssert.AssertCustomEnumDefinitionEqual(expected, result); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs b/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs deleted file mode 100644 index 4f9ab0f..0000000 --- a/src/DotTiled.Tests/UnitTests/Properties/HasPropertiesBaseTests.cs +++ /dev/null @@ -1,300 +0,0 @@ -using System.Globalization; - -namespace DotTiled.Tests; - -public class HasPropertiesBaseTests -{ - private sealed class TestHasProperties(IList props) : HasPropertiesBase - { - public override IList GetProperties() => props; - } - - [Fact] - public void TryGetProperty_PropertyNotFound_ReturnsFalseAndOutIsNull() - { - // Arrange - var hasProperties = new TestHasProperties([]); - - // Act - var result = hasProperties.TryGetProperty("Test", out var property); - - // Assert - Assert.False(result); - Assert.Null(property); - } - - [Fact] - public void TryGetProperty_PropertyFound_ReturnsTrueAndOutIsProperty() - { - // Arrange - List props = [new BoolProperty { Name = "Test", Value = true }]; - var hasProperties = new TestHasProperties(props); - - // Act - var result = hasProperties.TryGetProperty("Test", out var property); - - // Assert - Assert.True(result); - Assert.NotNull(property); - Assert.Equal("Test", property.Name); - Assert.True(property.Value); - } - - [Fact] - public void GetProperty_PropertyNotFound_ThrowsKeyNotFoundException() - { - // Arrange - var hasProperties = new TestHasProperties([]); - - // Act & Assert - _ = Assert.Throws(() => hasProperties.GetProperty("Test")); - } - - [Fact] - public void GetProperty_PropertyFound_ReturnsProperty() - { - // Arrange - List props = [new BoolProperty { Name = "Test", Value = true }]; - var hasProperties = new TestHasProperties(props); - - // Act - var property = hasProperties.GetProperty("Test"); - - // Assert - Assert.NotNull(property); - Assert.Equal("Test", property.Name); - Assert.True(property.Value); - } - - [Fact] - public void GetProperty_PropertyIsWrongType_ThrowsInvalidCastException() - { - // Arrange - List props = [new BoolProperty { Name = "Test", Value = true }]; - var hasProperties = new TestHasProperties(props); - - // Act & Assert - _ = Assert.Throws(() => hasProperties.GetProperty("Test")); - } - - private sealed class MapTo - { - public bool MapToBool { get; set; } = false; - public Color MapToColor { get; set; } = Color.Parse("#00000000", CultureInfo.InvariantCulture); - public float MapToFloat { get; set; } = 0.0f; - public string MapToFile { get; set; } = ""; - public int MapToInt { get; set; } = 0; - public int MapToObject { get; set; } = 0; - public string MapToString { get; set; } = ""; - } - - [Fact] - public void MapPropertiesTo_NestedPropertyNotFound_ThrowsKeyNotFoundException() - { - // Arrange - List props = [ - new ClassProperty { - Name = "ClassInObject", - PropertyType = "MapTo", - Value = [ - new StringProperty { Name = "PropertyThatDoesNotExistInMapTo", Value = "Test" } - ], - } - ]; - var hasProperties = new TestHasProperties(props); - - // Act & Assert - _ = Assert.Throws(() => hasProperties.GetProperty("ClassInObject").MapPropertiesTo()); - } - - [Fact] - public void MapPropertiesTo_NestedPropertyIsNotClassProperty_ThrowsInvalidCastException() - { - // Arrange - List props = [ - new StringProperty { Name = "ClassInObject", Value = "Test" } - ]; - var hasProperties = new TestHasProperties(props); - - // Act & Assert - _ = Assert.Throws(() => hasProperties.GetProperty("ClassInObject").MapPropertiesTo()); - } - - [Fact] - public void MapPropertiesTo_NestedAllBasicValidProperties_ReturnsMappedProperty() - { - // Arrange - List props = [ - new ClassProperty { - Name = "ClassInObject", - PropertyType = "MapTo", - Value = [ - new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, - new FloatProperty { Name = "MapToFloat", Value = 1.0f }, - new StringProperty { Name = "MapToFile", Value = "Test" }, - new IntProperty { Name = "MapToInt", Value = 1 }, - new IntProperty { Name = "MapToObject", Value = 1 }, - new StringProperty { Name = "MapToString", Value = "Test" }, - ], - } - ]; - var hasProperties = new TestHasProperties(props); - - // Act - var mappedProperty = hasProperties.GetProperty("ClassInObject").MapPropertiesTo(); - - // Assert - Assert.True(mappedProperty.MapToBool); - Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); - Assert.Equal(1.0f, mappedProperty.MapToFloat); - Assert.Equal("Test", mappedProperty.MapToFile); - Assert.Equal(1, mappedProperty.MapToInt); - Assert.Equal(1, mappedProperty.MapToObject); - Assert.Equal("Test", mappedProperty.MapToString); - } - - private sealed class NestedMapTo - { - public string NestedMapToString { get; set; } = ""; - public MapTo MapToInNested { get; set; } = new MapTo(); - } - - [Fact] - public void MapPropertiesTo_NestedNestedMapTo_ReturnsMappedProperty() - { - // Arrange - List props = [ - new ClassProperty { - Name = "ClassInObject", - PropertyType = "NestedMapTo", - Value = [ - new StringProperty { Name = "NestedMapToString", Value = "Test" }, - new ClassProperty { - Name = "MapToInNested", - PropertyType = "MapTo", - Value = [ - new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, - new FloatProperty { Name = "MapToFloat", Value = 1.0f }, - new StringProperty { Name = "MapToFile", Value = "Test" }, - new IntProperty { Name = "MapToInt", Value = 1 }, - new IntProperty { Name = "MapToObject", Value = 1 }, - new StringProperty { Name = "MapToString", Value = "Test" }, - ], - }, - ], - } - ]; - var hasProperties = new TestHasProperties(props); - - // Act - var mappedProperty = hasProperties.GetProperty("ClassInObject").MapPropertiesTo(); - - // Assert - Assert.Equal("Test", mappedProperty.NestedMapToString); - Assert.True(mappedProperty.MapToInNested.MapToBool); - Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToInNested.MapToColor); - Assert.Equal(1.0f, mappedProperty.MapToInNested.MapToFloat); - Assert.Equal("Test", mappedProperty.MapToInNested.MapToFile); - Assert.Equal(1, mappedProperty.MapToInNested.MapToInt); - Assert.Equal(1, mappedProperty.MapToInNested.MapToObject); - Assert.Equal("Test", mappedProperty.MapToInNested.MapToString); - } - - private enum TestEnum - { - TestValue1, - TestValue2, - TestValue3 - } - - private sealed class EnumMapTo - { - public TestEnum EnumMapToEnum { get; set; } = TestEnum.TestValue1; - } - - [Fact] - public void MapPropertiesTo_NestedEnumProperty_ReturnsMappedProperty() - { - // Arrange - List props = [ - new ClassProperty { - Name = "ClassInObject", - PropertyType = "EnumMapTo", - Value = [ - new EnumProperty { Name = "EnumMapToEnum", PropertyType = "TestEnum", Value = new HashSet { "TestValue1" } }, - ], - } - ]; - var hasProperties = new TestHasProperties(props); - - // Act - var mappedProperty = hasProperties.GetProperty("ClassInObject").MapPropertiesTo(); - - // Assert - Assert.Equal(TestEnum.TestValue1, mappedProperty.EnumMapToEnum); - } - - private enum TestEnumWithFlags - { - TestValue1 = 1, - TestValue2 = 2, - TestValue3 = 4 - } - - private sealed class EnumWithFlagsMapTo - { - public TestEnumWithFlags EnumWithFlagsMapToEnum { get; set; } = TestEnumWithFlags.TestValue1; - } - - [Fact] - public void MapPropertiesTo_NestedEnumWithFlagsProperty_ReturnsMappedProperty() - { - // Arrange - List props = [ - new ClassProperty { - Name = "ClassInObject", - PropertyType = "EnumWithFlagsMapTo", - Value = [ - new EnumProperty { Name = "EnumWithFlagsMapToEnum", PropertyType = "TestEnumWithFlags", Value = new HashSet { "TestValue1", "TestValue2" } }, - ], - } - ]; - var hasProperties = new TestHasProperties(props); - - // Act - var mappedProperty = hasProperties.GetProperty("ClassInObject").MapPropertiesTo(); - - // Assert - Assert.Equal(TestEnumWithFlags.TestValue1 | TestEnumWithFlags.TestValue2, mappedProperty.EnumWithFlagsMapToEnum); - } - - [Fact] - public void MapPropertiesTo_WithProperties_ReturnsMappedProperty() - { - // Arrange - List props = [ - new BoolProperty { Name = "MapToBool", Value = true }, - new ColorProperty { Name = "MapToColor", Value = Color.Parse("#FF0000FF", CultureInfo.InvariantCulture) }, - new FloatProperty { Name = "MapToFloat", Value = 1.0f }, - new StringProperty { Name = "MapToFile", Value = "Test" }, - new IntProperty { Name = "MapToInt", Value = 1 }, - new IntProperty { Name = "MapToObject", Value = 1 }, - new StringProperty { Name = "MapToString", Value = "Test" }, - ]; - var hasProperties = new TestHasProperties(props); - - // Act - var mappedProperty = hasProperties.MapPropertiesTo(); - - // Assert - Assert.True(mappedProperty.MapToBool); - Assert.Equal(Color.Parse("#FF0000FF", CultureInfo.InvariantCulture), mappedProperty.MapToColor); - Assert.Equal(1.0f, mappedProperty.MapToFloat); - Assert.Equal("Test", mappedProperty.MapToFile); - Assert.Equal(1, mappedProperty.MapToInt); - Assert.Equal(1, mappedProperty.MapToObject); - Assert.Equal("Test", mappedProperty.MapToString); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Serialization/DefaultResourceCacheTests.cs b/src/DotTiled.Tests/UnitTests/Serialization/DefaultResourceCacheTests.cs deleted file mode 100644 index 6108833..0000000 --- a/src/DotTiled.Tests/UnitTests/Serialization/DefaultResourceCacheTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -using DotTiled.Serialization; - -namespace DotTiled.Tests; - -public class DefaultResourceCacheTests -{ - [Fact] - public void GetTemplate_TemplateDoesNotExist_ReturnsEmptyOptional() - { - // Arrange - var cache = new DefaultResourceCache(); - var path = "template.tsx"; - - // Act - var result = cache.GetTemplate(path); - - // Assert - Assert.False(result.HasValue); - } - - [Fact] - public void GetTemplate_TemplateHasBeenInserted_ReturnsTemplate() - { - // Arrange - var cache = new DefaultResourceCache(); - var path = "template.tsx"; - var template = new Template - { - Object = new EllipseObject { } - }; - - // Act - cache.InsertTemplate(path, template); - var result = cache.GetTemplate(path); - - // Assert - Assert.True(result.HasValue); - Assert.Same(template, result.Value); - } - - [Fact] - public void GetTileset_TilesetDoesNotExist_ReturnsEmptyOptional() - { - // Arrange - var cache = new DefaultResourceCache(); - var path = "tileset.tsx"; - - // Act - var result = cache.GetTileset(path); - - // Assert - Assert.False(result.HasValue); - } - - [Fact] - public void GetTileset_TilesetHasBeenInserted_ReturnsTileset() - { - // Arrange - var cache = new DefaultResourceCache(); - var path = "tileset.tsx"; - var tileset = new Tileset - { - Name = "Tileset", - TileWidth = 32, - TileHeight = 32, - TileCount = 1, - Columns = 1 - }; - - // Act - cache.InsertTileset(path, tileset); - var result = cache.GetTileset(path); - - // Assert - Assert.True(result.HasValue); - Assert.Same(tileset, result.Value); - } -} diff --git a/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs b/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs deleted file mode 100644 index 7edff12..0000000 --- a/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs +++ /dev/null @@ -1,318 +0,0 @@ -using System.Numerics; -using DotTiled.Serialization; -using NSubstitute; - -namespace DotTiled.Tests; - -public class LoaderTests -{ - [Fact] - public void LoadMap_Always_ReadsFromResourceReader() - { - // Arrange - var resourceReader = Substitute.For(); - resourceReader.Read("map.tmx").Returns( - """ - - - - - 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 - - - - """); - - var resourceCache = Substitute.For(); - var customTypeDefinitions = Enumerable.Empty(); - var loader = new Loader(resourceReader, resourceCache, customTypeDefinitions); - - // Act - loader.LoadMap("map.tmx"); - - // Assert - resourceReader.Received(1).Read("map.tmx"); - } - - [Fact] - public void LoadMap_MapReferencesExternalTileset_ReadsTilesetFromResourceReaderAndAttemptsToRetrieveFromCache() - { - // Arrange - var resourceReader = Substitute.For(); - resourceReader.Read("map.tmx").Returns( - """ - - - - - - 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 - - - - """); - - resourceReader.Read("tileset.tsx").Returns( - """ - - - - - - - """); - - var resourceCache = Substitute.For(); - resourceCache.GetTileset(Arg.Any()).Returns(Optional.Empty); - resourceCache.GetTemplate(Arg.Any()).Returns(Optional