Add some tileset tests

This commit is contained in:
Daniel Cronqvist 2024-08-13 21:39:08 +02:00
parent e68f7c178a
commit 3645f8c2a2
8 changed files with 266 additions and 4 deletions

View file

@ -37,6 +37,7 @@ public static partial class TestData
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => TestData.MapWithEmbeddedTileset(), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => TestData.MapWithExternalTileset(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => TestData.MapWithFlippingFlags(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => TestData.MapExternalTilesetMulti(f), Array.Empty<CustomTypeDefinition>()],
];
private static CustomTypeDefinition[] typedefs = [

View file

@ -0,0 +1,121 @@
using System.Globalization;
namespace DotTiled.Tests;
public partial class TestData
{
public static Map MapExternalTilesetMulti(string fileExt) => new Map
{
Class = "",
Orientation = MapOrientation.Orthogonal,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
HexSideLength = null,
StaggerAxis = null,
StaggerIndex = null,
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,
Tilesets = [
new Tileset
{
TileOffset = new TileOffset
{
X = 1,
Y = 5
},
Version = "1.10",
TiledVersion = "1.11.0",
FirstGID = 1,
Name = "multi-tileset",
TileWidth = 256,
TileHeight = 96,
TileCount = 2,
Columns = 0,
Source = $"multi-tileset.{(fileExt == "tmx" ? "tsx" : "tsj")}",
Grid = new Grid
{
Orientation = GridOrientation.Orthogonal,
Width = 1,
Height = 1
},
Properties = new Dictionary<string, IProperty>
{
["tilesetbool"] = new BoolProperty { Name = "tilesetbool", Value = true },
["tilesetcolor"] = new ColorProperty { Name = "tilesetcolor", Value = Color.Parse("#ffff0000", CultureInfo.InvariantCulture) },
["tilesetfile"] = new FileProperty { Name = "tilesetfile", Value = "" },
["tilesetfloat"] = new FloatProperty { Name = "tilesetfloat", Value = 5.2f },
["tilesetint"] = new IntProperty { Name = "tilesetint", Value = 9 },
["tilesetobject"] = new ObjectProperty { Name = "tilesetobject", Value = 0 },
["tilesetstring"] = new StringProperty { Name = "tilesetstring", Value = "hello world!" }
},
Tiles = [
new Tile
{
ID = 0,
Width = 256,
Height = 96,
Image = new Image
{
Format = ImageFormat.Png,
Source = "tileset.png",
Width = 256,
Height = 96
}
},
new Tile
{
ID = 1,
Width = 256,
Height = 96,
Image = new Image
{
Format = ImageFormat.Png,
Source = "tileset.png",
Width = 256,
Height = 96
}
}
]
}
],
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Csv,
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 = [
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
]
}
}
]
};
}

View file

@ -0,0 +1,36 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"data":[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],
"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":[
{
"firstgid":1,
"source":"multi-tileset.tsj"
}],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="multi-tileset.tsx"/>
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="csv">
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
</data>
</layer>
</map>

View file

@ -0,0 +1,71 @@
{ "columns":0,
"grid":
{
"height":1,
"orientation":"orthogonal",
"width":1
},
"margin":0,
"name":"multi-tileset",
"properties":[
{
"name":"tilesetbool",
"type":"bool",
"value":true
},
{
"name":"tilesetcolor",
"type":"color",
"value":"#ffff0000"
},
{
"name":"tilesetfile",
"type":"file",
"value":""
},
{
"name":"tilesetfloat",
"type":"float",
"value":5.2
},
{
"name":"tilesetint",
"type":"int",
"value":9
},
{
"name":"tilesetobject",
"type":"object",
"value":0
},
{
"name":"tilesetstring",
"type":"string",
"value":"hello world!"
}],
"spacing":0,
"tilecount":2,
"tiledversion":"1.11.0",
"tileheight":96,
"tileoffset":
{
"x":1,
"y":5
},
"tiles":[
{
"id":0,
"image":"tileset.png",
"imageheight":96,
"imagewidth":256
},
{
"id":1,
"image":"tileset.png",
"imageheight":96,
"imagewidth":256
}],
"tilewidth":256,
"type":"tileset",
"version":"1.10"
}

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.11.0" name="multi-tileset" tilewidth="256" tileheight="96" tilecount="2" columns="0">
<tileoffset x="1" y="5"/>
<grid orientation="orthogonal" width="1" height="1"/>
<properties>
<property name="tilesetbool" type="bool" value="true"/>
<property name="tilesetcolor" type="color" value="#ffff0000"/>
<property name="tilesetfile" type="file" value=""/>
<property name="tilesetfloat" type="float" value="5.2"/>
<property name="tilesetint" type="int" value="9"/>
<property name="tilesetobject" type="object" value="0"/>
<property name="tilesetstring" value="hello world!"/>
</properties>
<tile id="0">
<image source="tileset.png" width="256" height="96"/>
</tile>
<tile id="1">
<image source="tileset.png" width="256" height="96"/>
</tile>
</tileset>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -77,14 +77,14 @@ internal partial class Tmj
return resolvedTileset;
}
var imageModel = new Image
var imageModel = image is not null ? new Image
{
Format = Helpers.ParseImageFormatFromSource(image!),
Format = Helpers.ParseImageFormatFromSource(image),
Source = image,
Height = imageHeight,
Width = imageWidth,
TransparentColor = transparentColor
};
} : null;
return new Tileset
{
@ -159,7 +159,7 @@ internal partial class Tmj
var width = e.GetOptionalProperty<uint>("width", imageWidth ?? 0);
var height = e.GetOptionalProperty<uint>("height", imageHeight ?? 0);
var objectGroup = e.GetOptionalPropertyCustom<ObjectLayer?>("objectgroup", e => ReadObjectLayer(e, externalTemplateResolver, customTypeDefinitions), null);
var probability = e.GetOptionalProperty<float>("probability", 1.0f);
var probability = e.GetOptionalProperty<float>("probability", 0.0f);
var properties = e.GetOptionalPropertyCustom<Dictionary<string, IProperty>?>("properties", el => ReadProperties(el, customTypeDefinitions), null);
// var terrain, replaced by wangsets
var type = e.GetOptionalProperty<string>("type", "");