From fc6b6db7761138f7ec68bb83ed314e98bf57e9c3 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sat, 16 Jan 2021 18:59:49 -0300 Subject: [PATCH 01/14] Adding machine states to `machine.lua` --- .../monitor-system/data/datasource/machine.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Programs/monitor-system/data/datasource/machine.lua b/Programs/monitor-system/data/datasource/machine.lua index 4d0668c..f0bb49c 100644 --- a/Programs/monitor-system/data/datasource/machine.lua +++ b/Programs/monitor-system/data/datasource/machine.lua @@ -1,27 +1,40 @@ -- Import section local mock = require("data.mock.mock-energy-provider") EnergyProvider = require("data.datasource.energy-provider") +MultiBlock = require("data.datasource.multi-block") Inherits = require("utils.inherits") -- local machine = Inherits(EnergyProvider) local machines = {} + machine.types = { energy = "energy", multiblock = "multiblock", singleblock = "singleblock" } +machine.states = { + ON = {name = "ON", color = Colors.workingColor}, + FULL = {name = "FULL", color = Colors.workingColor}, + IDLE = {name = "IDLE", color = Colors.idleColor}, + FILLING = {name = "FILLING", color = Colors.idleColor}, + OFF = {name = "OFF", color = Colors.offColor}, + DRAINING = {name = "DRAINING", color = Colors.offColor}, + BROKEN = {name = "BROKEN", color = Colors.errorColor}, + EMPTY = {name = "EMPTY", color = Colors.errorColor} +} + function machine.getMachine(address, name, type) if machines[address] then return machines[address] else local mach = {} if type == machine.types.energy then - print(machine.name) + mach = EnergyProvider:new(address, name) elseif type == machine.types.multiblock then + mach = MultiBlock:new(address, name) end - mach = machine:new(address, name) machines[address] = mach return mach end From 94ea75be6aaa4d8d4cefb5c6dc05c926cee2f2ce Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sat, 16 Jan 2021 19:03:26 -0300 Subject: [PATCH 02/14] Changing `getMultiblockstatusUsecase` to consider a single machine. Returning progress, state, problems, efficiency and consumption --- .../get-multiblock-status-usecase.lua | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua b/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua index 5c4292d..c680f00 100755 --- a/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua +++ b/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua @@ -1,22 +1,41 @@ -- Import section +Machine = require("data.datasource.machine") Alarm = require("api.sound.alarm") -- -local function exec(multiblocks) - local statuses = {} - for _, multiblock in ipairs(multiblocks) do - local problems = multiblock:getNumberOfProblems() - if problems > 0 then - Alarm() - end +local function exec(address, name) + local multiblock = Machine.getMachine(address, name, Machine.types.multiblock) + local status = {} + local problems = multiblock:getNumberOfProblems() - statuses[multiblock.name] = { - problems = problems, - probablyUses = multiblock:getEnergyUsage(), - efficiencyPercentage = multiblock:getEfficiencyPercentage() - } + local state = {} + if multiblock:isMachineEnabled() then + if multiblock:hasWork() then + state = Machine.states.ON + else + state = Machine.states.IDLE + end + else + state = Machine.states.OFF end - return statuses + + if problems > 0 then + state = Machine.states.BROKEN + end + + local totalProgress = multiblock:getProgress() + local maxProgress = totalProgress.maximum + local progress = totalProgress.current + + status[multiblock.name] = { + progress = progress, + maxProgress = maxProgress, + problems = problems, + probablyUses = multiblock:getEnergyUsage(), + efficiencyPercentage = multiblock:getEfficiencyPercentage(), + state = state + } + return status end return exec From 590255c1612ca3c53d16c6aa0a5b99b0514e66a8 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 13:32:59 -0300 Subject: [PATCH 03/14] Adding toggleMultiblockWorkUsecase --- .../domain/multiblock/toggle-multiblock-work.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua diff --git a/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua new file mode 100755 index 0000000..b0ce22b --- /dev/null +++ b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua @@ -0,0 +1,12 @@ +-- Import section +Machine = require("data.datasource.machine") +Alarm = require("api.sound.alarm") +-- + +local function exec(address, name) + local multiblock = Machine.getMachine(address, name, Machine.types.multiblock) + local workAllowed = multiblock:isWorkAllowed() + multiblock:setWorkAllowed(not workAllowed) +end + +return exec From c830dc58ff8eec635aa87b360c6c4bf40aa5f077 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 13:33:58 -0300 Subject: [PATCH 04/14] Improving multiblock mock Making it dynamic --- .../data/mock/mock-multi-block.lua | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Programs/monitor-system/data/mock/mock-multi-block.lua b/Programs/monitor-system/data/mock/mock-multi-block.lua index c35329a..cdf3121 100644 --- a/Programs/monitor-system/data/mock/mock-multi-block.lua +++ b/Programs/monitor-system/data/mock/mock-multi-block.lua @@ -7,20 +7,35 @@ local MockMultiBlock = Inherits( MockSingleBlock, { - name = "MockMultiBlock" + name = "MockMultiBlock", + progress = 0, + maxProgress = 0, } ) -function MockMultiBlock.getSensorInformation() +function MockMultiBlock:getSensorInformation() + self.progress = self.progress + 1 + if self.progress > self.maxProgress then + self.maxProgress = math.random(500) + self.progress = 0 + end + self.isBroken = self.isBroken or math.random(100000) > 99999 return { - "Progress: §a2§r s / §e5§r s", + "Progress: §a" .. self.progress .. "§r s / §e" .. self.maxProgress .. "§r s", "Stored Energy: §a1000§r EU / §e1000§r EU", "Probably uses: §c4§r EU/t", "Max Energy Income: §e128§r EU/t(x2A) Tier: §eMV§r", - "Problems: §c0§r Efficiency: §e100.0§r %", + "Problems: §c" .. self.isBroken and 1 or 0 .. "§r Efficiency: §e100.0§r %", "Pollution reduced to: §a0§r %", n = 6 } end +function MockMultiBlock:setWorkAllowed(allow) + if self.isBroken then + self.isBroken = false + end + self.workAllowed = allow +end + return MockMultiBlock From eab31f5f841f1c883c03280494df097317f072ba Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 13:56:10 -0300 Subject: [PATCH 05/14] Adding method to create machine widget --- Programs/monitor-system/api/gui/widget.lua | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Programs/monitor-system/api/gui/widget.lua b/Programs/monitor-system/api/gui/widget.lua index 6b3f0f6..9df3559 100644 --- a/Programs/monitor-system/api/gui/widget.lua +++ b/Programs/monitor-system/api/gui/widget.lua @@ -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, From f9a40c97deea69417e5d6000896487d82444e8cb Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 23:12:50 -0300 Subject: [PATCH 06/14] Improving setup Copying Libraries contents to the right directory --- setup.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.lua b/setup.lua index 0b5e41c..fcf679e 100644 --- a/setup.lua +++ b/setup.lua @@ -12,9 +12,6 @@ shell.execute("wget -fq " .. tarBin) local InfOS = "https://github.com/gordominossi/InfOS/releases/download/v0.2.1/InfOS.tar" shell.setWorkingDirectory("/home") -if not shell.resolve("/home/lib") then - shell.execute("mkdir lib") -end if not shell.resolve("/home/InfOS") then shell.execute("mkdir InfOS") end @@ -28,7 +25,8 @@ shell.execute("rm -f InfOS.tar") shell.setWorkingDirectory("/home/") shell.execute("rm -rf lib") -shell.execute("cp -r InfOS/Libraries lib") +shell.execute("mkdir lib") +shell.execute("cp -r InfOS/Libraries/* lib") shell.execute("rm -f .shrc") shell.execute("cp InfOS/.shrc .shrc") shell.execute("rm -f setup.lua") From 92c70b3e236894fcda96c4f3730fc782c96e5818 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 23:14:16 -0300 Subject: [PATCH 07/14] Adding multiblock addresses to `Page.setup` --- Programs/monitor-system/api/gui/page/init.lua | 2 +- Programs/monitor-system/init.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Programs/monitor-system/api/gui/page/init.lua b/Programs/monitor-system/api/gui/page/init.lua index d6ec4ed..a19b168 100644 --- a/Programs/monitor-system/api/gui/page/init.lua +++ b/Programs/monitor-system/api/gui/page/init.lua @@ -200,7 +200,7 @@ function page.fake() page.create(pages.overview) end -function page.setup(energyBufferAddress) +function page.setup(energyBufferAddress, multiblockAddresses) elements.machineWidgets = Widget.fakeWidgets() elements.powerWidget = Widget.createPowerWidget(energyBufferAddress) page.create(pages.overview) diff --git a/Programs/monitor-system/init.lua b/Programs/monitor-system/init.lua index 5ae180c..a3dda22 100755 --- a/Programs/monitor-system/init.lua +++ b/Programs/monitor-system/init.lua @@ -7,7 +7,7 @@ Page = require("api.gui.page") EnergyProvider = require("data.datasource.energy-provider") -- 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 protectCleanroomRecipes = require("domain.cleanroom.protect-recipes-usecase") @@ -62,7 +62,7 @@ end require("api.sound.zelda-secret")() --]] -Page.setup(energyBufferAddresses.batteryBuffer1) +Page.setup(energyBufferAddresses.batteryBuffer1, multiBlockAddresses) while true do Page.update() From f1d77a7eee48b322ba020e187548c88c120121be Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 23:16:26 -0300 Subject: [PATCH 08/14] Adjusting `getMultiblockStatusUsecase` Returning status outside of a table Using `isWorkAllowed` instead of an unexistent method --- .../multiblock/get-multiblock-status-usecase.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua b/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua index c680f00..889c1ab 100755 --- a/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua +++ b/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua @@ -1,6 +1,5 @@ -- Import section Machine = require("data.datasource.machine") -Alarm = require("api.sound.alarm") -- local function exec(address, name) @@ -9,7 +8,7 @@ local function exec(address, name) local problems = multiblock:getNumberOfProblems() local state = {} - if multiblock:isMachineEnabled() then + if multiblock:isWorkAllowed() then if multiblock:hasWork() then state = Machine.states.ON else @@ -24,12 +23,10 @@ local function exec(address, name) end local totalProgress = multiblock:getProgress() - local maxProgress = totalProgress.maximum - local progress = totalProgress.current - status[multiblock.name] = { - progress = progress, - maxProgress = maxProgress, + status = { + progress = totalProgress.current, + maxProgress = totalProgress.maximum, problems = problems, probablyUses = multiblock:getEnergyUsage(), efficiencyPercentage = multiblock:getEfficiencyPercentage(), From 54b99310f19032a2722577eec643190ef039eb48 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 23:26:18 -0300 Subject: [PATCH 09/14] Removing reference to self because real machines methods do not use self --- .../domain/multiblock/toggle-multiblock-work.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua index b0ce22b..b5039ef 100755 --- a/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua +++ b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua @@ -5,8 +5,8 @@ Alarm = require("api.sound.alarm") local function exec(address, name) local multiblock = Machine.getMachine(address, name, Machine.types.multiblock) - local workAllowed = multiblock:isWorkAllowed() - multiblock:setWorkAllowed(not workAllowed) + local workAllowed = multiblock.isWorkAllowed() + multiblock.setWorkAllowed(not workAllowed) end return exec From de5daf49bd4484f84f868aaefb098eb1b273e9e8 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 23:36:25 -0300 Subject: [PATCH 10/14] Removing references to self because real machines have no references to self Improving working/not working behaviour on MockMultiblock --- .../data/mock/mock-multi-block.lua | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Programs/monitor-system/data/mock/mock-multi-block.lua b/Programs/monitor-system/data/mock/mock-multi-block.lua index cdf3121..e465a31 100644 --- a/Programs/monitor-system/data/mock/mock-multi-block.lua +++ b/Programs/monitor-system/data/mock/mock-multi-block.lua @@ -8,34 +8,35 @@ local MockMultiBlock = MockSingleBlock, { name = "MockMultiBlock", - progress = 0, - maxProgress = 0, + isBroken = false } ) -function MockMultiBlock:getSensorInformation() - self.progress = self.progress + 1 - if self.progress > self.maxProgress then - self.maxProgress = math.random(500) - self.progress = 0 +function MockMultiBlock.getSensorInformation() + MockMultiBlock.workProgress = MockMultiBlock.workProgress + 1 + if MockMultiBlock.workProgress > MockMultiBlock.workMaxProgress then + MockMultiBlock.workProgress = 0 end - self.isBroken = self.isBroken or math.random(100000) > 99999 + if MockMultiBlock.workAllowed and not MockMultiBlock.isBroken and math.random(1000) > 999 then + MockMultiBlock.workMaxProgress = math.random(500) + end + MockMultiBlock.isBroken = MockMultiBlock.isBroken or math.random(100000) > 99999 return { - "Progress: §a" .. self.progress .. "§r s / §e" .. self.maxProgress .. "§r s", + "Progress: §a" .. MockMultiBlock.workProgress .. "§r s / §e" .. MockMultiBlock.workMaxProgress .. "§r s", "Stored Energy: §a1000§r EU / §e1000§r EU", "Probably uses: §c4§r EU/t", "Max Energy Income: §e128§r EU/t(x2A) Tier: §eMV§r", - "Problems: §c" .. self.isBroken and 1 or 0 .. "§r Efficiency: §e100.0§r %", + "Problems: §c" .. (MockMultiBlock.isBroken and 1 or 0) .. "§r Efficiency: §e100.0§r %", "Pollution reduced to: §a0§r %", n = 6 } end -function MockMultiBlock:setWorkAllowed(allow) - if self.isBroken then - self.isBroken = false +function MockMultiBlock.setWorkAllowed(allow) + if MockMultiBlock.isBroken then + MockMultiBlock.isBroken = false end - self.workAllowed = allow + MockMultiBlock.workAllowed = allow end return MockMultiBlock From c33589b2d38d77d1bb74ec945485ccd919fc936c Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Mon, 18 Jan 2021 15:36:06 -0300 Subject: [PATCH 11/14] Adding workaround for Parser.parseProgress Copying the body of the function to the file where it is called Avoiding weird bug that appears to cause the function not to be called(?) --- Libraries/utils/parser.lua | 24 +++++++++---------- .../data/datasource/multi-block.lua | 10 ++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Libraries/utils/parser.lua b/Libraries/utils/parser.lua index 0ef4c30..96c8fb9 100644 --- a/Libraries/utils/parser.lua +++ b/Libraries/utils/parser.lua @@ -1,16 +1,16 @@ -local Parser = {} +local parser = {} -function Parser.parseProgress(progressString) +function parser.parseProgress(progressString) local current = string.sub(progressString, string.find(progressString, "%ba§")) current = tonumber((string.gsub(string.gsub(current, "a", ""), "§", ""))) - local maximum = string.sub(progressString, string.find(progressString, "%be§")) + local maximum = string.sub(progressString, string.find(progressString, "%be§", (string.find(progressString, "/")))) maximum = tonumber((string.gsub(string.gsub(maximum, "e", ""), "§", ""))) return {current = current, maximum = maximum} end -function Parser.parseStoredEnergy(storedEnergyString) +function parser.parseStoredEnergy(storedEnergyString) local noCommaString = string.gsub(storedEnergyString, ",", "") local current = string.sub(noCommaString, string.find(noCommaString, "%ba§")) @@ -22,40 +22,40 @@ function Parser.parseStoredEnergy(storedEnergyString) return {current = current, maximum = maximum} end -function Parser.parseAverageInput(averageInputString) +function parser.parseAverageInput(averageInputString) local noCommaString = string.gsub(averageInputString, ",", "") return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+")))) end -function Parser.parseAverageOutput(averageOutputString) +function parser.parseAverageOutput(averageOutputString) local noCommaString = string.gsub(averageOutputString, ",", "") return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+")))) end -function Parser.parseProblems(problemsString) +function parser.parseProblems(problemsString) local problems = string.sub(problemsString, string.find(problemsString, "c%d")) return tonumber((string.gsub(problems, "c", ""))) end -function Parser.parseEfficiency(efficiencyString) +function parser.parseEfficiency(efficiencyString) local noParagraphMarkString = string.gsub(efficiencyString, "§r", "") local efficiency = string.sub(noParagraphMarkString, string.find(noParagraphMarkString, "%d+%.*%d*%s%%")) return tonumber((string.gsub(efficiency, "%s%%", ""))) end -function Parser.parseName(nameString) +function parser.parseName(nameString) return string.gsub(string.gsub(nameString, "§9", ""), "§r", "") end -function Parser.parseWorkArea(worAreaString) +function parser.parseWorkArea(worAreaString) local size = string.sub(worAreaString, string.find(worAreaString, "§a%d+x%d+§r")) return string.gsub(string.gsub(size, "§a", ""), "§r", "") end -function Parser.parseProbablyUses(probablyUsesString) +function parser.parseProbablyUses(probablyUsesString) local noCommaString = string.gsub(probablyUsesString, ",", "") local estimate = string.sub(noCommaString, string.find(noCommaString, "%bc§")) return tonumber((string.gsub(string.gsub(estimate, "c", ""), "§", ""))) end -return Parser +return parser diff --git a/Programs/monitor-system/data/datasource/multi-block.lua b/Programs/monitor-system/data/datasource/multi-block.lua index bee6ef9..0811884 100755 --- a/Programs/monitor-system/data/datasource/multi-block.lua +++ b/Programs/monitor-system/data/datasource/multi-block.lua @@ -14,6 +14,16 @@ local MultiBlock = } ) +function Parser.parseProgress(progressString) + local current = string.sub(progressString, string.find(progressString, "%ba§")) + current = tonumber((string.gsub(string.gsub(current, "a", ""), "§", ""))) + + local maximum = string.sub(progressString, string.find(progressString, "%be§", (string.find(progressString, "/")))) + maximum = tonumber((string.gsub(string.gsub(maximum, "e", ""), "§", ""))) + + return {current = current, maximum = maximum} +end + function MultiBlock:getNumberOfProblems() local sensorInformation = self:getSensorInformation() return Parser.parseProblems(sensorInformation[5]) From fe955b91e6f6f4eda4dccc09890ee971077e8712 Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Mon, 18 Jan 2021 16:17:05 -0300 Subject: [PATCH 12/14] Integrating with real machines --- Programs/monitor-system/api/gui/page/init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Programs/monitor-system/api/gui/page/init.lua b/Programs/monitor-system/api/gui/page/init.lua index a19b168..20d9b4b 100644 --- a/Programs/monitor-system/api/gui/page/init.lua +++ b/Programs/monitor-system/api/gui/page/init.lua @@ -201,7 +201,9 @@ function page.fake() end function page.setup(energyBufferAddress, multiblockAddresses) - elements.machineWidgets = Widget.fakeWidgets() + for name, address in pairs(multiblockAddresses) do + table.insert(elements.machineWidgets, Widget.createMachineWidget(address, name)) + end elements.powerWidget = Widget.createPowerWidget(energyBufferAddress) page.create(pages.overview) end @@ -211,7 +213,7 @@ function page.update() machineWidget:update() end for index, activeMachineWidget in ipairs(elements.machineWidgets.active) do - activeMachineWidget.draw(activeMachineWidget, index) + activeMachineWidget:draw(index) end elements.powerWidget:update() From 415ffe0fffad5d92b311b8dd8e074eb833bac11e Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Mon, 18 Jan 2021 16:31:58 -0300 Subject: [PATCH 13/14] Refactoring pages setup Grouping elements assingment by widget type --- Programs/monitor-system/api/gui/page/init.lua | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/Programs/monitor-system/api/gui/page/init.lua b/Programs/monitor-system/api/gui/page/init.lua index 20d9b4b..e499caa 100644 --- a/Programs/monitor-system/api/gui/page/init.lua +++ b/Programs/monitor-system/api/gui/page/init.lua @@ -95,15 +95,7 @@ local function drawRebootButton() Widget.drawBaseWidget(x, y, width, height, "Restart") end -local function clickNavigationButton(self) - if not self.active then - return - end - if self.title == "◀" then - elements.machineWidgets.active.index = elements.machineWidgets.active.index - 1 - else - elements.machineWidgets.active.index = elements.machineWidgets.active.index + 1 - end +local function refreshActiveMachineWidgets() for i = 1, 9 do elements.machineWidgets.active[i] = elements.machineWidgets[9 * (elements.machineWidgets.active.index - 1) + i] end @@ -117,12 +109,29 @@ local function clickNavigationButton(self) elements[14] = elements.machineWidgets.active[7] elements[15] = elements.machineWidgets.active[8] elements[16] = elements.machineWidgets.active[9] + Widget.clear() end +local function clickNavigationButton(self) + if not self.active then + return + end + if self.title == "◀" then + elements.machineWidgets.active.index = elements.machineWidgets.active.index - 1 + else + elements.machineWidgets.active.index = elements.machineWidgets.active.index + 1 + end + refreshActiveMachineWidgets() +end + function page.create(element) drawTitle(element.title) + elements.machineWidgets.active = {} + elements.machineWidgets.active.index = 1 + refreshActiveMachineWidgets() + local panelIndex = 1 for _, pg in ipairs(pages) do if pg ~= element then @@ -136,12 +145,11 @@ function page.create(element) panelIndex = panelIndex + 1 end end - - elements.machineWidgets.active = {} - elements.machineWidgets.active.index = 1 - for i = 1, 9 do - elements.machineWidgets.active[i] = elements.machineWidgets[9 * (elements.machineWidgets.active.index - 1) + i] - end + elements[1] = elements.panelSections[1] + elements[5] = elements.panelSections[2] + elements[9] = elements.panelSections[3] + elements[13] = elements.panelSections[4] + elements[17] = elements.panelSections[5] elements.navigationButtons[1] = { title = "◀", @@ -161,6 +169,8 @@ function page.create(element) onClick = clickNavigationButton, draw = drawNavigationButton } + elements[20] = elements.navigationButtons[1] + elements[20.5] = elements.navigationButtons[2] elements.rebootButton = { onClick = function() @@ -168,30 +178,10 @@ function page.create(element) end } drawRebootButton() - elements[4.5] = elements.rebootButton - elements[6] = elements.machineWidgets.active[1] - elements[7] = elements.machineWidgets.active[2] - elements[8] = elements.machineWidgets.active[3] - elements[10] = elements.machineWidgets.active[4] - elements[11] = elements.machineWidgets.active[5] - elements[12] = elements.machineWidgets.active[6] - elements[14] = elements.machineWidgets.active[7] - elements[15] = elements.machineWidgets.active[8] - elements[16] = elements.machineWidgets.active[9] - elements[18] = elements.powerWidget elements[19] = elements.powerWidget - - elements[1] = elements.panelSections[1] - elements[5] = elements.panelSections[2] - elements[9] = elements.panelSections[3] - elements[13] = elements.panelSections[4] - elements[17] = elements.panelSections[5] - - elements[20] = elements.navigationButtons[1] - elements[20.5] = elements.navigationButtons[2] end function page.fake() From eab8f3579133ab98d0fa71fa6579713da69ebe0e Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Mon, 18 Jan 2021 17:38:39 -0300 Subject: [PATCH 14/14] Fixing toggleMultiblockUsecase Referencing self so the multiblock class can pass the call to the machine --- Programs/monitor-system/api/gui/widget.lua | 4 ++-- .../domain/multiblock/toggle-multiblock-work.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Programs/monitor-system/api/gui/widget.lua b/Programs/monitor-system/api/gui/widget.lua index 9df3559..2e993cc 100644 --- a/Programs/monitor-system/api/gui/widget.lua +++ b/Programs/monitor-system/api/gui/widget.lua @@ -216,8 +216,8 @@ function widget.createMachineWidget(address, name) end local toggleMultiblockWork = require("domain.multiblock.toggle-multiblock-work") - local function onClick() - toggleMultiblockWork(address) + local function onClick(self) + toggleMultiblockWork(address, self.name) end local machineWidget = { diff --git a/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua index b5039ef..b0ce22b 100755 --- a/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua +++ b/Programs/monitor-system/domain/multiblock/toggle-multiblock-work.lua @@ -5,8 +5,8 @@ Alarm = require("api.sound.alarm") local function exec(address, name) local multiblock = Machine.getMachine(address, name, Machine.types.multiblock) - local workAllowed = multiblock.isWorkAllowed() - multiblock.setWorkAllowed(not workAllowed) + local workAllowed = multiblock:isWorkAllowed() + multiblock:setWorkAllowed(not workAllowed) end return exec