From 871f44a170805093bbe09608e652036c0b356b71 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Mon, 29 Oct 2018 22:00:59 -0400 Subject: [PATCH] milo wip --- milo/apis/milo.lua | 18 ++++++++--- milo/apis/storage.lua | 8 ++--- milo/core/machines.lua | 9 ++++-- milo/plugins/brewingStandView.lua | 35 +++++++++++++++++++++ milo/plugins/exportView.lua | 1 - milo/plugins/importView.lua | 1 - milo/plugins/item.lua | 52 ++++++++++++++++++++++++++++--- milo/plugins/listing.lua | 10 ++++-- milo/plugins/machineLearn.lua | 16 +++++++--- milo/plugins/storageView.lua | 4 +-- 10 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 milo/plugins/brewingStandView.lua diff --git a/milo/apis/milo.lua b/milo/apis/milo.lua index be44c09..be0dc36 100644 --- a/milo/apis/milo.lua +++ b/milo/apis/milo.lua @@ -132,10 +132,11 @@ end function Milo:getTurtleInventory() local list = { } for i = 1,16 do - -- TODO: update item db local item = self.context.introspectionModule.getInventory().getItemMeta(i) if item then - itemDB:add(item) + if not itemDB:get(item) then + itemDB:add(item) + end list[i] = item end end @@ -211,7 +212,8 @@ function Milo:mergeResources(t) item = Util.shallowCopy(v) item.count = 0 item.key = self:uniqueKey(v) - table.insert(t, item) +-- table.insert(t, item) + t[item.key] = item end end @@ -222,11 +224,19 @@ function Milo:mergeResources(t) item = Util.shallowCopy(v) item.count = 0 item.key = self:uniqueKey(v) - table.insert(t, item) + t[item.key] = item +-- table.insert(t, item) end item.has_recipe = true end + for key in pairs(Craft.machineLookup) do + local item = t[key] + if item then + item.is_craftable = true + end + end + for _,v in pairs(t) do if not v.displayName then v.displayName = itemDB:getName(v) diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index e18a752..6d7d6d5 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -44,7 +44,7 @@ function Storage:showStorage() end end if #t > 0 then - debug('Storage:') + debug('Adapter:') for _, k in pairs(t) do debug(' offline: ' .. k) end @@ -164,7 +164,6 @@ debug('STORAGE: refresh: ' .. adapter.name) adapter.dirty = false end local rcache = adapter.cache or { } --- TODO: add a method in each adapter that only updates a passed cache for key,v in pairs(rcache) do local entry = cache[key] if not entry then @@ -172,7 +171,8 @@ debug('STORAGE: refresh: ' .. adapter.name) entry.count = v.count entry.key = key cache[key] = entry - table.insert(items, entry) + items[key] = entry +-- table.insert(items, entry) else entry.count = entry.count + v.count end @@ -215,7 +215,7 @@ function Storage:provide(item, qty, slot, direction) end end - debug('miss: %s - %d', key, qty) + debug('STORAGE: MISS: %s - %d', key, qty) self.misses = self.misses + 1 for _, adapter in self:onlineAdapters() do diff --git a/milo/core/machines.lua b/milo/core/machines.lua index 208f110..cb162c0 100644 --- a/milo/core/machines.lua +++ b/milo/core/machines.lua @@ -22,6 +22,7 @@ local function saveConfig() for k,v in pairs(t) do context.config.remoteDefaults[k].adapter = v end + context.storage:initStorage() end local machinesPage = UI.Page { @@ -49,6 +50,7 @@ local machinesPage = UI.Page { ex = -7, backgroundColor = colors.cyan, }, + notification = UI.Notification { }, } function machinesPage.grid:getDisplayValues(row) @@ -68,7 +70,6 @@ function machinesPage.grid:getRowTextColor(row, selected) end function machinesPage:getList() - -- TODO: remove dedupe naming in perf code ? for _, v in pairs(device) do if v.pullItems then if not context.config.remoteDefaults[v.name] then @@ -100,7 +101,11 @@ end function machinesPage:eventHandler(event) if event.type == 'grid_select' then - UI:setPage('machineWizard', event.selected) + if not device[event.selected.name] then + self.notification:error('Unable to edit while disconnected') + else + UI:setPage('machineWizard', event.selected) + end elseif event.type == 'remove_machine' then local machine = self.grid:getSelected() diff --git a/milo/plugins/brewingStandView.lua b/milo/plugins/brewingStandView.lua new file mode 100644 index 0000000..e4471ba --- /dev/null +++ b/milo/plugins/brewingStandView.lua @@ -0,0 +1,35 @@ +local Ansi = require('ansi') +local UI = require('ui') + +local colors = _G.colors +local device = _G.device + +local template = +[[%sBrewing stands have the ability to automatically learn recipes.%s + +Simply craft potions in the brewing stand as normal except for these conditions. +1. Place item in top slot first. +2. At least 1 bottle must be placed in the first slot. + +When finished brewing, the recipe will be available upon refreshing. + +Note that you do not need to import items from the brewing stand, this will be done automatically.]] + +local brewingStandView = UI.Window { + title = 'Storage Options', + index = 2, + backgroundColor = colors.cyan, + [1] = UI.TextArea { + x = 2, ex = -2, y = 2, ey = -2, + value = string.format(template, Ansi.yellow, Ansi.reset), + }, +} + +function brewingStandView:isValidFor(machine) + if machine.mtype == 'machine' then + local m = device[machine.name] + return m and m.type == 'minecraft:brewing_stand' + end +end + +UI:getPage('machineWizard').wizard:add({ brewingStand = brewingStandView }) diff --git a/milo/plugins/exportView.lua b/milo/plugins/exportView.lua index d231e27..0bbb679 100644 --- a/milo/plugins/exportView.lua +++ b/milo/plugins/exportView.lua @@ -51,7 +51,6 @@ function exportView:setMachine(machine) { name = 'All', value = '*' } } - -- TODO: what if device is dettached ? local m = device[machine.name] for k = 1, m.size() do table.insert(self.slots.choices, { name = k, value = k }) diff --git a/milo/plugins/importView.lua b/milo/plugins/importView.lua index 38a4dac..af6af79 100644 --- a/milo/plugins/importView.lua +++ b/milo/plugins/importView.lua @@ -51,7 +51,6 @@ function importView:setMachine(machine) { name = 'All', value = '*' } } - -- TODO: what if device is dettached ? local m = device[machine.name] for k = 1, m.size() do table.insert(self.slots.choices, { name = k, value = k }) diff --git a/milo/plugins/item.lua b/milo/plugins/item.lua index f7e0879..4c98361 100644 --- a/milo/plugins/item.lua +++ b/milo/plugins/item.lua @@ -46,14 +46,12 @@ local itemPage = UI.Page { formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash', help = 'Ignore NBT of item' }, ---[[ [6] = UI.Button { x = 2, y = -2, width = 10, - formLabel = 'Redstone', - event = 'show_rs', + formLabel = 'Machine', + event = 'select_machine', text = 'Configure', }, -]] infoButton = UI.Button { x = 2, y = -2, event = 'show_info', @@ -99,6 +97,30 @@ local itemPage = UI.Page { }, }, }, + machines = UI.SlideOut { + backgroundColor = colors.cyan, + titleBar = UI.TitleBar { + title = 'Select Machine', + previousPage = true, + }, + grid = UI.ScrollingGrid { + y = 2, ey = -4, + disableHeader = true, + values = context.config.remoteDefaults, + columns = { + { heading = 'Name', key = 'displayName'}, + }, + sortColumn = 'displayName', + }, + button1 = UI.Button { + x = -14, y = -2, + text = 'Ok', event = 'set_machine', + }, + button2 = UI.Button { + x = -9, y = -2, + text = 'Cancel', event = 'cancel_machine', + }, + }, info = UI.SlideOut { titleBar = UI.TitleBar { title = "Information", @@ -126,6 +148,16 @@ function itemPage:enable(item) self:focusFirst() end +function itemPage.machines.grid:isRowValid(_, value) + return value.mtype == 'machine' +end + +function itemPage.machines.grid:getDisplayValues(row) + row = Util.shallowCopy(row) + row.displayName = row.displayName or row.name + return row +end + function itemPage.rsControl:enable() local devices = self.form[1].choices Util.clear(devices) @@ -160,6 +192,18 @@ function itemPage:eventHandler(event) elseif event.type == 'show_rs' then self.rsControl:show() + elseif event.type == 'select_machine' then + self.machines.grid:update() + self.machines.grid:setIndex(1) + self.machines:show() + + elseif event.type == 'set_machine' then + --TODO save machine + self.machines:hide() + + elseif event.type == 'cancel_machine' then + self.machines:hide() + elseif event.type == 'show_info' then local value = string.format('%s%s%s\n%s\n', diff --git a/milo/plugins/listing.lua b/milo/plugins/listing.lua index aab75c3..1c8ed15 100644 --- a/milo/plugins/listing.lua +++ b/milo/plugins/listing.lua @@ -172,7 +172,7 @@ function listingPage:eventHandler(event) end elseif event.type == 'refresh' then - self:refresh() + self:refresh(true) self.grid:draw() self.statusBar.filter:focus() @@ -257,8 +257,12 @@ function listingPage:disable() UI.Page.disable(self) end -function listingPage:refresh() - self.allItems = Milo:refreshItems() +function listingPage:refresh(force) + if force then + self.allItems = Milo:refreshItems() + else + self.allItems = Milo:listItems() + end Milo:mergeResources(self.allItems) self:applyFilter() end diff --git a/milo/plugins/machineLearn.lua b/milo/plugins/machineLearn.lua index d1197e2..1a3bddd 100644 --- a/milo/plugins/machineLearn.lua +++ b/milo/plugins/machineLearn.lua @@ -14,7 +14,7 @@ local machineLearnWizard = UI.Page { wizard = UI.Wizard { y = 2, ey = -2, pages = { - machine = UI.Window { + machines = UI.Window { index = 1, grid = UI.ScrollingGrid { y = 2, ey = -2, @@ -46,15 +46,23 @@ Example: Slot 1 is the top slot in a furnace.]], local pages = machineLearnWizard.wizard.pages local machine -function pages.machine.grid:getDisplayValues(row) +function pages.machines.grid:isRowValid(_, value) + return value.mtype == 'machine' and value.adapter and value.adapter.online +end + +function pages.machines.grid:getDisplayValues(row) row = Util.shallowCopy(row) row.displayName = row.displayName or row.name return row end -function pages.machine:validate() +function pages.machines:enable() + self.grid:update() + UI.Window.enable(self) +end + +function pages.machines:validate() --- TODO: validation should only be invoked when moving forward (i think) -- TODO: index number validation in wizard local selected = self.grid:getSelected() diff --git a/milo/plugins/storageView.lua b/milo/plugins/storageView.lua index 82f51a8..99856ca 100644 --- a/milo/plugins/storageView.lua +++ b/milo/plugins/storageView.lua @@ -24,7 +24,7 @@ local storageView = UI.Window { }, [3] = UI.Text { x = 16, ex = -2, y = 3, - value = 'minecraft:xxxxx:0' + value = '', }, [4] = UI.Checkbox { formLabel = 'Void', formKey = 'voidExcess', @@ -32,7 +32,7 @@ local storageView = UI.Window { pruneEmpty = true, }, [5] = UI.Checkbox { - formLabel = 'Partition', formKey = 'voidExcess', + formLabel = 'Partition', formKey = 'partition', help = 'TODO', pruneEmpty = true, },