Skip to content

Instantly share code, notes, and snippets.

@dacap
Last active October 24, 2024 16:54
Show Gist options
  • Save dacap/9df368ba276a45048dc85f96b23ea818 to your computer and use it in GitHub Desktop.
Save dacap/9df368ba276a45048dc85f96b23ea818 to your computer and use it in GitHub Desktop.
Export tileset
if TilesetMode == nil then return app.alert "Use Aseprite v1.3" end
local lay = app.activeLayer
if not lay.isTilemap then return app.alert "No active tilemap layer" end
local tileset = lay.tileset
local dlg = Dialog("Export Tileset")
dlg:file{ id="file", label="Export to File:", save=true, focus=true,
filename=app.fs.joinPath(app.fs.filePath(lay.sprite.filename),
lay.name .. ".png") }
:label{ label="# Tiles", text=tostring(#tileset) }
:separator()
:button{ text="&Export", focus=true, id="ok" }
:button{ text="&Cancel" }
:show()
local data = dlg.data
if data.ok then
local spec = lay.sprite.spec
local grid = tileset.grid
local size = grid.tileSize
spec.width = size.width
spec.height = size.height * #tileset
local image = Image(spec)
image:clear()
for i = 0,#tileset-1 do
local tile = tileset:getTile(i)
image:drawImage(tile, 0, i*size.height)
end
image:saveAs{ filename=data.file, palette=lay.sprite.palettes[1] }
-- Open exported file?
--app.open(data.file)
end
@lua-rocks
Copy link

Useful script, thanks! But it exports images with indexed colors as black-white.

@sigmasoldi3r
Copy link

Is there a way to fix the palette problem? I'm currently facing an engine limitation where my sprites larger than 64x64 must be composed of different pieces (Eg: a 128x128 sprite must be made from 4 64x64 smaller sprites arranged).

And the palette problem is crucial: The engine only supports 16 colours per sprite...

@dacap
Copy link
Author

dacap commented Oct 22, 2024

I've just updated the script to export the correct palette. I'm seeing another issue now that the exported file contains the first palette entry totally transparent.

@sigmasoldi3r could you check if this script now works for you?

@sigmasoldi3r
Copy link

It works! The palette is exported now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment