diff --git a/milo/Milo.lua b/milo/Milo.lua index c09cb7b..758bc1d 100644 --- a/milo/Milo.lua +++ b/milo/Milo.lua @@ -184,4 +184,6 @@ os.queueEvent( context.storage:isOnline() and 'storage_online' or 'storage_offline', context.storage:isOnline()) +--os.queueEvent('milo_cycle') + UI:pullEvents() diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index ae99bb0..1eae11e 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -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() diff --git a/milo/apps/enderchest.lua b/milo/apps/enderchest.lua new file mode 100644 index 0000000..1e88cb8 --- /dev/null +++ b/milo/apps/enderchest.lua @@ -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() diff --git a/milo/core/listing.lua b/milo/core/listing.lua index dc00592..9369aaa 100644 --- a/milo/core/listing.lua +++ b/milo/core/listing.lua @@ -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) diff --git a/milo/plugins/activityView.lua b/milo/plugins/activityView.lua index 4b0dbbe..2fa0357 100644 --- a/milo/plugins/activityView.lua +++ b/milo/plugins/activityView.lua @@ -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] = { diff --git a/milo/plugins/jobMonitor.lua b/milo/plugins/jobMonitor.lua index 95b2020..89334c8 100644 --- a/milo/plugins/jobMonitor.lua +++ b/milo/plugins/jobMonitor.lua @@ -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',