This commit is contained in:
kepler155c
2018-10-23 03:04:34 -04:00
parent f40f7ae7a8
commit a19960959b
22 changed files with 965 additions and 651 deletions

View File

@@ -1,38 +1,24 @@
local InventoryAdapter = require('inventoryAdapter')
local Lora = require('lora/lora')
local Lora = require('lora')
local device = _G.device
local modem = device.wired_modem
local InputChest = {
priority = 1,
adapters = { },
}
function InputChest:init(context)
for k,v in pairs(context.config.remoteDefaults) do
if v.mtype == 'input' then
local adapter = InventoryAdapter.wrap({ side = k, direction = modem.getNameLocal() })
if adapter then
table.insert(self.adapters, adapter)
end
end
function InputChest:cycle(context)
for name,v in pairs(context.config.remoteDefaults) do
if v.mtype == 'input' then
local inventory = device[name]
local list = inventory and inventory.list and inventory.list()
if list then
for slotNo, slot in pairs(list) do
context.inventoryAdapter:insert(slotNo, slot.count, nil, slot, name)
end
end
end
end
end
-- TODO: clear grid
-- TODO: extract directly to target
function InputChest:cycle(context)
for _, adapter in pairs(self.adapters) do
local list = adapter.list() -- raw list !
for k,v in pairs(list) do
adapter:extract(k, v.count, 1)
context.inventoryAdapter:insert(1, v.count, nil, v)
end
end
end
InputChest:init(Lora:getContext())
Lora:registerTask(InputChest)