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

@@ -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()

View File

@@ -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 })

View File

@@ -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 })

View File

@@ -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 })

View File

@@ -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()

View File

@@ -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

View File

@@ -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' },
},

View File

@@ -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 })

View File

@@ -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 })