util refactor + milo bulk crafting

This commit is contained in:
kepler155c@gmail.com
2019-02-26 09:47:44 -05:00
parent 4303aeb1f8
commit 442f1c4d47
7 changed files with 51 additions and 25 deletions

View File

@@ -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

View File

@@ -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()