mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 08:52:50 +02:00
Add Group to Model and to TmxSerializer
This commit is contained in:
parent
6349471a58
commit
5193ab5b61
7 changed files with 61 additions and 2 deletions
|
@ -8,8 +8,6 @@ public abstract class BaseLayer
|
|||
public required uint ID { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Class { get; set; } = "";
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public float Opacity { get; set; } = 1.0f;
|
||||
public bool Visible { get; set; } = true;
|
||||
public Color? TintColor { get; set; }
|
||||
|
|
11
DotTiled/Model/Layers/Group.cs
Normal file
11
DotTiled/Model/Layers/Group.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotTiled;
|
||||
|
||||
public class Group : BaseLayer
|
||||
{
|
||||
// Uses same attributes as BaseLayer
|
||||
|
||||
// Any number of
|
||||
public List<BaseLayer> Layers { get; set; } = [];
|
||||
}
|
|
@ -3,6 +3,8 @@ namespace DotTiled;
|
|||
public class ImageLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public required bool RepeatX { get; set; }
|
||||
public required bool RepeatY { get; set; }
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ public enum DrawOrder
|
|||
public class ObjectLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public uint? Width { get; set; }
|
||||
public uint? Height { get; set; }
|
||||
public required Color? Color { get; set; }
|
||||
|
|
|
@ -3,6 +3,8 @@ namespace DotTiled;
|
|||
public class TileLayer : BaseLayer
|
||||
{
|
||||
// Attributes
|
||||
public uint X { get; set; } = 0;
|
||||
public uint Y { get; set; } = 0;
|
||||
public required uint Width { get; set; }
|
||||
public required uint Height { get; set; }
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ public partial class TmxSerializer
|
|||
"layer" => () => layers.Add(ReadTileLayer(r, dataUsesChunks: infinite)),
|
||||
"objectgroup" => () => layers.Add(ReadObjectLayer(r)),
|
||||
"imagelayer" => () => layers.Add(ReadImageLayer(r)),
|
||||
"group" => () => layers.Add(ReadGroup(r)),
|
||||
_ => r.Skip
|
||||
});
|
||||
|
||||
|
|
|
@ -102,4 +102,47 @@ public partial class TmxSerializer
|
|||
RepeatY = repeatY
|
||||
};
|
||||
}
|
||||
|
||||
private Group ReadGroup(XmlReader reader)
|
||||
{
|
||||
var id = reader.GetRequiredAttributeParseable<uint>("id");
|
||||
var name = reader.GetOptionalAttribute("name") ?? "";
|
||||
var @class = reader.GetOptionalAttribute("class") ?? "";
|
||||
var opacity = reader.GetOptionalAttributeParseable<float>("opacity") ?? 1.0f;
|
||||
var visible = reader.GetOptionalAttributeParseable<bool>("visible") ?? true;
|
||||
var tintColor = reader.GetOptionalAttributeClass<Color>("tintcolor");
|
||||
var offsetX = reader.GetOptionalAttributeParseable<float>("offsetx") ?? 0.0f;
|
||||
var offsetY = reader.GetOptionalAttributeParseable<float>("offsety") ?? 0.0f;
|
||||
var parallaxX = reader.GetOptionalAttributeParseable<float>("parallaxx") ?? 1.0f;
|
||||
var parallaxY = reader.GetOptionalAttributeParseable<float>("parallaxy") ?? 1.0f;
|
||||
|
||||
Dictionary<string, IProperty>? properties = null;
|
||||
List<BaseLayer> layers = [];
|
||||
|
||||
reader.ProcessChildren("group", (r, elementName) => elementName switch
|
||||
{
|
||||
"properties" => () => Helpers.SetAtMostOnce(ref properties, ReadProperties(r), "Properties"),
|
||||
"layer" => () => layers.Add(ReadTileLayer(r, dataUsesChunks: false)),
|
||||
"objectgroup" => () => layers.Add(ReadObjectLayer(r)),
|
||||
"imagelayer" => () => layers.Add(ReadImageLayer(r)),
|
||||
"group" => () => layers.Add(ReadGroup(r)),
|
||||
_ => r.Skip
|
||||
});
|
||||
|
||||
return new Group
|
||||
{
|
||||
ID = id,
|
||||
Name = name,
|
||||
Class = @class,
|
||||
Opacity = opacity,
|
||||
Visible = visible,
|
||||
TintColor = tintColor,
|
||||
OffsetX = offsetX,
|
||||
OffsetY = offsetY,
|
||||
ParallaxX = parallaxX,
|
||||
ParallaxY = parallaxY,
|
||||
Properties = properties,
|
||||
Layers = layers
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue