gzip/base64 with Lua

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Skofo
Party member
Posts: 146
Joined: Mon Dec 22, 2008 10:55 pm

gzip/base64 with Lua

Post by Skofo »

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.
Working on: Viator
Need a 64-bit Debian package for LÖVE? Here it is!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: gzip/base64 with Lua

Post by bartbes »

I see results for both "base64" and "gzip" when searching on http://luaforge.net, have fun!
User avatar
Tad2020
Prole
Posts: 9
Joined: Fri Feb 06, 2009 12:00 am

Re: gzip/base64 with Lua

Post by Tad2020 »

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.
User avatar
Tad2020
Prole
Posts: 9
Joined: Fri Feb 06, 2009 12:00 am

Re: gzip/base64 with Lua

Post by Tad2020 »

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.

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)
Note: I used numeric layer names and it lacks tileset info


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;
        };
In to this:

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
			
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: gzip/base64 with Lua

Post by Inny »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests