-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoringstatus.lua
More file actions
54 lines (48 loc) · 1.57 KB
/
monitoringstatus.lua
File metadata and controls
54 lines (48 loc) · 1.57 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
StatusContainers = {}
EmptyContainerSpace = {}
-- updateContainer accepts 3 different states: running, stopped, created
-- sometimes "start" events arrive before "create" ones
-- in this case, we just ignore the update
function updateStatusContainer(id,name,percent)
LOG("Update container with ID: " .. id .. " state: " .. tostring(percent))
-- first pass, to see if the container is
-- already displayed (maybe with another state)
for i=1, table.getn(StatusContainers)
do
-- if container found with same ID, we update it
if StatusContainers[i] ~= EmptyContainerSpace and StatusContainers[i].id == id
then
StatusContainers[i]:setInfos(id,name,percent)
StatusContainers[i]:display()
LOG("found. updated. now return")
return
end
end
-- if container isn't already displayed, we see if there's an empty space
-- in the world to display the container
local x = STATUS_CONTAINER_START_X
local index = -1
for i=1, table.getn(StatusContainers)
do
-- use first empty location
if StatusContainers[i] == EmptyContainerSpace
then
LOG("Found empty location: StatusContainers[" .. tostring(i) .. "]")
index = i
break
end
x = x + ACTIVE_CONTAINER_OFFSET_X
end
LOG("create a new active statuss container")
local container = NewMonitoringStatusContainer()
container:init(x,STATUS_CONTAINER_START_Z)
container:setInfos(id,name,percent)
container:addGround()
container:display()
if index == -1
then
table.insert(StatusContainers, container)
else
StatusContainers[index] = container
end
end