lora wip
This commit is contained in:
30
inventoryManager/plugins/exportTask.lua
Normal file
30
inventoryManager/plugins/exportTask.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local ExportTask = {
|
||||
priority = 5,
|
||||
}
|
||||
|
||||
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 slotNo, item in pairs(v.exports) do
|
||||
local slot = machine.getItemMeta(slotNo) or { count = 0 }
|
||||
local maxCount = slot.maxCount or itemDB:getMaxCount(item)
|
||||
local count = maxCount - slot.count
|
||||
if count > 0 then
|
||||
context.inventoryAdapter:provide(itemDB:splitKey(item), count, slotNo, target)
|
||||
end
|
||||
end
|
||||
else
|
||||
debug('Invalid export target: ' .. target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Lora:registerTask(ExportTask)
|
||||
27
inventoryManager/plugins/importTask.lua
Normal file
27
inventoryManager/plugins/importTask.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
local Lora = require('lora/lora')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local ImportTask = {
|
||||
priority = 3,
|
||||
}
|
||||
|
||||
function ImportTask:cycle(context)
|
||||
for source, v in pairs(context.config.remoteDefaults) do
|
||||
if v.exports then
|
||||
local machine = device[source]
|
||||
if machine and machine.getItemMeta then
|
||||
for slotNo in pairs(v.imports) do
|
||||
local slot = machine.getItemMeta(slotNo)
|
||||
if slot then
|
||||
context.inventoryAdapter:insert(slotNo, slot.count, nil, slot, source)
|
||||
end
|
||||
end
|
||||
else
|
||||
debug('Invalid import source: ' .. source)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Lora:registerTask(ImportTask)
|
||||
@@ -1,5 +1,5 @@
|
||||
local InventoryAdapter = require('inventoryAdapter')
|
||||
local Lora = require('lora/lora')
|
||||
local InventoryAdapter = require('inventoryAdapter')
|
||||
local Lora = require('lora/lora')
|
||||
|
||||
local device = _G.device
|
||||
local modem = device.wired_modem
|
||||
@@ -21,6 +21,7 @@ function InputChest:init(context)
|
||||
end
|
||||
|
||||
-- TODO: clear grid
|
||||
-- TODO: extract directly to target
|
||||
|
||||
function InputChest:cycle(context)
|
||||
for _, adapter in pairs(self.adapters) do
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local Lora = require('lora/lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local os = _G.os
|
||||
|
||||
Reference in New Issue
Block a user