-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHitbox Data Exporter.lua
104 lines (88 loc) · 2.19 KB
/
Hitbox Data Exporter.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
local dlg = Dialog { title = "Hitbox Exporter" }
local filepath = ""
local scriptsFolder = os.getenv('APPDATA') .. "/Aseprite/scripts/"
local spr = app.activeSprite
if not spr then return print "No active sprite" end
local function write_json_data(filename, data)
local json = dofile(scriptsFolder .. ".utils/json.lua")
local file = io.open(filename, "w")
file:write(json.encode(data))
file:close()
end
local function getFrameData(layer, from, to)
local frames = {}
for i = from, to do
local cel = layer:cel(i)
if cel ~= nil then
local bounds = { x = cel.bounds.x, y = cel.bounds.y, width = cel.bounds.width, height = cel.bounds.height }
local frame = { frameIndex = i - from, bounds = bounds }
table.insert(frames, frame)
end
end
return frames
end
local function exportData()
if filepath == nil or filepath == "" then
app.alert("Please choose an output path")
else
local data = dlg.data;
local layers = { }
for i, layer in ipairs(spr.layers) do
if layer.name == data.hitboxName or layer.name == data.hurtboxName or layer.name == data.pushboxName then
local tags = { animationName, frames}
for j, tag in ipairs(spr.tags) do
local frameData = getFrameData(layer, tag.fromFrame.frameNumber, tag.toFrame.frameNumber)
if next(frameData) ~= nil then
tag = {
animationName = tag.name,
frames = frameData
}
table.insert(tags, tag)
end
end
layerData = { hitBoxName = layer.name, tagData = tags }
table.insert(layers, layerData)
end
end
write_json_data(filepath, layers)
app.alert("File exported to " .. filepath)
dlg:close()
end
end
dlg:entry {
id = "pushboxName",
label = "Push Box:",
text = "pushbox"
}
:entry {
id = "hitboxName",
label = "Hit Box:",
text = "hitbox"
}
:entry {
id = "hurtboxName",
label = "Hurt Box:",
text = "hurtbox"
}
:file {
id = "filepath",
save = true,
filetypes = {"json"},
label = "filepath",
onchange = function()
filepath = dlg.data["filepath"]
end
}
:button {
id = "ok",
text = "OK",
onclick = exportData
}
:button {
id = "cancel",
text = "Cancel",
onclick = function()
dlg:close()
end
}
dlg:show { wait = false; }