Skip to content

Commit

Permalink
Adding getRequiredEssentia usecase
Browse files Browse the repository at this point in the history
Changing `getMachine` to be compatible with the runic matrix
  • Loading branch information
gordominossi committed Sep 3, 2021
1 parent 796dd14 commit adbb9e4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/entities/machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local machine = {
coordinates = {}
}

function machine.setWorkAllowed(allow, machine)
function machine.setWorkAllowed(allow, self)
end

function machine:isWorkAllowed()
Expand Down
6 changes: 4 additions & 2 deletions server/usecases/get-lsc-status.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- Import section

local parser = require("lib.utils.parser")

local states = require("server.entities.states")
Expand All @@ -10,8 +11,9 @@ local getNumberOfProblems = require("server.usecases.get-number-of-problems")

local function exec(address, name, location)
local lsc = getMachine(address, name, location, require("server.entities.mocks.mock-lsc"))
if not lsc then
return {name = name, state = states.MISSING, location = location}
if not lsc.address then
lsc.state = states.MISSING
return lsc
end

local sensorInformation = lsc:getSensorInformation()
Expand Down
4 changes: 3 additions & 1 deletion server/usecases/get-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ local function exec(partialAdress, name, location, mock)
local machine =
(address and component.proxy(address)) or -- Exists
(component.list("ocemu", true)() and mock:getMock(partialAdress)) or -- Is running on emulator
nil -- Is missing
{} -- Is missing

machine.name = name or "Unnamed"
machine.location = location or {}
knownMachines[partialAdress] = machine

return knownMachines[partialAdress]
Expand Down
5 changes: 3 additions & 2 deletions server/usecases/get-multiblock-status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ local getEfficiencyPercentage = require("server.usecases.get-efficiency-percenta

local function exec(address, name, location)
local multiblock = getMachine(address, name, location)
if not multiblock then
return {name = name, state = states.MISSING, location = location}
if not multiblock.address then
multiblock.state = states.MISSING
return multiblock
end
local sensorInformation = multiblock:getSensorInformation()

Expand Down
24 changes: 24 additions & 0 deletions server/usecases/get-required-essentia.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Import section

local getMatrix = require("server.usecases.get-machine")

--

local function exec(address)
local matrix = getMatrix(address, nil, nil, require("server.entities.mocks.mock-matrix"))
if not matrix.address then
return {}
end

local aspects = matrix.getAspects().aspects
local formattedAspects = {}
if type(aspects) == "table" then
for _, aspectTable in ipairs(aspects) do
formattedAspects[aspectTable.name] = aspectTable.amount
end
end

return formattedAspects
end

return exec
4 changes: 0 additions & 4 deletions setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ shell.setWorkingDirectory("/bin")
shell.execute("wget -fq " .. tarBin)

local NIDAS
local release
local arg = {...}
if arg[1] == "test" or arg[1] == "latest" then
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/download/v-1/NIDAS.tar"
release = "latest"
elseif arg[1] == "dev" or arg[1] == "staging" then
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/download/v0/NIDAS.tar"
release = "dev"
else
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/latest/download/NIDAS.tar"
release = '"stable"'
end

local successful =
Expand Down

0 comments on commit adbb9e4

Please sign in to comment.