-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotania-pool-meter.lua
More file actions
126 lines (98 loc) · 2.68 KB
/
Copy pathbotania-pool-meter.lua
File metadata and controls
126 lines (98 loc) · 2.68 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
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
INTERVAL = 2
MONITOR_SIDE = "top"
TEXT_SCALE = 1.5
POOLS_AMT = 3
function readVals()
local vals = {}
vals[2] = redstone.getAnalogInput("left")
vals[3] = redstone.getAnalogInput("front")
vals[4] = redstone.getAnalogInput("right")
vals[1] = (vals[2] + vals[3] + vals[4]) / 3
return vals
end
local iter = 0
function updateMonitor(monitor, vals)
monitor.clear()
monitor.setTextScale(1.5)
monitor.setBackgroundColor(2048)
monitor.setTextColor(1)
monitor.setCursorPos(1, 1)
monitor.write(" Mana Reserves ")
monitor.setTextColor(32768)
monitor.setBackgroundColor(8)
monitor.setCursorPos(1, 3)
monitor.write(" Left Pool:")
monitor.setCursorPos(14, 3)
monitor.write(coloredPercent(monitor, vals[2]))
monitor.setBackgroundColor(8)
monitor.setTextColor(32768)
monitor.setCursorPos(1, 4)
monitor.write("Middle Pool:")
monitor.setCursorPos(14, 4)
monitor.write(coloredPercent(monitor, vals[3]))
monitor.setBackgroundColor(8)
monitor.setTextColor(32768)
monitor.setCursorPos(1, 5)
monitor.write(" Right Pool:")
monitor.setCursorPos(14, 5)
monitor.write(coloredPercent(monitor, vals[4]))
monitor.setBackgroundColor(8)
monitor.setTextColor(32768)
monitor.setCursorPos(1, 7)
monitor.write(" Total:")
monitor.setCursorPos(14, 7)
monitor.write(coloredPercent(monitor, vals[1]))
local iterIndic = ""
if iter >= 2 then
iter = 0
iterIndic = "°"
else
iterIndic = "*"
end
iter = iter + 1
monitor.setTextColor(1)
monitor.setBackgroundColor(2048)
monitor.setCursorPos(2, 1)
monitor.write(iterIndic)
monitor.setCursorPos(18, 1)
monitor.write(iterIndic)
monitor.setBackgroundColor(8)
monitor.setTextColor(32768)
end
function coloredPercent(monitor, value)
local col = 32768
local bgcol = nil
local val = calcPercent(value)
if val <= 35 then
bgcol = 16384
elseif val <= 80 then
bgcol = 2
else
bgcol = 8192
end
if bgcol ~= nil then
monitor.setBackgroundColor(bgcol)
end
monitor.setTextColor(col)
return val.." %"
end
function calcPercent(val, rangeMax)
if rangeMax == nil then
rangeMax = 15
end
return round(val * (100 / rangeMax))
end
function round(num, numDecimalPlaces)
return tonumber(string.format("%."..(numDecimalPlaces or 0).."f", num))
end
function run()
local monitor = peripheral.wrap(MONITOR_SIDE)
while true do
local vals = readVals()
if vals ~= nil then
updateMonitor(monitor, vals)
end
os.sleep(INTERVAL)
end
end
run()