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