parsing tmx data done

This commit is contained in:
2016-01-21 21:20:02 +06:00
parent 944b40b430
commit af12a9f6e2
4 changed files with 12 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4b96dccad0a464c0c8462411423c292a guid: 4b96dccad0a464c0c8462411423c292a
timeCreated: 1453320478 timeCreated: 1453389527
licenseType: Free licenseType: Free
NativeFormatImporter: NativeFormatImporter:
userData: userData:

View File

@@ -45,6 +45,7 @@
</tileset> </tileset>
<layer name="Tile Layer 2" width="25" height="25" visible="0" offsetx="32" offsety="16"> <layer name="Tile Layer 2" width="25" height="25" visible="0" offsetx="32" offsety="16">
<properties> <properties>
<property name="em" value=""/>
<property name="layer prop" value="765"/> <property name="layer prop" value="765"/>
</properties> </properties>
<data> <data>

View File

@@ -81,7 +81,7 @@ namespace IsoTools.Tiled.Internal {
} }
static void LoadTiledMapLayerFromTmxLayerElem(XElement layer_elem, TiledMapLayerData layer) { static void LoadTiledMapLayerFromTmxLayerElem(XElement layer_elem, TiledMapLayerData layer) {
layer.Name = SafeLoadStrFromElemAttr (layer_elem, "name" , string.Empty); layer.Name = SafeLoadStrFromElemAttr (layer_elem, "name" , layer.Name);
layer.Width = SafeLoadIntFromElemAttr (layer_elem, "width" , layer.Width); layer.Width = SafeLoadIntFromElemAttr (layer_elem, "width" , layer.Width);
layer.Height = SafeLoadIntFromElemAttr (layer_elem, "height" , layer.Height); layer.Height = SafeLoadIntFromElemAttr (layer_elem, "height" , layer.Height);
layer.OffsetX = SafeLoadIntFromElemAttr (layer_elem, "offsetx", layer.OffsetX); layer.OffsetX = SafeLoadIntFromElemAttr (layer_elem, "offsetx", layer.OffsetX);
@@ -138,7 +138,7 @@ namespace IsoTools.Tiled.Internal {
static int SafeLoadIntFromElemAttr(XElement elem, string attr_name, int def_value) { static int SafeLoadIntFromElemAttr(XElement elem, string attr_name, int def_value) {
int value; int value;
if ( int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) { if ( elem != null && int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
return value; return value;
} }
return def_value; return def_value;
@@ -146,7 +146,7 @@ namespace IsoTools.Tiled.Internal {
static bool SafeLoadBoolFromElemAttr(XElement elem, string attr_name, bool def_value) { static bool SafeLoadBoolFromElemAttr(XElement elem, string attr_name, bool def_value) {
int value; int value;
if ( int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) { if ( elem != null && int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
return value != 0; return value != 0;
} }
return def_value; return def_value;
@@ -158,8 +158,10 @@ namespace IsoTools.Tiled.Internal {
foreach ( var prop_elem in props_elem.Elements("property") ) { foreach ( var prop_elem in props_elem.Elements("property") ) {
var prop_name = SafeLoadStrFromElemAttr(prop_elem, "name" , string.Empty); var prop_name = SafeLoadStrFromElemAttr(prop_elem, "name" , string.Empty);
var prop_value = SafeLoadStrFromElemAttr(prop_elem, "value", string.Empty); var prop_value = SafeLoadStrFromElemAttr(prop_elem, "value", string.Empty);
props.Add(prop_name); if ( !string.IsNullOrEmpty(prop_name) && prop_value != string.Empty ) {
props.Add(prop_value); props.Add(prop_name);
props.Add(prop_value);
}
} }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace IsoTools.Tiled {
[System.Serializable] [System.Serializable]
public class TiledMapLayerData { public class TiledMapLayerData {
public string Name = string.Empty; public string Name = "";
public int Width = 0; public int Width = 0;
public int Height = 0; public int Height = 0;
public int OffsetX = 0; public int OffsetX = 0;
@@ -21,7 +21,7 @@ namespace IsoTools.Tiled {
[System.Serializable] [System.Serializable]
public class TiledMapTilesetData { public class TiledMapTilesetData {
public int FirstGid = 0; public int FirstGid = 0;
public string Name = string.Empty; public string Name = "";
public int Margin = 0; public int Margin = 0;
public int Spacing = 0; public int Spacing = 0;
public int TileWidth = 0; public int TileWidth = 0;
@@ -29,7 +29,7 @@ namespace IsoTools.Tiled {
public int TileCount = 0; public int TileCount = 0;
public int TileOffsetX = 0; public int TileOffsetX = 0;
public int TileOffsetY = 0; public int TileOffsetY = 0;
public string Image = string.Empty; public string Image = "";
public int ImageWidth = 0; public int ImageWidth = 0;
public int ImageHeight = 0; public int ImageHeight = 0;
public List<string> Properties = new List<string>(); public List<string> Properties = new List<string>();