fix: refactor modes update
This commit is contained in:
parent
9b9f2e3a99
commit
0f208f77f2
1 changed files with 12 additions and 12 deletions
|
|
@ -95,7 +95,7 @@ function createModes (items)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateModes (ticker, current_modes)
|
function updateModes (current_modes, current_stock)
|
||||||
local lower_lim, upper_lim
|
local lower_lim, upper_lim
|
||||||
local limits = {}
|
local limits = {}
|
||||||
for item, _ in pairs(current_modes) do
|
for item, _ in pairs(current_modes) do
|
||||||
|
|
@ -111,16 +111,16 @@ function updateModes (ticker, current_modes)
|
||||||
upper = upper_lim,
|
upper = upper_lim,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
for _, item in pairs(ticker.stock()) do
|
for item, limits in pairs(limits) do
|
||||||
if limits[item.name] ~= nil then
|
local count = current_stock[item]
|
||||||
if item.count <= limits[item.name].lower then
|
if count == nil then count = 0 end
|
||||||
current_modes[item.name] = {"recipe"}
|
if count <= limits.lower then
|
||||||
elseif item.count >= limits[item.name].upper then
|
current_modes[item] = {"recipe"}
|
||||||
current_modes[item.name] = {
|
elseif count >= limits.upper then
|
||||||
"export",
|
current_modes[item] = {
|
||||||
item.count - limits[item.name].lower,
|
"export",
|
||||||
}
|
count - limits.lower,
|
||||||
end
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -208,9 +208,9 @@ function run (ticker, export_storage, current_modes)
|
||||||
os.sleep(SLEEP_T)
|
os.sleep(SLEEP_T)
|
||||||
return run (ticker, export_storage, current_modes)
|
return run (ticker, export_storage, current_modes)
|
||||||
end
|
end
|
||||||
updateModes(ticker, current_modes)
|
|
||||||
local export_amounts = getAmounts(export_storage.list)
|
local export_amounts = getAmounts(export_storage.list)
|
||||||
local stock_amounts = getAmounts(ticker.stock)
|
local stock_amounts = getAmounts(ticker.stock)
|
||||||
|
updateModes(current_modes, stock_amounts)
|
||||||
cycleItems(ticker, stock_amounts)
|
cycleItems(ticker, stock_amounts)
|
||||||
for item, mode in pairs(current_modes) do
|
for item, mode in pairs(current_modes) do
|
||||||
-- mode[1] is mode, mode[2] is amt_extra when exporting
|
-- mode[1] is mode, mode[2] is amt_extra when exporting
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue