milo wip
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
35
milo/plugins/brewingStandView.lua
Normal file
35
milo/plugins/brewingStandView.lua
Normal file
@@ -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 })
|
||||
@@ -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 })
|
||||
|
||||
@@ -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 })
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user