mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-08-03 18:06:04 -04:00
Adding method to create machine widget
This commit is contained in:
parent
c830dc58ff
commit
eab31f5f84
@ -15,8 +15,9 @@ local states = {
|
||||
}
|
||||
|
||||
local types = {
|
||||
power = "power",
|
||||
machine = "machine"
|
||||
POWER = "POWER",
|
||||
MULTIBLOCK = "MULTIBLOCK",
|
||||
MACHINE = "MACHINE"
|
||||
}
|
||||
|
||||
local function drawProgress(x, y, width, height, progress, maxProgress, color)
|
||||
@ -70,7 +71,7 @@ function widget.drawBaseWidget(x, y, width, height, title)
|
||||
end
|
||||
|
||||
local function draw(self, index)
|
||||
if self.type == types.power then
|
||||
if self.type == types.POWER then
|
||||
index = 10
|
||||
end
|
||||
local scale = self.scale or 1
|
||||
@ -198,7 +199,7 @@ function fake.machineWidget.create()
|
||||
state = state,
|
||||
progress = 0,
|
||||
maxProgress = state ~= states[3] and state ~= states[4] and math.random(500) or 0,
|
||||
type = "machine",
|
||||
type = types.MACHINE,
|
||||
update = fake.machineWidget.update,
|
||||
onClick = fake.machineWidget.onClick,
|
||||
getMiddleString = fake.machineWidget.getMiddleString,
|
||||
@ -206,6 +207,34 @@ function fake.machineWidget.create()
|
||||
}
|
||||
end
|
||||
|
||||
function widget.createMachineWidget(address, name)
|
||||
local getMultiblockStatus = require("domain.multiblock.get-multiblock-status-usecase")
|
||||
local function update(self)
|
||||
for key, value in pairs(getMultiblockStatus(address, self.name)) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
local toggleMultiblockWork = require("domain.multiblock.toggle-multiblock-work")
|
||||
local function onClick()
|
||||
toggleMultiblockWork(address)
|
||||
end
|
||||
|
||||
local machineWidget = {
|
||||
name = name,
|
||||
type = types.MULTIBLOCK,
|
||||
update = update,
|
||||
onClick = onClick,
|
||||
getMiddleString = function()
|
||||
end,
|
||||
draw = draw
|
||||
}
|
||||
|
||||
machineWidget:update()
|
||||
|
||||
return machineWidget
|
||||
end
|
||||
|
||||
fake.powerWidget = {}
|
||||
|
||||
function fake.powerWidget:update()
|
||||
@ -231,7 +260,7 @@ function fake.powerWidget.create()
|
||||
maxProgress = 16000000,
|
||||
dProgress = 1,
|
||||
scale = 2,
|
||||
type = types.power,
|
||||
type = types.POWER,
|
||||
update = fake.powerWidget.update,
|
||||
onClick = fake.powerWidget.onClick,
|
||||
getMiddleString = fake.powerWidget.getMiddleString,
|
||||
@ -269,7 +298,7 @@ function widget.createPowerWidget(address)
|
||||
local powerWidget = {
|
||||
name = "Power",
|
||||
scale = 2,
|
||||
type = types.power,
|
||||
type = types.POWER,
|
||||
update = update,
|
||||
onClick = function()
|
||||
end,
|
||||
|
Loading…
x
Reference in New Issue
Block a user