milo wip
This commit is contained in:
@@ -22,7 +22,7 @@ local crops = Util.readTable(CONFIG_FILE) or {
|
|||||||
['minecraft:potatoes'] =
|
['minecraft:potatoes'] =
|
||||||
{ seed = 'minecraft:potato', mature = 7, action = 'plant' },
|
{ seed = 'minecraft:potato', mature = 7, action = 'plant' },
|
||||||
['minecraft:beetroots'] =
|
['minecraft:beetroots'] =
|
||||||
{ seed = 'minecraft:beetroot_seeds', mature = 3, 'plant' },
|
{ seed = 'minecraft:beetroot_seeds', mature = 3, action = 'plant' },
|
||||||
['minecraft:reeds'] = { action = 'bash' },
|
['minecraft:reeds'] = { action = 'bash' },
|
||||||
['minecraft:melon_block'] = { action = 'smash' },
|
['minecraft:melon_block'] = { action = 'smash' },
|
||||||
['minecraft:pumpkin'] = { action = 'smash' },
|
['minecraft:pumpkin'] = { action = 'smash' },
|
||||||
|
|||||||
@@ -1,28 +1,55 @@
|
|||||||
_G.requireInjector()
|
_G.requireInjector()
|
||||||
|
|
||||||
local Terminal = require('terminal')
|
local Terminal = require('terminal')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
local term = _G.term
|
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 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
|
if not mon then
|
||||||
error('mirror: Invalid device')
|
error('mirror: Invalid device')
|
||||||
end
|
end
|
||||||
|
|
||||||
mon.clear()
|
mon.clear()
|
||||||
mon.setTextScale(.5)
|
|
||||||
|
if options.scale.value then
|
||||||
|
mon.setTextScale(.5)
|
||||||
|
end
|
||||||
mon.setCursorPos(1, 1)
|
mon.setCursorPos(1, 1)
|
||||||
|
|
||||||
local oterm = Terminal.copy(term.current())
|
local oterm = Terminal.copy(term.current())
|
||||||
Terminal.mirror(term.current(), mon)
|
Terminal.mirror(term.current(), mon)
|
||||||
|
|
||||||
term.current().getSize = mon.getSize
|
if options.resize.value then
|
||||||
|
term.current().getSize = mon.getSize
|
||||||
if #args > 0 then
|
end
|
||||||
shell.run(unpack(args))
|
|
||||||
Terminal.copy(oterm, term.current())
|
debug(args)
|
||||||
|
debug(options)
|
||||||
mon.setCursorBlink(false)
|
|
||||||
|
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
|
end
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ local Util = require('util')
|
|||||||
|
|
||||||
local InventoryAdapter = require('inventoryAdapter')
|
local InventoryAdapter = require('inventoryAdapter')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
@@ -92,38 +93,6 @@ if not modem or not modem.getNameLocal then
|
|||||||
error('Wired modem is not connected')
|
error('Wired modem is not connected')
|
||||||
end
|
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 function loadResources()
|
||||||
local resources = Util.readTable(Milo.RESOURCE_FILE) or { }
|
local resources = Util.readTable(Milo.RESOURCE_FILE) or { }
|
||||||
for k,v in pairs(resources) do
|
for k,v in pairs(resources) do
|
||||||
@@ -135,13 +104,50 @@ end
|
|||||||
|
|
||||||
local context = {
|
local context = {
|
||||||
config = config,
|
config = config,
|
||||||
inventoryAdapter = inventoryAdapter,
|
|
||||||
resources = loadResources(),
|
resources = loadResources(),
|
||||||
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
|
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
|
||||||
learnTypes = { },
|
learnTypes = { },
|
||||||
machineTypes = { },
|
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)
|
Milo:init(context)
|
||||||
|
|
||||||
local function loadDirectory(dir)
|
local function loadDirectory(dir)
|
||||||
@@ -165,9 +171,7 @@ Milo:clearGrid()
|
|||||||
|
|
||||||
local page = UI:getPage('listing')
|
local page = UI:getPage('listing')
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
page:setFocus(page.statusBar.filter)
|
page:setFocus(page.statusBar.filter) -- todo: move this line into listing code
|
||||||
|
|
||||||
-- TODO: Event.on('device_detach', function() end)
|
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
Event.onInterval(5, function()
|
||||||
if not Milo:isCraftingPaused() then
|
if not Milo:isCraftingPaused() then
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ end
|
|||||||
|
|
||||||
function Milo:pauseCrafting()
|
function Milo:pauseCrafting()
|
||||||
self.craftingPaused = true
|
self.craftingPaused = true
|
||||||
|
Milo:showError('Crafting Paused')
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:resumeCrafting()
|
function Milo:resumeCrafting()
|
||||||
@@ -80,12 +81,12 @@ function Milo:registerTask(task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Milo:showError(msg)
|
function Milo:showError(msg)
|
||||||
term.clear()
|
--term.clear()
|
||||||
self.context.jobList:showError()
|
self.context.jobList:showError(msg)
|
||||||
print(msg)
|
--print(msg)
|
||||||
print('rebooting in 5 secs')
|
--print('rebooting in 5 secs')
|
||||||
os.sleep(5)
|
--os.sleep(5)
|
||||||
os.reboot()
|
--os.reboot()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
||||||
@@ -381,7 +382,7 @@ function Milo:craftItems(craftList)
|
|||||||
end
|
end
|
||||||
self:updateCraftingStatus(craftList)
|
self:updateCraftingStatus(craftList)
|
||||||
for _,v in pairs(craftList) do
|
for _,v in pairs(craftList) do
|
||||||
debug(v)
|
--debug(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function NetworkedAdapter:listItems(throttle)
|
|||||||
return self.items
|
return self.items
|
||||||
end
|
end
|
||||||
self.listCount = self.listCount + 1
|
self.listCount = self.listCount + 1
|
||||||
debug(self.listCount)
|
--debug(self.listCount)
|
||||||
|
|
||||||
-- todo: only listItems from dirty remotes
|
-- todo: only listItems from dirty remotes
|
||||||
-- todo: better handling of empty inventories
|
-- todo: better handling of empty inventories
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
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()
|
function machinesPage:enable()
|
||||||
|
self:getList()
|
||||||
self.grid:update()
|
self.grid:update()
|
||||||
UI.Page.enable(self)
|
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
|
end
|
||||||
|
|
||||||
function machinesPage.grid:getDisplayValues(row)
|
function machinesPage.grid:getDisplayValues(row)
|
||||||
@@ -41,6 +68,9 @@ function machinesPage.grid:getDisplayValues(row)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function machinesPage.grid:getRowTextColor(row, selected)
|
function machinesPage.grid:getRowTextColor(row, selected)
|
||||||
|
if not device[row.name] then
|
||||||
|
return colors.red
|
||||||
|
end
|
||||||
if row.mtype == 'ignore' then
|
if row.mtype == 'ignore' then
|
||||||
return colors.lightGray
|
return colors.lightGray
|
||||||
end
|
end
|
||||||
@@ -205,9 +235,6 @@ function machineWizard:eventHandler(event)
|
|||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'collapse' then
|
|
||||||
self.items:hide()
|
|
||||||
|
|
||||||
elseif event.type == 'enable_view' then
|
elseif event.type == 'enable_view' then
|
||||||
local current = event.next or event.prev
|
local current = event.next or event.prev
|
||||||
self.titleBar.title = current.title or 'Machine'
|
self.titleBar.title = current.title or 'Machine'
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ local listingPage = UI.Page {
|
|||||||
[ 'control-e' ] = 'eject',
|
[ 'control-e' ] = 'eject',
|
||||||
[ 'control-s' ] = 'eject_stack',
|
[ 'control-s' ] = 'eject_stack',
|
||||||
[ 'control-m' ] = 'machines',
|
[ 'control-m' ] = 'machines',
|
||||||
|
[ 'control-l' ] = 'resume',
|
||||||
},
|
},
|
||||||
displayMode = 0,
|
displayMode = 0,
|
||||||
}
|
}
|
||||||
@@ -113,10 +114,12 @@ function listingPage.grid:getDisplayValues(row)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:eventHandler(event)
|
function listingPage:eventHandler(event)
|
||||||
debug(event)
|
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:exitPullEvents()
|
UI:exitPullEvents()
|
||||||
|
|
||||||
|
elseif event.type == 'resume' then
|
||||||
|
Milo:resumeCrafting()
|
||||||
|
|
||||||
elseif event.type == 'eject' then
|
elseif event.type == 'eject' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function PotionImportTask:cycle(context)
|
|||||||
for _, v in pairs(device) do
|
for _, v in pairs(device) do
|
||||||
if v.type == 'minecraft:brewing_stand' and v.getBrewTime() == 0 then
|
if v.type == 'minecraft:brewing_stand' and v.getBrewTime() == 0 then
|
||||||
local list = v.list()
|
local list = v.list()
|
||||||
if not list[4] and list[1] then
|
if not list[4] then
|
||||||
for i = 1, 3 do
|
for i = 1, 3 do
|
||||||
if list[i] then
|
if list[i] then
|
||||||
context.inventoryAdapter:insert(i, 1, nil, list[i], v.name)
|
context.inventoryAdapter:insert(i, 1, nil, list[i], v.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user