fix: refactor modes update

This commit is contained in:
Emerson Rosen-Jones 2026-01-03 00:21:39 -05:00
parent 9b9f2e3a99
commit 0f208f77f2

View file

@ -95,7 +95,7 @@ function createModes (items)
return result
end
function updateModes (ticker, current_modes)
function updateModes (current_modes, current_stock)
local lower_lim, upper_lim
local limits = {}
for item, _ in pairs(current_modes) do
@ -111,19 +111,19 @@ function updateModes (ticker, current_modes)
upper = upper_lim,
}
end
for _, item in pairs(ticker.stock()) do
if limits[item.name] ~= nil then
if item.count <= limits[item.name].lower then
current_modes[item.name] = {"recipe"}
elseif item.count >= limits[item.name].upper then
current_modes[item.name] = {
for item, limits in pairs(limits) do
local count = current_stock[item]
if count == nil then count = 0 end
if count <= limits.lower then
current_modes[item] = {"recipe"}
elseif count >= limits.upper then
current_modes[item] = {
"export",
item.count - limits[item.name].lower,
count - limits.lower,
}
end
end
end
end
function cycleItems (ticker, items)
local makeRequest
@ -208,9 +208,9 @@ function run (ticker, export_storage, current_modes)
os.sleep(SLEEP_T)
return run (ticker, export_storage, current_modes)
end
updateModes(ticker, current_modes)
local export_amounts = getAmounts(export_storage.list)
local stock_amounts = getAmounts(ticker.stock)
updateModes(current_modes, stock_amounts)
cycleItems(ticker, stock_amounts)
for item, mode in pairs(current_modes) do
-- mode[1] is mode, mode[2] is amt_extra when exporting