mirror of https://github.com/kepler155c/opus
storage activity for refined storage
This commit is contained in:
parent
04a44163f4
commit
a074213b7c
|
@ -1,15 +1,20 @@
|
||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Peripheral = require('peripheral')
|
local RefinedProvider = require('refinedProvider')
|
||||||
|
local MEProvider = require('meProvider')
|
||||||
|
|
||||||
if not device.monitor then
|
if not device.monitor then
|
||||||
error('Monitor not found')
|
error('Monitor not found')
|
||||||
end
|
end
|
||||||
|
|
||||||
local me = Peripheral.getByMethod('getAvailableItems')
|
local storage = RefinedProvider()
|
||||||
if not me then
|
if not storage:isValid() then
|
||||||
error("No ME peripheral attached")
|
storage = MEProvider()
|
||||||
|
end
|
||||||
|
|
||||||
|
if not storage:isValid() then
|
||||||
|
error('Not connected to a storage device')
|
||||||
end
|
end
|
||||||
|
|
||||||
local monitor = UI.Device({
|
local monitor = UI.Device({
|
||||||
|
@ -118,7 +123,7 @@ function changedPage:eventHandler(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
function changedPage:refresh()
|
function changedPage:refresh()
|
||||||
local t = me.getAvailableItems('all')
|
local t = storage:listItems('all')
|
||||||
|
|
||||||
if not t or Util.empty(t) then
|
if not t or Util.empty(t) then
|
||||||
self:clear()
|
self:clear()
|
||||||
|
@ -127,11 +132,12 @@ function changedPage:refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
v.id = v.item.id
|
--v.id = v.id
|
||||||
v.dmg = v.item.dmg
|
--v.dmg = v.dmg
|
||||||
v.name = safeString(v.item.display_name)
|
v.name = safeString(v.display_name)
|
||||||
v.qty = v.size
|
t[k] = Util.shallowCopy(v)
|
||||||
end
|
--v.qty = v.qty
|
||||||
|
end
|
||||||
|
|
||||||
if not self.lastItems then
|
if not self.lastItems then
|
||||||
self.lastItems = t
|
self.lastItems = t
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
local class = require('class')
|
||||||
|
local Peripheral = require('peripheral')
|
||||||
|
|
||||||
|
local RefinedProvider = class()
|
||||||
|
|
||||||
|
function RefinedProvider:init(args)
|
||||||
|
|
||||||
|
local defaults = {
|
||||||
|
cache = { },
|
||||||
|
items = { },
|
||||||
|
name = 'refinedStorage',
|
||||||
|
}
|
||||||
|
Util.merge(self, defaults)
|
||||||
|
Util.merge(self, args)
|
||||||
|
|
||||||
|
self.controller = Peripheral.getByType('refinedstorage:controller')
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:isValid()
|
||||||
|
return not not self.controller
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:getCachedItemDetails(item)
|
||||||
|
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||||
|
|
||||||
|
local detail = self.cache[key]
|
||||||
|
if not detail then
|
||||||
|
detail = self.controller.findItem(item)
|
||||||
|
if detail then
|
||||||
|
Util.merge(detail, detail.getMetadata())
|
||||||
|
if detail.displayName then
|
||||||
|
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
|
||||||
|
detail.displayName = detail.displayName .. ' (damaged)'
|
||||||
|
end
|
||||||
|
detail.lname = detail.displayName:lower()
|
||||||
|
|
||||||
|
-- backwards capability
|
||||||
|
detail.dmg = detail.damage
|
||||||
|
detail.id = detail.name
|
||||||
|
detail.qty = detail.count
|
||||||
|
detail.display_name = detail.displayName
|
||||||
|
|
||||||
|
self.cache[key] = detail
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return detail
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:listItems()
|
||||||
|
local items = { }
|
||||||
|
local list
|
||||||
|
|
||||||
|
pcall(function()
|
||||||
|
list = self.controller.listAvailableItems()
|
||||||
|
end)
|
||||||
|
|
||||||
|
if list then
|
||||||
|
for _,v in pairs(list) do
|
||||||
|
local item = self:getCachedItemDetails(v)
|
||||||
|
if item then
|
||||||
|
item.count = v.count
|
||||||
|
item.qty = v.count
|
||||||
|
table.insert(items, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return items
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:getItemInfo(fingerprint)
|
||||||
|
|
||||||
|
local key = table.concat({ fingerprint.name, fingerprint.damage, fingerprint.nbtHash }, ':')
|
||||||
|
|
||||||
|
local item = self.cache[key]
|
||||||
|
if not item then
|
||||||
|
return self:getCachedItemDetails(fingerprint)
|
||||||
|
end
|
||||||
|
|
||||||
|
local detail = self.controller.findItem(item)
|
||||||
|
if detail then
|
||||||
|
item.count = detail.count
|
||||||
|
item.qty = detail.count
|
||||||
|
return item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:craft(id, dmg, qty)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:craftItems(items)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:provide(item, qty, slot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:extract(slot, qty)
|
||||||
|
-- self.controller.pushItems(self.direction, slot, qty)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedProvider:insert(slot, qty)
|
||||||
|
-- self.controller.pullItems(self.direction, slot, qty)
|
||||||
|
end
|
||||||
|
|
||||||
|
return RefinedProvider
|
Loading…
Reference in New Issue