plethora crafter rename to milo - wip
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,121 +0,0 @@
|
|||||||
local itemDB = require('itemDB')
|
|
||||||
local Lora = require('lora')
|
|
||||||
local UI = require('ui')
|
|
||||||
local Util = require('util')
|
|
||||||
|
|
||||||
local colors = _G.colors
|
|
||||||
local device = _G.device
|
|
||||||
|
|
||||||
local itemSlideout = UI.SlideOut {
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
grid = UI.ScrollingGrid {
|
|
||||||
y = 3, ey = -2,
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Name', key = 'displayName', width = 31 },
|
|
||||||
{ heading = 'Qty', key = 'count' , width = 5 },
|
|
||||||
},
|
|
||||||
sortColumn = 'displayName',
|
|
||||||
},
|
|
||||||
filter = UI.TextEntry {
|
|
||||||
x = 2, ex = -2, y = 2,
|
|
||||||
limit = 50,
|
|
||||||
shadowText = 'filter',
|
|
||||||
backgroundColor = colors.lightGray,
|
|
||||||
backgroundFocusColor = colors.lightGray,
|
|
||||||
},
|
|
||||||
button1 = UI.Button {
|
|
||||||
x = -14, y = -1,
|
|
||||||
text = 'Ok', event = 'accept',
|
|
||||||
},
|
|
||||||
button2 = UI.Button {
|
|
||||||
x = -9, y = -1,
|
|
||||||
text = 'Cancel', event = 'collapse',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
function itemSlideout:filterItems(t, filter)
|
|
||||||
if filter then
|
|
||||||
local r = {}
|
|
||||||
filter = filter:lower()
|
|
||||||
for _,v in pairs(t) do
|
|
||||||
if string.find(v.lname, filter) then
|
|
||||||
table.insert(r, v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
function itemSlideout.grid:enable()
|
|
||||||
if not self.allItems then
|
|
||||||
self.allItems = Lora:listItems()
|
|
||||||
Lora:mergeResources(self.allItems)
|
|
||||||
self:setValues(self.allItems)
|
|
||||||
end
|
|
||||||
UI.Grid.enable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function itemSlideout:eventHandler(event)
|
|
||||||
if event.type == 'text_change' and event.element == self.filter then
|
|
||||||
local t = self:filterItems(self.grid.allItems, event.text)
|
|
||||||
self.grid:setValues(t)
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
|
|
||||||
local exportView = UI.Window {
|
|
||||||
mtype = 'machine',
|
|
||||||
title = 'Export item into machine',
|
|
||||||
index = 3,
|
|
||||||
grid = UI.ScrollingGrid {
|
|
||||||
x = 2, ex = -6, y = 2, ey = -2,
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
|
||||||
{ heading = 'Item', key = 'displayName' },
|
|
||||||
},
|
|
||||||
sortColumn = 'slot',
|
|
||||||
},
|
|
||||||
add = UI.Button {
|
|
||||||
x = -4, y = 4,
|
|
||||||
text = '+', event = 'add_export', help = '...',
|
|
||||||
},
|
|
||||||
remove = UI.Button {
|
|
||||||
x = -4, y = 6,
|
|
||||||
text = '-', event = 'remove_export', help = '...',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
function exportView:save(machine)
|
|
||||||
machine.exports = not Util.empty(self.grid.values) and self.grid.values or nil
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function exportView:setMachine(machine)
|
|
||||||
local m = device[machine.name]
|
|
||||||
self.slotCount = m.size()
|
|
||||||
self.grid:setValues(machine.exports or { })
|
|
||||||
end
|
|
||||||
|
|
||||||
function exportView.grid:getDisplayValues(row)
|
|
||||||
row = Util.shallowCopy(row)
|
|
||||||
row.displayName = itemDB:getName(row.name)
|
|
||||||
return row
|
|
||||||
end
|
|
||||||
|
|
||||||
function exportView:eventHandler(event)
|
|
||||||
if event.type == 'grid_select' or event.type == 'add_export' then
|
|
||||||
itemSlideout:show()
|
|
||||||
elseif event.type == 'remove_export' then
|
|
||||||
local row = self.grid:getSelected()
|
|
||||||
if row then
|
|
||||||
Util.removeByValue(self.grid.values, row)
|
|
||||||
self.grid:update()
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
UI:getPage('machineWizard'):add({ items = itemSlideout })
|
|
||||||
UI:getPage('machineWizard').wizard:add({ export = exportView })
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
local Craft = require('turtle.craft')
|
|
||||||
local itemDB = require('itemDB')
|
|
||||||
local Lora = require('lora')
|
|
||||||
local UI = require('ui')
|
|
||||||
local Util = require('util')
|
|
||||||
|
|
||||||
local device = _G.device
|
|
||||||
local turtle = _G.turtle
|
|
||||||
|
|
||||||
local context = Lora:getContext()
|
|
||||||
|
|
||||||
-- TODO: try networked module
|
|
||||||
local introspectionModule = device['plethora:introspection'] or
|
|
||||||
error('Introspection module not found')
|
|
||||||
|
|
||||||
local function getTurtleInventory()
|
|
||||||
local list = { }
|
|
||||||
for i = 1,16 do
|
|
||||||
list[i] = introspectionModule.getInventory().getItemMeta(i)
|
|
||||||
end
|
|
||||||
return list
|
|
||||||
end
|
|
||||||
|
|
||||||
local function learnRecipe()
|
|
||||||
local ingredients = getTurtleInventory()
|
|
||||||
local listingPage = UI:getPage('listing')
|
|
||||||
|
|
||||||
if ingredients then
|
|
||||||
turtle.select(1)
|
|
||||||
if turtle.craft() then
|
|
||||||
local results = getTurtleInventory()
|
|
||||||
if results and results[1] then
|
|
||||||
Lora:clearGrid()
|
|
||||||
|
|
||||||
local maxCount
|
|
||||||
local newRecipe = {
|
|
||||||
ingredients = ingredients,
|
|
||||||
}
|
|
||||||
|
|
||||||
local numResults = 0
|
|
||||||
for _,v in pairs(results) do
|
|
||||||
if v.count > 0 then
|
|
||||||
numResults = numResults + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if numResults > 1 then
|
|
||||||
for _,v1 in pairs(results) do
|
|
||||||
for _,v2 in pairs(ingredients) do
|
|
||||||
if v1.name == v2.name and
|
|
||||||
v1.nbtHash == v2.nbtHash and
|
|
||||||
(v1.damage == v2.damage or
|
|
||||||
(v1.maxDamage > 0 and v2.maxDamage > 0 and
|
|
||||||
v1.damage ~= v2.damage)) then
|
|
||||||
if not newRecipe.crafingTools then
|
|
||||||
newRecipe.craftingTools = { }
|
|
||||||
end
|
|
||||||
local tool = Util.shallowCopy(v2)
|
|
||||||
if tool.maxDamage > 0 then
|
|
||||||
tool.damage = '*'
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Turtles can only craft one item at a time using a tool :(
|
|
||||||
]]--
|
|
||||||
maxCount = 1
|
|
||||||
|
|
||||||
newRecipe.craftingTools[Lora:uniqueKey(tool)] = true
|
|
||||||
v1.craftingTool = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local recipe
|
|
||||||
for _,v in pairs(results) do
|
|
||||||
if not v.craftingTool then
|
|
||||||
recipe = v
|
|
||||||
if maxCount then
|
|
||||||
recipe.maxCount = maxCount
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not recipe then
|
|
||||||
debug(results)
|
|
||||||
debug(newRecipe)
|
|
||||||
error('Failed - view system log')
|
|
||||||
end
|
|
||||||
|
|
||||||
newRecipe.count = recipe.count
|
|
||||||
|
|
||||||
local key = Lora:uniqueKey(recipe)
|
|
||||||
if recipe.maxCount ~= 64 then
|
|
||||||
newRecipe.maxCount = recipe.maxCount
|
|
||||||
end
|
|
||||||
for k,ingredient in pairs(Util.shallowCopy(ingredients)) do
|
|
||||||
if ingredient.maxDamage > 0 then
|
|
||||||
-- ingredient.damage = '*' -- I don't think this is right
|
|
||||||
end
|
|
||||||
ingredients[k] = Lora:uniqueKey(ingredient)
|
|
||||||
end
|
|
||||||
|
|
||||||
context.userRecipes[key] = newRecipe
|
|
||||||
Util.writeTable(Lora.RECIPES_FILE, context.userRecipes)
|
|
||||||
Craft.loadRecipes()
|
|
||||||
|
|
||||||
local displayName = itemDB:getName(recipe)
|
|
||||||
|
|
||||||
listingPage.statusBar.filter:setValue(displayName)
|
|
||||||
listingPage.notification:success('Learned: ' .. displayName)
|
|
||||||
listingPage.filter = displayName
|
|
||||||
listingPage:refresh()
|
|
||||||
listingPage.grid:draw()
|
|
||||||
|
|
||||||
Lora:eject(recipe, recipe.count)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
listingPage.notification:error('Failed to craft', 3)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
listingPage.notification:error('No recipe defined', 3)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local learnPage = UI.Dialog {
|
|
||||||
height = 7, width = UI.term.width - 6,
|
|
||||||
title = 'Learn Recipe',
|
|
||||||
idField = UI.Text {
|
|
||||||
x = 5,
|
|
||||||
y = 3,
|
|
||||||
width = UI.term.width - 10,
|
|
||||||
value = 'Place recipe in turtle'
|
|
||||||
},
|
|
||||||
accept = UI.Button {
|
|
||||||
x = -14, y = -3,
|
|
||||||
text = 'Ok', event = 'accept',
|
|
||||||
},
|
|
||||||
cancel = UI.Button {
|
|
||||||
x = -9, y = -3,
|
|
||||||
text = 'Cancel', event = 'cancel'
|
|
||||||
},
|
|
||||||
statusBar = UI.StatusBar {
|
|
||||||
status = 'Crafting paused'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function learnPage:enable()
|
|
||||||
Lora:pauseCrafting()
|
|
||||||
self:focusFirst()
|
|
||||||
UI.Dialog.enable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function learnPage:disable()
|
|
||||||
Lora:resumeCrafting()
|
|
||||||
UI.Dialog.disable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function learnPage:eventHandler(event)
|
|
||||||
if event.type == 'cancel' then
|
|
||||||
UI:setPreviousPage()
|
|
||||||
elseif event.type == 'accept' then
|
|
||||||
if learnRecipe(self) then
|
|
||||||
UI:setPreviousPage()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return UI.Dialog.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
UI:addPage('learn', learnPage)
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
required = {
|
required = {
|
||||||
'opus-inventory-manager',
|
'opus-develop-1.8',
|
||||||
},
|
},
|
||||||
title = 'Inventory manager for Opus OS',
|
title = 'Inventory manager for Opus OS',
|
||||||
description = [[
|
description = [[
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
via CC cables.
|
via CC cables.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
Configuration file is usr/config/inventoryManager
|
Configuration file is usr/config/milo
|
||||||
|
|
||||||
monitor : valid options include:
|
monitor : valid options include:
|
||||||
type/monitor - will use the first monitor found
|
type/monitor - will use the first monitor found
|
||||||
@@ -66,7 +66,7 @@ _G.requireInjector()
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -78,14 +78,14 @@ local multishell = _ENV.multishell
|
|||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
if multishell then
|
if multishell then
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Resource Manager')
|
multishell.setTitle(multishell.getCurrent(), 'Milo')
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
monitor = 'type/monitor',
|
monitor = 'type/monitor',
|
||||||
remoteDefaults = { },
|
remoteDefaults = { },
|
||||||
}
|
}
|
||||||
Config.load('inventoryManager', config)
|
Config.load('milo', config)
|
||||||
|
|
||||||
local modem = Peripheral.get('wired_modem')
|
local modem = Peripheral.get('wired_modem')
|
||||||
if not modem or not modem.getNameLocal then
|
if not modem or not modem.getNameLocal then
|
||||||
@@ -125,7 +125,7 @@ for _, v in pairs(modem.getNamesRemote()) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function loadResources()
|
local function loadResources()
|
||||||
local resources = Util.readTable(Lora.RESOURCE_FILE) or { }
|
local resources = Util.readTable(Milo.RESOURCE_FILE) or { }
|
||||||
for k,v in pairs(resources) do
|
for k,v in pairs(resources) do
|
||||||
Util.merge(v, itemDB:splitKey(k))
|
Util.merge(v, itemDB:splitKey(k))
|
||||||
end
|
end
|
||||||
@@ -137,10 +137,12 @@ local context = {
|
|||||||
config = config,
|
config = config,
|
||||||
inventoryAdapter = inventoryAdapter,
|
inventoryAdapter = inventoryAdapter,
|
||||||
resources = loadResources(),
|
resources = loadResources(),
|
||||||
userRecipes = Util.readTable(Lora.RECIPES_FILE) or { },
|
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
|
||||||
|
learnTypes = { },
|
||||||
|
machineTypes = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
Lora:init(context)
|
Milo:init(context)
|
||||||
|
|
||||||
local function loadDirectory(dir)
|
local function loadDirectory(dir)
|
||||||
for _, file in pairs(fs.list(dir)) do
|
for _, file in pairs(fs.list(dir)) do
|
||||||
@@ -155,22 +157,24 @@ local programDir = fs.getDir(shell.getRunningProgram())
|
|||||||
loadDirectory(fs.combine(programDir, 'core'))
|
loadDirectory(fs.combine(programDir, 'core'))
|
||||||
loadDirectory(fs.combine(programDir, 'plugins'))
|
loadDirectory(fs.combine(programDir, 'plugins'))
|
||||||
|
|
||||||
table.sort(Lora.tasks, function(a, b)
|
table.sort(Milo.tasks, function(a, b)
|
||||||
return a.priority < b.priority
|
return a.priority < b.priority
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Lora:clearGrid()
|
Milo:clearGrid()
|
||||||
|
|
||||||
local page = UI:getPage('listing')
|
local page = UI:getPage('listing')
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
page:setFocus(page.statusBar.filter)
|
page:setFocus(page.statusBar.filter)
|
||||||
|
|
||||||
|
-- TODO: Event.on('device_detach', function() end)
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
Event.onInterval(5, function()
|
||||||
if not Lora:isCraftingPaused() then
|
if not Milo:isCraftingPaused() then
|
||||||
Lora:resetCraftingStatus()
|
Milo:resetCraftingStatus()
|
||||||
context.inventoryAdapter:refresh()
|
context.inventoryAdapter:refresh()
|
||||||
|
|
||||||
for _, task in ipairs(Lora.tasks) do
|
for _, task in ipairs(Milo.tasks) do
|
||||||
local s, m = pcall(function() task:cycle(context) end)
|
local s, m = pcall(function() task:cycle(context) end)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
Util.print(task)
|
Util.print(task)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local Config = require('config')
|
||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -6,7 +7,7 @@ local os = _G.os
|
|||||||
local term = _G.term
|
local term = _G.term
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local Lora = {
|
local Milo = {
|
||||||
RECIPES_FILE = 'usr/config/recipes.db',
|
RECIPES_FILE = 'usr/config/recipes.db',
|
||||||
RESOURCE_FILE = 'usr/config/resources.db',
|
RESOURCE_FILE = 'usr/config/resources.db',
|
||||||
|
|
||||||
@@ -18,50 +19,67 @@ local Lora = {
|
|||||||
craftingStatus = { },
|
craftingStatus = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function Lora:init(context)
|
function Milo:init(context)
|
||||||
self.context = context
|
self.context = context
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:getContext()
|
function Milo:getContext()
|
||||||
return self.context
|
return self.context
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:pauseCrafting()
|
function Milo:pauseCrafting()
|
||||||
self.craftingPaused = true
|
self.craftingPaused = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:resumeCrafting()
|
function Milo:resumeCrafting()
|
||||||
self.craftingPaused = false
|
self.craftingPaused = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:isCraftingPaused()
|
function Milo:isCraftingPaused()
|
||||||
return self.craftingPaused
|
return self.craftingPaused
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:uniqueKey(item)
|
function Milo:getState(key)
|
||||||
|
if not self.state then
|
||||||
|
self.state = { }
|
||||||
|
Config.load('milo.state', self.state)
|
||||||
|
end
|
||||||
|
return self.state[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
function Milo:setState(key, value)
|
||||||
|
if not self.state then
|
||||||
|
self.state = { }
|
||||||
|
Config.load('milo.state', self.state)
|
||||||
|
end
|
||||||
|
self.state[key] = value
|
||||||
|
Config.update('milo.state', self.state)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Milo:uniqueKey(item)
|
||||||
return table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
return table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:getCraftingStatus()
|
function Milo:getCraftingStatus()
|
||||||
return self.craftingStatus
|
return self.craftingStatus
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:resetCraftingStatus()
|
function Milo:resetCraftingStatus()
|
||||||
self.craftingStatus = { }
|
self.craftingStatus = { }
|
||||||
self.context.inventoryAdapter.activity = { }
|
self.context.inventoryAdapter.activity = { }
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:updateCraftingStatus(list)
|
function Milo:updateCraftingStatus(list)
|
||||||
for k,v in pairs(list) do
|
for k,v in pairs(list) do
|
||||||
self.craftingStatus[k] = v
|
self.craftingStatus[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:registerTask(task)
|
function Milo:registerTask(task)
|
||||||
table.insert(self.tasks, task)
|
table.insert(self.tasks, task)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:showError(msg)
|
function Milo:showError(msg)
|
||||||
term.clear()
|
term.clear()
|
||||||
self.context.jobList:showError()
|
self.context.jobList:showError()
|
||||||
print(msg)
|
print(msg)
|
||||||
@@ -70,7 +88,7 @@ function Lora:showError(msg)
|
|||||||
os.reboot()
|
os.reboot()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
||||||
for _,item in pairs(items) do
|
for _,item in pairs(items) do
|
||||||
if item.name == inItem.name and
|
if item.name == inItem.name and
|
||||||
(ignoreDamage or item.damage == inItem.damage) and
|
(ignoreDamage or item.damage == inItem.damage) and
|
||||||
@@ -80,7 +98,7 @@ function Lora:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:getItemWithQty(res, ignoreDamage, ignoreNbtHash)
|
function Milo:getItemWithQty(res, ignoreDamage, ignoreNbtHash)
|
||||||
local items = self:listItems()
|
local items = self:listItems()
|
||||||
local item = self:getItem(items, res, ignoreDamage, ignoreNbtHash)
|
local item = self:getItem(items, res, ignoreDamage, ignoreNbtHash)
|
||||||
|
|
||||||
@@ -100,7 +118,7 @@ function Lora:getItemWithQty(res, ignoreDamage, ignoreNbtHash)
|
|||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:clearGrid()
|
function Milo:clearGrid()
|
||||||
local function clear()
|
local function clear()
|
||||||
turtle.eachFilledSlot(function(slot)
|
turtle.eachFilledSlot(function(slot)
|
||||||
self.context.inventoryAdapter:insert(slot.index, slot.count, nil, slot)
|
self.context.inventoryAdapter:insert(slot.index, slot.count, nil, slot)
|
||||||
@@ -116,7 +134,7 @@ function Lora:clearGrid()
|
|||||||
return clear() or clear()
|
return clear() or clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:eject(item, qty)
|
function Milo:eject(item, qty)
|
||||||
local s, m = pcall(function()
|
local s, m = pcall(function()
|
||||||
self.context.inventoryAdapter:provide(item, qty)
|
self.context.inventoryAdapter:provide(item, qty)
|
||||||
turtle.emptyInventory()
|
turtle.emptyInventory()
|
||||||
@@ -126,9 +144,9 @@ function Lora:eject(item, qty)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:mergeResources(t)
|
function Milo:mergeResources(t)
|
||||||
for _,v in pairs(self.context.resources) do
|
for _,v in pairs(self.context.resources) do
|
||||||
local item = Lora:getItem(t, v)
|
local item = self:getItem(t, v)
|
||||||
if item then
|
if item then
|
||||||
Util.merge(item, v)
|
Util.merge(item, v)
|
||||||
else
|
else
|
||||||
@@ -140,7 +158,7 @@ function Lora:mergeResources(t)
|
|||||||
|
|
||||||
for k in pairs(Craft.recipes) do
|
for k in pairs(Craft.recipes) do
|
||||||
local v = itemDB:splitKey(k)
|
local v = itemDB:splitKey(k)
|
||||||
local item = Lora:getItem(t, v)
|
local item = self:getItem(t, v)
|
||||||
if not item then
|
if not item then
|
||||||
item = Util.shallowCopy(v)
|
item = Util.shallowCopy(v)
|
||||||
item.count = 0
|
item.count = 0
|
||||||
@@ -157,7 +175,7 @@ function Lora:mergeResources(t)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:saveResources()
|
function Milo:saveResources()
|
||||||
local t = { }
|
local t = { }
|
||||||
|
|
||||||
for k,v in pairs(self.context.resources) do
|
for k,v in pairs(self.context.resources) do
|
||||||
@@ -176,11 +194,11 @@ function Lora:saveResources()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Util.writeTable(Lora.RESOURCE_FILE, t)
|
Util.writeTable(self.RESOURCE_FILE, t)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return a list of everything in the system
|
-- Return a list of everything in the system
|
||||||
function Lora:listItems()
|
function Milo:listItems()
|
||||||
for _ = 1, 5 do
|
for _ = 1, 5 do
|
||||||
self.items = self.context.inventoryAdapter:listItems()
|
self.items = self.context.inventoryAdapter:listItems()
|
||||||
if self.items then
|
if self.items then
|
||||||
@@ -196,7 +214,7 @@ function Lora:listItems()
|
|||||||
return self.items
|
return self.items
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:addCraftingRequest(item, craftList, count)
|
function Milo:addCraftingRequest(item, craftList, count)
|
||||||
local key = self:uniqueKey(item)
|
local key = self:uniqueKey(item)
|
||||||
local request = craftList[key]
|
local request = craftList[key]
|
||||||
if not craftList[key] then
|
if not craftList[key] then
|
||||||
@@ -209,7 +227,7 @@ function Lora:addCraftingRequest(item, craftList, count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Craft
|
-- Craft
|
||||||
function Lora:craftItem(recipe, items, originalItem, craftList, count)
|
function Milo:craftItem(recipe, items, originalItem, craftList, count)
|
||||||
local missing = { }
|
local missing = { }
|
||||||
local toCraft = Craft.getCraftableAmount(recipe, count, items, missing)
|
local toCraft = Craft.getCraftableAmount(recipe, count, items, missing)
|
||||||
if missing.name then
|
if missing.name then
|
||||||
@@ -245,7 +263,7 @@ function Lora:craftItem(recipe, items, originalItem, craftList, count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Craft as much as possible regardless if all ingredients are available
|
-- Craft as much as possible regardless if all ingredients are available
|
||||||
function Lora:forceCraftItem(inRecipe, items, originalItem, craftList, inCount)
|
function Milo:forceCraftItem(inRecipe, items, originalItem, craftList, inCount)
|
||||||
local summed = { }
|
local summed = { }
|
||||||
local throttle = Util.throttle()
|
local throttle = Util.throttle()
|
||||||
|
|
||||||
@@ -326,7 +344,7 @@ function Lora:forceCraftItem(inRecipe, items, originalItem, craftList, inCount)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:craft(recipe, items, item, craftList)
|
function Milo:craft(recipe, items, item, craftList)
|
||||||
item.status = nil
|
item.status = nil
|
||||||
item.statusCode = nil
|
item.statusCode = nil
|
||||||
item.crafted = 0
|
item.crafted = 0
|
||||||
@@ -348,7 +366,7 @@ function Lora:craft(recipe, items, item, craftList)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lora:craftItems(craftList)
|
function Milo:craftItems(craftList)
|
||||||
for _,key in pairs(Util.keys(craftList)) do
|
for _,key in pairs(Util.keys(craftList)) do
|
||||||
local item = craftList[key]
|
local item = craftList[key]
|
||||||
if item.count > 0 then
|
if item.count > 0 then
|
||||||
@@ -367,4 +385,4 @@ function Lora:craftItems(craftList)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Lora
|
return Milo
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Lora = require('lora')
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
|
|
||||||
local context = Lora:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local machinesPage = UI.Page {
|
local machinesPage = UI.Page {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
@@ -57,13 +59,13 @@ end
|
|||||||
local machineWizard = UI.Page {
|
local machineWizard = UI.Page {
|
||||||
titleBar = UI.TitleBar { title = 'Configure' },
|
titleBar = UI.TitleBar { title = 'Configure' },
|
||||||
wizard = UI.Wizard {
|
wizard = UI.Wizard {
|
||||||
y = 2, ey = -3,
|
y = 2, ey = -2,
|
||||||
pages = {
|
pages = {
|
||||||
general = UI.Window {
|
general = UI.Window {
|
||||||
index = 1,
|
index = 1,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
form = UI.Form {
|
form = UI.Form {
|
||||||
x = 1, y = 2, ex = -1, ey = -2,
|
x = 1, y = 1, ex = -1, ey = 3,
|
||||||
manualControls = true,
|
manualControls = true,
|
||||||
[1] = UI.TextEntry {
|
[1] = UI.TextEntry {
|
||||||
formLabel = 'Name', formKey = 'displayName',
|
formLabel = 'Name', formKey = 'displayName',
|
||||||
@@ -84,11 +86,21 @@ local machineWizard = UI.Page {
|
|||||||
help = 'Select type',
|
help = 'Select type',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
y = 5, ey = -2, x = 2, ex = -2,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||||
|
{ heading = 'Name', key = 'displayName', },
|
||||||
|
{ heading = 'Qty', key = 'count' , width = 3 },
|
||||||
|
},
|
||||||
|
sortColumn = 'slot',
|
||||||
|
help = 'Contents of inventory',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
confirmation = UI.Window {
|
confirmation = UI.Window {
|
||||||
title = 'Confirm changes',
|
title = 'Confirm changes',
|
||||||
index = 2,
|
index = 2,
|
||||||
grid = UI.TextArea {
|
notice = UI.TextArea {
|
||||||
x = 2, ex = -2, y = 2, ey = -2,
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
value =
|
value =
|
||||||
[[Press accept to save the changes.
|
[[Press accept to save the changes.
|
||||||
@@ -98,7 +110,9 @@ The settings will take effect immediately!]],
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
statusBar = UI.StatusBar(),
|
statusBar = UI.StatusBar {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
},
|
||||||
notification = UI.Notification { },
|
notification = UI.Notification { },
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +121,25 @@ function machineWizard.wizard.pages.general:enable()
|
|||||||
self:focusFirst()
|
self:focusFirst()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function machineWizard.wizard.pages.general:setMachine(machine)
|
||||||
|
local inventory
|
||||||
|
|
||||||
|
if device[machine.name] and device[machine.name].list then
|
||||||
|
inventory = device[machine.name].list()
|
||||||
|
for k,v in pairs(inventory) do
|
||||||
|
v.slot = k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.grid:setValues(inventory or { })
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineWizard.wizard.pages.general.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.displayName = itemDB:getName(row)
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
function machineWizard.wizard.pages.general:validate()
|
function machineWizard.wizard.pages.general:validate()
|
||||||
return self.form:save()
|
return self.form:save()
|
||||||
end
|
end
|
||||||
@@ -168,7 +201,7 @@ function machineWizard:eventHandler(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
context.config.remoteDefaults[self.machine.name] = self.machine
|
context.config.remoteDefaults[self.machine.name] = self.machine
|
||||||
Config.update('inventoryManagerX', context.config)
|
Config.update('milo', context.config)
|
||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local Autocraft = {
|
local Autocraft = {
|
||||||
@@ -12,13 +12,13 @@ function Autocraft:cycle(context)
|
|||||||
if res.auto then
|
if res.auto then
|
||||||
res = Util.shallowCopy(res)
|
res = Util.shallowCopy(res)
|
||||||
res.count = 256
|
res.count = 256
|
||||||
list[Lora:uniqueKey(res)] = res
|
list[Milo:uniqueKey(res)] = res
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Util.empty(list) then
|
if not Util.empty(list) then
|
||||||
Lora:craftItems(list)
|
Milo:craftItems(list)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(Autocraft)
|
Milo:registerTask(Autocraft)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ function craftPage.wizard:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function craftPage.wizard.pages.resources:enable()
|
function craftPage.wizard.pages.resources:enable()
|
||||||
local items = Lora:listItems()
|
local items = Milo:listItems()
|
||||||
local count = tonumber(self.parent.quantity.count.value)
|
local count = tonumber(self.parent.quantity.count.value)
|
||||||
local recipe = Craft.findRecipe(craftPage.item)
|
local recipe = Craft.findRecipe(craftPage.item)
|
||||||
if recipe then
|
if recipe then
|
||||||
@@ -118,7 +118,7 @@ function craftPage:eventHandler(event)
|
|||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'accept' then
|
elseif event.type == 'accept' then
|
||||||
local key = Lora:uniqueKey(self.item)
|
local key = Milo:uniqueKey(self.item)
|
||||||
demandCrafting[key] = Util.shallowCopy(self.item)
|
demandCrafting[key] = Util.shallowCopy(self.item)
|
||||||
demandCrafting[key].count = tonumber(self.wizard.pages.quantity.count.value)
|
demandCrafting[key].count = tonumber(self.wizard.pages.quantity.count.value)
|
||||||
demandCrafting[key].ocount = demandCrafting[key].count
|
demandCrafting[key].ocount = demandCrafting[key].count
|
||||||
@@ -155,7 +155,7 @@ function demandCraftingTask:cycle(context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Util.size(demandCrafted) > 0 then
|
if Util.size(demandCrafted) > 0 then
|
||||||
Lora:craftItems(demandCrafted)
|
Milo:craftItems(demandCrafted)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,key in pairs(Util.keys(demandCrafting)) do
|
for _,key in pairs(Util.keys(demandCrafting)) do
|
||||||
@@ -166,7 +166,7 @@ function demandCraftingTask:cycle(context)
|
|||||||
item.statusCode = 'success'
|
item.statusCode = 'success'
|
||||||
demandCrafting[key] = nil
|
demandCrafting[key] = nil
|
||||||
if item.eject then
|
if item.eject then
|
||||||
Lora:eject(item, item.ocount)
|
Milo:eject(item, item.ocount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -174,4 +174,4 @@ function demandCraftingTask:cycle(context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
UI:addPage('craft', craftPage)
|
UI:addPage('craft', craftPage)
|
||||||
Lora:registerTask(demandCraftingTask)
|
Milo:registerTask(demandCraftingTask)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
@@ -28,4 +28,4 @@ function ExportTask:cycle(context)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(ExportTask)
|
Milo:registerTask(ExportTask)
|
||||||
213
milo/plugins/exportView.lua
Normal file
213
milo/plugins/exportView.lua
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
|
|
||||||
|
local itemSlideout = UI.SlideOut {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
menuBar = UI.MenuBar {
|
||||||
|
buttons = {
|
||||||
|
{ text = 'Save', event = 'save' },
|
||||||
|
{ text = 'Cancel', event = 'cancel' },
|
||||||
|
{ text = 'Refresh', event = 'refresh', x = -9 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
y = 2, ey = -6,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Name', key = 'displayName', width = 31 },
|
||||||
|
{ heading = 'Qty', key = 'count' , width = 5 },
|
||||||
|
},
|
||||||
|
sortColumn = 'displayName',
|
||||||
|
help = 'Select item to export',
|
||||||
|
},
|
||||||
|
filter = UI.TextEntry {
|
||||||
|
x = 2, ex = 18, y = -3,
|
||||||
|
limit = 50,
|
||||||
|
shadowText = 'filter',
|
||||||
|
backgroundColor = colors.lightGray,
|
||||||
|
backgroundFocusColor = colors.lightGray,
|
||||||
|
},
|
||||||
|
form = UI.Form {
|
||||||
|
x = 21, y = -4, height = 3,
|
||||||
|
margin = 1,
|
||||||
|
manualControls = true,
|
||||||
|
[1] = UI.Chooser {
|
||||||
|
width = 7,
|
||||||
|
formLabel = 'Slot', formKey = 'slot',
|
||||||
|
nochoice = 1,
|
||||||
|
help = 'Export into this slot',
|
||||||
|
},
|
||||||
|
[2] = UI.Chooser {
|
||||||
|
width = 7,
|
||||||
|
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||||
|
pruneEmpty = true,
|
||||||
|
nochoice = 'No',
|
||||||
|
choices = {
|
||||||
|
{ name = 'Yes', value = true },
|
||||||
|
{ name = 'No', value = false },
|
||||||
|
},
|
||||||
|
help = 'Ignore damage of item when exporting'
|
||||||
|
},
|
||||||
|
[3] = UI.Chooser {
|
||||||
|
width = 7,
|
||||||
|
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||||
|
pruneEmpty = true,
|
||||||
|
nochoice = 'No',
|
||||||
|
choices = {
|
||||||
|
{ name = 'Yes', value = true },
|
||||||
|
{ name = 'No', value = false },
|
||||||
|
},
|
||||||
|
help = 'Ignore NBT of item when exporting'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
statusBar = UI.StatusBar {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function itemSlideout:filterItems(t, filter)
|
||||||
|
if filter and #filter > 0 then
|
||||||
|
local r = {}
|
||||||
|
filter = filter:lower()
|
||||||
|
for _,v in pairs(t) do
|
||||||
|
if string.find(v.lname, filter) then
|
||||||
|
table.insert(r, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
function itemSlideout.grid:enable()
|
||||||
|
if not self.allItems then
|
||||||
|
self.allItems = Milo:listItems()
|
||||||
|
Milo:mergeResources(self.allItems)
|
||||||
|
self:setValues(self.allItems)
|
||||||
|
end
|
||||||
|
UI.Grid.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function itemSlideout:show(machine, entry)
|
||||||
|
self.machine = machine
|
||||||
|
self.entry = entry
|
||||||
|
|
||||||
|
self.form.choices = { }
|
||||||
|
local m = device[machine.name]
|
||||||
|
for k = 1, m.size() do
|
||||||
|
table.insert(self.form[1].choices, {
|
||||||
|
name = k,
|
||||||
|
value = k,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if not entry.slot then
|
||||||
|
entry.slot = 1
|
||||||
|
end
|
||||||
|
self.form:setValues(entry)
|
||||||
|
|
||||||
|
UI.SlideOut.show(self)
|
||||||
|
self:setFocus(self.filter)
|
||||||
|
--self.filter:focus()
|
||||||
|
end
|
||||||
|
|
||||||
|
function itemSlideout:eventHandler(event)
|
||||||
|
if event.type == 'text_change' then
|
||||||
|
local t = self:filterItems(self.grid.allItems, event.text)
|
||||||
|
self.grid:setValues(t)
|
||||||
|
self.grid:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'focus_change' then
|
||||||
|
self.statusBar:setStatus(event.focused.help)
|
||||||
|
|
||||||
|
elseif event.type == 'save' then
|
||||||
|
local selected = self.grid:getSelected()
|
||||||
|
if not selected then
|
||||||
|
self.statusBar:setStatus('Select an item to export')
|
||||||
|
else
|
||||||
|
self.form:save()
|
||||||
|
self.form.values.name = itemDB:makeKey(selected)
|
||||||
|
table.insert(self.machine.exports, self.form.values)
|
||||||
|
self:hide()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'cancel' then
|
||||||
|
self:hide()
|
||||||
|
|
||||||
|
elseif event.type == 'refresh' then
|
||||||
|
self.allItems = Milo:listItems()
|
||||||
|
Milo:mergeResources(self.allItems)
|
||||||
|
local t = self:filterItems(self.allItems, self.filter.value)
|
||||||
|
self.grid:setValues(t)
|
||||||
|
self.grid:draw()
|
||||||
|
self.filter:focus()
|
||||||
|
else
|
||||||
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local exportView = UI.Window {
|
||||||
|
mtype = 'machine',
|
||||||
|
title = 'Export item into machine',
|
||||||
|
index = 3,
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
x = 2, ex = -6, y = 2, ey = -2,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||||
|
{ heading = 'Item', key = 'displayName' },
|
||||||
|
},
|
||||||
|
sortColumn = 'slot',
|
||||||
|
},
|
||||||
|
add = UI.Button {
|
||||||
|
x = -4, y = 4,
|
||||||
|
text = '+', event = 'add_export', help = '...',
|
||||||
|
},
|
||||||
|
remove = UI.Button {
|
||||||
|
x = -4, y = 6,
|
||||||
|
text = '-', event = 'remove_export', help = '...',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportView:save(machine)
|
||||||
|
machine.exports = not Util.empty(self.grid.values) and self.grid.values or nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function exportView:setMachine(machine)
|
||||||
|
self.machine = machine
|
||||||
|
if not self.machine.exports then
|
||||||
|
self.machine.exports = { }
|
||||||
|
end
|
||||||
|
self.grid:setValues(machine.exports)
|
||||||
|
end
|
||||||
|
|
||||||
|
function exportView.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.displayName = itemDB:getName(row.name)
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
|
function exportView:eventHandler(event)
|
||||||
|
if event.type == 'grid_select' then
|
||||||
|
itemSlideout:show(self.machine, self.grid:getSelected())
|
||||||
|
|
||||||
|
elseif event.type == 'add_export' then
|
||||||
|
itemSlideout:show(self.machine, { })
|
||||||
|
|
||||||
|
elseif event.type == 'remove_export' then
|
||||||
|
local row = self.grid:getSelected()
|
||||||
|
if row then
|
||||||
|
Util.removeByValue(self.grid.values, row)
|
||||||
|
self.grid:update()
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
UI:getPage('machineWizard'):add({ items = itemSlideout })
|
||||||
|
UI:getPage('machineWizard').wizard:add({ export = exportView })
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ local ImportTask = {
|
|||||||
|
|
||||||
function ImportTask:cycle(context)
|
function ImportTask:cycle(context)
|
||||||
for source, v in pairs(context.config.remoteDefaults) do
|
for source, v in pairs(context.config.remoteDefaults) do
|
||||||
if v.exports then
|
if v.imports then
|
||||||
local machine = device[source]
|
local machine = device[source]
|
||||||
if machine and machine.getItemMeta then
|
if machine and machine.getItemMeta then
|
||||||
for slotNo in pairs(v.imports) do
|
for slotNo in pairs(v.imports) do
|
||||||
@@ -24,4 +24,4 @@ function ImportTask:cycle(context)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(ImportTask)
|
Milo:registerTask(ImportTask)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
@@ -21,4 +21,4 @@ function InputChest:cycle(context)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(InputChest)
|
Milo:registerTask(InputChest)
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
local Ansi = require('ansi')
|
local Ansi = require('ansi')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
local context = Lora:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local itemPage = UI.Page {
|
local itemPage = UI.Page {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
@@ -204,7 +204,7 @@ function itemPage:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'form_complete' then
|
elseif event.type == 'form_complete' then
|
||||||
local values = self.form.values
|
local values = self.form.values
|
||||||
local originalKey = Lora:uniqueKey(self.item)
|
local originalKey = Milo:uniqueKey(self.item)
|
||||||
|
|
||||||
local filtered = Util.shallowCopy(values)
|
local filtered = Util.shallowCopy(values)
|
||||||
filtered.low = tonumber(filtered.low)
|
filtered.low = tonumber(filtered.low)
|
||||||
@@ -232,10 +232,10 @@ function itemPage:eventHandler(event)
|
|||||||
filtered.ignoreNbtHash = nil
|
filtered.ignoreNbtHash = nil
|
||||||
end
|
end
|
||||||
context.resources[originalKey] = nil
|
context.resources[originalKey] = nil
|
||||||
context.resources[Lora:uniqueKey(filtered)] = filtered
|
context.resources[Milo:uniqueKey(filtered)] = filtered
|
||||||
|
|
||||||
filtered.count = nil
|
filtered.count = nil
|
||||||
Lora:saveResources()
|
Milo:saveResources()
|
||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
|
|
||||||
local context = Lora:getContext()
|
local context = Milo:getContext()
|
||||||
local mon = Peripheral.lookup(context.config.monitor) or
|
local mon = Peripheral.lookup(context.config.monitor) or
|
||||||
error('Monitor is not attached')
|
error('Monitor is not attached')
|
||||||
local display = UI.Device {
|
local display = UI.Device {
|
||||||
@@ -39,11 +39,11 @@ function jobList:updateList(craftList)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function jobList.grid:getRowTextColor(row, selected)
|
function jobList.grid:getRowTextColor(row, selected)
|
||||||
if row.statusCode == Lora.STATUS_ERROR then
|
if row.statusCode == Milo.STATUS_ERROR then
|
||||||
return colors.red
|
return colors.red
|
||||||
elseif row.statusCode == Lora.STATUS_WARNING then
|
elseif row.statusCode == Milo.STATUS_WARNING then
|
||||||
return colors.yellow
|
return colors.yellow
|
||||||
elseif row.statusCode == Lora.STATUS_INFO then
|
elseif row.statusCode == Milo.STATUS_INFO then
|
||||||
return colors.lime
|
return colors.lime
|
||||||
end
|
end
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
@@ -58,8 +58,8 @@ local JobListTask = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function JobListTask:cycle()
|
function JobListTask:cycle()
|
||||||
jobList:updateList(Lora:getCraftingStatus())
|
jobList:updateList(Milo:getCraftingStatus())
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(JobListTask)
|
Milo:registerTask(JobListTask)
|
||||||
context.jobList = jobList
|
context.jobList = jobList
|
||||||
61
milo/plugins/learn.lua
Normal file
61
milo/plugins/learn.lua
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local learnPage = UI.Dialog {
|
||||||
|
height = 6, width = UI.term.width - 6,
|
||||||
|
title = 'Learn Recipe',
|
||||||
|
chooser = UI.Chooser {
|
||||||
|
x = 8, y = 3,
|
||||||
|
width = 20,
|
||||||
|
},
|
||||||
|
cancel = UI.Button {
|
||||||
|
x = 3, y = -2,
|
||||||
|
text = 'Cancel', event = 'cancel'
|
||||||
|
},
|
||||||
|
accept = UI.Button {
|
||||||
|
ex = -3, y = -2,
|
||||||
|
width = 8,
|
||||||
|
text = 'Ok', event = 'accept',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function learnPage:enable()
|
||||||
|
self.chooser.choices = { }
|
||||||
|
|
||||||
|
for k in pairs(context.learnTypes) do
|
||||||
|
table.insert(self.chooser.choices, {
|
||||||
|
name = k,
|
||||||
|
value = k,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
self.chooser.value =
|
||||||
|
Milo:getState('learnType') or
|
||||||
|
self.chooser.choices[1].value
|
||||||
|
|
||||||
|
self:focusFirst()
|
||||||
|
UI.Dialog.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function learnPage:disable()
|
||||||
|
UI.Dialog.disable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function learnPage:eventHandler(event)
|
||||||
|
if event.type == 'cancel' then
|
||||||
|
UI:setPreviousPage()
|
||||||
|
|
||||||
|
elseif event.type == 'accept' then
|
||||||
|
local choice = self.chooser.value
|
||||||
|
|
||||||
|
Milo:setState('learnType', choice)
|
||||||
|
UI:setPage(context.learnTypes[choice])
|
||||||
|
|
||||||
|
else
|
||||||
|
return UI.Dialog.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
UI:addPage('learn', learnPage)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
|
|
||||||
local LimitTask = {
|
local LimitTask = {
|
||||||
priority = 10,
|
priority = 10,
|
||||||
@@ -20,7 +20,7 @@ function LimitTask:cycle(context)
|
|||||||
|
|
||||||
for _,res in pairs(context.resources) do
|
for _,res in pairs(context.resources) do
|
||||||
if res.limit then
|
if res.limit then
|
||||||
local item = Lora:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
local item = Milo:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
||||||
if item and item.count > res.limit then
|
if item and item.count > res.limit then
|
||||||
context.inventoryAdapter:provide(
|
context.inventoryAdapter:provide(
|
||||||
{ name = item.name, damage = item.damage, nbtHash = item.nbtHash },
|
{ name = item.name, damage = item.damage, nbtHash = item.nbtHash },
|
||||||
@@ -32,4 +32,4 @@ function LimitTask:cycle(context)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(LimitTask)
|
Milo:registerTask(LimitTask)
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
|
||||||
local context = Lora:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local function queue(fn)
|
local function queue(fn)
|
||||||
while Lora:isCraftingPaused() do
|
while Milo:isCraftingPaused() do
|
||||||
os.sleep(1)
|
os.sleep(1)
|
||||||
end
|
end
|
||||||
fn()
|
fn()
|
||||||
@@ -120,13 +120,13 @@ debug(event)
|
|||||||
elseif event.type == 'eject' then
|
elseif event.type == 'eject' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
queue(function() Lora:eject(item, 1) end)
|
queue(function() Milo:eject(item, 1) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'eject_stack' then
|
elseif event.type == 'eject_stack' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
queue(function() Lora:eject(item, itemDB:getMaxCount(item)) end)
|
queue(function() Milo:eject(item, itemDB:getMaxCount(item)) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'machines' then
|
elseif event.type == 'machines' then
|
||||||
@@ -171,17 +171,17 @@ debug(event)
|
|||||||
elseif event.type == 'forget' then
|
elseif event.type == 'forget' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
local key = Lora:uniqueKey(item)
|
local key = Milo:uniqueKey(item)
|
||||||
|
|
||||||
if context.userRecipes[key] then
|
if context.userRecipes[key] then
|
||||||
context.userRecipes[key] = nil
|
context.userRecipes[key] = nil
|
||||||
Util.writeTable(Lora.RECIPES_FILE, context.userRecipes)
|
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
||||||
Craft.loadRecipes()
|
Craft.loadRecipes()
|
||||||
end
|
end
|
||||||
|
|
||||||
if context.resources[key] then
|
if context.resources[key] then
|
||||||
context.resources[key] = nil
|
context.resources[key] = nil
|
||||||
Lora:saveResources()
|
Milo:saveResources()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.notification:info('Forgot: ' .. item.name)
|
self.notification:info('Forgot: ' .. item.name)
|
||||||
@@ -211,8 +211,8 @@ function listingPage:enable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:refresh()
|
function listingPage:refresh()
|
||||||
self.allItems = Lora:listItems()
|
self.allItems = Milo:listItems()
|
||||||
Lora:mergeResources(self.allItems)
|
Milo:mergeResources(self.allItems)
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
end
|
end
|
||||||
|
|
||||||
172
milo/plugins/machineLearn.lua
Normal file
172
milo/plugins/machineLearn.lua
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
local Craft = require('turtle.craft')
|
||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local MACHINE_LOOKUP = 'usr/config/machine_crafting.db'
|
||||||
|
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local function getTurtleInventory()
|
||||||
|
local introspectionModule = device['plethora:introspection'] or
|
||||||
|
error('Introspection module not found')
|
||||||
|
|
||||||
|
local list = { }
|
||||||
|
for i = 1,16 do
|
||||||
|
list[i] = introspectionModule.getInventory().getItemMeta(i)
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
local machineLearnWizard = UI.Page {
|
||||||
|
titleBar = UI.TitleBar { title = 'Learn a crafting recipe' },
|
||||||
|
wizard = UI.Wizard {
|
||||||
|
y = 2, ey = -2,
|
||||||
|
pages = {
|
||||||
|
machine = UI.Window {
|
||||||
|
index = 1,
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
y = 2, ey = -2,
|
||||||
|
values = context.config.remoteDefaults,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Name', key = 'displayName' },
|
||||||
|
},
|
||||||
|
sortColumn = 'displayName',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
confirmation = UI.Window {
|
||||||
|
index = 2,
|
||||||
|
notice = UI.TextArea {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
|
backgroundColor = colors.black,
|
||||||
|
value =
|
||||||
|
[[Place items in slots according to the machine's inventory.
|
||||||
|
|
||||||
|
Place the result in the last slot of the turtle.
|
||||||
|
|
||||||
|
Example: Slot 1 is the top slot in a furnace.]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notification = UI.Notification { },
|
||||||
|
}
|
||||||
|
|
||||||
|
local pages = machineLearnWizard.wizard.pages
|
||||||
|
local machine
|
||||||
|
|
||||||
|
function pages.machine.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.displayName = row.displayName or row.name
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
|
function pages.machine:validate()
|
||||||
|
|
||||||
|
-- TODO: validation should only be invoked when moving forward (i think)
|
||||||
|
-- TODO: index number validation in wizard
|
||||||
|
|
||||||
|
local selected = self.grid:getSelected()
|
||||||
|
if not selected then
|
||||||
|
machineLearnWizard.notification:error('No machines configured')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
machine = device[selected.name]
|
||||||
|
if not machine then
|
||||||
|
machineLearnWizard.notification:error('Machine not found')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not machine.size then
|
||||||
|
machineLearnWizard.notification:error('Invalid machine')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function pages.confirmation:validate()
|
||||||
|
local inventory = getTurtleInventory()
|
||||||
|
local result = inventory[16]
|
||||||
|
local slotCount = machine.size()
|
||||||
|
|
||||||
|
inventory[16] = nil
|
||||||
|
|
||||||
|
if not result then
|
||||||
|
machineLearnWizard.notification:error('Result must be placed in last slot')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if Util.empty(inventory) then
|
||||||
|
machineLearnWizard.notification:error('Ingredients not present')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for k in pairs(inventory) do
|
||||||
|
if k > slotCount then
|
||||||
|
machineLearnWizard.notification:error(
|
||||||
|
'Slot ' .. k .. ' is not valid\nThe valid slots are 1 - ' .. machine.size())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local recipe = {
|
||||||
|
count = result.count,
|
||||||
|
ingredients = { },
|
||||||
|
maxCount = result.maxCount ~= 64 and result.maxCount or nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k,v in pairs(inventory) do
|
||||||
|
recipe.ingredients[k] = Milo:uniqueKey(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
local key = Milo:uniqueKey(result)
|
||||||
|
|
||||||
|
-- save the recipe
|
||||||
|
context.userRecipes[key] = recipe
|
||||||
|
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
||||||
|
Craft.loadRecipes()
|
||||||
|
|
||||||
|
-- save the machine association
|
||||||
|
Craft.machineLookup[key] = machine.name
|
||||||
|
Util.writeTable(MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
|
|
||||||
|
local listingPage = UI:getPage('listing')
|
||||||
|
local displayName = itemDB:getName(result)
|
||||||
|
|
||||||
|
listingPage.statusBar.filter:setValue(displayName)
|
||||||
|
listingPage.notification:success('Learned: ' .. displayName)
|
||||||
|
listingPage.filter = displayName
|
||||||
|
listingPage:refresh()
|
||||||
|
listingPage.grid:draw()
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineLearnWizard:enable()
|
||||||
|
Milo:pauseCrafting()
|
||||||
|
UI.Page.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineLearnWizard:disable()
|
||||||
|
Milo:resumeCrafting()
|
||||||
|
UI.Page.disable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineLearnWizard:eventHandler(event)
|
||||||
|
if event.type == 'cancel' or event.type == 'accept' then
|
||||||
|
turtle.emptyInventory()
|
||||||
|
UI:setPage('listing')
|
||||||
|
else
|
||||||
|
return UI.Page.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
context.learnTypes['Machine processing'] = machineLearnWizard
|
||||||
24
milo/plugins/potionImportTask.lua
Normal file
24
milo/plugins/potionImportTask.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
local Milo = require('milo')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
|
||||||
|
local PotionImportTask = {
|
||||||
|
priority = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
function PotionImportTask:cycle(context)
|
||||||
|
for _, v in pairs(device) do
|
||||||
|
if v.type == 'minecraft:brewing_stand' and v.getBrewTime() == 0 then
|
||||||
|
local list = v.list()
|
||||||
|
if not list[4] and list[1] then
|
||||||
|
for i = 1, 3 do
|
||||||
|
if list[i] then
|
||||||
|
context.inventoryAdapter:insert(i, 1, nil, list[i], v.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Milo:registerTask(PotionImportTask)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Lora = require('lora')
|
local Milo = require('milo')
|
||||||
|
|
||||||
local ReplenishTask = {
|
local ReplenishTask = {
|
||||||
priority = 30,
|
priority = 30,
|
||||||
@@ -10,7 +10,7 @@ function ReplenishTask:cycle(context)
|
|||||||
|
|
||||||
for _,res in pairs(context.resources) do
|
for _,res in pairs(context.resources) do
|
||||||
if res.low then
|
if res.low then
|
||||||
local item = Lora:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
local item = Milo:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
||||||
if not item then
|
if not item then
|
||||||
item = {
|
item = {
|
||||||
damage = res.damage,
|
damage = res.damage,
|
||||||
@@ -25,7 +25,7 @@ function ReplenishTask:cycle(context)
|
|||||||
if res.ignoreDamage then
|
if res.ignoreDamage then
|
||||||
item.damage = 0
|
item.damage = 0
|
||||||
end
|
end
|
||||||
local key = Lora:uniqueKey(res)
|
local key = Milo:uniqueKey(res)
|
||||||
|
|
||||||
craftList[key] = {
|
craftList[key] = {
|
||||||
damage = item.damage,
|
damage = item.damage,
|
||||||
@@ -40,7 +40,7 @@ function ReplenishTask:cycle(context)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:craftItems(craftList)
|
Milo:craftItems(craftList)
|
||||||
end
|
end
|
||||||
|
|
||||||
Lora:registerTask(ReplenishTask)
|
Milo:registerTask(ReplenishTask)
|
||||||
175
milo/plugins/turtleLearn.lua
Normal file
175
milo/plugins/turtleLearn.lua
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
local Craft = require('turtle.craft')
|
||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local function getTurtleInventory()
|
||||||
|
local introspectionModule = device['plethora:introspection'] or
|
||||||
|
error('Introspection module not found')
|
||||||
|
|
||||||
|
local list = { }
|
||||||
|
for i = 1,16 do
|
||||||
|
list[i] = introspectionModule.getInventory().getItemMeta(i)
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
local function learnRecipe()
|
||||||
|
local ingredients = getTurtleInventory()
|
||||||
|
|
||||||
|
if not ingredients then
|
||||||
|
return false, 'No recipe defined'
|
||||||
|
end
|
||||||
|
|
||||||
|
turtle.select(1)
|
||||||
|
if not turtle.craft() then
|
||||||
|
return false, 'Failed to craft'
|
||||||
|
end
|
||||||
|
|
||||||
|
local results = getTurtleInventory()
|
||||||
|
if not results or not results[1] then
|
||||||
|
return false, 'Failed to craft'
|
||||||
|
end
|
||||||
|
|
||||||
|
local maxCount
|
||||||
|
local newRecipe = {
|
||||||
|
ingredients = ingredients,
|
||||||
|
}
|
||||||
|
|
||||||
|
local numResults = 0
|
||||||
|
for _,v in pairs(results) do
|
||||||
|
if v.count > 0 then
|
||||||
|
numResults = numResults + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if numResults > 1 then
|
||||||
|
for _,v1 in pairs(results) do
|
||||||
|
for _,v2 in pairs(ingredients) do
|
||||||
|
if v1.name == v2.name and
|
||||||
|
v1.nbtHash == v2.nbtHash and
|
||||||
|
(v1.damage == v2.damage or
|
||||||
|
(v1.maxDamage > 0 and v2.maxDamage > 0 and
|
||||||
|
v1.damage ~= v2.damage)) then
|
||||||
|
if not newRecipe.crafingTools then
|
||||||
|
newRecipe.craftingTools = { }
|
||||||
|
end
|
||||||
|
local tool = Util.shallowCopy(v2)
|
||||||
|
if tool.maxDamage > 0 then
|
||||||
|
tool.damage = '*'
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Turtles can only craft one item at a time using a tool :(
|
||||||
|
]]--
|
||||||
|
maxCount = 1
|
||||||
|
|
||||||
|
newRecipe.craftingTools[Milo:uniqueKey(tool)] = true
|
||||||
|
v1.craftingTool = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local recipe
|
||||||
|
for _,v in pairs(results) do
|
||||||
|
if not v.craftingTool then
|
||||||
|
recipe = v
|
||||||
|
if maxCount then
|
||||||
|
recipe.maxCount = maxCount
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not recipe then
|
||||||
|
debug(results)
|
||||||
|
debug(newRecipe)
|
||||||
|
error('Failed - view system log')
|
||||||
|
end
|
||||||
|
|
||||||
|
newRecipe.count = recipe.count
|
||||||
|
|
||||||
|
local key = Milo:uniqueKey(recipe)
|
||||||
|
if recipe.maxCount ~= 64 then
|
||||||
|
newRecipe.maxCount = recipe.maxCount
|
||||||
|
end
|
||||||
|
for k,ingredient in pairs(Util.shallowCopy(ingredients)) do
|
||||||
|
if ingredient.maxDamage > 0 then
|
||||||
|
-- ingredient.damage = '*' -- I don't think this is right
|
||||||
|
end
|
||||||
|
ingredients[k] = Milo:uniqueKey(ingredient)
|
||||||
|
end
|
||||||
|
|
||||||
|
context.userRecipes[key] = newRecipe
|
||||||
|
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
||||||
|
Craft.loadRecipes()
|
||||||
|
|
||||||
|
turtle.emptyInventory()
|
||||||
|
|
||||||
|
return recipe
|
||||||
|
end
|
||||||
|
|
||||||
|
local turtleLearnWizard = UI.Page {
|
||||||
|
titleBar = UI.TitleBar { title = 'Learn a crafting recipe' },
|
||||||
|
wizard = UI.Wizard {
|
||||||
|
y = 2, ey = -3,
|
||||||
|
pages = {
|
||||||
|
confirmation = UI.Window {
|
||||||
|
index = 1,
|
||||||
|
notice = UI.TextArea {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
|
value =
|
||||||
|
[[Place recipe in turtle!]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notification = UI.Notification { },
|
||||||
|
}
|
||||||
|
|
||||||
|
function turtleLearnWizard:enable()
|
||||||
|
Milo:pauseCrafting()
|
||||||
|
UI.Page.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function turtleLearnWizard:disable()
|
||||||
|
Milo:resumeCrafting()
|
||||||
|
UI.Page.disable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function turtleLearnWizard.wizard.pages.confirmation:validate()
|
||||||
|
local recipe, msg = learnRecipe(self)
|
||||||
|
|
||||||
|
if recipe then
|
||||||
|
local listingPage = UI:getPage('listing')
|
||||||
|
local displayName = itemDB:getName(recipe)
|
||||||
|
|
||||||
|
listingPage.statusBar.filter:setValue(displayName)
|
||||||
|
listingPage.notification:success('Learned: ' .. displayName)
|
||||||
|
listingPage.filter = displayName
|
||||||
|
listingPage:refresh()
|
||||||
|
listingPage.grid:draw()
|
||||||
|
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
turtleLearnWizard.notification:error(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function turtleLearnWizard:eventHandler(event)
|
||||||
|
if event.type == 'cancel' or event.type == 'accept' then
|
||||||
|
UI:setPage('listing')
|
||||||
|
else
|
||||||
|
return UI.Page.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
context.learnTypes['Turtle crafting'] = turtleLearnWizard
|
||||||
Reference in New Issue
Block a user