mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-09-08 14:46:24 -04:00
Renaming state.state to state.name
This commit is contained in:
parent
f84c082d47
commit
2166eaf156
@ -1,12 +1,12 @@
|
|||||||
-- Import section
|
-- Import section
|
||||||
|
Colors = require("graphics.colors")
|
||||||
|
Unicode = require("unicode")
|
||||||
|
DoubleBuffer = require("graphics.doubleBuffering")
|
||||||
|
Event = require("event")
|
||||||
|
-- Graphics = require("graphics.graphics")
|
||||||
-- MultiBlock = require("data.datasource.multi-block")
|
-- MultiBlock = require("data.datasource.multi-block")
|
||||||
-- SingleBlock = require("data.datasource.single-block")
|
-- SingleBlock = require("data.datasource.single-block")
|
||||||
-- EnergyProvider = require("data.datasource.energy-provider")
|
-- EnergyProvider = require("data.datasource.energy-provider")
|
||||||
Colors = require("graphics.colors")
|
|
||||||
Unicode = require("unicode")
|
|
||||||
-- Graphics = require("graphics.graphics")
|
|
||||||
DoubleBuffer = require("graphics.doubleBuffering")
|
|
||||||
Event = require("event")
|
|
||||||
|
|
||||||
-- local cleanroomAddresses = require("config.addresses.cleanroom")
|
-- local cleanroomAddresses = require("config.addresses.cleanroom")
|
||||||
-- local multiBlockAddresses = require("config.addresses.multi-blocks")
|
-- local multiBlockAddresses = require("config.addresses.multi-blocks")
|
||||||
@ -68,10 +68,10 @@ local baseWidth = 40
|
|||||||
local baseHeight = 10
|
local baseHeight = 10
|
||||||
|
|
||||||
local states = {
|
local states = {
|
||||||
{state = "ON", color = Colors.workingColor},
|
{name = "ON", color = Colors.workingColor},
|
||||||
{state = "IDLE", color = Colors.idleColor},
|
{name = "IDLE", color = Colors.idleColor},
|
||||||
{state = "OFF", color = Colors.offColor},
|
{name = "OFF", color = Colors.offColor},
|
||||||
{state = "BROKEN", color = Colors.errorColor}
|
{name = "BROKEN", color = Colors.errorColor}
|
||||||
}
|
}
|
||||||
|
|
||||||
local fakeNames = {
|
local fakeNames = {
|
||||||
@ -87,9 +87,11 @@ local fakeNames = {
|
|||||||
"Implosion Compressor"
|
"Implosion Compressor"
|
||||||
}
|
}
|
||||||
|
|
||||||
local function updateMachineWidget(self)
|
local machineWidget = {}
|
||||||
|
|
||||||
|
function machineWidget:update()
|
||||||
local breakWidget = math.random(10000) > 9999
|
local breakWidget = math.random(10000) > 9999
|
||||||
if breakWidget and self.type ~= "power" and self.state ~= states[3] then
|
if breakWidget and self.state ~= states[3] then
|
||||||
self.state = states[4]
|
self.state = states[4]
|
||||||
end
|
end
|
||||||
if self.state == states[1] then
|
if self.state == states[1] then
|
||||||
@ -113,22 +115,28 @@ local function updateMachineWidget(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function machineOnClick(self)
|
function machineWidget:onClick()
|
||||||
if self.state == states[1] or self.state == states[2] then
|
if self.state == states[1] or self.state == states[2] then
|
||||||
self.state = states[3]
|
self.state = states[3]
|
||||||
elseif self.state == states[3] then
|
elseif self.state == states[3] then
|
||||||
if self.progress < self.maxProgress then
|
if self.progress < self.maxProgress then
|
||||||
self.state = states[1]
|
self.state = states[1]
|
||||||
else
|
else
|
||||||
|
self.progress = 0
|
||||||
|
self.maxProgress = 0
|
||||||
self.state = states[2]
|
self.state = states[2]
|
||||||
end
|
end
|
||||||
elseif self.state == states[4] then
|
elseif self.state == states[4] then
|
||||||
self.progress = 0
|
self.progress = 0
|
||||||
self.maxProgress = 0
|
self.maxProgress = 0
|
||||||
|
self.state = states[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fakewidget()
|
function machineWidget:getMiddleString()
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineWidget.fake()
|
||||||
local state = states[math.random(4)]
|
local state = states[math.random(4)]
|
||||||
return {
|
return {
|
||||||
name = fakeNames[math.random(10)] .. " " .. math.floor(math.random(3)),
|
name = fakeNames[math.random(10)] .. " " .. math.floor(math.random(3)),
|
||||||
@ -136,30 +144,49 @@ local function fakewidget()
|
|||||||
progress = 0,
|
progress = 0,
|
||||||
maxProgress = state ~= states[3] and state ~= states[4] and math.random(500) or 0,
|
maxProgress = state ~= states[3] and state ~= states[4] and math.random(500) or 0,
|
||||||
type = "machine",
|
type = "machine",
|
||||||
update = updateMachineWidget,
|
update = machineWidget.update,
|
||||||
onClick = machineOnClick
|
onClick = machineWidget.onClick,
|
||||||
|
getMiddleString = machineWidget.getMiddleString
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local widgets = {}
|
local powerWidget = {}
|
||||||
|
|
||||||
for i = 1, 9 do
|
function powerWidget:update()
|
||||||
table.insert(widgets, fakewidget())
|
self.progress = self.progress + self.dProgress
|
||||||
end
|
end
|
||||||
table.insert(
|
|
||||||
widgets,
|
function powerWidget:onClick()
|
||||||
{
|
self.dProgress = -self.dProgress
|
||||||
|
end
|
||||||
|
|
||||||
|
function powerWidget:getMiddleString()
|
||||||
|
local remaining = self.dProgress > 0 and self.maxProgress - self.progress or -self.progress
|
||||||
|
return (self.dProgress > 0 and "+" or "") ..
|
||||||
|
self.dProgress .. "EU/s. " .. (self.dProgress > 0 and "Full in: " or "Empty in: ") .. remaining / self.dProgress
|
||||||
|
end
|
||||||
|
|
||||||
|
function powerWidget.fake()
|
||||||
|
return {
|
||||||
name = "Power",
|
name = "Power",
|
||||||
state = states[1],
|
state = states[1],
|
||||||
progress = math.random(16000000),
|
progress = math.random(16000000),
|
||||||
maxProgress = 16000000,
|
maxProgress = 16000000,
|
||||||
scale = 2,
|
scale = 2,
|
||||||
type = "power",
|
type = "power",
|
||||||
update = updateMachineWidget,
|
dProgress = 1,
|
||||||
onClick = function()
|
update = powerWidget.update,
|
||||||
end
|
onClick = powerWidget.onClick,
|
||||||
|
getMiddleString = powerWidget.getMiddleString
|
||||||
}
|
}
|
||||||
)
|
end
|
||||||
|
|
||||||
|
local widgets = {}
|
||||||
|
|
||||||
|
for i = 1, 9 do
|
||||||
|
table.insert(widgets, machineWidget.fake())
|
||||||
|
end
|
||||||
|
table.insert(widgets, powerWidget.fake())
|
||||||
widgets[11] = widgets[10]
|
widgets[11] = widgets[10]
|
||||||
|
|
||||||
Event.listen(
|
Event.listen(
|
||||||
@ -233,12 +260,13 @@ local function drawWidget(index, widget)
|
|||||||
|
|
||||||
DoubleBuffer.drawLine(x + 3, y + 5, x + width - 3, y + 5, Colors.machineBackground, Colors.textColor, "─")
|
DoubleBuffer.drawLine(x + 3, y + 5, x + width - 3, y + 5, Colors.machineBackground, Colors.textColor, "─")
|
||||||
DoubleBuffer.drawText(x + 3, y + 3, Colors.labelColor, widget.name)
|
DoubleBuffer.drawText(x + 3, y + 3, Colors.labelColor, widget.name)
|
||||||
DoubleBuffer.drawText(x + 3, y + 7, widget.state.color, widget.state.state)
|
DoubleBuffer.drawText(x + 3, y + 7, widget.state.color, widget.state.name)
|
||||||
if widget.state == states[4] then
|
if widget.state == states[4] then
|
||||||
drawProgress(x, 2 * y, width - 1, 2 * (height - 1), 1, 1, Colors.errorColor)
|
drawProgress(x, 2 * y, width - 1, 2 * (height - 1), 1, 1, Colors.errorColor)
|
||||||
else
|
else
|
||||||
if widget.middleInfo then
|
local middleInfo = widget:getMiddleString()
|
||||||
DoubleBuffer.drawText(x + 3 + 3 + Unicode.len("IDLE"), y + height - 3, Colors.textColor, widget.middleInfo)
|
if middleInfo then
|
||||||
|
DoubleBuffer.drawText(x + 3 + 3 + Unicode.len("IDLE"), y + height - 3, Colors.textColor, middleInfo)
|
||||||
end
|
end
|
||||||
DoubleBuffer.drawText(
|
DoubleBuffer.drawText(
|
||||||
x + width - Unicode.len(widget.progress .. "/" .. widget.maxProgress .. " s") - 3,
|
x + width - Unicode.len(widget.progress .. "/" .. widget.maxProgress .. " s") - 3,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user