mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 08:52:50 +02:00
Further README updates
This commit is contained in:
parent
30318e6194
commit
6349471a58
4 changed files with 56 additions and 13 deletions
|
@ -15,4 +15,14 @@ public static class TmxSerializerTestData
|
||||||
var xmlStringReader = new StringReader(xml);
|
var xmlStringReader = new StringReader(xml);
|
||||||
return XmlReader.Create(xmlStringReader);
|
return XmlReader.Create(xmlStringReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetRawStringFor(string testDataFile)
|
||||||
|
{
|
||||||
|
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{testDataFile}";
|
||||||
|
using var stream = typeof(TmxSerializerTestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
||||||
|
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
||||||
|
|
||||||
|
using var stringReader = new StreamReader(stream);
|
||||||
|
return stringReader.ReadToEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,19 @@ public partial class TmxSerializerMapTests
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
using var reader = TmxSerializerTestData.GetReaderFor(testDataFile);
|
using var reader = TmxSerializerTestData.GetReaderFor(testDataFile);
|
||||||
|
var testDataFileText = TmxSerializerTestData.GetRawStringFor(testDataFile);
|
||||||
Func<string, Tileset> externalTilesetResolver = (string s) => throw new NotSupportedException("External tilesets are not supported in this test");
|
Func<string, Tileset> externalTilesetResolver = (string s) => throw new NotSupportedException("External tilesets are not supported in this test");
|
||||||
var tmxSerializer = new TmxSerializer(externalTilesetResolver);
|
var tmxSerializer = new TmxSerializer(externalTilesetResolver);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var map = tmxSerializer.DeserializeMap(reader);
|
var map = tmxSerializer.DeserializeMap(reader);
|
||||||
|
var raw = tmxSerializer.DeserializeMap(testDataFileText);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(map);
|
Assert.NotNull(map);
|
||||||
AssertMap(map, expectedMap);
|
AssertMap(map, expectedMap);
|
||||||
|
|
||||||
|
Assert.NotNull(raw);
|
||||||
|
AssertMap(raw, expectedMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
namespace DotTiled;
|
namespace DotTiled;
|
||||||
|
@ -17,4 +18,11 @@ public partial class TmxSerializer
|
||||||
reader.ReadToFollowing("map");
|
reader.ReadToFollowing("map");
|
||||||
return ReadMap(reader);
|
return ReadMap(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map DeserializeMap(string xml)
|
||||||
|
{
|
||||||
|
using var stringReader = new StringReader(xml);
|
||||||
|
using var reader = XmlReader.Create(stringReader);
|
||||||
|
return DeserializeMap(reader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
46
README.md
46
README.md
|
@ -1,26 +1,46 @@
|
||||||
# 📚 DotTiled
|
# 📚 DotTiled
|
||||||
|
|
||||||
DotTiled is a simple, lightweight, and easy-to-use library for loading, saving, and managing Tiled maps and tilesets 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.
|
<img src="https://www.mapeditor.org/img/tiled-logo-white.png" align="right" width="20%"/>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Other similar libraries exist, and you may want to consider them as well:
|
||||||
|
| Library | Active | Formats | Docs | License | Benchmark* Rank |
|
||||||
|
| --- | --- | --- | --- | --- | --- |
|
||||||
|
| **DotTiled** | ✅ | `.tmx`, `.tsx` | Usage, API, XML docs | MIT | 1 |
|
||||||
|
| [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) | ❌ | | | | |
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
### Loading a map with external tilesets
|
Here are a few examples to get you started with DotTiled.
|
||||||
|
|
||||||
|
### Loading a `.tmx` map
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using DotTiled;
|
var tmxSerializer = new TmxSerializer();
|
||||||
|
|
||||||
TmxSerializer tmxSerializer;
|
// A map may or may not contain tilesets that are stored in external
|
||||||
|
// files. To deserialize a map, you must provide a way to resolve such
|
||||||
// Tiled can store tilesets in external files or in a map itself
|
// tilesets.
|
||||||
// When they are stored externally, you need to provide a way
|
|
||||||
// to resolve them given their source path
|
|
||||||
Func<string, Tileset> externalTilesetResolver = (string path) =>
|
Func<string, Tileset> externalTilesetResolver = (string path) =>
|
||||||
{
|
{
|
||||||
// Load the tileset from however you want
|
string tilesetXml = fileSystem.ReadAllText(path);
|
||||||
var tilesetXml = fileSystem.ReadAllText(path);
|
return tmxSerializer.DeserializeTileset(tilesetXml);
|
||||||
var xmlStringReader = new StringReader(tilesetXml);
|
|
||||||
var xmlReader = XmlReader.Create(xmlStringReader);
|
|
||||||
var tmxSerializer = tmxSerializer.DeserializeTileset(xmlReader);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
string mapXml = fileSystem.ReadAllText("path/to/map.tmx");
|
||||||
|
Map map = tmxSerializer.DeserializeMap(mapXml, externalTilesetResolver);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Loading a `.tsx` tileset
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var tmxSerializer = new TmxSerializer();
|
||||||
|
|
||||||
|
string tilesetXml = fileSystem.ReadAllText("path/to/tileset.tsx");
|
||||||
|
Tileset tileset = tmxSerializer.DeserializeTileset(tilesetXml);
|
||||||
```
|
```
|
Loading…
Add table
Reference in a new issue