mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-07-09 23:27:52 +03:00
Add object Templates to Model and TmxSerializer
This commit is contained in:
parent
5193ab5b61
commit
0f6db5254d
16 changed files with 631 additions and 44 deletions
94
DotTiled.Tests/TmxSerializer/TestData/Map/map-with-group.cs
Normal file
94
DotTiled.Tests/TmxSerializer/TestData/Map/map-with-group.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TmxSerializerMapTests
|
||||
{
|
||||
private static Map MapWithGroup() => new Map
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
NextLayerID = 5,
|
||||
NextObjectID = 2,
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 4,
|
||||
Name = "Tile Layer 2",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
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 = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, 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 Group
|
||||
{
|
||||
ID = 3,
|
||||
Name = "Group 1",
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
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 = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, 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 ObjectLayer
|
||||
{
|
||||
ID = 2,
|
||||
Name = "Object Layer 1",
|
||||
Objects = [
|
||||
new RectangleObject
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Name",
|
||||
X = 35.5f,
|
||||
Y = 26,
|
||||
Width = 64.5f,
|
||||
Height = 64.5f,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
26
DotTiled.Tests/TmxSerializer/TestData/Map/map-with-group.tmx
Normal file
26
DotTiled.Tests/TmxSerializer/TestData/Map/map-with-group.tmx
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?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="5" nextobjectid="2">
|
||||
<layer id="4" name="Tile Layer 2" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
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>
|
||||
</layer>
|
||||
<group id="3" name="Group 1">
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
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>
|
||||
</layer>
|
||||
<objectgroup id="2" name="Object Layer 1">
|
||||
<object id="1" name="Name" x="35.5" y="26" width="64.5" height="64.5"/>
|
||||
</objectgroup>
|
||||
</group>
|
||||
</map>
|
|
@ -0,0 +1,125 @@
|
|||
namespace DotTiled.Tests;
|
||||
|
||||
public partial class TmxSerializerMapTests
|
||||
{
|
||||
private static Map MapWithObjectTemplate() => new Map
|
||||
{
|
||||
Version = "1.10",
|
||||
TiledVersion = "1.11.0",
|
||||
Orientation = MapOrientation.Orthogonal,
|
||||
RenderOrder = RenderOrder.RightDown,
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32,
|
||||
Infinite = false,
|
||||
NextLayerID = 3,
|
||||
NextObjectID = 3,
|
||||
Layers = [
|
||||
new TileLayer
|
||||
{
|
||||
ID = 1,
|
||||
Name = "Tile Layer 1",
|
||||
Width = 5,
|
||||
Height = 5,
|
||||
Data = new Data
|
||||
{
|
||||
Encoding = DataEncoding.Csv,
|
||||
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 = [
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
|
||||
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, 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 ObjectLayer
|
||||
{
|
||||
ID = 2,
|
||||
Name = "Object Layer 1",
|
||||
Objects = [
|
||||
new RectangleObject
|
||||
{
|
||||
ID = 1,
|
||||
Template = "map-with-object-template.tx",
|
||||
Name = "Thingy 2",
|
||||
X = 94.5749f,
|
||||
Y = 33.6842f,
|
||||
Width = 37.0156f,
|
||||
Height = 37.0156f,
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
|
||||
["TestClassInTemplate"] = new ClassProperty
|
||||
{
|
||||
Name = "TestClassInTemplate",
|
||||
PropertyType = "TestClass",
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Amount"] = new FloatProperty { Name = "Amount", Value = 37 },
|
||||
["Name"] = new StringProperty { Name = "Name", Value = "I am here" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new RectangleObject
|
||||
{
|
||||
ID = 2,
|
||||
Template = "map-with-object-template.tx",
|
||||
Name = "Thingy",
|
||||
X = 29.7976f,
|
||||
Y = 33.8693f,
|
||||
Width = 37.0156f,
|
||||
Height = 37.0156f,
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
|
||||
["TestClassInTemplate"] = new ClassProperty
|
||||
{
|
||||
Name = "TestClassInTemplate",
|
||||
PropertyType = "TestClass",
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Amount"] = new FloatProperty { Name = "Amount", Value = 4.2f },
|
||||
["Name"] = new StringProperty { Name = "Name", Value = "Hello there" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new RectangleObject
|
||||
{
|
||||
ID = 3,
|
||||
Template = "map-with-object-template.tx",
|
||||
Name = "Thingy 3",
|
||||
X = 5,
|
||||
Y = 5,
|
||||
Width = 37.0156f,
|
||||
Height = 37.0156f,
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Bool"] = new BoolProperty { Name = "Bool", Value = true },
|
||||
["TestClassInTemplate"] = new ClassProperty
|
||||
{
|
||||
Name = "TestClassInTemplate",
|
||||
PropertyType = "TestClass",
|
||||
Properties = new Dictionary<string, IProperty>
|
||||
{
|
||||
["Amount"] = new FloatProperty { Name = "Amount", Value = 4.2f },
|
||||
["Name"] = new StringProperty { Name = "Name", Value = "I am here 3" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?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="3" nextobjectid="3">
|
||||
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||
<data encoding="csv">
|
||||
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>
|
||||
</layer>
|
||||
<objectgroup id="2" name="Object Layer 1">
|
||||
<object id="1" template="map-with-object-template.tx" name="Thingy 2" x="94.5749" y="33.6842">
|
||||
<properties>
|
||||
<property name="Bool" type="bool" value="true"/>
|
||||
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
|
||||
<properties>
|
||||
<property name="Amount" type="float" value="37"/>
|
||||
<property name="Name" value="I am here"/>
|
||||
</properties>
|
||||
</property>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="2" template="map-with-object-template.tx" x="29.7976" y="33.8693"/>
|
||||
<object id="3" template="map-with-object-template.tx" name="Thingy 3" x="5" y="5">
|
||||
<properties>
|
||||
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
|
||||
<properties>
|
||||
<property name="Name" value="I am here 3"/>
|
||||
</properties>
|
||||
</property>
|
||||
</properties>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</map>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<object name="Thingy" width="37.0156" height="37.0156">
|
||||
<properties>
|
||||
<property name="Bool" type="bool" value="true"/>
|
||||
<property name="TestClassInTemplate" type="class" propertytype="TestClass">
|
||||
<properties>
|
||||
<property name="Amount" type="float" value="4.2"/>
|
||||
<property name="Name" value="Hello there"/>
|
||||
</properties>
|
||||
</property>
|
||||
</properties>
|
||||
</object>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue