From 2f25c384ee3031bcc7ab77a9e5db9e212bde0571 Mon Sep 17 00:00:00 2001 From: Sebastian Sejud Date: Wed, 3 Aug 2022 15:18:21 +0200 Subject: [PATCH 1/3] Fixed parsing problems, added Stream constructor --- src/TiledCS.csproj | 3 ++- src/TiledMap.cs | 28 ++++++++++++++++++++-------- src/TiledTileset.cs | 12 ++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/TiledCS.csproj b/src/TiledCS.csproj index 1823aa7..85f4617 100644 --- a/src/TiledCS.csproj +++ b/src/TiledCS.csproj @@ -1,7 +1,7 @@ - 3.1.0 + 3.1.1 Ruben Labruyere Ruben Labruyere TiledCS @@ -15,6 +15,7 @@ netstandard2.0 + True diff --git a/src/TiledMap.cs b/src/TiledMap.cs index 29c8ae8..9120729 100644 --- a/src/TiledMap.cs +++ b/src/TiledMap.cs @@ -129,6 +129,18 @@ public TiledMap(string path) } } + /// + /// Loads a Tiled map in TMX format and parses it + /// + /// Stream of opened tmx file + /// Thrown when the map could not be loaded + public TiledMap(Stream stream) + { + var streamReader = new StreamReader(stream); + var content = streamReader.ReadToEnd(); + ParseXml(content); + } + /// /// Can be used to parse the content of a TMX map manually instead of loading it using the constructor /// @@ -289,10 +301,10 @@ private TiledLayer ParseTileLayer(XmlNode node) if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1"; if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1"; if (attrTint != null) tiledLayer.tintcolor = attrTint.Value; - if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value); - if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value); - if (attrParallaxX != null) tiledLayer.offsetX = float.Parse(attrParallaxX.Value); - if (attrParallaxY != null) tiledLayer.offsetY = float.Parse(attrParallaxY.Value); + if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture); + if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture); + if (attrParallaxX != null) tiledLayer.offsetX = float.Parse(attrParallaxX.Value, CultureInfo.InvariantCulture); + if (attrParallaxY != null) tiledLayer.offsetY = float.Parse(attrParallaxY.Value, CultureInfo.InvariantCulture); if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty); ParseTileLayerData(nodeData, ref tiledLayer); @@ -468,8 +480,8 @@ private TiledLayer ParseObjectLayer(XmlNode node) if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1"; if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1"; if (attrTint != null) tiledLayer.tintcolor = attrTint.Value; - if (attrOffsetX != null) tiledLayer.offsetX = int.Parse(attrOffsetX.Value); - if (attrOffsetY != null) tiledLayer.offsetY = int.Parse(attrOffsetY.Value); + if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture); + if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture); if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty); return tiledLayer; @@ -494,8 +506,8 @@ private TiledLayer ParseImageLayer(XmlNode node) if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1"; if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1"; if (attrTint != null) tiledLayer.tintcolor = attrTint.Value; - if (attrOffsetX != null) tiledLayer.offsetX = int.Parse(attrOffsetX.Value); - if (attrOffsetY != null) tiledLayer.offsetY = int.Parse(attrOffsetY.Value); + if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture); + if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture); if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty); if (nodeImage != null) tiledLayer.image = ParseImage(nodeImage); diff --git a/src/TiledTileset.cs b/src/TiledTileset.cs index 44bf85a..176281c 100644 --- a/src/TiledTileset.cs +++ b/src/TiledTileset.cs @@ -90,6 +90,18 @@ public TiledTileset(string path) } } + /// + /// Loads a tileset in TSX format and parses it + /// + /// The file stream of the TSX file + /// Thrown when the file could not be parsed + public TiledTileset(Stream stream) + { + var streamReader = new StreamReader(stream); + var content = streamReader.ReadToEnd(); + ParseXml(content); + } + /// /// Can be used to parse the content of a TSX tileset manually instead of loading it using the constructor /// From f2b5f8de10ab983243fd429685fd23dc49227494 Mon Sep 17 00:00:00 2001 From: Sebastian Sejud Date: Wed, 3 Aug 2022 15:20:40 +0200 Subject: [PATCH 2/3] Removed package build --- src/TiledCS.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TiledCS.csproj b/src/TiledCS.csproj index 85f4617..1823aa7 100644 --- a/src/TiledCS.csproj +++ b/src/TiledCS.csproj @@ -1,7 +1,7 @@ - 3.1.1 + 3.1.0 Ruben Labruyere Ruben Labruyere TiledCS @@ -15,7 +15,6 @@ netstandard2.0 - True From f2bb80f75ec7789f0579133f15adfbb748beb5db Mon Sep 17 00:00:00 2001 From: Sebastian Sejud Date: Thu, 4 Aug 2022 22:05:21 +0200 Subject: [PATCH 3/3] restored opacity parsing --- src/TiledMap.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TiledMap.cs b/src/TiledMap.cs index e145a47..52abd53 100644 --- a/src/TiledMap.cs +++ b/src/TiledMap.cs @@ -303,6 +303,7 @@ private TiledLayer ParseTileLayer(XmlNode node) if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1"; if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1"; if (attrTint != null) tiledLayer.tintcolor = attrTint.Value; + if (attrOpacity != null) tiledLayer.opacity = float.Parse(attrOpacity.Value); if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture); if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture); if (attrParallaxX != null) tiledLayer.offsetX = float.Parse(attrParallaxX.Value, CultureInfo.InvariantCulture); @@ -828,4 +829,4 @@ public bool IsTileFlippedDiagonal(TiledLayer layer, int dataIndex) return (layer.dataRotationFlags[dataIndex] & (FLIPPED_DIAGONALLY_FLAG >> SHIFT_FLIP_FLAG_TO_BYTE)) > 0; } } -} +}