Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script for Aseprite to export a Tilemap to a 2D-Array of Tileset-Numbers
- -- Please don't hate on me that was the first lua-Script I have ever written in my whole life I really hate interpreter languages
- -- License: Bro just use it
- if TilesetMode == nil then return app.alert "Use Aseprite 1.3" end
- local spr = app.activeSprite
- if not spr then return end
- local d = Dialog("Export Tilemap as .txt File")
- d:label{id="lab1",label="",text="Export Tilemap as .txt File for your own GameEngine"}
- :file{id = "path", label="Export Path", filename="",open=false,filetypes={"txt"}, save=true, focus=true}
- :number{id="vbegin",label="Index of first Tileset (Default 1): ", text="1",focus=true}
- :number{id="Size",label="Tiles per Row (Layer-Width / Tile-Width): ",text="16"}
- :entry{id="seperator",label="Seperator",text=";"}
- :separator{}
- :label{id="lab2", label="",text="In the last row of the tilemap-layer there has to be at least one Tile \"colored\" to fully export the whole Tilemap"}
- :button{id="ok",text="&OK",focus=true}
- :button{text="&Cancel" }
- :show()
- local data = d.data
- if not data.ok then return end
- local lay = app.activeLayer
- if(#data.path<=0)then app.alert("No path selected") end
- if not lay.isTilemap then return app.alert("Layer is not tilemap") end
- pc = app.pixelColor
- mapFile = io.open(data.path,"w")
- for _,c in ipairs(lay.cels) do
- local img = c.image
- local i = 0
- for p in img:pixels() do
- if(p ~= nil) then
- i=i+1
- if(data.vbegin==1) then
- mapFile:write(pc.tileI(p()))
- if(i+1<=data.Size and #data.seperator > 0)then mapFile:write(data.seperator) end
- else
- mapFile:write(pc.tileI(p()+data.vbegin-1))
- if(i+1<=data.Size and #data.seperator > 0)then mapFile:write(data.seperator) end
- end
- if(i==data.Size) then
- mapFile:write("\n")
- i=0
- end
- end
- end
- end
- mapFile:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement