fix Script bug + crafter
This commit is contained in:
@@ -126,22 +126,9 @@ end
|
||||
function ChestAdapter:craftItems()
|
||||
end
|
||||
|
||||
local function rpairs(t)
|
||||
local tkeys = Util.keys(t)
|
||||
local i = #tkeys
|
||||
return function()
|
||||
local key = tkeys[i]
|
||||
local k,v = key, t[key]
|
||||
i = i - 1
|
||||
if v then
|
||||
return k, v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChestAdapter:provide(item, qty, slot, direction)
|
||||
local stacks = self.list()
|
||||
for key,stack in rpairs(stacks) do
|
||||
for key,stack in Util.rpairs(stacks) do
|
||||
if stack.name == item.name and stack.damage == item.damage then
|
||||
local amount = math.min(qty, stack.count)
|
||||
if amount > 0 then
|
||||
|
||||
@@ -308,7 +308,6 @@ function editorPage:enable()
|
||||
end
|
||||
|
||||
function editorPage.grid2:draw()
|
||||
|
||||
getActiveComputers(self.values)
|
||||
|
||||
for k in pairs(editorPage.grid1.values) do
|
||||
@@ -320,7 +319,6 @@ function editorPage.grid2:draw()
|
||||
end
|
||||
|
||||
function editorPage:eventHandler(event)
|
||||
|
||||
if event.type == 'back' then
|
||||
UI:setPage(groupsPage)
|
||||
|
||||
@@ -347,18 +345,17 @@ function editorPage:eventHandler(event)
|
||||
end
|
||||
|
||||
local function nameDialog(f)
|
||||
local dialog = UI.Dialog({
|
||||
-- x = (UI.term.width - 28) / 2,
|
||||
local dialog = UI.Dialog {
|
||||
width = 22,
|
||||
height = 6,
|
||||
title = 'Enter Name',
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2,
|
||||
textEntry = UI.TextEntry({ y = 2, width = 20, limit = 20 })
|
||||
textEntry = UI.TextEntry { y = 2, width = 20, limit = 20 },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
dialog.eventHandler = function(self, event)
|
||||
function dialog:eventHandler(event)
|
||||
if event.type == 'form_complete' then
|
||||
local name = self.form.textEntry.value
|
||||
if name then
|
||||
|
||||
@@ -24,6 +24,7 @@ local recipes = Util.readTable(RECIPES_FILE) or { }
|
||||
local resources
|
||||
local machines = { }
|
||||
local jobListGrid
|
||||
local lastItems
|
||||
|
||||
local function getItem(items, inItem, ignoreDamage)
|
||||
for _,item in pairs(items) do
|
||||
@@ -162,17 +163,17 @@ local function craftItem(recipe, items, cItem, count)
|
||||
end
|
||||
end
|
||||
|
||||
local function craftItems(craftList, items)
|
||||
local function craftItems(craftList)
|
||||
for key, item in pairs(craftList) do
|
||||
local recipe = recipes[key]
|
||||
if recipe then
|
||||
craftItem(recipe, items, item, item.count)
|
||||
craftItem(recipe, lastItems, item, item.count)
|
||||
repeat until not turtle.forward()
|
||||
jobListGrid:update()
|
||||
jobListGrid:draw()
|
||||
jobListGrid:sync()
|
||||
clearGrid()
|
||||
items = inventoryAdapter:listItems() -- refresh counts
|
||||
lastItems = inventoryAdapter:listItems() -- refresh counts
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -450,7 +451,7 @@ local learnPage = UI.Page {
|
||||
|
||||
function learnPage:enable(target)
|
||||
self.target = target
|
||||
self.allItems = inventoryAdapter:listItems()
|
||||
self.allItems = lastItems
|
||||
mergeResources(self.allItems)
|
||||
|
||||
local screen1 = self.wizard.screen1
|
||||
@@ -466,11 +467,7 @@ function learnPage:enable(target)
|
||||
if target.has_recipe then
|
||||
local recipe = recipes[uniqueKey(target)]
|
||||
screen2.count.value = recipe.count
|
||||
if type(recipe.machine) == 'number' then
|
||||
screen2.machine:setIndex(select(2, Util.find(machines, 'index', recipe.machine)))
|
||||
else
|
||||
screen2.machine:setIndex(select(2, Util.find(machines, 'name', recipe.machine)))
|
||||
end
|
||||
screen2.machine:setIndex(select(2, Util.find(machines, 'index', recipe.machine)))
|
||||
for k,v in pairs(recipe.ingredients) do
|
||||
screen1.ingredients.values[k] =
|
||||
{ name = k, count = v, displayName = itemDB:getName(k) }
|
||||
@@ -573,7 +570,7 @@ local listingPage = UI.Page {
|
||||
grid = UI.Grid {
|
||||
y = 2, height = UI.term.height - 2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' , width = 22 },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Qty', key = 'count' , width = 5 },
|
||||
{ heading = 'Min', key = 'low' , width = 4 },
|
||||
},
|
||||
@@ -691,7 +688,7 @@ function listingPage:enable()
|
||||
end
|
||||
|
||||
function listingPage:refresh()
|
||||
self.allItems = inventoryAdapter:listItems()
|
||||
self.allItems = lastItems
|
||||
mergeResources(self.allItems)
|
||||
self:applyFilter()
|
||||
end
|
||||
@@ -702,6 +699,11 @@ function listingPage:applyFilter()
|
||||
end
|
||||
|
||||
loadResources()
|
||||
findMachines()
|
||||
repeat until not turtle.forward()
|
||||
clearGrid()
|
||||
jobMonitor()
|
||||
lastItems = inventoryAdapter:listItems()
|
||||
|
||||
UI:setPages({
|
||||
listing = listingPage,
|
||||
@@ -712,11 +714,6 @@ UI:setPages({
|
||||
UI:setPage(listingPage)
|
||||
listingPage:setFocus(listingPage.statusBar.filter)
|
||||
|
||||
findMachines()
|
||||
repeat until not turtle.forward()
|
||||
clearGrid()
|
||||
jobMonitor()
|
||||
|
||||
Event.on('turtle_abort', function()
|
||||
UI:exitPullEvents()
|
||||
end)
|
||||
@@ -728,15 +725,16 @@ Event.onInterval(30, function()
|
||||
inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1)
|
||||
turtle.refuel()
|
||||
end
|
||||
local items = inventoryAdapter:listItems()
|
||||
local craftList = watchResources(items)
|
||||
lastItems = inventoryAdapter:listItems()
|
||||
local craftList = watchResources(lastItems)
|
||||
|
||||
jobListGrid:setValues(craftList)
|
||||
jobListGrid:update()
|
||||
jobListGrid:draw()
|
||||
jobListGrid:sync()
|
||||
|
||||
craftItems(craftList, items)
|
||||
craftItems(craftList)
|
||||
end)
|
||||
|
||||
UI:pullEvents()
|
||||
jobListGrid.parent:reset()
|
||||
|
||||
Reference in New Issue
Block a user