mirror of
https://github.com/kepler155c/opus
synced 2025-10-20 18:27:40 +00:00
builder improvements - resource manager
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
local class = require('class')
|
||||
local TableDB = require('tableDB')
|
||||
local itemDB = require('itemDB')
|
||||
local Peripheral = require('peripheral')
|
||||
|
||||
local ChestProvider = class()
|
||||
@@ -28,14 +28,6 @@ function ChestProvider:init(args)
|
||||
if chest then
|
||||
Util.merge(self, chest)
|
||||
end
|
||||
|
||||
if not self.itemInfoDB then
|
||||
self.itemInfoDB = TableDB({
|
||||
fileName = 'items.db'
|
||||
})
|
||||
|
||||
self.itemInfoDB:load()
|
||||
end
|
||||
end
|
||||
|
||||
function ChestProvider:isValid()
|
||||
@@ -43,9 +35,9 @@ function ChestProvider:isValid()
|
||||
end
|
||||
|
||||
function ChestProvider:getCachedItemDetails(item, k)
|
||||
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local key = { item.name, item.damage, item.nbtHash }
|
||||
|
||||
local detail = self.itemInfoDB:get(key)
|
||||
local detail = itemDB:get(key)
|
||||
if not detail then
|
||||
pcall(function() detail = self.getItemMeta(k) end)
|
||||
if not detail then
|
||||
@@ -64,7 +56,7 @@ function ChestProvider:getCachedItemDetails(item, k)
|
||||
end
|
||||
end
|
||||
|
||||
self.itemInfoDB:add(key, detail)
|
||||
itemDB:add(key, detail)
|
||||
end
|
||||
if detail then
|
||||
return Util.shallowCopy(detail)
|
||||
@@ -108,7 +100,7 @@ function ChestProvider:listItems(throttle)
|
||||
throttle()
|
||||
end
|
||||
|
||||
self.itemInfoDB:flush()
|
||||
itemDB:flush()
|
||||
|
||||
return items
|
||||
end
|
||||
@@ -127,12 +119,14 @@ end
|
||||
function ChestProvider:craftItems(items)
|
||||
end
|
||||
|
||||
function ChestProvider:provide(item, qty, slot)
|
||||
function ChestProvider:provide(item, qty, slot, direction)
|
||||
local stacks = self.list()
|
||||
for key,stack in pairs(stacks) do
|
||||
if stack.name == item.id and stack.damage == item.dmg then
|
||||
local amount = math.min(qty, stack.count)
|
||||
self.pushItems(self.direction, key, amount, slot)
|
||||
if amount > 0 then
|
||||
self.pushItems(direction or self.direction, key, amount, slot)
|
||||
end
|
||||
qty = qty - amount
|
||||
if qty <= 0 then
|
||||
break
|
||||
|
@@ -153,9 +153,9 @@ function Event.pullEvents(...)
|
||||
end
|
||||
else
|
||||
while true do
|
||||
local e = { os.pullEvent() }
|
||||
local e = { os.pullEventRaw() }
|
||||
Event.processEvent(e)
|
||||
if exitPullEvents or e == 'terminate' then
|
||||
if exitPullEvents or e[1] == 'terminate' then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
35
sys/apis/itemDB.lua
Normal file
35
sys/apis/itemDB.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
local TableDB = require('tableDB')
|
||||
|
||||
local itemDB = TableDB({ fileName = 'usr/config/items.db' })
|
||||
|
||||
function itemDB:get(key)
|
||||
|
||||
local item = TableDB.get(self, key)
|
||||
|
||||
if item then
|
||||
return item
|
||||
end
|
||||
|
||||
if key[2] ~= 0 then
|
||||
item = TableDB.get(self, { key[1], 0, key[3] })
|
||||
if item and item.maxDamage > 0 then
|
||||
return item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function itemDB:add(key, item)
|
||||
|
||||
if item.maxDamage > 0 then
|
||||
key = { key[1], 0, key[3] }
|
||||
end
|
||||
TableDB.add(self, key, item)
|
||||
end
|
||||
|
||||
function itemDB:makeKey(item)
|
||||
return { item.name, item.damage, item.nbtHash }
|
||||
end
|
||||
|
||||
itemDB:load()
|
||||
|
||||
return itemDB
|
@@ -1,6 +1,6 @@
|
||||
local class = require('class')
|
||||
local Peripheral = require('peripheral')
|
||||
local TableDB = require('tableDB')
|
||||
local itemDB = require('itemDB')
|
||||
|
||||
local RefinedProvider = class()
|
||||
|
||||
@@ -14,7 +14,6 @@ local keys = {
|
||||
}
|
||||
|
||||
function RefinedProvider:init(args)
|
||||
|
||||
local defaults = {
|
||||
items = { },
|
||||
name = 'refinedStorage',
|
||||
@@ -26,14 +25,6 @@ function RefinedProvider:init(args)
|
||||
if controller then
|
||||
Util.merge(self, controller)
|
||||
end
|
||||
|
||||
if not self.itemInfoDB then
|
||||
self.itemInfoDB = TableDB({
|
||||
fileName = 'items.db'
|
||||
})
|
||||
|
||||
self.itemInfoDB:load()
|
||||
end
|
||||
end
|
||||
|
||||
function RefinedProvider:isValid()
|
||||
@@ -45,9 +36,9 @@ function RefinedProvider:isOnline()
|
||||
end
|
||||
|
||||
function RefinedProvider:getCachedItemDetails(item)
|
||||
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local key = { item.name, item.damage, item.nbtHash }
|
||||
|
||||
local detail = self.itemInfoDB:get(key)
|
||||
local detail = itemDB:get(key)
|
||||
if not detail then
|
||||
detail = self.findItem(item)
|
||||
if detail then
|
||||
@@ -63,12 +54,12 @@ function RefinedProvider:getCachedItemDetails(item)
|
||||
detail.lname = detail.displayName:lower()
|
||||
|
||||
local t = { }
|
||||
for _,key in pairs(keys) do
|
||||
t[key] = detail[key]
|
||||
for _,k in pairs(keys) do
|
||||
t[k] = detail[k]
|
||||
end
|
||||
|
||||
detail = t
|
||||
self.itemInfoDB:add(key, detail)
|
||||
itemDB:add(key, detail)
|
||||
end
|
||||
end
|
||||
if detail then
|
||||
@@ -99,7 +90,7 @@ function RefinedProvider:listItems()
|
||||
end
|
||||
throttle()
|
||||
end
|
||||
self.itemInfoDB:flush()
|
||||
itemDB:flush()
|
||||
end
|
||||
|
||||
return items
|
||||
@@ -107,9 +98,9 @@ end
|
||||
|
||||
function RefinedProvider:getItemInfo(fingerprint)
|
||||
|
||||
local key = table.concat({ fingerprint.name, fingerprint.damage, fingerprint.nbtHash }, ':')
|
||||
local key = { fingerprint.name, fingerprint.damage, fingerprint.nbtHash }
|
||||
|
||||
local item = self.itemInfoDB:get(key)
|
||||
local item = itemDB:get(key)
|
||||
if not item then
|
||||
return self:getCachedItemDetails(fingerprint)
|
||||
end
|
||||
|
@@ -706,11 +706,14 @@ function Schematic:determineBlockPlacement(y)
|
||||
table.remove(dirtyBlocks, k)
|
||||
end
|
||||
elseif d == 'bottom' then
|
||||
b.bottom = true -- flag this as a bottom block
|
||||
local _,db = self:findIndexAt(b.x, b.z, b.y-1)
|
||||
if db then
|
||||
if not db.direction or db.direction ~= 'bottom' then
|
||||
-- not a slab below, ok to place from above
|
||||
b.direction = nil
|
||||
if not db.bottom then
|
||||
b.direction = nil
|
||||
end
|
||||
end
|
||||
-- it is a slab below - must be pistoned
|
||||
table.remove(dirtyBlocks, k)
|
||||
|
Reference in New Issue
Block a user