Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- the width and height of the map
- local width,height=0,0
- -- create the filename from the current date and time
- local filename=""
- for i=90,95 do
- filename=filename..sub("0"..stat(i),-2)
- end
- -- ascertain the width and height of our map
- for y=0,127 do
- for x=0,63 do
- local t=mget(x,y)
- if t>0 then
- if x>width then width=x+1 end
- if y>height then height=y+1 end
- end
- end
- end
- -- start building an xml string to write to file
- local tmx='<?xml version="1.0" encoding="UTF-8"?>\n'
- tmx=tmx..'<map version="1.2" tiledversion="1.3.1" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="'..width..'" height="'..height..'" tilewidth="8" tileheight="8" infinite="0" nextlayerid="2" nextobjectid="1">\n'
- tmx=tmx..' <editorsettings>\n'
- tmx=tmx..' <export target="'..filename..'.lua" format="lua"/>\n'
- tmx=tmx..' </editorsettings>\n'
- tmx=tmx..' <tileset firstgid="1" name="'..filename..'" tilewidth="8" tileheight="8" tilecount="256" columns="16">\n'
- tmx=tmx..' <image source="'..filename..'.png" trans="000000" width="128" height="128"/>\n'
- tmx=tmx..' </tileset>\n'
- tmx=tmx..' <layer id="1" name="pico8" width="'..width..'" height="'..height..'">\n'
- tmx=tmx..' <data encoding="csv">\n'
- -- add the map data to the string in csv format
- local comma=","
- for y=0,height-1 do
- for x=0,width-1 do
- if y==height-1 and x==width-1 then comma="" end
- tmx=tmx..mget(x,y)..comma
- end
- tmx=tmx..'\n'
- end
- -- complete the xml string
- tmx=tmx..' </data>\n'
- tmx=tmx..' </layer>\n'
- tmx=tmx..'</map>\n'
- -- dump the xml to a p8l file in the current directory (remove the .p8l extension manually)
- printh(tmx,filename..".tmx",true)
- -- dump the xml to the clipboard (paste into a new file and save as .tmx)
- printh(tmx,"@clip",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement