Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion TiledSharp/src/ImageLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TiledSharp
public class TmxImageLayer : ITmxElement
{
public string Name {get; private set;}
public int Index {get; private set;}

// TODO: Legacy (Tiled Java) attributes (x, y, width, height)
public int? Width {get; private set;}
Expand All @@ -23,9 +24,10 @@ public class TmxImageLayer : ITmxElement

public PropertyDict Properties {get; private set;}

public TmxImageLayer(XElement xImageLayer, string tmxDir = "")
public TmxImageLayer(XElement xImageLayer, int index, string tmxDir = "")
{
Name = (string) xImageLayer.Attribute("name");
Index = index;

Width = (int?) xImageLayer.Attribute("width");
Height = (int?) xImageLayer.Attribute("height");
Expand Down
4 changes: 3 additions & 1 deletion TiledSharp/src/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TiledSharp
public class TmxLayer : ITmxElement
{
public string Name {get; private set;}
public int Index {get; private set;}

// TODO: Legacy (Tiled Java) attributes (x, y, width, height)

Expand All @@ -23,13 +24,14 @@ public class TmxLayer : ITmxElement
public Collection<TmxLayerTile> Tiles {get; private set;}
public PropertyDict Properties {get; private set;}

public TmxLayer(XElement xLayer, int width, int height)
public TmxLayer(XElement xLayer, int index, int width, int height)
{
Name = (string) xLayer.Attribute("name");
Opacity = (double?) xLayer.Attribute("opacity") ?? 1.0;
Visible = (bool?) xLayer.Attribute("visible") ?? true;
OffsetX = (double?) xLayer.Attribute("offsetx") ?? 0.0;
OffsetY = (double?) xLayer.Attribute("offsety") ?? 0.0;
Index = index;

var xData = xLayer.Element("data");
var encoding = (string)xData.Attribute("encoding");
Expand Down
37 changes: 23 additions & 14 deletions TiledSharp/src/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,29 @@ private void Load(XDocument xDoc)
Properties = new PropertyDict(xMap.Element("properties"));

Tilesets = new TmxList<TmxTileset>();
foreach (var e in xMap.Elements("tileset"))
Tilesets.Add(new TmxTileset(e, TmxDirectory));

Layers = new TmxList<TmxLayer>();
foreach (var e in xMap.Elements("layer"))
Layers.Add(new TmxLayer(e, Width, Height));

ObjectGroups = new TmxList<TmxObjectGroup>();
foreach (var e in xMap.Elements("objectgroup"))
ObjectGroups.Add(new TmxObjectGroup(e));

ImageLayers = new TmxList<TmxImageLayer>();
foreach (var e in xMap.Elements("imagelayer"))
ImageLayers.Add(new TmxImageLayer(e, TmxDirectory));
Layers = new TmxList<TmxLayer>();
ObjectGroups = new TmxList<TmxObjectGroup>();
ImageLayers = new TmxList<TmxImageLayer>();

int layerIndex = 0;
foreach (var e in xMap.Elements())
{
switch (e.Name.LocalName)
{
case "tileset":
Tilesets.Add(new TmxTileset(e, TmxDirectory));
break;
case "layer":
Layers.Add(new TmxLayer(e, layerIndex++, Width, Height));
break;
case "objectgroup":
ObjectGroups.Add(new TmxObjectGroup(e, layerIndex++));
break;
case "imagelayer":
ImageLayers.Add(new TmxImageLayer(e, layerIndex++, TmxDirectory));
break;
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion TiledSharp/src/ObjectGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TiledSharp
public class TmxObjectGroup : ITmxElement
{
public string Name {get; private set;}
public int Index {get; private set;}

// TODO: Legacy (Tiled Java) attributes (x, y, width, height)

Expand All @@ -26,9 +27,10 @@ public class TmxObjectGroup : ITmxElement
public TmxList<TmxObject> Objects {get; private set;}
public PropertyDict Properties {get; private set;}

public TmxObjectGroup(XElement xObjectGroup)
public TmxObjectGroup(XElement xObjectGroup, int index = 0)
{
Name = (string) xObjectGroup.Attribute("name") ?? String.Empty;
Index = index;
Color = new TmxColor(xObjectGroup.Attribute("color"));
Opacity = (double?) xObjectGroup.Attribute("opacity") ?? 1.0;
Visible = (bool?) xObjectGroup.Attribute("visible") ?? true;
Expand Down