milo wip
This commit is contained in:
@@ -132,10 +132,11 @@ end
|
|||||||
function Milo:getTurtleInventory()
|
function Milo:getTurtleInventory()
|
||||||
local list = { }
|
local list = { }
|
||||||
for i = 1,16 do
|
for i = 1,16 do
|
||||||
-- TODO: update item db
|
|
||||||
local item = self.context.introspectionModule.getInventory().getItemMeta(i)
|
local item = self.context.introspectionModule.getInventory().getItemMeta(i)
|
||||||
if item then
|
if item then
|
||||||
itemDB:add(item)
|
if not itemDB:get(item) then
|
||||||
|
itemDB:add(item)
|
||||||
|
end
|
||||||
list[i] = item
|
list[i] = item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -211,7 +212,8 @@ function Milo:mergeResources(t)
|
|||||||
item = Util.shallowCopy(v)
|
item = Util.shallowCopy(v)
|
||||||
item.count = 0
|
item.count = 0
|
||||||
item.key = self:uniqueKey(v)
|
item.key = self:uniqueKey(v)
|
||||||
table.insert(t, item)
|
-- table.insert(t, item)
|
||||||
|
t[item.key] = item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -222,11 +224,19 @@ function Milo:mergeResources(t)
|
|||||||
item = Util.shallowCopy(v)
|
item = Util.shallowCopy(v)
|
||||||
item.count = 0
|
item.count = 0
|
||||||
item.key = self:uniqueKey(v)
|
item.key = self:uniqueKey(v)
|
||||||
table.insert(t, item)
|
t[item.key] = item
|
||||||
|
-- table.insert(t, item)
|
||||||
end
|
end
|
||||||
item.has_recipe = true
|
item.has_recipe = true
|
||||||
end
|
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
|
for _,v in pairs(t) do
|
||||||
if not v.displayName then
|
if not v.displayName then
|
||||||
v.displayName = itemDB:getName(v)
|
v.displayName = itemDB:getName(v)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function Storage:showStorage()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #t > 0 then
|
if #t > 0 then
|
||||||
debug('Storage:')
|
debug('Adapter:')
|
||||||
for _, k in pairs(t) do
|
for _, k in pairs(t) do
|
||||||
debug(' offline: ' .. k)
|
debug(' offline: ' .. k)
|
||||||
end
|
end
|
||||||
@@ -164,7 +164,6 @@ debug('STORAGE: refresh: ' .. adapter.name)
|
|||||||
adapter.dirty = false
|
adapter.dirty = false
|
||||||
end
|
end
|
||||||
local rcache = adapter.cache or { }
|
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
|
for key,v in pairs(rcache) do
|
||||||
local entry = cache[key]
|
local entry = cache[key]
|
||||||
if not entry then
|
if not entry then
|
||||||
@@ -172,7 +171,8 @@ debug('STORAGE: refresh: ' .. adapter.name)
|
|||||||
entry.count = v.count
|
entry.count = v.count
|
||||||
entry.key = key
|
entry.key = key
|
||||||
cache[key] = entry
|
cache[key] = entry
|
||||||
table.insert(items, entry)
|
items[key] = entry
|
||||||
|
-- table.insert(items, entry)
|
||||||
else
|
else
|
||||||
entry.count = entry.count + v.count
|
entry.count = entry.count + v.count
|
||||||
end
|
end
|
||||||
@@ -215,7 +215,7 @@ function Storage:provide(item, qty, slot, direction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
debug('miss: %s - %d', key, qty)
|
debug('STORAGE: MISS: %s - %d', key, qty)
|
||||||
self.misses = self.misses + 1
|
self.misses = self.misses + 1
|
||||||
|
|
||||||
for _, adapter in self:onlineAdapters() do
|
for _, adapter in self:onlineAdapters() do
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ local function saveConfig()
|
|||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
context.config.remoteDefaults[k].adapter = v
|
context.config.remoteDefaults[k].adapter = v
|
||||||
end
|
end
|
||||||
|
context.storage:initStorage()
|
||||||
end
|
end
|
||||||
|
|
||||||
local machinesPage = UI.Page {
|
local machinesPage = UI.Page {
|
||||||
@@ -49,6 +50,7 @@ local machinesPage = UI.Page {
|
|||||||
ex = -7,
|
ex = -7,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
},
|
},
|
||||||
|
notification = UI.Notification { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function machinesPage.grid:getDisplayValues(row)
|
function machinesPage.grid:getDisplayValues(row)
|
||||||
@@ -68,7 +70,6 @@ function machinesPage.grid:getRowTextColor(row, selected)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function machinesPage:getList()
|
function machinesPage:getList()
|
||||||
-- TODO: remove dedupe naming in perf code ?
|
|
||||||
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.remoteDefaults[v.name] then
|
||||||
@@ -100,7 +101,11 @@ end
|
|||||||
|
|
||||||
function machinesPage:eventHandler(event)
|
function machinesPage:eventHandler(event)
|
||||||
if event.type == 'grid_select' then
|
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
|
elseif event.type == 'remove_machine' then
|
||||||
local machine = self.grid:getSelected()
|
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 = '*' }
|
{ name = 'All', value = '*' }
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TODO: what if device is dettached ?
|
|
||||||
local m = device[machine.name]
|
local m = device[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 })
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ function importView:setMachine(machine)
|
|||||||
{ name = 'All', value = '*' }
|
{ name = 'All', value = '*' }
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TODO: what if device is dettached ?
|
|
||||||
local m = device[machine.name]
|
local m = device[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 })
|
||||||
|
|||||||
@@ -46,14 +46,12 @@ local itemPage = UI.Page {
|
|||||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||||
help = 'Ignore NBT of item'
|
help = 'Ignore NBT of item'
|
||||||
},
|
},
|
||||||
--[[
|
|
||||||
[6] = UI.Button {
|
[6] = UI.Button {
|
||||||
x = 2, y = -2, width = 10,
|
x = 2, y = -2, width = 10,
|
||||||
formLabel = 'Redstone',
|
formLabel = 'Machine',
|
||||||
event = 'show_rs',
|
event = 'select_machine',
|
||||||
text = 'Configure',
|
text = 'Configure',
|
||||||
},
|
},
|
||||||
]]
|
|
||||||
infoButton = UI.Button {
|
infoButton = UI.Button {
|
||||||
x = 2, y = -2,
|
x = 2, y = -2,
|
||||||
event = 'show_info',
|
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 {
|
info = UI.SlideOut {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
title = "Information",
|
title = "Information",
|
||||||
@@ -126,6 +148,16 @@ function itemPage:enable(item)
|
|||||||
self:focusFirst()
|
self:focusFirst()
|
||||||
end
|
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()
|
function itemPage.rsControl:enable()
|
||||||
local devices = self.form[1].choices
|
local devices = self.form[1].choices
|
||||||
Util.clear(devices)
|
Util.clear(devices)
|
||||||
@@ -160,6 +192,18 @@ function itemPage:eventHandler(event)
|
|||||||
elseif event.type == 'show_rs' then
|
elseif event.type == 'show_rs' then
|
||||||
self.rsControl:show()
|
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
|
elseif event.type == 'show_info' then
|
||||||
local value =
|
local value =
|
||||||
string.format('%s%s%s\n%s\n',
|
string.format('%s%s%s\n%s\n',
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ function listingPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'refresh' then
|
elseif event.type == 'refresh' then
|
||||||
self:refresh()
|
self:refresh(true)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
self.statusBar.filter:focus()
|
self.statusBar.filter:focus()
|
||||||
|
|
||||||
@@ -257,8 +257,12 @@ function listingPage:disable()
|
|||||||
UI.Page.disable(self)
|
UI.Page.disable(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:refresh()
|
function listingPage:refresh(force)
|
||||||
self.allItems = Milo:refreshItems()
|
if force then
|
||||||
|
self.allItems = Milo:refreshItems()
|
||||||
|
else
|
||||||
|
self.allItems = Milo:listItems()
|
||||||
|
end
|
||||||
Milo:mergeResources(self.allItems)
|
Milo:mergeResources(self.allItems)
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ local machineLearnWizard = UI.Page {
|
|||||||
wizard = UI.Wizard {
|
wizard = UI.Wizard {
|
||||||
y = 2, ey = -2,
|
y = 2, ey = -2,
|
||||||
pages = {
|
pages = {
|
||||||
machine = UI.Window {
|
machines = UI.Window {
|
||||||
index = 1,
|
index = 1,
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2, ey = -2,
|
y = 2, ey = -2,
|
||||||
@@ -46,15 +46,23 @@ Example: Slot 1 is the top slot in a furnace.]],
|
|||||||
local pages = machineLearnWizard.wizard.pages
|
local pages = machineLearnWizard.wizard.pages
|
||||||
local machine
|
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 = Util.shallowCopy(row)
|
||||||
row.displayName = row.displayName or row.name
|
row.displayName = row.displayName or row.name
|
||||||
return row
|
return row
|
||||||
end
|
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
|
-- TODO: index number validation in wizard
|
||||||
|
|
||||||
local selected = self.grid:getSelected()
|
local selected = self.grid:getSelected()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ local storageView = UI.Window {
|
|||||||
},
|
},
|
||||||
[3] = UI.Text {
|
[3] = UI.Text {
|
||||||
x = 16, ex = -2, y = 3,
|
x = 16, ex = -2, y = 3,
|
||||||
value = 'minecraft:xxxxx:0'
|
value = '',
|
||||||
},
|
},
|
||||||
[4] = UI.Checkbox {
|
[4] = UI.Checkbox {
|
||||||
formLabel = 'Void', formKey = 'voidExcess',
|
formLabel = 'Void', formKey = 'voidExcess',
|
||||||
@@ -32,7 +32,7 @@ local storageView = UI.Window {
|
|||||||
pruneEmpty = true,
|
pruneEmpty = true,
|
||||||
},
|
},
|
||||||
[5] = UI.Checkbox {
|
[5] = UI.Checkbox {
|
||||||
formLabel = 'Partition', formKey = 'voidExcess',
|
formLabel = 'Partition', formKey = 'partition',
|
||||||
help = 'TODO',
|
help = 'TODO',
|
||||||
pruneEmpty = true,
|
pruneEmpty = true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user