diff --git a/milo/Milo.lua b/milo/Milo.lua index cdb16af..cd529fa 100644 --- a/milo/Milo.lua +++ b/milo/Milo.lua @@ -39,10 +39,16 @@ end local config = { monitor = 'type/monitor', activityMonitor = 'none', - remoteDefaults = { }, + nodes = { }, } 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') if not modem or not modem.getNameLocal then error('Wired modem is not connected') diff --git a/milo/MiloMonitor.lua b/milo/MiloMonitor.lua deleted file mode 100644 index 1e59828..0000000 --- a/milo/MiloMonitor.lua +++ /dev/null @@ -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 ') -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() diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index e0f3528..aa652d4 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -12,7 +12,7 @@ local Storage = class() function Storage:init(args) local defaults = { - remoteDefaults = { }, + nodes = { }, dirty = true, activity = { }, storageOnline = true, @@ -35,9 +35,9 @@ end function Storage:showStorage() 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 - if not online then + if not online and v.mtype ~= 'ignore' then table.insert(t, k) end end @@ -58,7 +58,7 @@ function Storage:initStorage() local online = true _G._debug('Initializing storage') - for k,v in pairs(self.remoteDefaults) do + for k,v in pairs(self.nodes) do if v.adapter then v.adapter.online = not not device[k] 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) 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 not filter or filter(v) then table.insert(iter, v) @@ -97,7 +97,7 @@ end function Storage:onlineAdapters(reversed) 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 table.insert(iter, v) end @@ -191,7 +191,8 @@ function Storage:updateCache(adapter, key, count) adapter.dirty = true self.dirty = true else - entry = Util.shallowCopy(itemDB:get(key)) + local item = itemDB:get(key) or itemDB:splitKey(key) + entry = Util.shallowCopy(item) entry.count = count entry.key = key adapter.cache[key] = entry @@ -311,7 +312,7 @@ end -- When importing items into a locked chest, trash any remaining items if full 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 _G._debug('TRA: %s[%d] (%d)', source or self.localName, slot, count or 64) diff --git a/milo/core/machines.lua b/milo/core/machines.lua index bc7b621..0dda36f 100644 --- a/milo/core/machines.lua +++ b/milo/core/machines.lua @@ -14,7 +14,7 @@ local context = Milo:getContext() local function saveConfig() local t = { } - for k,v in pairs(context.config.remoteDefaults) do + for k,v in pairs(context.config.nodes) do t[k] = v.adapter v.adapter = nil end @@ -22,19 +22,29 @@ local function saveConfig() Config.update('milo', context.config) for k,v in pairs(t) do - context.config.remoteDefaults[k].adapter = v + context.config.nodes[k].adapter = v end context.storage:initStorage() end -local machinesPage = UI.Page { +local networkPage = UI.Page { titleBar = UI.TitleBar { 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 { - y = 2, ey = -2, - values = context.config.remoteDefaults, + y = 2, ey = -3, + values = context.config.nodes, columns = { { key = 'suffix', width = 4, justify = 'right' }, { heading = 'Name', key = 'displayName' }, @@ -42,23 +52,25 @@ local machinesPage = UI.Page { { heading = 'Pri', key = 'priority', width = 3 }, }, sortColumn = 'displayName', - help = 'Select Machine', + help = 'Select Node', }, remove = UI.Button { - y = -1, x = -4, - text = '-', event = 'remove_machine', - help = 'Remove Machine', + y = -2, x = -4, + text = '-', event = 'remove_node', + help = 'Remove Node', }, statusBar = UI.StatusBar { - ex = -7, - backgroundColor = colors.cyan, + backgroundColor = colors.lightGray, }, notification = UI.Notification { }, } -function machinesPage.grid:getDisplayValues(row) +function networkPage.grid:getDisplayValues(row) row = Util.shallowCopy(row) local t = { row.name:match(':(.+)_(%d+)$') } + if #t ~= 2 then + t = { row.name:match('(.+)_(%d+)$') } + end if t and #t == 2 then row.name, row.suffix = table.unpack(t) row.name = row.name .. '_' .. row.suffix @@ -67,7 +79,7 @@ function machinesPage.grid:getDisplayValues(row) return row end -function machinesPage.grid:getRowTextColor(row, selected) +function networkPage.grid:getRowTextColor(row, selected) if not device[row.name] then return colors.red end @@ -77,11 +89,11 @@ function machinesPage.grid:getRowTextColor(row, selected) return UI.Grid:getRowTextColor(row, selected) end -function machinesPage:getList() +function networkPage:getList() for _, v in pairs(device) do if v.pullItems then - if not context.config.remoteDefaults[v.name] then - context.config.remoteDefaults[v.name] = { + if not context.config.nodes[v.name] then + context.config.nodes[v.name] = { name = v.name, mtype = 'ignore', } @@ -90,9 +102,10 @@ function machinesPage:getList() end end -function machinesPage:enable() +function networkPage:enable() self:getList() self.grid:update() + self:setFocus(self.filter) UI.Page.enable(self) self.handler = Event.on({ 'device_attach', 'device_detach'}, function() self:getList() @@ -102,28 +115,50 @@ function machinesPage:enable() end) end -function machinesPage:disable() +function networkPage:disable() UI.Page.disable(self) Event.off(self.handler) 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 not device[event.selected.name] then self.notification:error('Unable to edit while disconnected') else - UI:setPage('machineWizard', event.selected) + UI:setPage('nodeWizard', event.selected) end - elseif event.type == 'remove_machine' then - local machine = self.grid:getSelected() - if machine then - context.config.remoteDefaults[machine.name] = nil + elseif event.type == 'remove_node' then + local node = self.grid:getSelected() + if node then + context.config.nodes[node.name] = nil saveConfig() end self.grid:update() self.grid:draw() + elseif event.type == 'text_change' then + self:applyFilter() + self.grid:draw() + elseif event.type == 'focus_change' then self.statusBar:setStatus(event.focused.help) @@ -133,7 +168,7 @@ function machinesPage:eventHandler(event) return true end -local machineWizard = UI.Page { +local nodeWizard = UI.Page { titleBar = UI.TitleBar { title = 'Configure' }, wizard = UI.Wizard { y = 2, ey = -2, @@ -260,7 +295,7 @@ The settings will take effect immediately!]], } --[[ Filter slide out ]] -- -function machineWizard.filter:show(entry, callback, whitelistOnly) +function nodeWizard.filter:show(entry, callback, whitelistOnly) self.entry = entry self.callback = callback @@ -280,13 +315,13 @@ function machineWizard.filter:show(entry, callback, whitelistOnly) sync.lock(turtle) end -function machineWizard.filter:hide() +function nodeWizard.filter:hide() UI.SlideOut.hide(self) Milo:resumeCrafting() sync.release(turtle) end -function machineWizard.filter:resetGrid() +function nodeWizard.filter:resetGrid() local t = { } for k in pairs(self.entry.filter) do table.insert(t, itemDB:splitKey(k)) @@ -294,13 +329,13 @@ function machineWizard.filter:resetGrid() self.grid:setValues(t) end -function machineWizard.filter.grid:getDisplayValues(row) +function nodeWizard.filter.grid:getDisplayValues(row) row = Util.shallowCopy(row) row.displayName = itemDB:getName(row) return row end -function machineWizard.filter:eventHandler(event) +function nodeWizard.filter:eventHandler(event) if event.type == 'focus_change' then self.statusBar:setStatus(event.focused.help) @@ -341,16 +376,16 @@ function machineWizard.filter:eventHandler(event) end --[[ General Page ]] -- -function machineWizard.wizard.pages.general:enable() +function nodeWizard.wizard.pages.general:enable() UI.Window.enable(self) self:focusFirst() end -function machineWizard.wizard.pages.general:setMachine(machine) +function nodeWizard.wizard.pages.general:setNode(node) local inventory - if device[machine.name] and device[machine.name].list then - inventory = device[machine.name].list() + if device[node.name] and device[node.name].list then + inventory = device[node.name].list() for k,v in pairs(inventory) do v.slot = k end @@ -359,18 +394,18 @@ function machineWizard.wizard.pages.general:setMachine(machine) self.grid:setValues(inventory or { }) end -function machineWizard.wizard.pages.general.grid:getDisplayValues(row) +function nodeWizard.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 nodeWizard.wizard.pages.general:validate() return self.form:save() end --[[ Wizard ]] -- -function machineWizard.wizard:eventHandler(event) +function nodeWizard.wizard:eventHandler(event) if event.type == 'nextView' and Util.find(self.pages, 'enabled', true) == self.pages.general then @@ -383,7 +418,7 @@ function machineWizard.wizard:eventHandler(event) self.pages.confirmation.index = 2 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 index = index + 1 end @@ -396,16 +431,16 @@ function machineWizard.wizard:eventHandler(event) end end -function machineWizard:enable(machine) - local adapter = machine.adapter - machine.adapter = nil -- don't deep copy the adapter - self.machine = Util.deepCopy(machine) - self.machine.adapter = adapter - machine.adapter = adapter +function nodeWizard:enable(node) + local adapter = node.adapter + node.adapter = nil -- don't deep copy the adapter + self.node = Util.deepCopy(node) + self.node.adapter = adapter + node.adapter = adapter -_G._p2 = self.machine - self.wizard.pages.general.form:setValues(self.machine) - self.wizard.pages.general.form[1].shadowText = self.machine.name +_G._p2 = self.node + self.wizard.pages.general.form:setValues(self.node) + self.wizard.pages.general.form[1].shadowText = self.node.name -- restore indices for _, page in pairs(self.wizard.pages) do @@ -418,18 +453,18 @@ _G._p2 = self.machine UI.Page.enable(self) for _, v in pairs(self.wizard.pages) do - if v.setMachine then - v:setMachine(self.machine) + if v.setNode then + v:setNode(self.node) end end end -function machineWizard:eventHandler(event) +function nodeWizard:eventHandler(event) if event.type == 'cancel' then UI:setPreviousPage() elseif event.type == 'accept' then - Util.prune(self.machine, function(v) + Util.prune(self.node, function(v) if type(v) == 'boolean' then return v elseif type(v) == 'string' then @@ -440,8 +475,8 @@ function machineWizard:eventHandler(event) return true end) - Util.clear(context.config.remoteDefaults[self.machine.name]) - Util.merge(context.config.remoteDefaults[self.machine.name], self.machine) + Util.clear(context.config.nodes[self.node.name]) + Util.merge(context.config.nodes[self.node.name], self.node) saveConfig() UI:setPreviousPage() @@ -451,7 +486,7 @@ function machineWizard:eventHandler(event) elseif event.type == 'enable_view' then local current = event.next or event.prev - self.titleBar.title = current.title or 'Machine' + self.titleBar.title = current.title or 'Node' self.titleBar:draw() elseif event.type == 'focus_change' then @@ -467,5 +502,5 @@ function machineWizard:eventHandler(event) return true end -UI:addPage('machines', machinesPage) -UI:addPage('machineWizard', machineWizard) +UI:addPage('network', networkPage) +UI:addPage('nodeWizard', nodeWizard) diff --git a/milo/plugins/activityView.lua b/milo/plugins/activityView.lua index 44b420f..61ca2f0 100644 --- a/milo/plugins/activityView.lua +++ b/milo/plugins/activityView.lua @@ -4,11 +4,15 @@ local Peripheral = require('peripheral') local UI = require('ui') local Util = require('util') -local colors = _G.colors - +local colors = _G.colors local context = Milo:getContext() local mon = Peripheral.lookup(context.config.activityMonitor) +local ActivityTask = { + name = 'activity', + priority = 30, +} + if not mon then return end @@ -110,7 +114,7 @@ function page:refresh() self.grid:draw() end -Event.onInterval(5, function() +function page:update() if context.storage:isOnline() then page:refresh() page:sync() @@ -119,6 +123,10 @@ Event.onInterval(5, function() page.grid:centeredWrite(math.ceil(page.height / 2), 'Storage Offline') page:sync() end +end + +Event.on({ 'storage_offline', 'storage_online' }, function() + page:update() end) Event.on('monitor_touch', function(_, side) @@ -128,5 +136,11 @@ Event.on('monitor_touch', function(_, side) end end) +function ActivityTask:cycle() + page:update() +end + +Milo:registerTask(ActivityTask) + page:draw() page:sync() diff --git a/milo/plugins/brewingStandView.lua b/milo/plugins/brewingStandView.lua index e4471ba..332aa5e 100644 --- a/milo/plugins/brewingStandView.lua +++ b/milo/plugins/brewingStandView.lua @@ -25,11 +25,11 @@ local brewingStandView = UI.Window { }, } -function brewingStandView:isValidFor(machine) - if machine.mtype == 'machine' then - local m = device[machine.name] +function brewingStandView:isValidFor(node) + if node.mtype == 'machine' then + local m = device[node.name] return m and m.type == 'minecraft:brewing_stand' end end -UI:getPage('machineWizard').wizard:add({ brewingStand = brewingStandView }) +UI:getPage('nodeWizard').wizard:add({ brewingStand = brewingStandView }) diff --git a/milo/plugins/exportView.lua b/milo/plugins/exportView.lua index 0bbb679..98d868d 100644 --- a/milo/plugins/exportView.lua +++ b/milo/plugins/exportView.lua @@ -36,22 +36,22 @@ local exportView = UI.Window { }, } -function exportView:isValidFor(machine) - return machine.mtype == 'machine' +function exportView:isValidFor(node) + return node.mtype == 'machine' end -function exportView:setMachine(machine) - self.machine = machine +function exportView:setNode(node) + self.machine = node if not self.machine.exports then self.machine.exports = { } end - self.grid:setValues(machine.exports) + self.grid:setValues(self.machine.exports) self.slots.choices = { { name = 'All', value = '*' } } - local m = device[machine.name] + local m = device[self.machine.name] for k = 1, m.size() do table.insert(self.slots.choices, { name = k, value = k }) end @@ -101,4 +101,4 @@ function exportView:eventHandler(event) end end -UI:getPage('machineWizard').wizard:add({ export = exportView }) +UI:getPage('nodeWizard').wizard:add({ export = exportView }) diff --git a/milo/plugins/importView.lua b/milo/plugins/importView.lua index af6af79..06a7fcb 100644 --- a/milo/plugins/importView.lua +++ b/milo/plugins/importView.lua @@ -36,22 +36,22 @@ local importView = UI.Window { }, } -function importView:isValidFor(machine) - return machine.mtype == 'machine' +function importView:isValidFor(node) + return node.mtype == 'machine' end -function importView:setMachine(machine) - self.machine = machine +function importView:setNode(node) + self.machine = node if not self.machine.imports then self.machine.imports = { } end - self.grid:setValues(machine.imports) + self.grid:setValues(self.machine.imports) self.slots.choices = { { name = 'All', value = '*' } } - local m = device[machine.name] + local m = device[self.machine.name] for k = 1, m.size() do table.insert(self.slots.choices, { name = k, value = k }) end @@ -100,4 +100,4 @@ function importView:eventHandler(event) end end -UI:getPage('machineWizard').wizard:add({ import = importView }) +UI:getPage('nodeWizard').wizard:add({ import = importView }) diff --git a/milo/plugins/item.lua b/milo/plugins/item.lua index 137dbd9..052d2d0 100644 --- a/milo/plugins/item.lua +++ b/milo/plugins/item.lua @@ -1,4 +1,5 @@ local Ansi = require('ansi') +local Craft = require('turtle.craft') local Milo = require('milo') local UI = require('ui') local Util = require('util') @@ -59,6 +60,12 @@ local itemPage = UI.Page { event = 'show_info', text = 'Info', }, + resetButton = UI.Button { + x = 9, y = -2, + event = 'reset', + text = 'Reset', + help = 'Clear recipe and all settings', + }, }, rsControl = UI.SlideOut { backgroundColor = colors.cyan, @@ -108,7 +115,7 @@ local itemPage = UI.Page { grid = UI.ScrollingGrid { y = 2, ey = -4, disableHeader = true, - values = context.config.remoteDefaults, + values = context.config.nodes, columns = { { heading = 'Name', key = 'displayName'}, }, @@ -201,6 +208,25 @@ function itemPage:eventHandler(event) self.machines.grid:setIndex(1) 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 --TODO save machine self.machines:hide() diff --git a/milo/plugins/listing.lua b/milo/plugins/listing.lua index 4f50832..def0050 100644 --- a/milo/plugins/listing.lua +++ b/milo/plugins/listing.lua @@ -32,20 +32,21 @@ end local listingPage = UI.Page { menuBar = UI.MenuBar { buttons = { - { text = 'Learn', event = 'learn' }, - { text = 'Forget', event = 'forget' }, - { text = 'Craft', event = 'craft' }, - { text = '...', event = 'machines' }, + { text = 'Learn', event = 'learn' }, + --{ text = 'Forget', event = 'forget' }, + { text = 'Craft', event = 'craft' }, + { text = 'Edit', event = 'details' }, + { text = 'Network', event = 'network' }, { text = 'Refresh', event = 'refresh', x = -9 }, }, }, grid = UI.Grid { y = 2, ey = -2, columns = { - { heading = ' Qty', key = 'count' , width = 4, justify = 'right' }, + { heading = ' Qty', key = 'count' , width = 4, justify = 'right' }, { heading = 'Name', key = 'displayName' }, - { heading = 'Min', key = 'low' , width = 4 }, - { heading = 'Max', key = 'limit' , width = 4 }, + { heading = 'Min', key = 'low' , width = 4 }, + { heading = 'Max', key = 'limit' , width = 4 }, }, sortColumn = 'displayName', }, @@ -95,7 +96,7 @@ local listingPage = UI.Page { [ 'control-s' ] = 'eject_stack', [ 'control-a' ] = 'eject_all', - [ 'control-m' ] = 'machines', + [ 'control-m' ] = 'network', q = 'quit', }, @@ -132,7 +133,7 @@ function listingPage:eventHandler(event) if event.type == 'quit' then UI:exitPullEvents() - elseif event.type == 'eject' then + elseif event.type == 'eject' or event.type == 'grid_select' then local item = self.grid:getSelected() if item then item.count = Milo:craftAndEject(item, 1) @@ -164,8 +165,8 @@ function listingPage:eventHandler(event) Milo:craftAndEject(item, count) end - elseif event.type == 'machines' then - UI:setPage('machines') + elseif event.type == 'network' then + UI:setPage('network') elseif event.type == 'details' or event.type == 'grid_select_right' then local item = self.grid:getSelected() @@ -195,7 +196,7 @@ function listingPage:eventHandler(event) elseif event.type == 'learn' then UI:setPage('learn') - elseif event.type == 'craft' or event.type == 'grid_select' then + elseif event.type == 'craft' then local item = self.grid:getSelected() if Craft.findRecipe(item) or true then -- or item.is_craftable then UI:setPage('craft', self.grid:getSelected()) @@ -203,27 +204,6 @@ function listingPage:eventHandler(event) self.notification:error('No recipe defined') 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 self.filter = event.text if #self.filter == 0 then diff --git a/milo/plugins/machineLearn.lua b/milo/plugins/machineLearn.lua index b85a2e9..4d33afc 100644 --- a/milo/plugins/machineLearn.lua +++ b/milo/plugins/machineLearn.lua @@ -19,7 +19,7 @@ local machineLearnWizard = UI.Page { index = 1, grid = UI.ScrollingGrid { y = 2, ey = -2, - values = context.config.remoteDefaults, + values = context.config.nodes, columns = { { heading = 'Name', key = 'displayName' }, }, diff --git a/milo/plugins/redstoneView.lua b/milo/plugins/redstoneView.lua index 0ed3dfc..0ceb93a 100644 --- a/milo/plugins/redstoneView.lua +++ b/milo/plugins/redstoneView.lua @@ -37,10 +37,10 @@ local dispenserView = UI.Window { }, } -function dispenserView:isValidFor(machine) - if machine.mtype == 'machine' then - local m = device[machine.name] - return m and m.type == 'minecraft:dispenser' +function dispenserView:isValidFor(node) + if node.mtype == 'machine' then + local m = device[node.name] + --return m and m.type == 'minecraft:dispenser' end end @@ -63,11 +63,11 @@ function dispenserView:validate() return self.form:save() end -function dispenserView:setMachine(machine) - if not machine.redstone then - machine.redstone = { } +function dispenserView:setNode(node) + if not node.redstone then + node.redstone = { } end - self.form:setValues(machine.redstone) + self.form:setValues(node.redstone) end -UI:getPage('machineWizard').wizard:add({ dispenser = dispenserView }) +UI:getPage('nodeWizard').wizard:add({ dispenser = dispenserView }) diff --git a/milo/plugins/storageView.lua b/milo/plugins/storageView.lua index 99856ca..e792cc3 100644 --- a/milo/plugins/storageView.lua +++ b/milo/plugins/storageView.lua @@ -48,14 +48,14 @@ function storageView:validate() return self.form:save() end -function storageView:isValidFor(machine) - return machine.mtype == 'storage' +function storageView:isValidFor(node) + return node.mtype == 'storage' end -function storageView:setMachine(machine) - self.machine = machine - self.form:setValues(machine) - self.form[3].value = machine.lock and itemDB:getName(machine.lock) or '' +function storageView:setNode(node) + self.machine = node + self.form:setValues(node) + self.form[3].value = node.lock and itemDB:getName(node.lock) or '' end function storageView:eventHandler(event) @@ -83,4 +83,4 @@ function storageView:eventHandler(event) end end -UI:getPage('machineWizard').wizard:add({ storage = storageView }) +UI:getPage('nodeWizard').wizard:add({ storage = storageView })