forked from KirbyKid256/mari0_aces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animationsystem.lua
150 lines (136 loc) · 4.47 KB
/
animationsystem.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
144
145
146
147
148
149
150
function animationsystem_load()
animationtriggerfuncs = {}
animationbuttontriggerfuncs = {}
animationbuttonreleasetriggerfuncs = {}
animationswitchtriggerfuncs = {}
animationplayerlandtriggerfuncs = {}
animationplayerhurttriggerfuncs = {}
animations = {}
animationschar = {}
if not dcplaying then
local fl = love.filesystem.getDirectoryItems("mappacks/" .. mappack .. "/animations")
for i = 1, #fl do
if love.filesystem.getInfo("mappacks/" .. mappack .. "/animations/" .. fl[i], "directory") then
--load animations from folder
local fl2 = love.filesystem.getDirectoryItems("mappacks/" .. mappack .. "/animations/" .. fl[i])
for i2 = 1, #fl2 do
if string.sub(fl2[i2], -4) == "json" then
table.insert(animations, animation:new("mappacks/" .. mappack .. "/animations/" .. fl[i] .. "/" .. fl2[i2], fl2[i2]))
end
end
elseif string.sub(fl[i], -4) == "json" then
table.insert(animations, animation:new("mappacks/" .. mappack .. "/animations/" .. fl[i], fl[i]))
end
end
end
--custom chracters animations
local characterenemiesloaded = {} --don't load the same enemy multiple times
for i = 1, #mariocharacter do
if mariocharacter[i] and (not characterenemiesloaded[mariocharacter[i]]) and love.filesystem.getInfo("characters/" .. mariocharacter[i] .. "/animations/") then
local dir = love.filesystem.getDirectoryItems("characters/" .. mariocharacter[i] .. "/animations/")
for i2 = 1, #dir do
if dir[i2] and string.sub(dir[i2], -4) == "json" then
local t = animationschar
if editormode and (characters.data[mariocharacter[i]] and not characters.data[mariocharacter[i]].hideanimations) then
t = animations
end
table.insert(t, animation:new("characters/" .. mariocharacter[i] .. "/animations/" .. dir[i2], dir[i2]))
end
end
characterenemiesloaded[mariocharacter[i]] = true
end
end
end
function animationsystem_update(dt)
if not editormode then
for i, v in pairs(animations) do
v:update(dt)
end
for i, v in pairs(animationschar) do
v:update(dt)
end
end
end
function animationsystem_draw()
if not editormode then
for i, v in pairs(animations) do
v:draw()
end
for i, v in pairs(animationschar) do
v:draw()
end
end
end
function animationsystem_buttontrigger(i, button)
if editormode then
--if the player is frozen make them not static
--this doesn't have anything to do with animations but this is an easy place to put this
if i == 1 and objects["player"][1] and objects["player"][1].static then
objects["player"][1].static = false
end
return
end
if not animationbuttontriggerfuncs[button] then
return
end
if objects and objects["player"][i] and objects["player"][i].dead then
return
end
for id = 1, #animationbuttontriggerfuncs[button] do
if animationbuttontriggerfuncs[button][id][2] == "everyone" or ("player " .. i) == animationbuttontriggerfuncs[button][id][2] then
animationbuttontriggerfuncs[button][id][1]:trigger()
end
end
end
function animationsystem_buttonreleasetrigger(i, button)
if editormode then
return
end
if not animationbuttonreleasetriggerfuncs[button] then
return
end
if objects and objects["player"][i] and objects["player"][i].dead then
return
end
for id = 1, #animationbuttonreleasetriggerfuncs[button] do
if animationbuttonreleasetriggerfuncs[button][id][2] == "everyone" or ("player " .. i) == animationbuttonreleasetriggerfuncs[button][id][2] then
animationbuttonreleasetriggerfuncs[button][id][1]:trigger()
end
end
end
function animationsystem_playerlandtrigger(i)
if editormode then
return
end
if objects and objects["player"][i] and objects["player"][i].dead then
return
end
if animationplayerlandtriggerfuncs[i] then
for id = 1, #animationplayerlandtriggerfuncs[i] do
animationplayerlandtriggerfuncs[i][id]:trigger()
end
end
if animationplayerlandtriggerfuncs["everyone"] then
for id = 1, #animationplayerlandtriggerfuncs["everyone"] do
animationplayerlandtriggerfuncs["everyone"][id]:trigger()
end
end
end
function animationsystem_playerhurttrigger(i)
if editormode then
return
end
if objects and objects["player"][i] and objects["player"][i].dead then
return
end
if animationplayerhurttriggerfuncs[i] then
for id = 1, #animationplayerhurttriggerfuncs[i] do
animationplayerhurttriggerfuncs[i][id]:trigger()
end
end
if animationplayerhurttriggerfuncs["everyone"] then
for id = 1, #animationplayerhurttriggerfuncs["everyone"] do
animationplayerhurttriggerfuncs["everyone"][id]:trigger()
end
end
end