This commit is contained in:
kepler155c
2018-11-15 12:17:50 -05:00
parent 560b9e42c9
commit 3e756abe42
10 changed files with 118 additions and 95 deletions

View File

@@ -19,17 +19,29 @@ function Milo:getContext()
return self.context
end
function Milo:pauseCrafting()
self.craftingPaused = true
Milo:showError('Crafting Paused')
function Milo:pauseCrafting(reason)
local _, key = Util.find(self.context.state, 'key', reason.key)
if not key then
table.insert(self.context.state, reason)
os.queueEvent('milo_pause', reason)
end
end
function Milo:resumeCrafting()
self.craftingPaused = false
function Milo:resumeCrafting(reason)
local _, key = Util.find(self.context.state, 'key', reason.key)
if key then
table.remove(self.context.state, key)
local n = self.context.state[#self.context.state]
if n then
os.queueEvent('milo_pause', n)
else
os.queueEvent('milo_resume')
end
end
end
function Milo:isCraftingPaused()
return self.craftingPaused
return self.context.state[#self.context.state]
end
function Milo:getState(key)
@@ -72,13 +84,6 @@ function Milo:registerTask(task)
table.insert(self.context.tasks, task)
end
function Milo:showError(msg)
-- TODO: break dependency
if self.context.jobMonitor then
self.context.jobMonitor:showError(msg)
end
end
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
if not ignoreDamage and not ignoreNbtHash then
return items[inItem.key or self:uniqueKey(inItem)]

View File

@@ -114,7 +114,7 @@ function Storage:filterActive(mtype, filter)
end)
end
function Storage:onlineAdapters(reversed)
function Storage:onlineAdapters()
local iter = { }
for _, v in pairs(self.nodes) do
if v.adapter and v.adapter.online and v.mtype == 'storage' then
@@ -122,20 +122,14 @@ function Storage:onlineAdapters(reversed)
end
end
local function forwardSort(a, b)
table.sort(iter, function(a, b)
if not a.priority then
return false
elseif not b.priority then
return true
end
return a.priority > b.priority
end
local function backwardSort(a, b)
return not forwardSort(a, b)
end
table.sort(iter, reversed and backwardSort or forwardSort)
end)
local i = 0
return function()
@@ -378,12 +372,12 @@ function Storage:import(source, slot, count, item)
end
-- high to low priority
for remote in self:onlineAdapters() do
for node in self:onlineAdapters() do
if count <= 0 then
break
end
if not remote.lock then
insert(remote.adapter)
if not node.lock then
insert(node.adapter)
end
end