-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlagManager.lua
More file actions
76 lines (63 loc) · 1.47 KB
/
FlagManager.lua
File metadata and controls
76 lines (63 loc) · 1.47 KB
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
-- Import
local Class = require "Class"
local pairs = pairs
local FlagManager = Class{}
setfenv (1, FlagManager)
local Flag = Class{
set = false
}
function FlagManager:init()
self.flagList = {}
end
function FlagManager:addFlag(id, update, onEnter, onLeave)
if id then
flag = Flag()
flag.update = update
flag.onEnter = onEnter
flag.onLeave = onLeave
self.flagList[id] = flag
end
end
function FlagManager:setFlag(id, ...)
if not self.flagList[id].set then
self.flagList[id].set = true
if self.flagList[id].onEnter then
self.flagList[id].onEnter(...)
end
end
end
function FlagManager:resetFlag(id, ...)
if self.flagList[id].set then
self.flagList[id].set = false
if self.flagList[id].onLeave then
self.flagList[id].onLeave(...)
end
end
end
function FlagManager:isFlagSet(id)
return self.flagList[id].set
end
function FlagManager:areFlagsSet(table)
for i = 1, #table do
if not self:isFlagSet(table[i]) then
return false
end
end
return true
end
function FlagManager:isOneFlagSet(table)
for i = 1, #table do
if self:isFlagSet(table[i]) then
return true
end
end
return false
end
function FlagManager:update(dt)
for id, flag in pairs(self.flagList) do
if flag.update and flag.set then
flag.update(dt)
end
end
end
return FlagManager