util refactor + milo bulk crafting
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user