1
+ ---- ------------------------------------------------------------------------------------------------
2
+ -- Exports the defined tags of the sprite as individual image files according to the supplied root
3
+ -- directory and the export directory specified in the user data of each tag.
4
+ ---- ------------------------------------------------------------------------------------------------
5
+
6
+ --
7
+ -- Get a handle to the current sprite.
8
+ --
9
+ local spr = app .activeSprite
10
+ if not spr then
11
+ return app .alert (" There is no active sprite." )
12
+ end
13
+
14
+ --
15
+ -- Ask the user where the root directory that they would like tags to be exported to resides.
16
+ --
17
+ local dlg = Dialog (" Export Tags" )
18
+ dlg :entry { id = " directory" , label = " Output Directory" , focus = true }
19
+ dlg :slider { id = " scale" , label = " Scale" , min = 1 , max = 10 , value = 2 }
20
+ :button { id = " ok" , text = " &Export" }
21
+ :button { text = " &Cancel" }
22
+ :show ()
23
+
24
+ if not dlg .data .ok then
25
+ return end
26
+
27
+ --
28
+ -- Export each tagged frame as its own PNG file according to the exportPath defined in its user data
29
+ -- and its name.
30
+ --
31
+ -- NOTE: Currently, we only support exporting single-frame tags and PNG files. In the future, we
32
+ -- might add support for exporting multi-frame tags (either as sprite strips or as GIF files).
33
+ --
34
+ for i , tag in ipairs (spr .tags ) do
35
+ local _ , exportPathKeyEnd = string.find (tag .data , " exportPath=\" " )
36
+ local exportPathValueEnd , _ = string.find (tag .data , " \" " , (exportPathKeyEnd + 1 ))
37
+ local exportPath = string.sub (tag .data , (exportPathKeyEnd + 1 ), (exportPathValueEnd - 1 ))
38
+ local img = Image (spr .width , spr .height )
39
+
40
+ img :drawSprite (spr , tag .fromFrame .frameNumber , 0 )
41
+ img :resize (spr .width * dlg .data .scale , spr .height * dlg .data .scale )
42
+ img :saveAs (dlg .data .directory .. " /" .. exportPath .. tag .name .. " .png" )
43
+ end
44
+
45
+ --
46
+ -- Make sure the UI and state update.
47
+ --
48
+ app .refresh ()
0 commit comments