gzip/base64 with Lua
gzip/base64 with Lua
I was thinking of creating a LOVE library which can parse Tiled maps, but Tiled map files' data is apparently gzip compressed and base64 encoded. Anyone know if there is functionality (or ability to implement functionality) in LOVE/Lua which can decompress gzip and decode base64? I couldn't find anything on Google.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: gzip/base64 with Lua
I see results for both "base64" and "gzip" when searching on http://luaforge.net, have fun!
Re: gzip/base64 with Lua
I just read about this and tried it. Why not turn off the compression and encoding? Edit>Perfs>Saving, untick Compress, Use encoding, Embed images. This made it save in clear txt. I would run this map file through a cleanup filter afterwards though, I saw a ton of waste with the Lua file export.
Re: gzip/base64 with Lua
Yeah, turn off the compress, encode and embed, and export as lua. I made a quick and dirty re-serializer for use with stand alone Lua. Its rather simple, but it shows what I'm talking about.
Note: I used numeric layer names and it lacks tileset info
Turns this:
In to this:
Code: Select all
--Usage: Lua.exe map_file.lua
dofile(arg[1])
output = "map = {\n"
output = output.."\ttile_size = "..map.tilewidth..",\n"
output = output.."\twidth = "..map.width..",\n"
output = output.."\theight = "..map.height..",\n"
output = output.."\tlayers = {\n"
for k,layer in pairs (map.layers) do
output = output.."\t\t["..layer.name.."] = {\n"
for i,t in pairs (layer.data) do
local y = math.floor((i-1)/map.width)
local x = (i-1) % layer.width
if x == 0 then
output = output.."\t\t\t{"
end
output = output..t.gid..", "
if x == layer.width - 1 then
output = output.."},--"..(y+1).."\n"
end
end
output = output.."\t\t},\n"
end
output = output.."\t},\n}"
function save_file(filename,data)
local file = assert(io.open(filename,"w+"))
file:write(data)
file:flush()
file:close()
end
save_file("converted_"..arg[1],output)
Turns this:
Code: Select all
-- Generated by Tiled's Lua Exporter Plugin.
map = {
["label"] = "map";
["version"] = "0.99b";
["luaversion"] = "5.1";
["orientation"] = "orthogonal";
["width"] = 64;
["height"] = 64;
["tilewidth"] = 32;
["tileheight"] = 32;
["tilesets"] = {
{
["label"] = "tileset";
["name"] = "Untitled";
["firstgid"] = 1;
["tilewidth"] = 32;
["tileheight"] = 32;
{
["label"] = "image";
["source"] = "1b.png";
};
};
};
["layers"] = {
{
["label"] = "layer";
["name"] = "0";
["width"] = 64;
["height"] = 64;
["data"] = {
{
["label"] = "tile";
["gid"] = 1;
};
{
["label"] = "tile";
["gid"] = 1;
};
{
["label"] = "tile";
["gid"] = 1;
};
{
["label"] = "tile";
["gid"] = 1;
};
{
["label"] = "tile";
["gid"] = 1;
};
{
["label"] = "tile";
["gid"] = 1;
};
Code: Select all
map = {
tile_size = 32,
width = 64,
height = 64,
layers = {
[0] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },--0
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },--1
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 8, 8, 1, 1, },--2
Re: gzip/base64 with Lua
When I wrote that plugin, I didn't write an importer, so don't use it as an active development file. Use the default TMX files for something you'll keep editing, and save the lua file when you're ready to test it. I whole heartily encourage anyone who feels they can to spruce up the Lua plugin. My Java is rusty from disuse and I don't have the time to refresh it.
Who is online
Users browsing this forum: No registered users and 0 guests