milo bugfixes + enderchest app
This commit is contained in:
@@ -184,4 +184,6 @@ os.queueEvent(
|
|||||||
context.storage:isOnline() and 'storage_online' or 'storage_offline',
|
context.storage:isOnline() and 'storage_online' or 'storage_offline',
|
||||||
context.storage:isOnline())
|
context.storage:isOnline())
|
||||||
|
|
||||||
|
--os.queueEvent('milo_cycle')
|
||||||
|
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ function Storage:initStorage()
|
|||||||
os.queueEvent(self.storageOnline and 'storage_online' or 'storage_offline', online)
|
os.queueEvent(self.storageOnline and 'storage_online' or 'storage_offline', online)
|
||||||
_G._debug('Storage: %s', self.storageOnline and 'online' or 'offline')
|
_G._debug('Storage: %s', self.storageOnline and 'online' or 'offline')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:listItems()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Storage:saveConfiguration()
|
function Storage:saveConfiguration()
|
||||||
|
|||||||
61
milo/apps/enderchest.lua
Normal file
61
milo/apps/enderchest.lua
Normal 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()
|
||||||
@@ -168,10 +168,12 @@ function page:eject(amount)
|
|||||||
amount = item.maxCount or 64
|
amount = item.maxCount or 64
|
||||||
elseif amount == 'all' then
|
elseif amount == 'all' then
|
||||||
item = Milo:getItem(Milo:listItems(), item)
|
item = Milo:getItem(Milo:listItems(), item)
|
||||||
amount = item.count
|
if item then
|
||||||
|
amount = item.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if amount > 0 then
|
if item and amount > 0 then
|
||||||
item = Util.shallowCopy(item)
|
item = Util.shallowCopy(item)
|
||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
||||||
local request = Milo:craftAndEject(item, amount)
|
local request = Milo:craftAndEject(item, amount)
|
||||||
|
|||||||
@@ -69,11 +69,18 @@ UI:getPage('nodeWizard').wizard:add({ activity = wizardPage })
|
|||||||
|
|
||||||
--[[ Display ]]--
|
--[[ Display ]]--
|
||||||
local function createPage(node)
|
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 {
|
local page = UI.Page {
|
||||||
parent = UI.Device {
|
parent = monitor,
|
||||||
device = node.adapter,
|
|
||||||
textScale = node.textScale or .5,
|
|
||||||
},
|
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
ey = -6,
|
ey = -6,
|
||||||
columns = {
|
columns = {
|
||||||
@@ -161,7 +168,7 @@ local function createPage(node)
|
|||||||
function page:refresh()
|
function page:refresh()
|
||||||
local t = context.storage.cache
|
local t = context.storage.cache
|
||||||
|
|
||||||
if not self.lastItems then
|
if t and not self.lastItems then
|
||||||
self.lastItems = { }
|
self.lastItems = { }
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
self.lastItems[k] = {
|
self.lastItems[k] = {
|
||||||
|
|||||||
@@ -67,13 +67,19 @@ end
|
|||||||
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
|
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
|
||||||
|
|
||||||
--[[ Display ]]
|
--[[ Display ]]
|
||||||
-- TODO: some way to cancel a job
|
|
||||||
local function createPage(node)
|
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 {
|
local page = UI.Page {
|
||||||
parent = UI.Device {
|
parent = monitor,
|
||||||
device = node.adapter,
|
|
||||||
textScale = node.textScale or .5,
|
|
||||||
},
|
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
ey = -6,
|
ey = -6,
|
||||||
sortColumn = 'index',
|
sortColumn = 'index',
|
||||||
|
|||||||
Reference in New Issue
Block a user