-
Notifications
You must be signed in to change notification settings - Fork 2
/
aspmcmeta.lua
144 lines (121 loc) · 3.58 KB
/
aspmcmeta.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function SplitFilename(strFilename)
-- Returns the Path, Filename, and Extension as 3 values
return string.match(strFilename, "(.-)([^\\]-([^\\%.]+))$")
end
function GetFrames()
local frame = app.activeFrame
--Get the first frame
while(true) do
local new_frame = frame.previous
if new_frame == nil then
break
end
frame = new_frame
end
local frames = {}
-- Add all frames from first to last to the table
local j = 0;
while(true) do
if frame == nil then
break
end
frames[j] = frame
frame = frame.next
j = j + 1
end
return frames
end
-- array of all the frames ordered from first to last
Frames = GetFrames()
local dlg = Dialog { title = "Export settings" }
local path = ""
local filename = ""
local file_extension = ""
path, filename, file_extension = SplitFilename(app.editor.sprite.filename)
if path == nil then
path = ""
end
dlg:entry{ id="name",
label="texture name",
text=filename,
focus=true,
}
dlg:entry{ id="path",
label="Path",
text=path,
focus=false,
}
dlg:button{ id="export",
label="",
text="export",
selected=false,
focus=false,
onclick=function()
dlg:close()
path = dlg.data.path
if path:sub(#path, #path) ~= "/" then
path = path.."/"
end
local name = dlg.data.name:gsub("%.png", "")..".png"
local fullPath = path..name
-- export the animation
Export(fullPath)
--Write animation settings to .mcmeta file
local filename = fullPath..".mcmeta"
local mcmetafile = io.open( filename, "w")
local settings = GetSettings()
if mcmetafile ~= nil then
mcmetafile:write(settings)
else
print(fullPath.." is not a valid place to write the file to. do the directories exist?")
end
print("exported the files "..name.." and "..name..".mcmeta to "..path)
mcmetafile:close()
end
}
dlg:show()
function GetSettings ()
local settings = "{\"animation\":{\"frames\":["
local settimgs_end = "]}}"
for i = 0, #Frames do
settings = settings.."{\"index\": "..tostring(Frames[i].frameNumber - 1)..", \"time\": "..tostring(math.floor(Frames[i].duration * 20)).."}"
if i ~= #Frames then
settings = settings..", "
end
end
settings = settings..settimgs_end
return settings
end
function Export(fullPath)
app.command.ExportSpriteSheet {
ui=false,
askOverwrite=true,
type=SpriteSheetType.VERTICAL,
columns=Frames[0].sprite.height * #Frames + 1,
rows=1,
width=Frames[0].sprite.width,
height=0,
bestFit=false,
textureFilename=fullPath,
dataFilename="",
dataFormat=SpriteSheetDataFormat.JSON_HASH,
filenameFormat="png",
borderPadding=0,
shapePadding=0,
innerPadding=0,
trimSprite=false,
trim=false,
trimByGrid=false,
extrude=false,
ignoreEmpty=false,
mergeDuplicates=false,
openGenerated=false,
layer="",
tag="",
splitLayers=false,
splitTags=false,
listLayers=true,
listTags=true,
listSlices=true
}
end