Skip to content
Snippets Groups Projects
Commit cec00368 authored by Wayne Johnson's avatar Wayne Johnson
Browse files

v0.6 xml, base64, base64/gzip and base64/zlib support.

parent c9f50b38
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Configuration;
namespace TiledToOrx
{
......@@ -19,12 +20,14 @@ namespace TiledToOrx
const string CR = "\n";
const string AT = "@";
const string version = "0.5";
readonly string version = "";
public ConverterForm()
{
InitializeComponent();
version = ConfigurationManager.AppSettings.Get("version");
this.Text += version;
watcher.Changed += Watcher_Changed;
......@@ -94,6 +97,19 @@ namespace TiledToOrx
XmlSerializer serialiser = new XmlSerializer(typeof(Map));
Map map = (Map)serialiser.Deserialize(reader);
//If any xml tile data, convert it. This is post process due to a bug in the deserializer library
foreach (Layer layer in map.layers)
{
if (layer.data.tiles.Count > 0) //there are xml tiles
{
for (int x = 0; x < layer.data.tiles.Count; x++)
{
layer.data.mapData.Add(layer.data.tiles[x].gid);
}
}
}
return map;
}
......@@ -323,7 +339,7 @@ namespace TiledToOrx
{
string message = @"
This converter accepts a Tiled file and will generate Orx Config Data.
This converter accepts a Tiled file and will generate Orx Config Data. All map formats are accepted: CSV, XML, Base64, Base64/gzip and Base64/zlib.
Use the loader button to choose a TMX file.
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml.Serialization;
using System.Linq;
using System.IO;
using Ionic.Zlib;
namespace TiledToOrx
{
......@@ -70,21 +70,41 @@ namespace TiledToOrx
public Data data;
}
[XmlRoot("tile")]
public class XmlTile
{
[XmlAttribute(AttributeName = "gid")]
public int gid;
}
[XmlRoot("data")]
public class Data
{
private List<int> _mapData;
private string _textData;
private List<int> _mapData = new List<int>();
private List<XmlTile> _tileData = new List<XmlTile>(); //when map is xml format
private string _textData = "";
[XmlAttribute(AttributeName = "encoding")]
public string encoding;
[XmlAttribute(AttributeName = "compression")]
public string compression;
public List<int> mapData {
get {
return _mapData;
}
}
/// <summary>
/// This is for when the tile map is supplied in XML format
/// </summary>
[XmlElement(ElementName = "tile")]
public List<XmlTile> tiles;
/// <summary>
/// This is for when the tile map is supplied in csv, base64, gzip or zlib formats
/// </summary>
[XmlText]
public string textData
{
......@@ -94,25 +114,69 @@ namespace TiledToOrx
}
set
{
_textData = value;
string incomingData = value.Trim();
_mapData = new List<int>();
_textData = incomingData;
string stringInts = value;
_mapData = new List<int>();
if (stringInts == null)
if (this.encoding == "base64")
{
return;
}
byte[] bytes = Convert.FromBase64String(incomingData);
if (this.compression == "gzip")
{
MemoryStream stream = new MemoryStream(bytes);
System.IO.Compression.GZipStream gzipStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress);
MemoryStream decompressedStream = new MemoryStream();
gzipStream.CopyTo(decompressedStream);
bytes = decompressedStream.ToArray();
}
stringInts = stringInts.Replace("\n", "");
if (this.compression == "zlib")
{
MemoryStream stream = new MemoryStream(bytes);
List<string> stringIntsList = stringInts.Split(',').ToList();
ZlibStream zlibStream = new ZlibStream(stream, Ionic.Zlib.CompressionMode.Decompress);
MemoryStream decompressedStream = new MemoryStream();
foreach (string stringInt in stringIntsList)
zlibStream.CopyTo(decompressedStream);
bytes = decompressedStream.ToArray();
}
for (int b = 0; b < bytes.Length; b+=4)
{
int intValue = (bytes[b + 3] << 24)
| (bytes[b + 2] << 16)
| (bytes[b + 1] << 8)
| bytes[b];
_mapData.Add(intValue);
}
}
if (this.encoding == "csv")
{
_mapData.Add(Convert.ToInt32(stringInt));
string stringInts = incomingData;
if (stringInts == null)
{
return;
}
stringInts = stringInts.Replace("\n", "");
List<string> stringIntsList = stringInts.Split(',').ToList();
foreach (string stringInt in stringIntsList)
{
_mapData.Add(Convert.ToInt32(stringInt));
}
}
}
}
}
......
......@@ -53,6 +53,10 @@
<ApplicationIcon>orx.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.10.1.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
......@@ -86,6 +90,7 @@
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="version" value="0.6" />
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.10.1" targetFramework="net4" />
</packages>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment