mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 08:52:50 +02:00
commit
88352cfa45
9 changed files with 19 additions and 49 deletions
1
Makefile
1
Makefile
|
@ -1,6 +1,7 @@
|
||||||
test:
|
test:
|
||||||
dotnet build src/DotTiled.sln
|
dotnet build src/DotTiled.sln
|
||||||
dotnet test 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: docs/index.md
|
||||||
docfx docs/docfx.json --serve
|
docfx docs/docfx.json --serve
|
||||||
|
|
|
@ -14,4 +14,4 @@ The representation model is designed to be compatible with the latest version of
|
||||||
|
|
||||||
| Tiled version | Compatible DotTiled version(s) |
|
| Tiled version | Compatible DotTiled version(s) |
|
||||||
|---------------|--------------------------------|
|
|---------------|--------------------------------|
|
||||||
| 1.11 | 0.1.0, 0.2.0 |
|
| 1.11 | 0.1.0, 0.2.0, 0.2.1 |
|
|
@ -12,27 +12,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="tilemap.tmx">
|
<EmbeddedResource Include="tilemap.tmx" />
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<EmbeddedResource Include="tileset.png" />
|
||||||
</None>
|
<EmbeddedResource Include="tileset.tsx" />
|
||||||
<None Update="tileset.png">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="assets\tileset.tsx">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="tileset.tsx">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="embedded-tilemap.tmx" />
|
|
||||||
<EmbeddedResource Include="embedded-tilemap.tmx" />
|
|
||||||
<None Remove="embedded-tileset.png" />
|
|
||||||
<EmbeddedResource Include="embedded-tileset.png" />
|
|
||||||
<None Remove="embedded-tileset.tsx" />
|
|
||||||
<EmbeddedResource Include="embedded-tileset.tsx" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -5,18 +5,20 @@ namespace DotTiled.Example;
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private static void Main()
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Quick();
|
Quick(args[0]);
|
||||||
Manual();
|
Manual();
|
||||||
}
|
}
|
||||||
|
|
||||||
// QUICK START
|
// QUICK START
|
||||||
// Automatic and easy way to load tilemaps.
|
// Automatic and easy way to load tilemaps.
|
||||||
private static void Quick()
|
private static void Quick(string basePath)
|
||||||
{
|
{
|
||||||
|
var tilemapPath = Path.Combine(basePath, "tilemap.tmx");
|
||||||
|
|
||||||
var loader = Loader.Default();
|
var loader = Loader.Default();
|
||||||
var map = loader.LoadMap("tilemap.tmx");
|
var map = loader.LoadMap(tilemapPath);
|
||||||
|
|
||||||
// You can do stuff with it like...
|
// You can do stuff with it like...
|
||||||
Console.WriteLine($"Tile width and height: {map.TileWidth}x{map.TileHeight}");
|
Console.WriteLine($"Tile width and height: {map.TileWidth}x{map.TileHeight}");
|
||||||
|
@ -28,9 +30,10 @@ public class Program
|
||||||
// Manually load a map, if you need to load from a custom source
|
// Manually load a map, if you need to load from a custom source
|
||||||
private static void Manual()
|
private static void Manual()
|
||||||
{
|
{
|
||||||
using var mapFileReader = new StreamReader("tilemap.tmx");
|
using Stream? tilemapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.tilemap.tmx")
|
||||||
var mapString = mapFileReader.ReadToEnd();
|
?? throw new FileLoadException($"DotTiled.Example.Console.tilemap.tmx not found in assembly.");
|
||||||
using var mapReader = new MapReader(mapString, ResolveTileset, ResolveTemplate, ResolveCustomType);
|
string tileMapString = new StreamReader(tilemapStream).ReadToEnd();
|
||||||
|
using var mapReader = new MapReader(tileMapString, ResolveTileset, ResolveTemplate, ResolveCustomType);
|
||||||
var map = mapReader.ReadMap();
|
var map = mapReader.ReadMap();
|
||||||
|
|
||||||
// Now do some other stuff with it...
|
// Now do some other stuff with it...
|
||||||
|
@ -50,7 +53,7 @@ public class Program
|
||||||
{
|
{
|
||||||
// Read a file from assembly
|
// Read a file from assembly
|
||||||
// You can use any other source for files, eg. compressed archive, or even file from internet.
|
// You can use any other source for files, eg. compressed archive, or even file from internet.
|
||||||
using Stream? tilesetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.embedded-{source}")
|
using Stream? tilesetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.{source}")
|
||||||
?? throw new FileLoadException($"{source} not found in assembly.");
|
?? throw new FileLoadException($"{source} not found in assembly.");
|
||||||
string tilesetString = new StreamReader(tilesetStream).ReadToEnd();
|
string tilesetString = new StreamReader(tilesetStream).ReadToEnd();
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ public class Program
|
||||||
// This is pretty similar to above, but instead it loads templates, not tilesets.
|
// This is pretty similar to above, but instead it loads templates, not tilesets.
|
||||||
private static Template ResolveTemplate(string source)
|
private static Template ResolveTemplate(string source)
|
||||||
{
|
{
|
||||||
using Stream? templateStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.{source}")
|
using Stream? templateStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"DotTiled.Example.Console.{source}")
|
||||||
?? throw new FileLoadException($"{source} not found in assembly.");
|
?? throw new FileLoadException($"{source} not found in assembly.");
|
||||||
string templateString = new StreamReader(templateStream).ReadToEnd();
|
string templateString = new StreamReader(templateStream).ReadToEnd();
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="1">
|
|
||||||
<properties>
|
|
||||||
<property name="hello" value="Hello from DotTiled!"/>
|
|
||||||
</properties>
|
|
||||||
<tileset firstgid="1" source="tileset.tsx"/>
|
|
||||||
<layer id="1" name="Tile Layer 1" width="10" height="10">
|
|
||||||
<data encoding="base64">
|
|
||||||
AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAA==
|
|
||||||
</data>
|
|
||||||
</layer>
|
|
||||||
</map>
|
|
Binary file not shown.
Before Width: | Height: | Size: 149 B |
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<tileset version="1.8" tiledversion="1.10.2" name="tileset" tilewidth="16" tileheight="16" tilecount="1" columns="1">
|
|
||||||
<image source="tileset.png" width="16" height="16"/>
|
|
||||||
</tileset>
|
|
|
@ -18,7 +18,7 @@
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<Copyright>Copyright © 2024 dcronqvist</Copyright>
|
<Copyright>Copyright © 2024 dcronqvist</Copyright>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<Version>0.2.0</Version>
|
<Version>0.2.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -97,7 +97,7 @@ public abstract partial class TmxReaderBase
|
||||||
var height = _reader.GetOptionalAttributeParseable<float>("height").GetValueOr(heightDefault);
|
var height = _reader.GetOptionalAttributeParseable<float>("height").GetValueOr(heightDefault);
|
||||||
var rotation = _reader.GetOptionalAttributeParseable<float>("rotation").GetValueOr(rotationDefault);
|
var rotation = _reader.GetOptionalAttributeParseable<float>("rotation").GetValueOr(rotationDefault);
|
||||||
var gid = _reader.GetOptionalAttributeParseable<uint>("gid").GetValueOrOptional(gidDefault);
|
var gid = _reader.GetOptionalAttributeParseable<uint>("gid").GetValueOrOptional(gidDefault);
|
||||||
var visible = _reader.GetOptionalAttributeParseable<bool>("visible").GetValueOr(visibleDefault);
|
var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(visibleDefault ? 1u : 0u) == 1;
|
||||||
|
|
||||||
// Elements
|
// Elements
|
||||||
DotTiled.Object foundObject = null;
|
DotTiled.Object foundObject = null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue