milo bugfixes + enderchest app

This commit is contained in:
kepler155c@gmail.com
2019-01-02 23:57:06 -05:00
parent 859977f75c
commit 00e698eb18
6 changed files with 92 additions and 12 deletions

View File

@@ -184,4 +184,6 @@ os.queueEvent(
context.storage:isOnline() and 'storage_online' or 'storage_offline',
context.storage:isOnline())
--os.queueEvent('milo_cycle')
UI:pullEvents()

View File

@@ -128,6 +128,8 @@ function Storage:initStorage()
os.queueEvent(self.storageOnline and 'storage_online' or 'storage_offline', online)
_G._debug('Storage: %s', self.storageOnline and 'online' or 'offline')
end
self:listItems()
end
function Storage:saveConfiguration()

61
milo/apps/enderchest.lua Normal file
View File

@@ -0,0 +1,61 @@
--[[
Send items to a players enderchest.
--]]
local Event = require('event')
local Util = require('util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/enderchest.lua'
local enderChest = device.manipulator and
device.manipulator.getEnder or
error('Must be connected to a manipulator with a bound introspection module')
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('packages/milo/apps/enderchest')]])
end
local directions = Util.transpose {
'north', 'south', 'east', 'west', 'up', 'down'
}
Event.on('turtle_inventory', function()
print('processing')
local s, m = pcall(function()
local direction
for _, d in pairs(enderChest().getTransferLocations()) do
if directions[d] then
direction = d
break
end
end
if not direction then
error('Unable to determine transfer direction')
end
turtle.eachFilledSlot(function(s)
enderChest().pullItems(direction, s.index)
end)
end)
if s and not m then
_G.printError(m)
end
print('idle')
end)
Event.onInterval(5, function()
-- for some reason, it keeps stalling ...
os.queueEvent('turtle_inventory')
end)
os.queueEvent('turtle_inventory')
Event.pullEvents()

View File

@@ -168,10 +168,12 @@ function page:eject(amount)
amount = item.maxCount or 64
elseif amount == 'all' then
item = Milo:getItem(Milo:listItems(), item)
amount = item.count
if item then
amount = item.count
end
end
if amount > 0 then
if item and amount > 0 then
item = Util.shallowCopy(item)
self.grid.values[self.grid.sorted[self.grid.index]] = item
local request = Milo:craftAndEject(item, amount)

View File

@@ -69,11 +69,18 @@ UI:getPage('nodeWizard').wizard:add({ activity = wizardPage })
--[[ Display ]]--
local function createPage(node)
local monitor = UI.Device {
device = node.adapter,
textScale = node.textScale or .5,
}
function monitor:resize()
self.textScale = node.textScale or .5
UI.Device.resize(self)
end
local page = UI.Page {
parent = UI.Device {
device = node.adapter,
textScale = node.textScale or .5,
},
parent = monitor,
grid = UI.Grid {
ey = -6,
columns = {
@@ -161,7 +168,7 @@ local function createPage(node)
function page:refresh()
local t = context.storage.cache
if not self.lastItems then
if t and not self.lastItems then
self.lastItems = { }
for k,v in pairs(t) do
self.lastItems[k] = {

View File

@@ -67,13 +67,19 @@ end
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
--[[ Display ]]
-- TODO: some way to cancel a job
local function createPage(node)
local monitor = UI.Device {
device = node.adapter,
textScale = node.textScale or .5,
}
function monitor:resize()
self.textScale = node.textScale or .5
UI.Device.resize(self)
end
local page = UI.Page {
parent = UI.Device {
device = node.adapter,
textScale = node.textScale or .5,
},
parent = monitor,
grid = UI.Grid {
ey = -6,
sortColumn = 'index',