-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport Tileset.lua
70 lines (54 loc) · 2.15 KB
/
Export Tileset.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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="filename", label="Export to Tilemap file:", save=true, focus=true,
filename=app.fs.joinPath(app.fs.filePath(lay.sprite.filename), "tileset.png") }
:label{ label="Number of Tiles to be exported", text=tostring(#tileset) }
:separator()
:number { id="tilemap_cols", label="Number of columns in Tilemap:", text="16" }
:check { id="ask_overwrite", label="Ask before overwrite existing Tilemap file", selected=true }
:check { id="tiles_extruded", label="Extrude Tiles in Tilemap", selected=false }
:check { id="keep_sprite_frames", label="Keep generated sprite frames open", selected=false }
:check { id="open_generated", label="Open generated Tilemap", selected=false }
:separator()
:button{ text="&Export", focus=true, id="ok" }
:button{ text="&Cancel" }
:show()
-- Data validation
local data = dlg.data
if not data.ok then return end
local spec = lay.sprite.spec
local grid = tileset.grid
local size = grid.tileSize
-- Create a new sprite with the dimension of one single tile
local newSpr = Sprite(size.width, size.height, lay.sprite.colorMode)
-- give the new sprite the same palette as the source sprite
newSpr:setPalette(lay.sprite.palettes[1])
-- First copy first tile into sprite frame 1
local tile = tileset:getTile(0)
newSpr.cels[1].image = tile
-- Then create new frame and copy each tile into a new frame of sprite
for i = 1, #tileset - 1 do
app.command.NewFrame { ["content"]="current" }
local tile = tileset:getTile(i)
newSpr.cels[i + 1].image = tile
end
if app.apiVersion >= 3 then
newSpr.filename = "sprite frames"
end
-- Export sprite frames as an extruded sprite sheet
app.command.ExportSpriteSheet{
ui=false,
askOverwrite=data.ask_overwrite,
type=SpriteSheetType.ROWS,
columns=data.tilemap_cols,
textureFilename=data.filename,
extrude=data.tiles_extruded,
openGenerated=data.open_generated
}
-- Close sprite frames again
if data.keep_sprite_frames == false then
newSpr:close()
end