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