milo node rework

This commit is contained in:
kepler155c
2018-11-11 21:59:13 -05:00
parent fe1fc6ea93
commit 9ee8ce9f33
13 changed files with 317 additions and 83 deletions

View File

@@ -1,25 +1,47 @@
local Ansi = require('ansi')
local Event = require('event')
local Milo = require('milo')
local Peripheral = require('peripheral')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local context = Milo:getContext()
local mon = Peripheral.lookup(context.config.activityMonitor)
local colors = _G.colors
local context = Milo:getContext()
local device = _G.device
local monitor = context.storage:getSingleNode('activity')
local ActivityTask = {
name = 'activity',
priority = 30,
--[[ Configuration Page ]]--
local template =
[[%sDisplays the amount of items entering or leaving storage%s
Right-clicking on the activity monitor will reset the totals.
%sMilo must be restarted to activate diplay.
]]
local activityWizardPage = UI.Window {
title = 'Activity Monitor',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.yellow, Ansi.reset, Ansi.orange),
},
}
if not mon then
return
function activityWizardPage:isValidType(node)
local m = device[node.name]
return m and m.type == 'monitor' and { name = 'Activity Monitor', value = 'activity' }
end
function activityWizardPage:isValidFor(node)
return node.mtype == 'activity'
end
UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage })
local page = UI.Window {
parent = UI.Device {
device = mon,
device = monitor.adapter,
textScale = .5,
},
grid = UI.Grid {
@@ -130,17 +152,23 @@ Event.on({ 'storage_offline', 'storage_online' }, function()
end)
Event.on('monitor_touch', function(_, side)
if side == mon.side then
if side == monitor.adapter.side then
page:reset()
page:sync()
end
end)
page:draw()
page:sync()
--[[ Task ]]--
local ActivityTask = {
name = 'activity',
priority = 30,
}
function ActivityTask:cycle()
page:update()
end
Milo:registerTask(ActivityTask)
page:draw()
page:sync()

View File

@@ -16,7 +16,7 @@ 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',
title = 'Brewing Stand',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
@@ -25,11 +25,13 @@ local brewingStandView = UI.Window {
},
}
function brewingStandView:isValidType(node)
local m = device[node.name]
return m and m.type == 'minecraft:brewing_stand'and { name = 'Brewing Stand', value = 'brewingStand' }
end
function brewingStandView:isValidFor(node)
if node.mtype == 'machine' then
local m = device[node.name]
return m and m.type == 'minecraft:brewing_stand'
end
return node.mtype == 'brewingStand'
end
UI:getPage('nodeWizard').wizard:add({ brewingStand = brewingStandView })

View File

@@ -36,6 +36,11 @@ local exportView = UI.Window {
},
}
function exportView:isValidType(node)
local m = device[node.name]
return m and m.pullItems and { name = 'Generic Inventory', value = 'machine' }
end
function exportView:isValidFor(node)
return node.mtype == 'machine'
end

View File

@@ -36,6 +36,11 @@ local importView = UI.Window {
},
}
function importView:isValidType(node)
local m = device[node.name]
return m and m.pullItems and { name = 'Generic Inventory', value = 'machine' }
end
function importView:isValidFor(node)
return node.mtype == 'machine'
end

View File

@@ -0,0 +1,33 @@
local Ansi = require('ansi')
local UI = require('ui')
local colors = _G.colors
local device = _G.device
--[[ Configuration Screen ]]
local template =
[[%sInput Chest%s
Any items placed in this chest will be imported into storage.
]]
local inputChestWizardPage = UI.Window {
title = 'Input Chest',
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 inputChestWizardPage:isValidType(node)
local m = device[node.name]
return m and m.pullItems and { name = 'Input Chest', value = 'input' }
end
function inputChestWizardPage:isValidFor(node)
return node.mtype == 'input'
end
UI:getPage('nodeWizard').wizard:add({ inputChest = inputChestWizardPage })

View File

@@ -1,21 +1,53 @@
local Ansi = require('ansi')
local Craft = require('turtle.craft')
local itemDB = require('itemDB')
local Milo = require('milo')
local Peripheral = require('peripheral')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local context = Milo:getContext()
local device = _G.device
local monNode = context.storage:getSingleNode('jobs')
local context = Milo:getContext()
local mon = Peripheral.lookup(context.config.monitor) or
error('Monitor is not attached')
--[[ Configuration Screen ]]
local template =
[[%sDisplays the crafting progress%s
%sMilo must be restarted to activate diplay.
]]
local jobsWizardPage = UI.Window {
title = 'Crafting Monitor',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.yellow, Ansi.reset, Ansi.orange),
},
}
function jobsWizardPage:isValidType(node)
local m = device[node.name]
return m and m.type == 'monitor' and { name = 'Crafting Monitor', value = 'jobs' }
end
function jobsWizardPage:isValidFor(node)
return node.mtype == 'jobs'
end
UI:getPage('nodeWizard').wizard:add({ jobs = jobsWizardPage })
--[[ Display ]]
if not monNode then
return
end
-- TODO: some way to cancel a job
local jobMonitor = UI.Page {
parent = UI.Device {
device = mon,
device = monNode.adapter,
textScale = .5,
},
grid = UI.Grid {
@@ -90,6 +122,7 @@ jobMonitor:enable()
jobMonitor:draw()
jobMonitor:sync()
--[[ Task ]]
local jobMonitorTask = {
name = 'job status',
priority = 80,

View File

@@ -0,0 +1,64 @@
local Ansi = require('ansi')
local Milo = require('milo')
local Sync = require('sync')
local UI = require('ui')
local colors = _G.colors
local device = _G.device
local turtle = _G.turtle
--[[ Configuration Screen ]]
local template =
[[%sBound Manipulator%s
Automatically import items into storage from your ender chest.
]]
local wizardPage = UI.Window {
title = 'Manipulator',
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 wizardPage:isValidType(node)
local m = device[node.name]
return m and
m.type == 'manipulator' and
m.getEnder and
{ name = 'Manipulator', value = 'manipulator' }
end
function wizardPage:isValidFor(node)
return node.mtype == 'manipulator'
end
UI:getPage('nodeWizard').wizard:add({ manipulator = wizardPage })
local task = {
name = 'manipulator',
priority = 15,
}
function task:cycle(context)
local function filter(v)
return v.adapter.getEnder
end
for manipulator in context.storage:filterActive('manipulator', filter) do
for slot, item in pairs(manipulator.adapter.getEnder().list()) do
Sync.sync(turtle, function()
manipulator.adapter.getEnder().pushItems(
context.localName,
slot,
item.count)
Milo:clearGrid()
end)
end
end
end
Milo:registerTask(task)

View File

@@ -70,4 +70,4 @@ function dispenserView:setNode(node)
self.form:setValues(node.redstone)
end
UI:getPage('nodeWizard').wizard:add({ dispenser = dispenserView })
--UI:getPage('nodeWizard').wizard:add({ dispenser = dispenserView })

View File

@@ -29,7 +29,7 @@ local function client(socket)
local manipulator = getManipulatorForUser(user)
if not manipulator then
_debug('REMOTE: Manipulator with introspection module bound with user not found. Closing connection.')
_G._debug('REMOTE: Manipulator with introspection module bound with user not found. Closing connection.')
socket:write({
msg = 'Manipulator not found'
})
@@ -37,7 +37,7 @@ local function client(socket)
return
end
_debug('REMOTE: all good')
_G._debug('REMOTE: all good')
socket:write({
data = 'ok',
})
@@ -98,12 +98,14 @@ local function client(socket)
request.requested,
data.item)
turtle.eachFilledSlot(function(slot)
manipulator.getInventory().pullItems(
context.localName,
slot.index,
transferred)
end)
if transferred > 0 then
turtle.eachFilledSlot(function(slot)
manipulator.getInventory().pullItems(
context.localName,
slot.index,
slot.count)
end)
end
end)
end

View File

@@ -48,6 +48,11 @@ function storageView:validate()
return self.form:save()
end
function storageView:isValidType(node)
local m = device[node.name]
return m and m.pullItems and { name = 'Storage', value = 'storage' }
end
function storageView:isValidFor(node)
return node.mtype == 'storage'
end

View File

@@ -0,0 +1,35 @@
local Ansi = require('ansi')
local UI = require('ui')
local colors = _G.colors
local device = _G.device
--[[ Configuration Screen ]]
local template =
[[%sUse this inventory as a trashcan%s
If the number of items exceed the maximum value will be sent to this inventory.
Any items that cannot fit into a locked chest will automatically be sent to this inventory.
]]
local trashcanWizardPage = UI.Window {
title = 'Trashcan',
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 trashcanWizardPage:isValidType(node)
local m = device[node.name]
return m and m.pullItems and { name = 'Trashcan', value = 'trashcan' }
end
function trashcanWizardPage:isValidFor(node)
return node.mtype == 'trashcan'
end
UI:getPage('nodeWizard').wizard:add({ trashcan = trashcanWizardPage })