Merge pull request #776 from surprised-turtle/tiled-1.9.0-fix

Tiled: Support class attribute as alias for object types
This commit is contained in:
Lucas Girouard-Stranks
2022-08-06 17:26:04 -04:00
committed by GitHub
6 changed files with 11 additions and 3 deletions
@@ -69,6 +69,9 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
if (string.IsNullOrWhiteSpace(obj.Type) && !string.IsNullOrWhiteSpace(template.Object.Type))
obj.Type = template.Object.Type;
if (string.IsNullOrWhiteSpace(obj.Class) && !string.IsNullOrWhiteSpace(template.Object.Class))
obj.Class = template.Object.Class;
}
}
}
@@ -74,7 +74,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
writer.Write(@object.Identifier);
writer.Write(@object.Name ?? string.Empty);
writer.Write(@object.Type ?? string.Empty);
writer.Write(@object.Class ?? @object.Type ?? string.Empty);
writer.Write(@object.X);
writer.Write(@object.Y);
writer.Write(@object.Width);
@@ -152,7 +152,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
writer.Write(@object.Identifier);
writer.Write(@object.Name ?? string.Empty);
writer.Write(@object.Type ?? string.Empty);
writer.Write(@object.Class ?? @object.Type ?? string.Empty);
writer.Write(@object.X);
writer.Write(@object.Y);
writer.Write(@object.Width);
@@ -29,9 +29,13 @@ namespace MonoGame.Extended.Tiled.Serialization
[XmlAttribute(DataType = "string", AttributeName = "name")]
public string Name { get; set; }
// Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
[XmlAttribute(DataType = "string", AttributeName = "type")]
public string Type { get; set; }
[XmlAttribute(DataType = "string", AttributeName = "class")]
public string Class { get; set; }
[XmlAttribute(DataType = "float", AttributeName = "x")]
public float X { get => _x ?? 0; set => _x = value; }
@@ -7,7 +7,7 @@
</properties>
<ellipse/>
</object>
<object id="7" x="240" y="440" width="322" height="186" visible="0"/>
<object id="7" class="sprite" x="240" y="440" width="322" height="186" visible="0"/>
<object id="8" type="rectangle" x="506" y="142" width="136" height="234">
<properties>
<property name="area" value="player-spawn"/>
@@ -177,6 +177,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tests.Tiled
Assert.Equal((uint)0, tmxObjectGroup.Objects[1].GlobalIdentifier);
Assert.Equal((uint)23, tmxObjectGroup.Objects[5].GlobalIdentifier);
Assert.Equal("rectangle", tmxObjectGroup.Objects[2].Type);
Assert.Equal("sprite", tmxObjectGroup.Objects[1].Class);
Assert.NotNull(tmxPolygon);
Assert.Equal("0,0 180,90 -8,275 -45,81 38,77", tmxPolygon.Points);
Assert.NotNull(tmxPolyline);