fix(inferium-gui): fix createCountersMap function
This commit is contained in:
parent
309cc3aae4
commit
f1174fb6a2
@ -10,17 +10,6 @@ local function centerString(str, width)
|
|||||||
return string.rep(' ', padding) .. str
|
return string.rep(' ', padding) .. str
|
||||||
end
|
end
|
||||||
|
|
||||||
local function objectValues(t)
|
|
||||||
local result = {}
|
|
||||||
|
|
||||||
local i = 1
|
|
||||||
for _, v in pairs(t) do
|
|
||||||
result[i] = v
|
|
||||||
i = i + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
local function formatSeedName(essenceName)
|
local function formatSeedName(essenceName)
|
||||||
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
||||||
@ -102,17 +91,29 @@ local function getMaxCounter(harvesters)
|
|||||||
local maxCounter = 0
|
local maxCounter = 0
|
||||||
|
|
||||||
for _, harvester in pairs(harvesters) do
|
for _, harvester in pairs(harvesters) do
|
||||||
maxCounter = maxCounter + utils.sizeof(harvester.plan)
|
maxCounter = maxCounter + utils.sizeof(harvester.config.plan)
|
||||||
end
|
end
|
||||||
|
|
||||||
return maxCounter
|
return maxCounter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getCountersMapFromIndexed(countersMapIndexed)
|
||||||
|
local countersMap = {}
|
||||||
|
|
||||||
|
local i = 1
|
||||||
|
for name, count in pairs(countersMapIndexed) do
|
||||||
|
countersMap[i] = { name = name, count = count }
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return countersMap
|
||||||
|
end
|
||||||
|
|
||||||
local function createCountersMap(harvesters)
|
local function createCountersMap(harvesters)
|
||||||
local countersMapIndexed = {}
|
local countersMapIndexed = {}
|
||||||
|
|
||||||
for _, harvester in pairs(harvesters) do
|
for _, harvester in pairs(harvesters) do
|
||||||
for _, seedName in pairs(harvester.plan) do
|
for _, seedName in pairs(harvester.config.plan) do
|
||||||
local name = parseSeedName(seedName)
|
local name = parseSeedName(seedName)
|
||||||
if name then
|
if name then
|
||||||
local currentCounter = countersMapIndexed[name] or 0
|
local currentCounter = countersMapIndexed[name] or 0
|
||||||
@ -121,10 +122,11 @@ local function createCountersMap(harvesters)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return objectValues(countersMapIndexed)
|
return getCountersMapFromIndexed(countersMapIndexed)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function main(serverName)
|
local function main(serverName)
|
||||||
|
net.openRednet()
|
||||||
print('> fetching all configs from ' .. serverName)
|
print('> fetching all configs from ' .. serverName)
|
||||||
local harvesters = fetchAllHarvesters(serverName)
|
local harvesters = fetchAllHarvesters(serverName)
|
||||||
print('> ' .. utils.sizeof(harvesters) .. ' harvesters fetched')
|
print('> ' .. utils.sizeof(harvesters) .. ' harvesters fetched')
|
||||||
@ -133,6 +135,7 @@ local function main(serverName)
|
|||||||
local countersMap = createCountersMap(harvesters)
|
local countersMap = createCountersMap(harvesters)
|
||||||
local countersMapResult = CountersSelector(countersMap, getCountersSelectorConfig(maxCounter))
|
local countersMapResult = CountersSelector(countersMap, getCountersSelectorConfig(maxCounter))
|
||||||
print(textutils.serialize(countersMapResult))
|
print(textutils.serialize(countersMapResult))
|
||||||
|
net.closeRednet()
|
||||||
end
|
end
|
||||||
|
|
||||||
main(INFERIUM_SERVER)
|
main(INFERIUM_SERVER)
|
||||||
Loading…
Reference in New Issue
Block a user