milo storage filter + crafting fixes
This commit is contained in:
@@ -1,49 +1,44 @@
|
||||
local itemDB = require('itemDB')
|
||||
local Milo = require('milo')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local ExportTask = {
|
||||
name = 'exporter',
|
||||
priority = 40,
|
||||
}
|
||||
|
||||
local function filter(a)
|
||||
return a.exports
|
||||
end
|
||||
|
||||
function ExportTask:cycle(context)
|
||||
for target, v in pairs(context.config.remoteDefaults) do
|
||||
if v.exports then
|
||||
local machine = device[target]
|
||||
if machine and machine.getItemMeta then
|
||||
for _, entry in pairs(v.exports) do
|
||||
local slotNo = type(entry.slot) == 'number' and entry.slot or nil -- '*' indicates any slot
|
||||
for machine in context.storage:filterActive('machine', filter) do
|
||||
for _, entry in pairs(machine.exports) do
|
||||
local slotNo = type(entry.slot) == 'number' and entry.slot or nil -- '*' indicates any slot
|
||||
|
||||
local slot = (slotNo and machine.getItemMeta(slotNo)) or { count = 0 }
|
||||
for key in pairs(entry.filter) do
|
||||
local item = itemDB:splitKey(key)
|
||||
local slot = (slotNo and machine.adapter.getItemMeta(slotNo)) or { count = 0 }
|
||||
for key in pairs(entry.filter or { }) do
|
||||
local item = itemDB:splitKey(key)
|
||||
|
||||
-- is something else is in this slot
|
||||
if not slot.name or slot.name == item.name then
|
||||
local maxCount = slot.maxCount or itemDB:getMaxCount(item)
|
||||
local count = maxCount - slot.count
|
||||
if not slotNo then
|
||||
-- TODO: should we just execute export -
|
||||
-- or scan all slots for space ??
|
||||
count = machine.size() * maxCount - slot.count
|
||||
end
|
||||
if count > 0 then
|
||||
item = Milo:getItemWithQty(item)
|
||||
if item and count > 0 then
|
||||
context.storage:export(
|
||||
target,
|
||||
slotNo,
|
||||
math.min(count, item.count),
|
||||
item)
|
||||
end
|
||||
end
|
||||
-- is something else is in this slot
|
||||
if not slot.name or slot.name == item.name then
|
||||
local maxCount = slot.maxCount or itemDB:getMaxCount(item)
|
||||
local count = maxCount - slot.count
|
||||
if not slotNo then
|
||||
-- TODO: should we just execute export -
|
||||
-- or scan all slots for space ??
|
||||
count = machine.adapter.size() * maxCount - slot.count
|
||||
end
|
||||
if count > 0 then
|
||||
item = Milo:getItemWithQty(item)
|
||||
if item and count > 0 then
|
||||
context.storage:export(
|
||||
machine.name,
|
||||
slotNo,
|
||||
math.min(count, item.count),
|
||||
item)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
debug('Invalid export target: ' .. target)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user