milo cleanup

This commit is contained in:
kepler155c
2018-11-11 14:45:39 -05:00
parent a00a66f4e6
commit fe1fc6ea93
13 changed files with 200 additions and 200 deletions

View File

@@ -39,10 +39,16 @@ end
local config = { local config = {
monitor = 'type/monitor', monitor = 'type/monitor',
activityMonitor = 'none', activityMonitor = 'none',
remoteDefaults = { }, nodes = { },
} }
Config.load('milo', config) Config.load('milo', config)
-- TODO: remove - temporary
if config.remoteDefaults then
config.nodes = config.remoteDefaults
config.remoteDefaults = nil
end
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
error('Wired modem is not connected') error('Wired modem is not connected')

View File

@@ -1,62 +0,0 @@
_G.requireInjector(_ENV)
local Util = require('util')
local colors = _G.colors
local device = _G.device
local args = { ... }
local mon = device[args[1] or 'monitor'] or error('Syntax: MiloMonitor <monitor>')
local config = Util.readTable('/usr/config/milo') or error('Milo is not configured')
local row
local monWidth, monHeight = mon.getSize()
local machines = { }
local function write(x, y, s, bg, fg)
mon.setCursorPos(x, y)
mon.setBackgroundColor(bg)
if fg then
mon.setTextColor(fg)
end
mon.write(s)
end
local function progress(y, percent)
local width = math.ceil(percent / 100 * monWidth)
write(2, y, string.rep(' ', monWidth - 2), colors.gray)
write(2, y, string.rep(' ', width), colors.lime)
end
local function draw(machine, percent)
write(2, row, machine.displayName or machine.name, colors.black, colors.yellow)
progress(row + 1, percent)
row = row + 3
end
local function redraw()
row = 1
mon.setBackgroundColor(colors.black)
mon.clear()
for _,machine in ipairs(machines) do
local dev = device[machine.name]
if dev then
local percent = 50
if machine.mtype == 'storage' then
percent = Util.size(dev.list()) / dev.size() * 100
end
draw(machine, percent)
end
end
end
for _, v in pairs(config.remoteDefaults) do
table.insert(machines, v)
end
table.sort(machines, function(a, b)
return (a.displayName or a.name) < (b.displayName or b.name)
end)
mon.setTextScale(.5)
redraw()

View File

@@ -12,7 +12,7 @@ local Storage = class()
function Storage:init(args) function Storage:init(args)
local defaults = { local defaults = {
remoteDefaults = { }, nodes = { },
dirty = true, dirty = true,
activity = { }, activity = { },
storageOnline = true, storageOnline = true,
@@ -35,9 +35,9 @@ end
function Storage:showStorage() function Storage:showStorage()
local t = { } local t = { }
for k,v in pairs(self.remoteDefaults) do for k,v in pairs(self.nodes) do
local online = v.adapter and v.adapter.online local online = v.adapter and v.adapter.online
if not online then if not online and v.mtype ~= 'ignore' then
table.insert(t, k) table.insert(t, k)
end end
end end
@@ -58,7 +58,7 @@ function Storage:initStorage()
local online = true local online = true
_G._debug('Initializing storage') _G._debug('Initializing storage')
for k,v in pairs(self.remoteDefaults) do for k,v in pairs(self.nodes) do
if v.adapter then if v.adapter then
v.adapter.online = not not device[k] v.adapter.online = not not device[k]
elseif device[k] and device[k].list and device[k].size and device[k].pullItems then elseif device[k] and device[k].list and device[k].size and device[k].pullItems then
@@ -80,7 +80,7 @@ end
function Storage:filterActive(mtype, filter) function Storage:filterActive(mtype, filter)
local iter = { } local iter = { }
for _, v in pairs(self.remoteDefaults) do for _, v in pairs(self.nodes) do
if v.adapter and v.adapter.online and v.mtype == mtype then if v.adapter and v.adapter.online and v.mtype == mtype then
if not filter or filter(v) then if not filter or filter(v) then
table.insert(iter, v) table.insert(iter, v)
@@ -97,7 +97,7 @@ end
function Storage:onlineAdapters(reversed) function Storage:onlineAdapters(reversed)
local iter = { } local iter = { }
for _, v in pairs(self.remoteDefaults) do for _, v in pairs(self.nodes) do
if v.adapter and v.adapter.online and v.mtype == 'storage' then if v.adapter and v.adapter.online and v.mtype == 'storage' then
table.insert(iter, v) table.insert(iter, v)
end end
@@ -191,7 +191,8 @@ function Storage:updateCache(adapter, key, count)
adapter.dirty = true adapter.dirty = true
self.dirty = true self.dirty = true
else else
entry = Util.shallowCopy(itemDB:get(key)) local item = itemDB:get(key) or itemDB:splitKey(key)
entry = Util.shallowCopy(item)
entry.count = count entry.count = count
entry.key = key entry.key = key
adapter.cache[key] = entry adapter.cache[key] = entry
@@ -311,7 +312,7 @@ end
-- When importing items into a locked chest, trash any remaining items if full -- When importing items into a locked chest, trash any remaining items if full
function Storage:trash(source, slot, count) function Storage:trash(source, slot, count)
local trashcan = Util.find(self.remoteDefaults, 'mtype', 'trashcan') local trashcan = Util.find(self.nodes, 'mtype', 'trashcan')
if trashcan and trashcan.adapter and trashcan.adapter.online then if trashcan and trashcan.adapter and trashcan.adapter.online then
_G._debug('TRA: %s[%d] (%d)', source or self.localName, slot, count or 64) _G._debug('TRA: %s[%d] (%d)', source or self.localName, slot, count or 64)

View File

@@ -14,7 +14,7 @@ local context = Milo:getContext()
local function saveConfig() local function saveConfig()
local t = { } local t = { }
for k,v in pairs(context.config.remoteDefaults) do for k,v in pairs(context.config.nodes) do
t[k] = v.adapter t[k] = v.adapter
v.adapter = nil v.adapter = nil
end end
@@ -22,19 +22,29 @@ local function saveConfig()
Config.update('milo', context.config) Config.update('milo', context.config)
for k,v in pairs(t) do for k,v in pairs(t) do
context.config.remoteDefaults[k].adapter = v context.config.nodes[k].adapter = v
end end
context.storage:initStorage() context.storage:initStorage()
end end
local machinesPage = UI.Page { local networkPage = UI.Page {
titleBar = UI.TitleBar { titleBar = UI.TitleBar {
previousPage = true, previousPage = true,
title = 'Machines', title = 'Network',
},
filter = UI.TextEntry {
y = -2, x = 1, ex = -9,
limit = 50,
shadowText = 'filter',
backgroundColor = colors.cyan,
backgroundFocusColor = colors.cyan,
accelerators = {
[ 'enter' ] = 'eject',
},
}, },
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 2, ey = -2, y = 2, ey = -3,
values = context.config.remoteDefaults, values = context.config.nodes,
columns = { columns = {
{ key = 'suffix', width = 4, justify = 'right' }, { key = 'suffix', width = 4, justify = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
@@ -42,23 +52,25 @@ local machinesPage = UI.Page {
{ heading = 'Pri', key = 'priority', width = 3 }, { heading = 'Pri', key = 'priority', width = 3 },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
help = 'Select Machine', help = 'Select Node',
}, },
remove = UI.Button { remove = UI.Button {
y = -1, x = -4, y = -2, x = -4,
text = '-', event = 'remove_machine', text = '-', event = 'remove_node',
help = 'Remove Machine', help = 'Remove Node',
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
ex = -7, backgroundColor = colors.lightGray,
backgroundColor = colors.cyan,
}, },
notification = UI.Notification { }, notification = UI.Notification { },
} }
function machinesPage.grid:getDisplayValues(row) function networkPage.grid:getDisplayValues(row)
row = Util.shallowCopy(row) row = Util.shallowCopy(row)
local t = { row.name:match(':(.+)_(%d+)$') } local t = { row.name:match(':(.+)_(%d+)$') }
if #t ~= 2 then
t = { row.name:match('(.+)_(%d+)$') }
end
if t and #t == 2 then if t and #t == 2 then
row.name, row.suffix = table.unpack(t) row.name, row.suffix = table.unpack(t)
row.name = row.name .. '_' .. row.suffix row.name = row.name .. '_' .. row.suffix
@@ -67,7 +79,7 @@ function machinesPage.grid:getDisplayValues(row)
return row return row
end end
function machinesPage.grid:getRowTextColor(row, selected) function networkPage.grid:getRowTextColor(row, selected)
if not device[row.name] then if not device[row.name] then
return colors.red return colors.red
end end
@@ -77,11 +89,11 @@ function machinesPage.grid:getRowTextColor(row, selected)
return UI.Grid:getRowTextColor(row, selected) return UI.Grid:getRowTextColor(row, selected)
end end
function machinesPage:getList() function networkPage:getList()
for _, v in pairs(device) do for _, v in pairs(device) do
if v.pullItems then if v.pullItems then
if not context.config.remoteDefaults[v.name] then if not context.config.nodes[v.name] then
context.config.remoteDefaults[v.name] = { context.config.nodes[v.name] = {
name = v.name, name = v.name,
mtype = 'ignore', mtype = 'ignore',
} }
@@ -90,9 +102,10 @@ function machinesPage:getList()
end end
end end
function machinesPage:enable() function networkPage:enable()
self:getList() self:getList()
self.grid:update() self.grid:update()
self:setFocus(self.filter)
UI.Page.enable(self) UI.Page.enable(self)
self.handler = Event.on({ 'device_attach', 'device_detach'}, function() self.handler = Event.on({ 'device_attach', 'device_detach'}, function()
self:getList() self:getList()
@@ -102,28 +115,50 @@ function machinesPage:enable()
end) end)
end end
function machinesPage:disable() function networkPage:disable()
UI.Page.disable(self) UI.Page.disable(self)
Event.off(self.handler) Event.off(self.handler)
end end
function machinesPage:eventHandler(event) function networkPage:applyFilter()
local t = context.config.nodes
local filter = self.filter.value
if #filter > 0 then
t = { }
filter = filter:lower()
for _,v in pairs(context.config.nodes) do
if (v.displayName and string.find(string.lower(v.displayName), filter, 1, true)) or
string.find(string.lower(v.name), filter, 1, true) then
table.insert(t, v)
end
end
end
self.grid:setValues(t)
end
function networkPage:eventHandler(event)
if event.type == 'grid_select' then if event.type == 'grid_select' then
if not device[event.selected.name] then if not device[event.selected.name] then
self.notification:error('Unable to edit while disconnected') self.notification:error('Unable to edit while disconnected')
else else
UI:setPage('machineWizard', event.selected) UI:setPage('nodeWizard', event.selected)
end end
elseif event.type == 'remove_machine' then elseif event.type == 'remove_node' then
local machine = self.grid:getSelected() local node = self.grid:getSelected()
if machine then if node then
context.config.remoteDefaults[machine.name] = nil context.config.nodes[node.name] = nil
saveConfig() saveConfig()
end end
self.grid:update() self.grid:update()
self.grid:draw() self.grid:draw()
elseif event.type == 'text_change' then
self:applyFilter()
self.grid:draw()
elseif event.type == 'focus_change' then elseif event.type == 'focus_change' then
self.statusBar:setStatus(event.focused.help) self.statusBar:setStatus(event.focused.help)
@@ -133,7 +168,7 @@ function machinesPage:eventHandler(event)
return true return true
end end
local machineWizard = UI.Page { local nodeWizard = UI.Page {
titleBar = UI.TitleBar { title = 'Configure' }, titleBar = UI.TitleBar { title = 'Configure' },
wizard = UI.Wizard { wizard = UI.Wizard {
y = 2, ey = -2, y = 2, ey = -2,
@@ -260,7 +295,7 @@ The settings will take effect immediately!]],
} }
--[[ Filter slide out ]] -- --[[ Filter slide out ]] --
function machineWizard.filter:show(entry, callback, whitelistOnly) function nodeWizard.filter:show(entry, callback, whitelistOnly)
self.entry = entry self.entry = entry
self.callback = callback self.callback = callback
@@ -280,13 +315,13 @@ function machineWizard.filter:show(entry, callback, whitelistOnly)
sync.lock(turtle) sync.lock(turtle)
end end
function machineWizard.filter:hide() function nodeWizard.filter:hide()
UI.SlideOut.hide(self) UI.SlideOut.hide(self)
Milo:resumeCrafting() Milo:resumeCrafting()
sync.release(turtle) sync.release(turtle)
end end
function machineWizard.filter:resetGrid() function nodeWizard.filter:resetGrid()
local t = { } local t = { }
for k in pairs(self.entry.filter) do for k in pairs(self.entry.filter) do
table.insert(t, itemDB:splitKey(k)) table.insert(t, itemDB:splitKey(k))
@@ -294,13 +329,13 @@ function machineWizard.filter:resetGrid()
self.grid:setValues(t) self.grid:setValues(t)
end end
function machineWizard.filter.grid:getDisplayValues(row) function nodeWizard.filter.grid:getDisplayValues(row)
row = Util.shallowCopy(row) row = Util.shallowCopy(row)
row.displayName = itemDB:getName(row) row.displayName = itemDB:getName(row)
return row return row
end end
function machineWizard.filter:eventHandler(event) function nodeWizard.filter:eventHandler(event)
if event.type == 'focus_change' then if event.type == 'focus_change' then
self.statusBar:setStatus(event.focused.help) self.statusBar:setStatus(event.focused.help)
@@ -341,16 +376,16 @@ function machineWizard.filter:eventHandler(event)
end end
--[[ General Page ]] -- --[[ General Page ]] --
function machineWizard.wizard.pages.general:enable() function nodeWizard.wizard.pages.general:enable()
UI.Window.enable(self) UI.Window.enable(self)
self:focusFirst() self:focusFirst()
end end
function machineWizard.wizard.pages.general:setMachine(machine) function nodeWizard.wizard.pages.general:setNode(node)
local inventory local inventory
if device[machine.name] and device[machine.name].list then if device[node.name] and device[node.name].list then
inventory = device[machine.name].list() inventory = device[node.name].list()
for k,v in pairs(inventory) do for k,v in pairs(inventory) do
v.slot = k v.slot = k
end end
@@ -359,18 +394,18 @@ function machineWizard.wizard.pages.general:setMachine(machine)
self.grid:setValues(inventory or { }) self.grid:setValues(inventory or { })
end end
function machineWizard.wizard.pages.general.grid:getDisplayValues(row) function nodeWizard.wizard.pages.general.grid:getDisplayValues(row)
row = Util.shallowCopy(row) row = Util.shallowCopy(row)
row.displayName = itemDB:getName(row) row.displayName = itemDB:getName(row)
return row return row
end end
function machineWizard.wizard.pages.general:validate() function nodeWizard.wizard.pages.general:validate()
return self.form:save() return self.form:save()
end end
--[[ Wizard ]] -- --[[ Wizard ]] --
function machineWizard.wizard:eventHandler(event) function nodeWizard.wizard:eventHandler(event)
if event.type == 'nextView' and if event.type == 'nextView' and
Util.find(self.pages, 'enabled', true) == self.pages.general then Util.find(self.pages, 'enabled', true) == self.pages.general then
@@ -383,7 +418,7 @@ function machineWizard.wizard:eventHandler(event)
self.pages.confirmation.index = 2 self.pages.confirmation.index = 2
for _, page in pairs(self.pages) do for _, page in pairs(self.pages) do
if not page.index and page:isValidFor(self.parent.machine) then if not page.index and page:isValidFor(self.parent.node) then
page.index = index page.index = index
index = index + 1 index = index + 1
end end
@@ -396,16 +431,16 @@ function machineWizard.wizard:eventHandler(event)
end end
end end
function machineWizard:enable(machine) function nodeWizard:enable(node)
local adapter = machine.adapter local adapter = node.adapter
machine.adapter = nil -- don't deep copy the adapter node.adapter = nil -- don't deep copy the adapter
self.machine = Util.deepCopy(machine) self.node = Util.deepCopy(node)
self.machine.adapter = adapter self.node.adapter = adapter
machine.adapter = adapter node.adapter = adapter
_G._p2 = self.machine _G._p2 = self.node
self.wizard.pages.general.form:setValues(self.machine) self.wizard.pages.general.form:setValues(self.node)
self.wizard.pages.general.form[1].shadowText = self.machine.name self.wizard.pages.general.form[1].shadowText = self.node.name
-- restore indices -- restore indices
for _, page in pairs(self.wizard.pages) do for _, page in pairs(self.wizard.pages) do
@@ -418,18 +453,18 @@ _G._p2 = self.machine
UI.Page.enable(self) UI.Page.enable(self)
for _, v in pairs(self.wizard.pages) do for _, v in pairs(self.wizard.pages) do
if v.setMachine then if v.setNode then
v:setMachine(self.machine) v:setNode(self.node)
end end
end end
end end
function machineWizard:eventHandler(event) function nodeWizard:eventHandler(event)
if event.type == 'cancel' then if event.type == 'cancel' then
UI:setPreviousPage() UI:setPreviousPage()
elseif event.type == 'accept' then elseif event.type == 'accept' then
Util.prune(self.machine, function(v) Util.prune(self.node, function(v)
if type(v) == 'boolean' then if type(v) == 'boolean' then
return v return v
elseif type(v) == 'string' then elseif type(v) == 'string' then
@@ -440,8 +475,8 @@ function machineWizard:eventHandler(event)
return true return true
end) end)
Util.clear(context.config.remoteDefaults[self.machine.name]) Util.clear(context.config.nodes[self.node.name])
Util.merge(context.config.remoteDefaults[self.machine.name], self.machine) Util.merge(context.config.nodes[self.node.name], self.node)
saveConfig() saveConfig()
UI:setPreviousPage() UI:setPreviousPage()
@@ -451,7 +486,7 @@ function machineWizard:eventHandler(event)
elseif event.type == 'enable_view' then elseif event.type == 'enable_view' then
local current = event.next or event.prev local current = event.next or event.prev
self.titleBar.title = current.title or 'Machine' self.titleBar.title = current.title or 'Node'
self.titleBar:draw() self.titleBar:draw()
elseif event.type == 'focus_change' then elseif event.type == 'focus_change' then
@@ -467,5 +502,5 @@ function machineWizard:eventHandler(event)
return true return true
end end
UI:addPage('machines', machinesPage) UI:addPage('network', networkPage)
UI:addPage('machineWizard', machineWizard) UI:addPage('nodeWizard', nodeWizard)

View File

@@ -4,11 +4,15 @@ local Peripheral = require('peripheral')
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 context = Milo:getContext() local context = Milo:getContext()
local mon = Peripheral.lookup(context.config.activityMonitor) local mon = Peripheral.lookup(context.config.activityMonitor)
local ActivityTask = {
name = 'activity',
priority = 30,
}
if not mon then if not mon then
return return
end end
@@ -110,7 +114,7 @@ function page:refresh()
self.grid:draw() self.grid:draw()
end end
Event.onInterval(5, function() function page:update()
if context.storage:isOnline() then if context.storage:isOnline() then
page:refresh() page:refresh()
page:sync() page:sync()
@@ -119,6 +123,10 @@ Event.onInterval(5, function()
page.grid:centeredWrite(math.ceil(page.height / 2), 'Storage Offline') page.grid:centeredWrite(math.ceil(page.height / 2), 'Storage Offline')
page:sync() page:sync()
end end
end
Event.on({ 'storage_offline', 'storage_online' }, function()
page:update()
end) end)
Event.on('monitor_touch', function(_, side) Event.on('monitor_touch', function(_, side)
@@ -128,5 +136,11 @@ Event.on('monitor_touch', function(_, side)
end end
end) end)
function ActivityTask:cycle()
page:update()
end
Milo:registerTask(ActivityTask)
page:draw() page:draw()
page:sync() page:sync()

View File

@@ -25,11 +25,11 @@ local brewingStandView = UI.Window {
}, },
} }
function brewingStandView:isValidFor(machine) function brewingStandView:isValidFor(node)
if machine.mtype == 'machine' then if node.mtype == 'machine' then
local m = device[machine.name] local m = device[node.name]
return m and m.type == 'minecraft:brewing_stand' return m and m.type == 'minecraft:brewing_stand'
end end
end end
UI:getPage('machineWizard').wizard:add({ brewingStand = brewingStandView }) UI:getPage('nodeWizard').wizard:add({ brewingStand = brewingStandView })

View File

@@ -36,22 +36,22 @@ local exportView = UI.Window {
}, },
} }
function exportView:isValidFor(machine) function exportView:isValidFor(node)
return machine.mtype == 'machine' return node.mtype == 'machine'
end end
function exportView:setMachine(machine) function exportView:setNode(node)
self.machine = machine self.machine = node
if not self.machine.exports then if not self.machine.exports then
self.machine.exports = { } self.machine.exports = { }
end end
self.grid:setValues(machine.exports) self.grid:setValues(self.machine.exports)
self.slots.choices = { self.slots.choices = {
{ name = 'All', value = '*' } { name = 'All', value = '*' }
} }
local m = device[machine.name] local m = device[self.machine.name]
for k = 1, m.size() do for k = 1, m.size() do
table.insert(self.slots.choices, { name = k, value = k }) table.insert(self.slots.choices, { name = k, value = k })
end end
@@ -101,4 +101,4 @@ function exportView:eventHandler(event)
end end
end end
UI:getPage('machineWizard').wizard:add({ export = exportView }) UI:getPage('nodeWizard').wizard:add({ export = exportView })

View File

@@ -36,22 +36,22 @@ local importView = UI.Window {
}, },
} }
function importView:isValidFor(machine) function importView:isValidFor(node)
return machine.mtype == 'machine' return node.mtype == 'machine'
end end
function importView:setMachine(machine) function importView:setNode(node)
self.machine = machine self.machine = node
if not self.machine.imports then if not self.machine.imports then
self.machine.imports = { } self.machine.imports = { }
end end
self.grid:setValues(machine.imports) self.grid:setValues(self.machine.imports)
self.slots.choices = { self.slots.choices = {
{ name = 'All', value = '*' } { name = 'All', value = '*' }
} }
local m = device[machine.name] local m = device[self.machine.name]
for k = 1, m.size() do for k = 1, m.size() do
table.insert(self.slots.choices, { name = k, value = k }) table.insert(self.slots.choices, { name = k, value = k })
end end
@@ -100,4 +100,4 @@ function importView:eventHandler(event)
end end
end end
UI:getPage('machineWizard').wizard:add({ import = importView }) UI:getPage('nodeWizard').wizard:add({ import = importView })

View File

@@ -1,4 +1,5 @@
local Ansi = require('ansi') local Ansi = require('ansi')
local Craft = require('turtle.craft')
local Milo = require('milo') local Milo = require('milo')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
@@ -59,6 +60,12 @@ local itemPage = UI.Page {
event = 'show_info', event = 'show_info',
text = 'Info', text = 'Info',
}, },
resetButton = UI.Button {
x = 9, y = -2,
event = 'reset',
text = 'Reset',
help = 'Clear recipe and all settings',
},
}, },
rsControl = UI.SlideOut { rsControl = UI.SlideOut {
backgroundColor = colors.cyan, backgroundColor = colors.cyan,
@@ -108,7 +115,7 @@ local itemPage = UI.Page {
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 2, ey = -4, y = 2, ey = -4,
disableHeader = true, disableHeader = true,
values = context.config.remoteDefaults, values = context.config.nodes,
columns = { columns = {
{ heading = 'Name', key = 'displayName'}, { heading = 'Name', key = 'displayName'},
}, },
@@ -201,6 +208,25 @@ function itemPage:eventHandler(event)
self.machines.grid:setIndex(1) self.machines.grid:setIndex(1)
self.machines:show() self.machines:show()
elseif event.type == 'reset' then
if context.userRecipes[self.item.key] then
context.userRecipes[self.item.key] = nil
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
Craft.loadRecipes()
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 == 'set_machine' then elseif event.type == 'set_machine' then
--TODO save machine --TODO save machine
self.machines:hide() self.machines:hide()

View File

@@ -32,20 +32,21 @@ end
local listingPage = UI.Page { local listingPage = UI.Page {
menuBar = UI.MenuBar { menuBar = UI.MenuBar {
buttons = { buttons = {
{ text = 'Learn', event = 'learn' }, { text = 'Learn', event = 'learn' },
{ text = 'Forget', event = 'forget' }, --{ text = 'Forget', event = 'forget' },
{ text = 'Craft', event = 'craft' }, { text = 'Craft', event = 'craft' },
{ text = '...', event = 'machines' }, { text = 'Edit', event = 'details' },
{ text = 'Network', event = 'network' },
{ text = 'Refresh', event = 'refresh', x = -9 }, { text = 'Refresh', event = 'refresh', x = -9 },
}, },
}, },
grid = UI.Grid { grid = UI.Grid {
y = 2, ey = -2, y = 2, ey = -2,
columns = { columns = {
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' }, { heading = ' Qty', key = 'count' , width = 4, justify = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Min', key = 'low' , width = 4 }, { heading = 'Min', key = 'low' , width = 4 },
{ heading = 'Max', key = 'limit' , width = 4 }, { heading = 'Max', key = 'limit' , width = 4 },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
}, },
@@ -95,7 +96,7 @@ local listingPage = UI.Page {
[ 'control-s' ] = 'eject_stack', [ 'control-s' ] = 'eject_stack',
[ 'control-a' ] = 'eject_all', [ 'control-a' ] = 'eject_all',
[ 'control-m' ] = 'machines', [ 'control-m' ] = 'network',
q = 'quit', q = 'quit',
}, },
@@ -132,7 +133,7 @@ function listingPage:eventHandler(event)
if event.type == 'quit' then if event.type == 'quit' then
UI:exitPullEvents() UI:exitPullEvents()
elseif event.type == 'eject' then elseif event.type == 'eject' or event.type == 'grid_select' then
local item = self.grid:getSelected() local item = self.grid:getSelected()
if item then if item then
item.count = Milo:craftAndEject(item, 1) item.count = Milo:craftAndEject(item, 1)
@@ -164,8 +165,8 @@ function listingPage:eventHandler(event)
Milo:craftAndEject(item, count) Milo:craftAndEject(item, count)
end end
elseif event.type == 'machines' then elseif event.type == 'network' then
UI:setPage('machines') UI:setPage('network')
elseif event.type == 'details' or event.type == 'grid_select_right' then elseif event.type == 'details' or event.type == 'grid_select_right' then
local item = self.grid:getSelected() local item = self.grid:getSelected()
@@ -195,7 +196,7 @@ function listingPage:eventHandler(event)
elseif event.type == 'learn' then elseif event.type == 'learn' then
UI:setPage('learn') UI:setPage('learn')
elseif event.type == 'craft' or event.type == 'grid_select' then elseif event.type == 'craft' then
local item = self.grid:getSelected() local item = self.grid:getSelected()
if Craft.findRecipe(item) or true then -- or item.is_craftable then if Craft.findRecipe(item) or true then -- or item.is_craftable then
UI:setPage('craft', self.grid:getSelected()) UI:setPage('craft', self.grid:getSelected())
@@ -203,27 +204,6 @@ function listingPage:eventHandler(event)
self.notification:error('No recipe defined') self.notification:error('No recipe defined')
end end
elseif event.type == 'forget' then
local item = self.grid:getSelected()
if item then
local key = Milo:uniqueKey(item)
if context.userRecipes[key] then
context.userRecipes[key] = nil
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
Craft.loadRecipes()
end
--TODO: remove machine assoc
if context.resources[key] then
context.resources[key] = nil
Milo:saveResources()
end
self.notification:info('Forgot: ' .. item.name)
self:refresh()
self.grid:draw()
end
elseif event.type == 'text_change' and event.element == self.statusBar.filter then elseif event.type == 'text_change' and event.element == self.statusBar.filter then
self.filter = event.text self.filter = event.text
if #self.filter == 0 then if #self.filter == 0 then

View File

@@ -19,7 +19,7 @@ local machineLearnWizard = UI.Page {
index = 1, index = 1,
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 2, ey = -2, y = 2, ey = -2,
values = context.config.remoteDefaults, values = context.config.nodes,
columns = { columns = {
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
}, },

View File

@@ -37,10 +37,10 @@ local dispenserView = UI.Window {
}, },
} }
function dispenserView:isValidFor(machine) function dispenserView:isValidFor(node)
if machine.mtype == 'machine' then if node.mtype == 'machine' then
local m = device[machine.name] local m = device[node.name]
return m and m.type == 'minecraft:dispenser' --return m and m.type == 'minecraft:dispenser'
end end
end end
@@ -63,11 +63,11 @@ function dispenserView:validate()
return self.form:save() return self.form:save()
end end
function dispenserView:setMachine(machine) function dispenserView:setNode(node)
if not machine.redstone then if not node.redstone then
machine.redstone = { } node.redstone = { }
end end
self.form:setValues(machine.redstone) self.form:setValues(node.redstone)
end end
UI:getPage('machineWizard').wizard:add({ dispenser = dispenserView }) UI:getPage('nodeWizard').wizard:add({ dispenser = dispenserView })

View File

@@ -48,14 +48,14 @@ function storageView:validate()
return self.form:save() return self.form:save()
end end
function storageView:isValidFor(machine) function storageView:isValidFor(node)
return machine.mtype == 'storage' return node.mtype == 'storage'
end end
function storageView:setMachine(machine) function storageView:setNode(node)
self.machine = machine self.machine = node
self.form:setValues(machine) self.form:setValues(node)
self.form[3].value = machine.lock and itemDB:getName(machine.lock) or '' self.form[3].value = node.lock and itemDB:getName(node.lock) or ''
end end
function storageView:eventHandler(event) function storageView:eventHandler(event)
@@ -83,4 +83,4 @@ function storageView:eventHandler(event)
end end
end end
UI:getPage('machineWizard').wizard:add({ storage = storageView }) UI:getPage('nodeWizard').wizard:add({ storage = storageView })