Skip to content

Commit db357db

Browse files
authored
Merge pull request #33 from ShawnCowles/master
Load maps from streams and xdocuments.
2 parents b10aeec + ee1e54f commit db357db

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

TiledSharp/src/Map.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Xml.Linq;
77
using System.Globalization;
8+
using System.IO;
89

910
namespace TiledSharp
1011
{
@@ -31,9 +32,22 @@ public class TmxMap : TmxDocument
3132

3233
public TmxMap(string filename)
3334
{
34-
XDocument xDoc = ReadXml(filename);
35-
var xMap = xDoc.Element("map");
35+
Load(ReadXml(filename));
36+
}
37+
38+
public TmxMap(Stream inputStream)
39+
{
40+
Load(XDocument.Load(inputStream));
41+
}
3642

43+
public TmxMap(XDocument xDoc)
44+
{
45+
Load(xDoc);
46+
}
47+
48+
private void Load(XDocument xDoc)
49+
{
50+
var xMap = xDoc.Element("map");
3751
Version = (string) xMap.Attribute("version");
3852

3953
Width = (int) xMap.Attribute("width");

TiledSharp/src/TiledCore.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public class TmxDocument
1818
{
1919
public string TmxDirectory {get; private set;}
2020

21+
public TmxDocument()
22+
{
23+
TmxDirectory = string.Empty;
24+
}
25+
2126
protected XDocument ReadXml(string filepath)
2227
{
2328
XDocument xDoc;

0 commit comments

Comments
 (0)