feat(inferium-gui): implement preparePayloads
This commit is contained in:
parent
3ef5930f4f
commit
472415a59f
@ -12,6 +12,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function formatSeedName(essenceName)
|
local function formatSeedName(essenceName)
|
||||||
|
if not essenceName then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -125,6 +129,60 @@ local function createCountersMap(harvesters)
|
|||||||
return getCountersMapFromIndexed(countersMapIndexed)
|
return getCountersMapFromIndexed(countersMapIndexed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function pickSeedNameFromCountersMap(countersMap)
|
||||||
|
local newCountersMap = {}
|
||||||
|
local pickedCounterName = nil
|
||||||
|
|
||||||
|
for k, counterPayload in pairs(countersMap) do
|
||||||
|
local count = counterPayload.count
|
||||||
|
local name = counterPayload.name
|
||||||
|
|
||||||
|
if not pickedCounterName and count > 0 then
|
||||||
|
pickedCounterName = name
|
||||||
|
count = count - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local newCounterPayload = {
|
||||||
|
count = count,
|
||||||
|
name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
newCountersMap[k] = newCounterPayload
|
||||||
|
end
|
||||||
|
|
||||||
|
return formatSeedName(pickedCounterName), newCountersMap
|
||||||
|
end
|
||||||
|
|
||||||
|
local function preparePayloads(countersMap, maxCounter, harvesters)
|
||||||
|
local payloads = {}
|
||||||
|
|
||||||
|
local globalCounter = 1
|
||||||
|
local configIndex = 1
|
||||||
|
for _, harvester in pairs(harvesters) do
|
||||||
|
local newConfig = {}
|
||||||
|
payloads[configIndex] = { id = harvester.id, config = newConfig }
|
||||||
|
|
||||||
|
for k, _ in pairs(harvester.config.plan) do
|
||||||
|
local seedName, newCountersMaps = pickSeedNameFromCountersMap(countersMap)
|
||||||
|
countersMap = newCountersMaps
|
||||||
|
newConfig[k] = seedName
|
||||||
|
globalCounter = globalCounter + 1
|
||||||
|
if globalCounter > maxCounter then
|
||||||
|
error('preparePayload fatal error: globalCounter is greater than maxCounter')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
configIndex = configIndex + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return payloads
|
||||||
|
end
|
||||||
|
|
||||||
|
local function saveAllConfigs(payloads)
|
||||||
|
-- TODO
|
||||||
|
return false, "not implemented"
|
||||||
|
end
|
||||||
|
|
||||||
local function main(serverName)
|
local function main(serverName)
|
||||||
net.openRednet()
|
net.openRednet()
|
||||||
print('> fetching all configs from ' .. serverName)
|
print('> fetching all configs from ' .. serverName)
|
||||||
@ -134,7 +192,18 @@ local function main(serverName)
|
|||||||
local maxCounter = getMaxCounter(harvesters)
|
local maxCounter = getMaxCounter(harvesters)
|
||||||
local countersMap = createCountersMap(harvesters)
|
local countersMap = createCountersMap(harvesters)
|
||||||
local countersMapResult = CountersSelector(countersMap, getCountersSelectorConfig(maxCounter))
|
local countersMapResult = CountersSelector(countersMap, getCountersSelectorConfig(maxCounter))
|
||||||
print(textutils.serialize(countersMapResult))
|
|
||||||
|
local payloads = preparePayloads(countersMapResult, maxCounter, harvesters)
|
||||||
|
|
||||||
|
print('> saving...')
|
||||||
|
local saveOk, saveErrMessage = saveAllConfigs(payloads)
|
||||||
|
|
||||||
|
if saveOk then
|
||||||
|
print('> done.')
|
||||||
|
else
|
||||||
|
error('Cannot save configs because: ' .. tostring(saveErrMessage), 0)
|
||||||
|
end
|
||||||
|
|
||||||
net.closeRednet()
|
net.closeRednet()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user