-
Notifications
You must be signed in to change notification settings - Fork 0
/
effectsHandler.lua
59 lines (47 loc) · 1.5 KB
/
effectsHandler.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
local IterableMap = require("include/IterableMap")
local util = require("include/util")
local EffectDefs = util.LoadDefDirectory("effects")
local NewEffect = require("objects/effect")
local self = {}
local api = {}
function api.SpawnEffect(name, pos, data)
local def = EffectDefs[name]
data = data or {}
data.pos = pos
if def.interface then
IterableMap.Add(self.interfaceEffects, NewEffect(data, def))
else
IterableMap.Add(self.worldEffects, NewEffect(data, def))
end
end
function api.Update(dt)
IterableMap.ApplySelf(self.worldEffects, "Update", dt)
IterableMap.ApplySelf(self.interfaceEffects, "Update", dt)
end
function api.Draw(drawQueue)
local left, top, right, bot = self.world.GetCameraExtents(200)
--IterableMap.ApplySelf(self.worldEffects, "Draw", drawQueue, left, top, right, bot)
local indexMax, keyByIndex, dataByKey = IterableMap.GetBarbarianData(self.worldEffects)
--print(indexMax)
for i = 1, indexMax do
dataByKey[keyByIndex[i]].Draw(drawQueue, left, top, right, bot)
end
end
function api.DrawInterface()
IterableMap.ApplySelf(self.interfaceEffects, "DrawInterface")
end
function api.GetActivity()
return IterableMap.Count(self.worldEffects)
end
function api.GetActivityInterface()
return IterableMap.Count(self.interfaceEffects)
end
function api.Initialize(parentWorld)
self = {
worldEffects = IterableMap.New(),
interfaceEffects = IterableMap.New(),
animationTimer = 0,
world = parentWorld,
}
end
return api