mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-09-09 23:30:02 -04:00
Setting up fake components with states
This commit is contained in:
parent
7daf955b89
commit
8921e57d77
@ -1,23 +1,23 @@
|
|||||||
-- Import section
|
-- Import section
|
||||||
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")
|
Colors = require("graphics.colors")
|
||||||
Unicode = require("unicode")
|
Unicode = require("unicode")
|
||||||
Graphics = require("graphics.graphics")
|
Graphics = require("graphics.graphics")
|
||||||
DoubleBuffer = require("graphics.doubleBuffering")
|
DoubleBuffer = require("graphics.doubleBuffering")
|
||||||
|
|
||||||
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")
|
||||||
local energyBufferAddresses = require("config.addresses.energy-buffers")
|
-- local energyBufferAddresses = require("config.addresses.energy-buffers")
|
||||||
|
|
||||||
local protectCleanroomRecipes = require("domain.cleanroom.protect-recipes-usecase")
|
-- local protectCleanroomRecipes = require("domain.cleanroom.protect-recipes-usecase")
|
||||||
local getMultiblockStatuses = require("domain.multiblock.get-multiblock-status-usecase")
|
-- local getMultiblockStatuses = require("domain.multiblock.get-multiblock-status-usecase")
|
||||||
local getEnergyStatus = require("domain.energy.get-energy-status-usecase")
|
-- local getEnergyStatus = require("domain.energy.get-energy-status-usecase")
|
||||||
local listMiners = require("domain.miner.list-miners-usecase")
|
-- local listMiners = require("domain.miner.list-miners-usecase")
|
||||||
local getMinersStatuses = require("domain.miner.get-miner-status-usecase")
|
-- local getMinersStatuses = require("domain.miner.get-miner-status-usecase")
|
||||||
|
|
||||||
local GPU = Component.gpu
|
-- local GPU = Component.gpu
|
||||||
--
|
--
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@ -63,16 +63,53 @@ end
|
|||||||
|
|
||||||
require("api.sound.zelda-secret")()
|
require("api.sound.zelda-secret")()
|
||||||
--]]
|
--]]
|
||||||
local component = {
|
local states = {
|
||||||
name = "Machine",
|
{state = "ON", color = Colors.workingColor},
|
||||||
state = true,
|
{state = "IDLE", color = Colors.idleColor},
|
||||||
leftInfo = "ON",
|
{state = "OFF", color = Colors.offColor},
|
||||||
middleInfo = "something",
|
{state = "BROKEN", color = Colors.errorColor}
|
||||||
rightInfo = "16 / 32 s",
|
|
||||||
progress = 0,
|
|
||||||
maxProgress = 1000
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local fakeNames = {
|
||||||
|
"Cleanroom",
|
||||||
|
"Electric Blast Furnace",
|
||||||
|
"Miner",
|
||||||
|
"Vacuum Freezer",
|
||||||
|
"Multi Smelter",
|
||||||
|
"Sifter",
|
||||||
|
"Large Chemical Reactor",
|
||||||
|
"Distillery",
|
||||||
|
"Oil Cracking Unit",
|
||||||
|
"Implosion Compressor"
|
||||||
|
}
|
||||||
|
|
||||||
|
local function fakeComponent()
|
||||||
|
return {
|
||||||
|
name = fakeNames[math.random(10)] .. " " .. math.random(3),
|
||||||
|
state = states[math.random(4)],
|
||||||
|
progress = 0,
|
||||||
|
maxProgress = math.random(500),
|
||||||
|
idleTime = 0
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local components = {}
|
||||||
|
|
||||||
|
for i = 1, 9 do
|
||||||
|
table.insert(components, fakeComponent())
|
||||||
|
end
|
||||||
|
table.insert(
|
||||||
|
components,
|
||||||
|
{
|
||||||
|
name = "Power",
|
||||||
|
state = states[1],
|
||||||
|
progress = math.random(16000000),
|
||||||
|
maxProgress = 16000000,
|
||||||
|
idleTime = 0,
|
||||||
|
scale = 2
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
local baseWidth = 40
|
local baseWidth = 40
|
||||||
local baseHeight = 10
|
local baseHeight = 10
|
||||||
|
|
||||||
@ -112,9 +149,9 @@ local function drawProgress(x, y, width, height, progress, maxProgress, color)
|
|||||||
DoubleBuffer.drawSemiPixelRectangle(x + 1 + width - lengths.third, y + 1, lengths.third, 1, color)
|
DoubleBuffer.drawSemiPixelRectangle(x + 1 + width - lengths.third, y + 1, lengths.third, 1, color)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawWidget(index, component, scale)
|
local function drawWidget(index, component)
|
||||||
local globalWidth = baseWidth
|
local globalWidth = baseWidth
|
||||||
scale = scale or 1
|
local scale = component.scale or 1
|
||||||
local x = globalWidth + globalWidth * ((index - 1) % 3)
|
local x = globalWidth + globalWidth * ((index - 1) % 3)
|
||||||
local width = globalWidth * scale
|
local width = globalWidth * scale
|
||||||
local height = baseHeight
|
local height = baseHeight
|
||||||
@ -134,58 +171,55 @@ local function drawWidget(index, component, scale)
|
|||||||
|
|
||||||
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, component.name)
|
DoubleBuffer.drawText(x + 3, y + 3, Colors.labelColor, component.name)
|
||||||
DoubleBuffer.drawText(
|
DoubleBuffer.drawText(x + 3, y + 7, component.state.color, component.state.state)
|
||||||
x + 3,
|
if component.state == states[4] then
|
||||||
y + 7,
|
drawProgress(x, 2 * y, width - 1, 2 * (height - 1), 1, 1, Colors.errorColor)
|
||||||
component.state and Colors.workingColor or Colors.idleColor,
|
else
|
||||||
component.leftInfo
|
if component.middleInfo then
|
||||||
)
|
DoubleBuffer.drawText(
|
||||||
if component.middleInfo then
|
x + 3 + 3 + Unicode.len("IDLE"),
|
||||||
|
y + height - 3,
|
||||||
|
Colors.textColor,
|
||||||
|
component.middleInfo
|
||||||
|
)
|
||||||
|
end
|
||||||
DoubleBuffer.drawText(
|
DoubleBuffer.drawText(
|
||||||
x + 3 + 3 + Unicode.len("IDLE"),
|
x + width - Unicode.len(component.progress .. "/" .. component.maxProgress) - 3,
|
||||||
y + height - 3,
|
|
||||||
Colors.textColor,
|
|
||||||
component.middleInfo
|
|
||||||
)
|
|
||||||
end
|
|
||||||
if component.rightInfo then
|
|
||||||
DoubleBuffer.drawText(
|
|
||||||
x + width - Unicode.len(tostring(component.rightInfo)) - 3,
|
|
||||||
y + height - 3,
|
y + height - 3,
|
||||||
Colors.accentA,
|
Colors.accentA,
|
||||||
tostring(component.rightInfo)
|
component.progress .. "/" .. component.maxProgress
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
drawTitle("Overview")
|
drawTitle("Overview")
|
||||||
while true do
|
while true do
|
||||||
component.progress = component.progress + 1
|
for index, component in ipairs(components) do
|
||||||
if component.progress >= component.maxProgress then
|
local breakComponent = math.random(10000) > 9999
|
||||||
component.progress = 0
|
if breakComponent then
|
||||||
component.state = false
|
component.state = states[4]
|
||||||
component.leftInfo = "IDLE"
|
|
||||||
component.maxProgress = 0
|
|
||||||
os.sleep(0.5)
|
|
||||||
end
|
|
||||||
component.rightInfo = component.progress .. "/" .. component.maxProgress .. " s"
|
|
||||||
for index = 1, 10 do
|
|
||||||
if index < 10 then
|
|
||||||
drawWidget(index, component, 1)
|
|
||||||
elseif index == 10 then
|
|
||||||
drawWidget(index, component, 2)
|
|
||||||
end
|
end
|
||||||
|
if component.state == states[1] then
|
||||||
|
component.progress = component.progress + 1
|
||||||
|
if component.progress >= component.maxProgress then
|
||||||
|
component.progress = 0
|
||||||
|
component.state = states[2]
|
||||||
|
component.maxProgress = 0
|
||||||
|
component.idleTime = 0
|
||||||
|
end
|
||||||
|
elseif component.state == states[2] then
|
||||||
|
component.idleTime = component.idleTime + 1
|
||||||
|
if component.idleTime > math.random(1000) then
|
||||||
|
component.state = states[1]
|
||||||
|
component.maxProgress = math.random(500)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
drawWidget(index, component)
|
||||||
end
|
end
|
||||||
DoubleBuffer.drawChanges()
|
DoubleBuffer.drawChanges()
|
||||||
if not component.state then
|
|
||||||
component.state = true
|
|
||||||
component.leftInfo = "ON"
|
|
||||||
component.maxProgress = 1000
|
|
||||||
os.sleep(3.5)
|
|
||||||
end
|
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Page = require("api.gui.page")
|
Page = require("api.gui.page")
|
||||||
Notifications = {}
|
Notifications = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user