This commit is contained in:
kepler155c
2018-10-24 06:51:05 -04:00
parent 9664077f2e
commit e45aad7ed0
8 changed files with 122 additions and 60 deletions

View File

@@ -22,7 +22,7 @@ local crops = Util.readTable(CONFIG_FILE) or {
['minecraft:potatoes'] =
{ seed = 'minecraft:potato', mature = 7, action = 'plant' },
['minecraft:beetroots'] =
{ seed = 'minecraft:beetroot_seeds', mature = 3, 'plant' },
{ seed = 'minecraft:beetroot_seeds', mature = 3, action = 'plant' },
['minecraft:reeds'] = { action = 'bash' },
['minecraft:melon_block'] = { action = 'smash' },
['minecraft:pumpkin'] = { action = 'smash' },

View File

@@ -1,28 +1,55 @@
_G.requireInjector()
local Terminal = require('terminal')
local Util = require('util')
local shell = _ENV.shell
local term = _G.term
local options = {
scale = { arg = 's', type = 'flag', value = false,
desc = 'Set monitor to .5 text scaling' },
resize = { arg = 'r', type = 'flag', value = false,
desc = 'Resize terminal to monitor size' },
execute = { arg = 'e', type = 'string',
desc = 'Execute a program' },
monitor = { arg = 'm', type = 'string', value = 'monitor',
desc = 'Name of monitor' },
help = { arg = 'h', type = 'flag', value = false,
desc = 'Displays the options' },
}
local args = { ... }
local mon = _G.device[table.remove(args, 1) or 'monitor']
if not Util.getOptions(options, args) then
return
end
local mon = _G.device[options.monitor.value]
if not mon then
error('mirror: Invalid device')
error('mirror: Invalid device')
end
mon.clear()
mon.setTextScale(.5)
if options.scale.value then
mon.setTextScale(.5)
end
mon.setCursorPos(1, 1)
local oterm = Terminal.copy(term.current())
Terminal.mirror(term.current(), mon)
term.current().getSize = mon.getSize
if #args > 0 then
shell.run(unpack(args))
Terminal.copy(oterm, term.current())
mon.setCursorBlink(false)
if options.resize.value then
term.current().getSize = mon.getSize
end
debug(args)
debug(options)
if options.execute.value then
-- TODO: allow args to be passed
shell.run(options.execute.value) -- unpack(args))
Terminal.copy(oterm, term.current())
mon.setCursorBlink(false)
end

View File

@@ -73,6 +73,7 @@ local Util = require('util')
local InventoryAdapter = require('inventoryAdapter')
local device = _G.device
local fs = _G.fs
local multishell = _ENV.multishell
local shell = _ENV.shell
@@ -92,38 +93,6 @@ if not modem or not modem.getNameLocal then
error('Wired modem is not connected')
end
local storage = { }
for k,v in pairs(config.remoteDefaults) do
if v.mtype == 'storage' then
storage[k] = v
elseif v.mtype == 'controller' then
-- TODO: look for controller
end
end
local inventoryAdapter = InventoryAdapter.wrap({ remoteDefaults = storage })
if not inventoryAdapter then
error('Invalid inventory configuration')
end
-- TODO: cleanup
for _, v in pairs(modem.getNamesRemote()) do
local remote = Peripheral.get({ name = v })
if remote.pullItems then
if not config.remoteDefaults[v] then
config.remoteDefaults[v] = {
name = v,
mtype = 'ignore',
}
else
config.remoteDefaults[v].name = v
end
if not config.remoteDefaults[v].mtype then
config.remoteDefaults[v].mtype = 'ignore'
end
end
end
local function loadResources()
local resources = Util.readTable(Milo.RESOURCE_FILE) or { }
for k,v in pairs(resources) do
@@ -135,13 +104,50 @@ end
local context = {
config = config,
inventoryAdapter = inventoryAdapter,
resources = loadResources(),
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
learnTypes = { },
machineTypes = { },
}
local function initStorage()
debug('Initializing storage')
local storage = { }
for k,v in pairs(config.remoteDefaults) do
if v.mtype == 'storage' and device[v.name] then
storage[k] = v
end
end
debug(storage)
context.inventoryAdapter = InventoryAdapter.wrap({ remoteDefaults = storage })
if not context.inventoryAdapter then
error('Invalid inventory configuration')
end
end
Event.on({ 'device_attach' }, function(_, dev)
debug('attach: ' .. dev)
if config.remoteDefaults[dev] and
config.remoteDefaults[dev].mtype == 'storage' then
initStorage()
end
end)
Event.on({ 'device_detach' }, function(_, dev)
debug('detach: ' .. dev)
if config.remoteDefaults[dev] and
config.remoteDefaults[dev].mtype == 'storage' then
Milo:pauseCrafting()
debug('Crafting paused')
Milo:showError('Check log')
initStorage()
end
end)
initStorage()
Milo:init(context)
local function loadDirectory(dir)
@@ -165,9 +171,7 @@ Milo:clearGrid()
local page = UI:getPage('listing')
UI:setPage(page)
page:setFocus(page.statusBar.filter)
-- TODO: Event.on('device_detach', function() end)
page:setFocus(page.statusBar.filter) -- todo: move this line into listing code
Event.onInterval(5, function()
if not Milo:isCraftingPaused() then

View File

@@ -29,6 +29,7 @@ end
function Milo:pauseCrafting()
self.craftingPaused = true
Milo:showError('Crafting Paused')
end
function Milo:resumeCrafting()
@@ -80,12 +81,12 @@ function Milo:registerTask(task)
end
function Milo:showError(msg)
term.clear()
self.context.jobList:showError()
print(msg)
print('rebooting in 5 secs')
os.sleep(5)
os.reboot()
--term.clear()
self.context.jobList:showError(msg)
--print(msg)
--print('rebooting in 5 secs')
--os.sleep(5)
--os.reboot()
end
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
@@ -381,7 +382,7 @@ function Milo:craftItems(craftList)
end
self:updateCraftingStatus(craftList)
for _,v in pairs(craftList) do
debug(v)
--debug(v)
end
end

View File

@@ -64,7 +64,7 @@ function NetworkedAdapter:listItems(throttle)
return self.items
end
self.listCount = self.listCount + 1
debug(self.listCount)
--debug(self.listCount)
-- todo: only listItems from dirty remotes
-- todo: better handling of empty inventories

View File

@@ -1,4 +1,5 @@
local Config = require('config')
local Event = require('event')
local itemDB = require('itemDB')
local Milo = require('milo')
local UI = require('ui')
@@ -29,9 +30,35 @@ local machinesPage = UI.Page {
},
}
function machinesPage:getList()
-- TODO: remove dedupe naming in perf code ?
for _, v in pairs(device) do
if v.pullItems then
if not context.config.remoteDefaults[v.name] then
context.config.remoteDefaults[v.name] = {
name = v.name,
mtype = 'ignore',
}
end
end
end
end
function machinesPage:enable()
self:getList()
self.grid:update()
UI.Page.enable(self)
self.handler = Event.on({ 'device_attach', 'device_detach'}, function()
self:getList()
self.grid:update()
self.grid:draw()
self.grid:sync()
end)
end
function machinesPage:disable()
UI.Page.disable(self)
Event.off(self.handler)
end
function machinesPage.grid:getDisplayValues(row)
@@ -41,6 +68,9 @@ function machinesPage.grid:getDisplayValues(row)
end
function machinesPage.grid:getRowTextColor(row, selected)
if not device[row.name] then
return colors.red
end
if row.mtype == 'ignore' then
return colors.lightGray
end
@@ -205,9 +235,6 @@ function machineWizard:eventHandler(event)
UI:setPreviousPage()
elseif event.type == 'collapse' then
self.items:hide()
elseif event.type == 'enable_view' then
local current = event.next or event.prev
self.titleBar.title = current.title or 'Machine'

View File

@@ -82,6 +82,7 @@ local listingPage = UI.Page {
[ 'control-e' ] = 'eject',
[ 'control-s' ] = 'eject_stack',
[ 'control-m' ] = 'machines',
[ 'control-l' ] = 'resume',
},
displayMode = 0,
}
@@ -113,10 +114,12 @@ function listingPage.grid:getDisplayValues(row)
end
function listingPage:eventHandler(event)
debug(event)
if event.type == 'quit' then
UI:exitPullEvents()
elseif event.type == 'resume' then
Milo:resumeCrafting()
elseif event.type == 'eject' then
local item = self.grid:getSelected()
if item then

View File

@@ -10,7 +10,7 @@ function PotionImportTask:cycle(context)
for _, v in pairs(device) do
if v.type == 'minecraft:brewing_stand' and v.getBrewTime() == 0 then
local list = v.list()
if not list[4] and list[1] then
if not list[4] then
for i = 1, 3 do
if list[i] then
context.inventoryAdapter:insert(i, 1, nil, list[i], v.name)