-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
145 lines (124 loc) · 4.92 KB
/
Copy pathmain.lua
File metadata and controls
145 lines (124 loc) · 4.92 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
local keyboard = require("keyboard")
local serialization = require("serialization")
local programLib = require("lib.program-lib")
local guiLib = require("lib.gui-lib")
local chargeBar = require("lib.gui-widgets.charge-bar")
local scrollList = require("lib.gui-widgets.scroll-list")
package.loaded.config = nil
local config = require("config")
local version = require("version")
local repository = "Navatusein/GTNH-OC-LSC-Control"
local archiveName = "LSCControl"
local program = programLib:new(config.logger, config.enableAutoUpdate, version, repository, archiveName)
local gui = guiLib:new(program)
local logo = {
" _ ____ ____ ____ _ _ ",
"| | / ___| / ___| / ___|___ _ __ | |_ _ __ ___ | |",
"| | \\___ \\| | | | / _ \\| '_ \\| __| '__/ _ \\| |",
"| |___ ___) | |___ | |__| (_) | | | | |_| | | (_) | |",
"|_____|____/ \\____| \\____\\___/|_| |_|\\__|_| \\___/|_|"
}
local generatorStatuses = {}
local localModeTemplate = {
width = 60,
background = gui.palette.black,
foreground = gui.palette.white,
widgets = {
chargeBar = chargeBar:new("percent", "charge", 5, 8),
generatorList = scrollList:new("generatorList", "generatorStatuses", keyboard.keys.up, keyboard.keys.down)
},
lines = {
"Charge: $percent:s,%.2f$% $stored:mu,EU$ / $capacity:mu,EU$",
"In: &green;$input:mu,EU/t$&white; Out: &red;$output:mu,EU/t$",
"@c;?charge >=0|&green;|&red;?$charge:mu,EU/t$",
"#chargeBar#",
"?(percent >= 99.9 and charge == 0)|&green;@c;Fully charged|?"..
"?(percent == 0 and charge == 0)|&red;@c;Completely discharged|?"..
"?(percent < 99.9 and charge > 0)|Time to full: &green;$chargeLeft:t,2$|?"..
"?(percent < 99.9 and charge < 0)|Time to empty: &red;$chargeLeft:t,2$|?"..
"?(percent > 0 and percent < 99.9 and charge == 0)|@c;Idle|?",
"?isWorkAllowed == false|@c;&&golden; LSC Disabled |?"..
"?needMaintenance == true|@c;&&red; Need Maintenance |?",
"#generatorList#",
"#generatorList#",
"#generatorList#",
"#generatorList#",
"#generatorList#",
}
}
local wirelessModeTemplate = {
width = 60,
background = gui.palette.black,
foreground = gui.palette.white,
widgets = {
chargeBar = chargeBar:new("percent", "charge", 5, 8),
generatorList = scrollList:new("generatorList", "generatorStatuses", keyboard.keys.up, keyboard.keys.down)
},
lines = {
"Wireless Charge: $wirelessStored:mu,EU$",
"@c;?wirelessCharge >=0|&green;|&red;?$wirelessCharge:mu,EU/t$",
"",
"Charge: $percent:s,%.2f$% $stored:mu,EU$ / $capacity:mu,EU$",
"#chargeBar#",
"@c;?charge >=0|&green;|&red;?$charge:mu,EU/t$",
"?(percent >= 99.9 and charge == 0)|&green;@c;Fully charged|?"..
"?(percent == 0 and charge == 0)|&red;@c;Completely discharged|?"..
"?(percent < 99.9 and charge > 0)|Time to full: &green;$chargeLeft:t,2$|?"..
"?(percent < 99.9 and charge < 0)|Time to empty: &red;$chargeLeft:t,2$|?"..
"?(percent > 0 and percent < 99.9 and charge == 0)|@c;Idle|?",
"?isWorkAllowed == false|@c;&&golden; LSC Disabled |?"..
"?needMaintenance == true|@c;&&red; Need Maintenance |?",
"#generatorList#",
"#generatorList#",
"#generatorList#",
}
}
local function init()
gui:setTemplate(config.lsc.wirelessMode and wirelessModeTemplate or localModeTemplate)
config.lsc:init()
end
local function loop()
while true do
config.lsc:update()
for index, generator in pairs(config.generators) do
if not generator:getState() and config.lsc.percent < generator.enableEuPercent then
generator:setState(true)
end
if generator:getState() and config.lsc.percent > generator.disableEuPercent then
generator:setState(false)
end
generatorStatuses[index] = "[G] "..generator.name..": "..(generator:getState() and "&green;On" or "&red;Off")
end
for index, machine in pairs(config.machines) do
if not machine:getState() and config.lsc.percent > machine.enableEuPercent then
machine:setState(true)
end
if machine:getState() and config.lsc.percent < machine.disableEuPercent then
machine:setState(false)
end
generatorStatuses[index + #config.generators] = "[M] "..machine.name..": "..(machine:getState() and "&green;On" or "&red;Off")
end
os.sleep(3)
end
end
local function guiLoop()
gui:render({
isWorkAllowed = config.lsc.isWorkAllowed,
percent = config.lsc.percent,
stored = config.lsc.stored,
capacity = config.lsc.capacity,
charge = config.lsc.charge,
input = config.lsc.input,
output = config.lsc.output,
chargeLeft = config.lsc.chargeLeft,
wirelessStored = config.lsc.wirelessStored,
wirelessCharge = config.lsc.wirelessCharge,
needMaintenance = config.lsc.needMaintenance,
generatorStatuses = generatorStatuses
})
end
program:registerLogo(logo)
program:registerInit(init)
program:registerThread(loop)
program:registerTimer(guiLoop, math.huge)
program:start()