This commit is contained in:
kepler155c
2018-10-25 17:12:37 -04:00
parent 9f9dcafc60
commit ceb558dcff
5 changed files with 137 additions and 106 deletions

View File

@@ -13,6 +13,7 @@ function NetworkedAdapter:init(args)
dirty = true,
listCount = 0,
activity = { },
nameArray = { },
}
Util.merge(self, defaults)
Util.merge(self, args)
@@ -29,6 +30,7 @@ listCount = 0,
local adapter = InventoryAdapter.wrap({ side = k, direction = self.localName })
if adapter then
table.insert(self.remotes, adapter)
self.nameArray[adapter.direction] = true
end
end
end
@@ -47,6 +49,7 @@ listCount = 0,
return a.priority > b.priority
end)
end
debug(self.nameArray)
end
function NetworkedAdapter:isValid()
@@ -116,13 +119,15 @@ function NetworkedAdapter:provide(item, qty, slot, direction)
for _, remote in ipairs(self.remotes) do
local amount = remote:provide(item, qty, slot, direction)
if amount > 0 then
debug('%s(%d): %s -> %s%s',
debug('EXT: %s(%d): %s -> %s%s',
item.name, amount, remote.side, direction or self.localName,
slot and string.format('[%d]', slot) or '')
self.dirty = true
remote.dirty = true
local entry = self.activity[key] or 0
self.activity[key] = entry + amount
--if self.nameArray[direction or self.localName] then
-- local entry = self.activity[key] or 0
-- self.activity[key] = entry + amount
--end
end
qty = qty - amount
total = total + amount
@@ -168,13 +173,16 @@ function NetworkedAdapter:insert(slot, qty, toSlot, item, source)
local function insert(remote)
local amount = remote:insert(slot, qty, toSlot, source or self.direction)
if amount > 0 then
debug('%s(%d): %s[%d] -> %s',
debug('INS: %s(%d): %s[%d] -> %s',
item.name, amount,
source or self.localName, slot, remote.side)
self.dirty = true
remote.dirty = true
local entry = self.activity[key] or 0
self.activity[key] = entry + amount
debug('insert: ' .. (source or self.localName))
--if self.nameArray[source or self.localName] then
local entry = self.activity[key] or 0
self.activity[key] = entry + amount
--end
end
qty = qty - amount
total = total + amount