milo: refactor item page
This commit is contained in:
@@ -85,8 +85,6 @@ local context = {
|
|||||||
context.storage.nodes[localName] = context.turtleInventory
|
context.storage.nodes[localName] = context.turtleInventory
|
||||||
context.storage.nodes[localName].adapter.name = localName
|
context.storage.nodes[localName].adapter.name = localName
|
||||||
|
|
||||||
_G._p = context --debug
|
|
||||||
|
|
||||||
Milo:init(context)
|
Milo:init(context)
|
||||||
context.storage:initStorage()
|
context.storage:initStorage()
|
||||||
|
|
||||||
@@ -135,8 +133,6 @@ Event.on('milo_cycle', function()
|
|||||||
if not s and m then
|
if not s and m then
|
||||||
_G._debug(task.name .. ' crashed')
|
_G._debug(task.name .. ' crashed')
|
||||||
_G._debug(m)
|
_G._debug(m)
|
||||||
-- _G.printError(task.name .. ' crashed')
|
|
||||||
-- _G.printError(m)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
processing = false
|
processing = false
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ local directions = Util.transpose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Event.on('turtle_inventory', function()
|
Event.on('turtle_inventory', function()
|
||||||
print('processing')
|
|
||||||
local s, m = pcall(function()
|
local s, m = pcall(function()
|
||||||
local direction
|
local direction
|
||||||
|
|
||||||
@@ -43,10 +42,11 @@ Event.on('turtle_inventory', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
turtle.eachFilledSlot(function(s)
|
turtle.eachFilledSlot(function(s)
|
||||||
|
print('sending')
|
||||||
enderChest().pullItems(direction, s.index)
|
enderChest().pullItems(direction, s.index)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
if s and not m then
|
if not s and m then
|
||||||
_G.printError(m)
|
_G.printError(m)
|
||||||
end
|
end
|
||||||
print('idle')
|
print('idle')
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ Event.on('turtle_inventory', function()
|
|||||||
if s and not active then
|
if s and not active then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if s and not m then
|
if not s and m then
|
||||||
_G.printError(m)
|
_G.printError(m)
|
||||||
end
|
end
|
||||||
os.sleep(3)
|
os.sleep(3)
|
||||||
|
|||||||
@@ -1,262 +1,52 @@
|
|||||||
local Ansi = require('ansi')
|
|
||||||
local Craft = require('craft2')
|
|
||||||
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 fs = _G.fs
|
||||||
|
local shell = _ENV.shell
|
||||||
|
|
||||||
local context = Milo:getContext()
|
local function loadDirectory(dir)
|
||||||
|
local tabs = { }
|
||||||
|
for _, file in pairs(fs.list(dir)) do
|
||||||
|
if not fs.isDir(fs.combine(dir, file)) then
|
||||||
|
local s, m = Util.run(_ENV, fs.combine(dir, file))
|
||||||
|
if not s and m then
|
||||||
|
_G.printError('Error loading: ' .. file)
|
||||||
|
error(m or 'Unknown error')
|
||||||
|
end
|
||||||
|
table.insert(tabs, m)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tabs
|
||||||
|
end
|
||||||
|
|
||||||
local manageTab = UI.Window {
|
local programDir = fs.getDir(shell.getRunningProgram())
|
||||||
tabTitle = 'Manage',
|
local tabs = loadDirectory(fs.combine(programDir, 'plugins/item'))
|
||||||
form = UI.Form {
|
|
||||||
x = 1, ex = -1, ey = -1,
|
|
||||||
--manualControls = true,
|
|
||||||
[1] = UI.TextEntry {
|
|
||||||
formLabel = 'Name', formKey = 'displayName', help = 'Override display name',
|
|
||||||
shadowText = 'Display name',
|
|
||||||
required = true,
|
|
||||||
limit = 120,
|
|
||||||
},
|
|
||||||
[2] = UI.TextEntry {
|
|
||||||
width = 7,
|
|
||||||
formLabel = 'Min', formKey = 'low', help = 'Craft if below min',
|
|
||||||
validate = 'numeric',
|
|
||||||
},
|
|
||||||
[3] = UI.TextEntry {
|
|
||||||
width = 7,
|
|
||||||
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
|
||||||
validate = 'numeric',
|
|
||||||
},
|
|
||||||
[4] = UI.Checkbox {
|
|
||||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
|
||||||
help = 'Ignore damage of item',
|
|
||||||
},
|
|
||||||
[5] = UI.Checkbox {
|
|
||||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
|
||||||
help = 'Ignore NBT of item',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local machinesTab = UI.Window {
|
table.sort(tabs, function(a, b) return a.index < b.index end)
|
||||||
tabTitle = 'Machine',
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
grid = UI.ScrollingGrid {
|
|
||||||
x = 2, ex = -2, y = 2, ey = -2,
|
|
||||||
disableHeader = true,
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Name', key = 'displayName'},
|
|
||||||
},
|
|
||||||
sortColumn = 'displayName',
|
|
||||||
help = 'Double-click to set machine',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local recipeTab = UI.Window {
|
|
||||||
tabTitle = 'Recipe',
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
grid = UI.ScrollingGrid {
|
|
||||||
x = 2, ex = -2, y = 2, ey = -4,
|
|
||||||
disableHeader = true,
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Slot', key = 'slot', width = 2 },
|
|
||||||
{ heading = 'Key', key = 'key' },
|
|
||||||
},
|
|
||||||
sortColumn = 'slot',
|
|
||||||
},
|
|
||||||
ignoreNBT = UI.Button {
|
|
||||||
x = -13, y = -2,
|
|
||||||
text = 'Ignore NBT', event = 'ignore_nbt',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local infoTab = UI.Window {
|
|
||||||
tabTitle = 'Info',
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
textArea = UI.TextArea {
|
|
||||||
x = 2, ex = -2, y = 2,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local resetTab = UI.Window {
|
|
||||||
tabTitle = 'Reset',
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
textArea = UI.TextArea {
|
|
||||||
y = 2, ey = 6,
|
|
||||||
textColor = colors.yellow,
|
|
||||||
value = [[ Warning!
|
|
||||||
|
|
||||||
This will clear all setting,
|
|
||||||
recipe, and machine for this item.]]
|
|
||||||
},
|
|
||||||
resetButton = UI.Button {
|
|
||||||
x = 17, y = 7,
|
|
||||||
event = 'reset',
|
|
||||||
text = 'Reset',
|
|
||||||
help = 'Clear recipe and all settings',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local page = UI.Page {
|
local page = UI.Page {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
title = 'Item settings',
|
title = 'Item settings',
|
||||||
previousPage = true,
|
previousPage = true,
|
||||||
},
|
},
|
||||||
tabs = UI.Tabs {
|
|
||||||
y = 2, ey = -2,
|
|
||||||
[1] = manageTab,
|
|
||||||
[2] = recipeTab,
|
|
||||||
[3] = machinesTab,
|
|
||||||
[4] = infoTab,
|
|
||||||
[5] = resetTab,
|
|
||||||
},
|
|
||||||
statusBar = UI.StatusBar { },
|
statusBar = UI.StatusBar { },
|
||||||
notification = UI.Notification { },
|
notification = UI.Notification { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function page:enable(item)
|
function page:enable(item)
|
||||||
self.origItem = item
|
for _, v in pairs(tabs) do
|
||||||
self.item = Util.shallowCopy(item)
|
if v.UIElement then
|
||||||
self.res = item.resource or { }
|
v:setItem(item)
|
||||||
self.res.displayName = self.item.displayName
|
end
|
||||||
manageTab.form:setValues(self.res)
|
|
||||||
|
|
||||||
local machine = Craft.machineLookup[self.item.key]
|
|
||||||
if machine then
|
|
||||||
self:filterMachines(machine)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.tabs:selectTab(manageTab)
|
self.tabs:selectTab(self.tabs[1])
|
||||||
|
|
||||||
self.tabs:setActive(machinesTab, machine)
|
|
||||||
self.tabs:setActive(recipeTab, Craft.findRecipe(item))
|
|
||||||
|
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:filterMachines(machine)
|
|
||||||
local t = Util.filter(context.storage.nodes, function(node)
|
|
||||||
if node.category == 'machine' or node.category == 'custom' then -- TODO: - need a setting instead (ie. canCraft)
|
|
||||||
return node.adapter and node.adapter.online and node.adapter.pushItems
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
machinesTab.grid:setValues(t)
|
|
||||||
machinesTab.grid:setSelected('name', machine)
|
|
||||||
end
|
|
||||||
|
|
||||||
function machinesTab.grid:getDisplayValues(row)
|
|
||||||
row = Util.shallowCopy(row)
|
|
||||||
row.displayName = row.displayName or row.name
|
|
||||||
return row
|
|
||||||
end
|
|
||||||
|
|
||||||
function machinesTab.grid:getRowTextColor(row, selected)
|
|
||||||
if row.name == Craft.machineLookup[page.item.key] then
|
|
||||||
return colors.yellow
|
|
||||||
end
|
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
|
||||||
end
|
|
||||||
|
|
||||||
function machinesTab:eventHandler(event)
|
|
||||||
if event.type == 'grid_select' then
|
|
||||||
Craft.machineLookup[page.item.key] = event.selected.name
|
|
||||||
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
|
||||||
|
|
||||||
self.grid:draw()
|
|
||||||
page.notification:info('Machine saved')
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function recipeTab:enable()
|
|
||||||
self.recipe = Craft.findRecipe(page.item)
|
|
||||||
|
|
||||||
local t = { }
|
|
||||||
if self.recipe then
|
|
||||||
for k, v in pairs(self.recipe.ingredients) do
|
|
||||||
table.insert(t, {
|
|
||||||
slot = k,
|
|
||||||
key = v,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.grid:setValues(t)
|
|
||||||
UI.Window.enable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function recipeTab:eventHandler(event)
|
|
||||||
if event.type == 'ignore_nbt' then
|
|
||||||
local selected = self.grid:getSelected()
|
|
||||||
local item = itemDB:splitKey(selected.key)
|
|
||||||
item.nbtHash = nil
|
|
||||||
selected.key = itemDB:makeKey(item)
|
|
||||||
self.grid:draw()
|
|
||||||
|
|
||||||
self.recipe.ingredients = { }
|
|
||||||
for _, v in pairs(self.grid.values) do
|
|
||||||
self.recipe.ingredients[v.slot] = v.key
|
|
||||||
end
|
|
||||||
|
|
||||||
Milo:updateRecipe(self.recipe.result, self.recipe)
|
|
||||||
page.notification:info('Recipe updated')
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function infoTab:draw()
|
|
||||||
local item = page.item
|
|
||||||
local value =
|
|
||||||
string.format('%s%s%s\n%s\n',
|
|
||||||
Ansi.orange, item.displayName, Ansi.reset,
|
|
||||||
item.name)
|
|
||||||
|
|
||||||
if item.nbtHash then
|
|
||||||
value = value .. item.nbtHash .. '\n'
|
|
||||||
end
|
|
||||||
|
|
||||||
value = value .. string.format('\n%sDamage:%s %s',
|
|
||||||
Ansi.yellow, Ansi.reset, item.damage)
|
|
||||||
|
|
||||||
if item.maxDamage and item.maxDamage > 0 then
|
|
||||||
value = value .. string.format(' (max: %s)', item.maxDamage)
|
|
||||||
end
|
|
||||||
|
|
||||||
if item.maxCount then
|
|
||||||
value = value .. string.format('\n%sStack Size: %s%s',
|
|
||||||
Ansi.yellow, Ansi.reset, item.maxCount)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.textArea.value = value
|
|
||||||
UI.Window.draw(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'form_cancel' then
|
if event.type == 'tab_activate' then
|
||||||
UI:setPreviousPage()
|
|
||||||
|
|
||||||
elseif event.type == 'reset' then
|
|
||||||
if context.userRecipes[self.item.key] then
|
|
||||||
Milo:updateRecipe(self.item.key, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
if context.resources[self.item.key] then
|
|
||||||
context.resources[self.item.key] = nil
|
|
||||||
Milo:saveResources()
|
|
||||||
end
|
|
||||||
|
|
||||||
if Craft.machineLookup[self.item.key] then
|
|
||||||
Craft.machineLookup[self.item.key] = nil
|
|
||||||
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
|
||||||
end
|
|
||||||
|
|
||||||
UI:setPreviousPage()
|
|
||||||
|
|
||||||
elseif event.type == 'tab_activate' then
|
|
||||||
event.activated:focusFirst()
|
event.activated:focusFirst()
|
||||||
|
|
||||||
elseif event.type == 'form_invalid' then
|
elseif event.type == 'form_invalid' then
|
||||||
@@ -266,54 +56,25 @@ function page:eventHandler(event)
|
|||||||
self.statusBar:setStatus(event.focused.help)
|
self.statusBar:setStatus(event.focused.help)
|
||||||
self.statusBar:draw()
|
self.statusBar:draw()
|
||||||
|
|
||||||
elseif event.type == 'form_complete' then
|
elseif event.type == 'success_message' then
|
||||||
local item = self.item
|
self.notification:success(event.message)
|
||||||
|
|
||||||
if manageTab.form:save() then
|
elseif event.type == 'info_message' then
|
||||||
if self.res.displayName ~= self.origItem.displayName then
|
self.notification:info(event.message)
|
||||||
self.origItem.displayName = self.res.displayName
|
|
||||||
itemDB:add(self.origItem)
|
|
||||||
itemDB:flush()
|
|
||||||
|
|
||||||
-- TODO: ugh
|
elseif event.type == 'error_message' then
|
||||||
if context.storage.cache[self.origItem.key] then
|
self.notification:error(event.message)
|
||||||
context.storage.cache[self.origItem.key].displayName = self.res.displayName
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.res.displayName = nil
|
|
||||||
Util.prune(self.res, function(v)
|
|
||||||
if type(v) == 'boolean' then
|
|
||||||
return v
|
|
||||||
elseif type(v) == 'string' then
|
|
||||||
return #v > 0
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end)
|
|
||||||
|
|
||||||
local newKey = {
|
|
||||||
name = item.name,
|
|
||||||
damage = self.res.ignoreDamage and 0 or item.damage,
|
|
||||||
nbtHash = not self.res.ignoreNbtHash and item.nbtHash or nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
for k,v in pairs(context.resources) do
|
|
||||||
if v == self.res then
|
|
||||||
context.resources[k] = nil
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not Util.empty(self.res) then
|
|
||||||
context.resources[Milo:uniqueKey(newKey)] = self.res
|
|
||||||
end
|
|
||||||
|
|
||||||
Milo:saveResources()
|
|
||||||
UI:setPreviousPage()
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local t = Util.shallowCopy(tabs)
|
||||||
|
t.y = 2
|
||||||
|
t.ey = -2
|
||||||
|
|
||||||
|
page:add({ tabs = UI.Tabs(t) })
|
||||||
|
|
||||||
UI:addPage('item', page)
|
UI:addPage('item', page)
|
||||||
|
|||||||
46
milo/plugins/item/infoTab.lua
Normal file
46
milo/plugins/item/infoTab.lua
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
local Ansi = require('ansi')
|
||||||
|
local UI = require('ui')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
|
||||||
|
local infoTab = UI.Window {
|
||||||
|
tabTitle = 'Info',
|
||||||
|
index = 4,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
textArea = UI.TextArea {
|
||||||
|
x = 2, ex = -2, y = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function infoTab:setItem(item)
|
||||||
|
self.item = item
|
||||||
|
end
|
||||||
|
|
||||||
|
function infoTab:draw()
|
||||||
|
local item = self.item
|
||||||
|
local value =
|
||||||
|
string.format('%s%s%s\n%s\n',
|
||||||
|
Ansi.orange, item.displayName, Ansi.reset,
|
||||||
|
item.name)
|
||||||
|
|
||||||
|
if item.nbtHash then
|
||||||
|
value = value .. item.nbtHash .. '\n'
|
||||||
|
end
|
||||||
|
|
||||||
|
value = value .. string.format('\n%sDamage:%s %s',
|
||||||
|
Ansi.yellow, Ansi.reset, item.damage)
|
||||||
|
|
||||||
|
if item.maxDamage and item.maxDamage > 0 then
|
||||||
|
value = value .. string.format(' (max: %s)', item.maxDamage)
|
||||||
|
end
|
||||||
|
|
||||||
|
if item.maxCount then
|
||||||
|
value = value .. string.format('\n%sStack Size: %s%s',
|
||||||
|
Ansi.yellow, Ansi.reset, item.maxCount)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.textArea.value = value
|
||||||
|
UI.Window.draw(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
return infoTab
|
||||||
64
milo/plugins/item/machinesTab.lua
Normal file
64
milo/plugins/item/machinesTab.lua
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
local Craft = require('craft2')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local machinesTab = UI.Window {
|
||||||
|
tabTitle = 'Machine',
|
||||||
|
index = 3,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
|
disableHeader = true,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Name', key = 'displayName'},
|
||||||
|
},
|
||||||
|
sortColumn = 'displayName',
|
||||||
|
help = 'Double-click to set machine',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function machinesTab:setItem(item)
|
||||||
|
self.item = item
|
||||||
|
local machine = Craft.machineLookup[self.item.key]
|
||||||
|
if machine then
|
||||||
|
local t = Util.filter(context.storage.nodes, function(node)
|
||||||
|
if node.category == 'machine' or node.category == 'custom' then -- TODO: - need a setting instead (ie. canCraft)
|
||||||
|
return node.adapter and node.adapter.online and node.adapter.pushItems
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
self.grid:setValues(t)
|
||||||
|
self.grid:setSelected('name', machine)
|
||||||
|
end
|
||||||
|
self.parent:setActive(self, machine)
|
||||||
|
end
|
||||||
|
|
||||||
|
function machinesTab.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.displayName = row.displayName or row.name
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
|
function machinesTab.grid:getRowTextColor(row, selected)
|
||||||
|
if row.name == Craft.machineLookup[self.parent.item.key] then
|
||||||
|
return colors.yellow
|
||||||
|
end
|
||||||
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
|
end
|
||||||
|
|
||||||
|
function machinesTab:eventHandler(event)
|
||||||
|
if event.type == 'grid_select' then
|
||||||
|
Craft.machineLookup[self.item.key] = event.selected.name
|
||||||
|
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
|
|
||||||
|
self.grid:draw()
|
||||||
|
self:emit({ type = 'info_message', message = 'Machine saved' })
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return machinesTab
|
||||||
103
milo/plugins/item/manageTab.lua
Normal file
103
milo/plugins/item/manageTab.lua
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local manageTab = UI.Window {
|
||||||
|
tabTitle = 'Manage',
|
||||||
|
index = 1,
|
||||||
|
form = UI.Form {
|
||||||
|
x = 1, ex = -1, ey = -1,
|
||||||
|
--manualControls = true,
|
||||||
|
[1] = UI.TextEntry {
|
||||||
|
formLabel = 'Name', formKey = 'displayName', help = 'Override display name',
|
||||||
|
shadowText = 'Display name',
|
||||||
|
required = true,
|
||||||
|
limit = 120,
|
||||||
|
},
|
||||||
|
[2] = UI.TextEntry {
|
||||||
|
width = 7,
|
||||||
|
formLabel = 'Min', formKey = 'low', help = 'Craft if below min',
|
||||||
|
validate = 'numeric',
|
||||||
|
},
|
||||||
|
[3] = UI.TextEntry {
|
||||||
|
width = 7,
|
||||||
|
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
||||||
|
validate = 'numeric',
|
||||||
|
},
|
||||||
|
[4] = UI.Checkbox {
|
||||||
|
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||||
|
help = 'Ignore damage of item',
|
||||||
|
},
|
||||||
|
[5] = UI.Checkbox {
|
||||||
|
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||||
|
help = 'Ignore NBT of item',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function manageTab:setItem(item)
|
||||||
|
self.origItem = item
|
||||||
|
self.item = Util.shallowCopy(item)
|
||||||
|
self.res = item.resource or { }
|
||||||
|
self.res.displayName = self.item.displayName
|
||||||
|
manageTab.form:setValues(self.res)
|
||||||
|
end
|
||||||
|
|
||||||
|
function manageTab:eventHandler(event)
|
||||||
|
if event.type == 'form_cancel' then
|
||||||
|
UI:setPreviousPage()
|
||||||
|
|
||||||
|
elseif event.type == 'form_complete' then
|
||||||
|
local item = self.item
|
||||||
|
|
||||||
|
if self.form:save() then
|
||||||
|
if self.res.displayName ~= self.origItem.displayName then
|
||||||
|
self.origItem.displayName = self.res.displayName
|
||||||
|
itemDB:add(self.origItem)
|
||||||
|
itemDB:flush()
|
||||||
|
|
||||||
|
-- TODO: ugh
|
||||||
|
if context.storage.cache[self.origItem.key] then
|
||||||
|
context.storage.cache[self.origItem.key].displayName = self.res.displayName
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.res.displayName = nil
|
||||||
|
Util.prune(self.res, function(v)
|
||||||
|
if type(v) == 'boolean' then
|
||||||
|
return v
|
||||||
|
elseif type(v) == 'string' then
|
||||||
|
return #v > 0
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end)
|
||||||
|
|
||||||
|
local newKey = {
|
||||||
|
name = item.name,
|
||||||
|
damage = self.res.ignoreDamage and 0 or item.damage,
|
||||||
|
nbtHash = not self.res.ignoreNbtHash and item.nbtHash or nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k,v in pairs(context.resources) do
|
||||||
|
if v == self.res then
|
||||||
|
context.resources[k] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not Util.empty(self.res) then
|
||||||
|
context.resources[Milo:uniqueKey(newKey)] = self.res
|
||||||
|
end
|
||||||
|
|
||||||
|
Milo:saveResources()
|
||||||
|
UI:setPreviousPage()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return manageTab
|
||||||
65
milo/plugins/item/recipeTab.lua
Normal file
65
milo/plugins/item/recipeTab.lua
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
local Craft = require('craft2')
|
||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
|
||||||
|
local recipeTab = UI.Window {
|
||||||
|
tabTitle = 'Recipe',
|
||||||
|
index = 2,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -4,
|
||||||
|
disableHeader = true,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Slot', key = 'slot', width = 2 },
|
||||||
|
{ heading = 'Key', key = 'key' },
|
||||||
|
},
|
||||||
|
sortColumn = 'slot',
|
||||||
|
},
|
||||||
|
ignoreNBT = UI.Button {
|
||||||
|
x = -13, y = -2,
|
||||||
|
text = 'Ignore NBT', event = 'ignore_nbt',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function recipeTab:setItem(item)
|
||||||
|
self.item = item
|
||||||
|
self.recipe = Craft.findRecipe(self.item)
|
||||||
|
|
||||||
|
self.parent:setActive(self, self.recipe)
|
||||||
|
|
||||||
|
local t = { }
|
||||||
|
if self.recipe then
|
||||||
|
for k, v in pairs(self.recipe.ingredients) do
|
||||||
|
table.insert(t, {
|
||||||
|
slot = k,
|
||||||
|
key = v,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.grid:setValues(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
function recipeTab:eventHandler(event)
|
||||||
|
if event.type == 'ignore_nbt' then
|
||||||
|
local selected = self.grid:getSelected()
|
||||||
|
local item = itemDB:splitKey(selected.key)
|
||||||
|
item.nbtHash = nil
|
||||||
|
selected.key = itemDB:makeKey(item)
|
||||||
|
self.grid:draw()
|
||||||
|
|
||||||
|
self.recipe.ingredients = { }
|
||||||
|
for _, v in pairs(self.grid.values) do
|
||||||
|
self.recipe.ingredients[v.slot] = v.key
|
||||||
|
end
|
||||||
|
|
||||||
|
Milo:updateRecipe(self.recipe.result, self.recipe)
|
||||||
|
self:emit({ type = 'info_message', message = 'Recipe updated' })
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return recipeTab
|
||||||
55
milo/plugins/item/resetTab.lua
Normal file
55
milo/plugins/item/resetTab.lua
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
local Craft = require('craft2')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
local resetTab = UI.Window {
|
||||||
|
tabTitle = 'Reset',
|
||||||
|
index = 5,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
textArea = UI.TextArea {
|
||||||
|
y = 2, ey = 6,
|
||||||
|
textColor = colors.yellow,
|
||||||
|
value = [[ Warning!
|
||||||
|
|
||||||
|
This will clear all setting,
|
||||||
|
recipe, and machine for this item.]]
|
||||||
|
},
|
||||||
|
resetButton = UI.Button {
|
||||||
|
x = 17, y = 7,
|
||||||
|
event = 'reset',
|
||||||
|
text = 'Reset',
|
||||||
|
help = 'Clear recipe and all settings',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetTab:setItem(item)
|
||||||
|
self.item = item
|
||||||
|
end
|
||||||
|
|
||||||
|
function resetTab:eventHandler(event)
|
||||||
|
if event.type == 'reset' then
|
||||||
|
if context.userRecipes[self.item.key] then
|
||||||
|
Milo:updateRecipe(self.item.key, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
if context.resources[self.item.key] then
|
||||||
|
context.resources[self.item.key] = nil
|
||||||
|
Milo:saveResources()
|
||||||
|
end
|
||||||
|
|
||||||
|
if Craft.machineLookup[self.item.key] then
|
||||||
|
Craft.machineLookup[self.item.key] = nil
|
||||||
|
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
|
end
|
||||||
|
|
||||||
|
UI:setPreviousPage()
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return resetTab
|
||||||
Reference in New Issue
Block a user