lora wip
This commit is contained in:
@@ -146,12 +146,12 @@ function ChestAdapter:provide(item, qty, slot, direction)
|
|||||||
return total, m
|
return total, m
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:extract(slot, qty, toSlot)
|
function ChestAdapter:extract(slot, qty, toSlot, direction)
|
||||||
return self.pushItems(self.direction, slot, qty, toSlot)
|
return self.pushItems(direction or self.direction, slot, qty, toSlot)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:insert(slot, qty, toSlot)
|
function ChestAdapter:insert(slot, qty, toSlot, direction)
|
||||||
return self.pullItems(self.direction, slot, qty, toSlot)
|
return self.pullItems(direction or self.direction, slot, qty, toSlot)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ChestAdapter
|
return ChestAdapter
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ function NetworkedAdapter:init(args)
|
|||||||
remotes = { },
|
remotes = { },
|
||||||
remoteDefaults = { },
|
remoteDefaults = { },
|
||||||
dirty = true,
|
dirty = true,
|
||||||
|
listCount = 0,
|
||||||
}
|
}
|
||||||
Util.merge(self, defaults)
|
Util.merge(self, defaults)
|
||||||
Util.merge(self, args)
|
Util.merge(self, args)
|
||||||
@@ -63,15 +64,16 @@ function NetworkedAdapter:listItems(throttle)
|
|||||||
if not self.dirty then
|
if not self.dirty then
|
||||||
return self.items
|
return self.items
|
||||||
end
|
end
|
||||||
|
self.listCount = self.listCount + 1
|
||||||
|
debug(self.listCount)
|
||||||
local cache = { }
|
local cache = { }
|
||||||
local items = { }
|
local items = { }
|
||||||
throttle = throttle or Util.throttle()
|
throttle = throttle or Util.throttle()
|
||||||
|
|
||||||
for _, remote in pairs(self.remotes) do
|
for _, remote in pairs(self.remotes) do
|
||||||
if not remote:listItems(throttle) then
|
if not remote:listItems(throttle) then
|
||||||
debug('no List')
|
debug('no List: ' .. remote.name)
|
||||||
error('Listing failed: ', remote.name)
|
--error('Listing failed: ' .. remote.name)
|
||||||
end
|
end
|
||||||
local rcache = remote.cache or { }
|
local rcache = remote.cache or { }
|
||||||
|
|
||||||
@@ -145,7 +147,7 @@ debug('extract %d slot:%d', qty, slot)
|
|||||||
return total
|
return total
|
||||||
end
|
end
|
||||||
|
|
||||||
function NetworkedAdapter:insert(slot, qty, toSlot, item)
|
function NetworkedAdapter:insert(slot, qty, toSlot, item, source)
|
||||||
local total = 0
|
local total = 0
|
||||||
|
|
||||||
-- toSlot is not really valid with this adapter
|
-- toSlot is not really valid with this adapter
|
||||||
@@ -159,12 +161,10 @@ function NetworkedAdapter:insert(slot, qty, toSlot, item)
|
|||||||
self:listItems()
|
self:listItems()
|
||||||
end
|
end
|
||||||
|
|
||||||
debug('attempting to insert ' .. item.name)
|
|
||||||
|
|
||||||
local function insert(remote)
|
local function insert(remote)
|
||||||
debug('slot %d -> %s: %s', slot, remote.side, qty)
|
local amount = remote:insert(slot, qty, toSlot, source or self.direction)
|
||||||
local amount = remote:insert(slot, qty, toSlot)
|
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
|
debug('%s(%d) -> %s: %d', source or self.direction, slot, remote.side, amount)
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
remote.dirty = true
|
remote.dirty = true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ local fs = _G.fs
|
|||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
|
|
||||||
if multishell then
|
if multishell then
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Resource Manager')
|
multishell.setTitle(multishell.getCurrent(), 'Resource Manager')
|
||||||
end
|
end
|
||||||
|
|||||||
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 InventoryAdapter = require('inventoryAdapter')
|
||||||
local Lora = require('lora/lora')
|
local Lora = require('lora/lora')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local modem = device.wired_modem
|
local modem = device.wired_modem
|
||||||
@@ -21,6 +21,7 @@ function InputChest:init(context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: clear grid
|
-- TODO: clear grid
|
||||||
|
-- TODO: extract directly to target
|
||||||
|
|
||||||
function InputChest:cycle(context)
|
function InputChest:cycle(context)
|
||||||
for _, adapter in pairs(self.adapters) do
|
for _, adapter in pairs(self.adapters) do
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora/lora')
|
local Lora = require('lora/lora')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
|||||||
Reference in New Issue
Block a user