-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoringstatuscontainer.lua
More file actions
96 lines (85 loc) · 2.34 KB
/
monitoringstatuscontainer.lua
File metadata and controls
96 lines (85 loc) · 2.34 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-- Container object is the representation of a Docker
-- container in the Minecraft world
-- NewMonitoringStatusContainer returns a Container object,
-- representation of a container in
-- the Minecraft world
function NewMonitoringStatusContainer()
c = {
displayed = false,
x = 0,
z = 0,
name="",
id="",
percent=0,
init=MonitoringStatusContainer.init,
setInfos=MonitoringStatusContainer.setInfos,
destroy=MonitoringStatusContainer.destroy,
display=MonitoringStatusContainer.display,
addGround=MonitoringStatusContainer.addGround
}
return c
end
MonitoringStatusContainer = {
displayed = false,
x = 0,
z = 0,
name="",
id="",
percent=0,
}
-- MonitoringStatusContainer:init sets Container's position
function MonitoringStatusContainer:init(x,z)
self.x = x
self.z = z
self.displayed = false
end
-- MonitoringStatusContainer:setInfos sets Container's id, name, imageRepo,
-- image tag and running state
function MonitoringStatusContainer:setInfos(id,name,percent)
self.id = id
self.name = name
self.percent = percent
end
-- MonitoringStatusContainer:display displays all Container's blocks
-- Blocks will be blue if the container is running,
-- orange otherwise.
function MonitoringStatusContainer:display()
local metaPrimaryColor = E_META_WOOL_LIGHTBLUE
local metaSecondaryColor = E_META_WOOL_ORANGE
self.displayed = true
local counter = self.percent
for i=1, 10
do
if counter > 0
then
counter = counter - 10
setBlock(UpdateQueue,self.x+1,GROUND_TABLE_LEVEL+i,self.z + 1,E_BLOCK_WOOL,metaSecondaryColor)
else
setBlock(UpdateQueue,self.x+1,GROUND_TABLE_LEVEL+i,self.z + 1,E_BLOCK_WOOL,metaPrimaryColor)
end
end
end
-- MonitoringStatusContainer:addGround creates ground blocks
-- necessary to display the container
function MonitoringStatusContainer:addGround()
local y = GROUND_TABLE_LEVEL
local max_x = GROUND_TABLE_MAX_X
if GROUND_TABLE_MIN_X > self.x - 2
then
max_x = GROUND_TABLE_MIN_X
GROUND_TABLE_MIN_X = self.x - 2
min_x = GROUND_TABLE_MIN_X
end
local min_x = GROUND_TABLE_MIN_X
for x= min_x, max_x
do
for z=GROUND_TABLE_MIN_Z,GROUND_TABLE_MAX_Z
do
setBlock(UpdateQueue,x,y,z,E_BLOCK_GRASS,0)
for sky=y+1,y+6
do
setBlock(UpdateQueue,x,sky,z,E_BLOCK_AIR,0)
end
end
end
end