mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-08 15:46:02 +03:00
Simplified loader a bit and added more docs
This commit is contained in:
parent
738a9fc5a8
commit
247f9294af
3 changed files with 48 additions and 34 deletions
|
@ -6,13 +6,19 @@ Install DotTiled from NuGet:
|
|||
dotnet add package DotTiled
|
||||
```
|
||||
|
||||
Use the `DotTiled` namespace (if you want).
|
||||
|
||||
```csharp
|
||||
using DotTiled;
|
||||
```
|
||||
|
||||
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 <xref:DotTiled.Serialization.FileSystemResourceReader>. It will also be configured to use an in-memory cache to avoid loading the same tileset or template multiple times using <xref:DotTiled.Serialization.DefaultResourceCache>.
|
||||
|
||||
```csharp
|
||||
using DotTiled;
|
||||
|
||||
var loader = Loader.Default();
|
||||
var map = loader.LoadMap("path/to/map.tmx");
|
||||
```
|
||||
|
@ -22,8 +28,6 @@ var map = loader.LoadMap("path/to/map.tmx");
|
|||
If you want to load resources (maps, tilesets, templates) from a different source than the underlying file system, you can override the <xref:DotTiled.Serialization.FileSystemResourceReader> that is being used with your own implementation of <xref:DotTiled.Serialization.IResourceReader>.
|
||||
|
||||
```csharp
|
||||
using DotTiled;
|
||||
|
||||
var loader = Loader.DefaultWith(
|
||||
resourceReader: new MyCustomResourceReader());
|
||||
var map = loader.LoadMap("path/to/map.tmx");
|
||||
|
@ -34,8 +38,6 @@ var map = loader.LoadMap("path/to/map.tmx");
|
|||
Similarly, you can override the <xref:DotTiled.Serialization.DefaultResourceCache> that is being used with your own implementation of <xref:DotTiled.Serialization.IResourceCache>.
|
||||
|
||||
```csharp
|
||||
using DotTiled;
|
||||
|
||||
var loader = Loader.DefaultWith(
|
||||
resourceReader: new MyCustomResourceReader(),
|
||||
resourceCache: new MyCustomResourceCache());
|
||||
|
@ -47,12 +49,21 @@ var map = loader.LoadMap("path/to/map.tmx");
|
|||
If you have custom types in your map, you can provide any `IEnumerable<ICustomTypeDefinition>` to the loader. This will allow the loader to deserialize the custom types in your map.
|
||||
|
||||
```csharp
|
||||
using DotTiled;
|
||||
|
||||
var monsterSpawnerDef = new CustomClassDefinition { ... };
|
||||
var chestDef = new CustomClassDefinition { ... };
|
||||
var chestDef = new CustomClassDefinition
|
||||
{
|
||||
Name = "Chest",
|
||||
UseAs = CustomClassUseAs.All,
|
||||
Members = [
|
||||
new IntProperty { Name = "coins", Value = 0 },
|
||||
new BoolProperty { Name = "locked", Value = true }
|
||||
]
|
||||
};
|
||||
|
||||
var loader = Loader.DefaultWith(
|
||||
customTypeDefinitions: [monsterSpawnerDef, chestDef]);
|
||||
var map = loader.LoadMap("path/to/map.tmx");
|
||||
|
||||
var chest = map.GetProperty<CustomClassProperty>("chest").Value;
|
||||
var coinsToSpawn = chest.GetProperty<IntProperty>("coins").Value;
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue