milo wip
This commit is contained in:
@@ -72,6 +72,16 @@ end
|
|||||||
|
|
||||||
-- provide a consolidated list of items
|
-- provide a consolidated list of items
|
||||||
function ChestAdapter:listItems(throttle)
|
function ChestAdapter:listItems(throttle)
|
||||||
|
for _ = 1, 5 do
|
||||||
|
local list = self:listItemsInternal(throttle)
|
||||||
|
if list then
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error('Error accessing inventory: ' .. self.direction)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChestAdapter:listItemsInternal(throttle)
|
||||||
local cache = { }
|
local cache = { }
|
||||||
local items = { }
|
local items = { }
|
||||||
throttle = throttle or Util.throttle()
|
throttle = throttle or Util.throttle()
|
||||||
@@ -100,10 +110,8 @@ function ChestAdapter:listItems(throttle)
|
|||||||
end
|
end
|
||||||
itemDB:flush()
|
itemDB:flush()
|
||||||
|
|
||||||
if not Util.empty(items) then
|
self.cache = cache
|
||||||
self.cache = cache
|
return items
|
||||||
return items
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:getItemInfo(item)
|
function ChestAdapter:getItemInfo(item)
|
||||||
|
|||||||
@@ -67,12 +67,11 @@ local Config = require('config')
|
|||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
|
local NetworkAdapter = require('networkedAdapter18')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local InventoryAdapter = require('inventoryAdapter')
|
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
@@ -147,7 +146,7 @@ debug(storage)
|
|||||||
--TODO: cannot do this, must be able to add and mark inactive
|
--TODO: cannot do this, must be able to add and mark inactive
|
||||||
-- due to activity table
|
-- due to activity table
|
||||||
-- add an networkAdapter:scan()
|
-- add an networkAdapter:scan()
|
||||||
context.inventoryAdapter = InventoryAdapter.wrap({ remoteDefaults = storage })
|
context.inventoryAdapter = NetworkAdapter({ remoteDefaults = storage })
|
||||||
|
|
||||||
if not context.inventoryAdapter then
|
if not context.inventoryAdapter then
|
||||||
error('Invalid inventory configuration')
|
error('Invalid inventory configuration')
|
||||||
@@ -201,7 +200,7 @@ local page = UI:getPage('listing')
|
|||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
page:setFocus(page.statusBar.filter) -- todo: move this line into listing code
|
page:setFocus(page.statusBar.filter) -- todo: move this line into listing code
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
Event.onInterval(500, function()
|
||||||
if not Milo:isCraftingPaused() then
|
if not Milo:isCraftingPaused() then
|
||||||
Milo:resetCraftingStatus()
|
Milo:resetCraftingStatus()
|
||||||
context.inventoryAdapter:refresh()
|
context.inventoryAdapter:refresh()
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
local Adapter = { }
|
|
||||||
|
|
||||||
function Adapter.wrap(args)
|
|
||||||
local adapters = {
|
|
||||||
'networkedAdapter18',
|
|
||||||
'refinedAdapter',
|
|
||||||
'meAdapter18',
|
|
||||||
'chestAdapter18',
|
|
||||||
|
|
||||||
-- adapters for version 1.7
|
|
||||||
'meAdapter',
|
|
||||||
'chestAdapter',
|
|
||||||
}
|
|
||||||
|
|
||||||
for _,adapterType in ipairs(adapters) do
|
|
||||||
local adapter = require(adapterType)(args)
|
|
||||||
|
|
||||||
if adapter:isValid() then
|
|
||||||
|
|
||||||
-- figure out which direction to push/pull items from an inventory
|
|
||||||
-- based on the side the inventory is attached and which way the
|
|
||||||
-- turtle/computer is facing
|
|
||||||
if args and args.facing and adapter.side and not adapter.direction then
|
|
||||||
local horz = { top = 'down', bottom = 'up' }
|
|
||||||
adapter.direction = horz[adapter.side]
|
|
||||||
|
|
||||||
if not adapter.direction then
|
|
||||||
local sides = {
|
|
||||||
front = 0,
|
|
||||||
right = 1,
|
|
||||||
back = 2,
|
|
||||||
left = 3,
|
|
||||||
}
|
|
||||||
-- pretty sure computer/turtle have sides reversed
|
|
||||||
local cards = {
|
|
||||||
east = 0,
|
|
||||||
south = 1,
|
|
||||||
west = 2,
|
|
||||||
north = 3,
|
|
||||||
}
|
|
||||||
local icards = {
|
|
||||||
[ 0 ] = 'west',
|
|
||||||
[ 1 ] = 'north',
|
|
||||||
[ 2 ] = 'east',
|
|
||||||
[ 3 ] = 'south',
|
|
||||||
}
|
|
||||||
adapter.direction = icards[(cards[args.facing] + sides[adapter.side]) % 4]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return adapter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return Adapter
|
|
||||||
@@ -201,8 +201,7 @@ end
|
|||||||
|
|
||||||
-- Return a list of everything in the system
|
-- Return a list of everything in the system
|
||||||
function Milo:listItems()
|
function Milo:listItems()
|
||||||
self.items = self.context.inventoryAdapter:listItems()
|
return self.context.inventoryAdapter:listItems()
|
||||||
return self.items
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Milo
|
return Milo
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local InventoryAdapter = require('inventoryAdapter')
|
local InventoryAdapter = require('inventoryAdapter')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
|
|
||||||
local NetworkedAdapter = class()
|
local NetworkedAdapter = class()
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ function listingPage:enable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:refresh()
|
function listingPage:refresh()
|
||||||
self.allItems = Milo:listItems()
|
self.allItems = context.inventoryAdapter:refresh()
|
||||||
Milo:mergeResources(self.allItems)
|
Milo:mergeResources(self.allItems)
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user