util refactor + milo bulk crafting
This commit is contained in:
@@ -89,6 +89,7 @@ local function follow(member)
|
||||
end
|
||||
|
||||
member.snmp = Socket.connect(member.id, 161)
|
||||
member.snmp.co = coroutine.running()
|
||||
|
||||
local pt
|
||||
|
||||
@@ -109,8 +110,10 @@ end
|
||||
|
||||
function swarm:onRemove(member, status, message)
|
||||
if member.socket then
|
||||
member.turtle.set({ status = 'idle' })
|
||||
member.turtle.abort(true)
|
||||
pcall(function()
|
||||
member.turtle.set({ status = 'idle' })
|
||||
member.turtle.abort(true)
|
||||
end)
|
||||
end
|
||||
if member.snmp then
|
||||
member.snmp:close()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local class = require('class')
|
||||
local Event = require('event')
|
||||
local Map = require('map')
|
||||
local Socket = require('socket')
|
||||
local Util = require('util')
|
||||
|
||||
local function hijackTurtle(remoteId)
|
||||
local socket, msg = Socket.connect(remoteId, 188)
|
||||
@@ -10,8 +10,10 @@ local function hijackTurtle(remoteId)
|
||||
error(msg)
|
||||
end
|
||||
|
||||
socket.co = coroutine.running()
|
||||
|
||||
socket:write('turtle')
|
||||
local methods = socket:read()
|
||||
local methods = socket:read() or error('Timed out')
|
||||
|
||||
local hijack = { }
|
||||
for _,method in pairs(methods) do
|
||||
@@ -31,11 +33,11 @@ end
|
||||
local Swarm = class()
|
||||
function Swarm:init(args)
|
||||
self.pool = { }
|
||||
Util.merge(self, args)
|
||||
Map.merge(self, args)
|
||||
end
|
||||
|
||||
function Swarm:add(id, args)
|
||||
local member = Util.shallowCopy(args or { })
|
||||
local member = Map.shallowCopy(args or { })
|
||||
member.id = id
|
||||
self.pool[id] = member
|
||||
end
|
||||
|
||||
@@ -320,6 +320,7 @@ function page:scan()
|
||||
else
|
||||
queue[b.pkey] = nil
|
||||
end
|
||||
return acc
|
||||
end,
|
||||
{ })
|
||||
|
||||
|
||||
@@ -481,6 +481,7 @@ local function findDroppedSaplings()
|
||||
b.sapling = true
|
||||
acc[makeKey(b)] = b
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
return sensed
|
||||
@@ -502,6 +503,7 @@ local function scan(pt, filter, blocks)
|
||||
acc[makeKey(b)] = b
|
||||
end
|
||||
end
|
||||
return acc
|
||||
end, blocks or { })
|
||||
end
|
||||
|
||||
|
||||
@@ -96,28 +96,32 @@ local function machineCraft(recipe, storage, machineName, request, count, item)
|
||||
end
|
||||
end
|
||||
|
||||
local xferred = { }
|
||||
for k,v in pairs(recipe.ingredients) do
|
||||
local provided = storage:export(machine, k, count, splitKey(v))
|
||||
xferred[k] = {
|
||||
key = v,
|
||||
count = provided,
|
||||
}
|
||||
if provided ~= count then
|
||||
-- take back out whatever we put in
|
||||
for k2,v2 in pairs(xferred) do
|
||||
if v2.count > 0 then
|
||||
storage:import(machine, k2, v2.count, splitKey(v2.key))
|
||||
local pending = item.pending[recipe.result] or 0
|
||||
|
||||
if count > 0 then
|
||||
local xferred = { }
|
||||
for k,v in pairs(recipe.ingredients) do
|
||||
local provided = storage:export(machine, k, count, splitKey(v))
|
||||
xferred[k] = {
|
||||
key = v,
|
||||
count = provided,
|
||||
}
|
||||
if provided ~= count then
|
||||
-- take back out whatever we put in
|
||||
for k2,v2 in pairs(xferred) do
|
||||
if v2.count > 0 then
|
||||
storage:import(machine, k2, v2.count, splitKey(v2.key))
|
||||
end
|
||||
end
|
||||
request.status = 'Invalid recipe'
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
return
|
||||
end
|
||||
request.status = 'Invalid recipe'
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
return
|
||||
end
|
||||
end
|
||||
request.status = 'processing'
|
||||
request.statusCode = Craft.STATUS_INFO
|
||||
item.pending[recipe.result] = count * recipe.count
|
||||
item.pending[recipe.result] = pending + (count * recipe.count)
|
||||
end
|
||||
|
||||
local function turtleCraft(recipe, storage, request, count)
|
||||
@@ -202,12 +206,14 @@ end
|
||||
function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
||||
local request = origItem.ingredients[recipe.result]
|
||||
|
||||
--[[
|
||||
if origItem.pending[recipe.result] then
|
||||
request.status = 'processing'
|
||||
request.statusCode = Craft.STATUS_INFO
|
||||
return 0
|
||||
end
|
||||
|
||||
--]]
|
||||
count = count - (origItem.pending[recipe.result] or 0)
|
||||
local canCraft = Craft.getCraftableAmount(recipe, count, origItem.ingredients)
|
||||
if not origItem.forceCrafting and canCraft == 0 then
|
||||
return 0
|
||||
|
||||
@@ -310,7 +310,18 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
self.onlineLabel.value = string.format('Storage Status: (%s chests)',
|
||||
stats.totalChests)
|
||||
|
||||
self.crafting.progressColor = Milo:isCraftingPaused() and colors.yellow or colors.green
|
||||
local total, crafted = 0, 0
|
||||
for _,v in pairs(context.craftingQueue) do
|
||||
total = total + v.requested
|
||||
crafted = crafted + v.crafted
|
||||
end
|
||||
if Milo:isCraftingPaused() then
|
||||
self.crafting.progressColor = colors.yellow
|
||||
self.crafting.value = 100
|
||||
else
|
||||
self.crafting.progressColor = colors.green
|
||||
self.crafting.value = total > 0 and math.ceil(crafted / total * 100) or 0
|
||||
end
|
||||
|
||||
local percent = math.floor(stats.usedSlots / stats.totalSlots * 100)
|
||||
local color = colors.green
|
||||
@@ -338,7 +349,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
self.unlockedLabel.value = string.format('Unlocked Usage: %s%% (%s of %s slots)',
|
||||
percent, stats.usedUnlockedSlots, stats.unlockedSlots)
|
||||
|
||||
UI.Tab.draw(self)
|
||||
UI.Tab.draw(self)
|
||||
end
|
||||
|
||||
function overviewTab:enable()
|
||||
|
||||
@@ -81,6 +81,7 @@ function page:scan()
|
||||
acc[b.key] = entry
|
||||
end
|
||||
throttle()
|
||||
return acc
|
||||
end,
|
||||
{ }))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user