remove dependency on device global + milo backup config
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local term = _G.term
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local term = _G.term
|
||||
|
||||
local args = { ... }
|
||||
local mon = device[args[1] or 'monitor'] or error('Syntax: debug <monitor>')
|
||||
local mon = args[1] and peripheral.wrap(args[1]) or
|
||||
peripheral.find('monitor') or
|
||||
error('Syntax: debug <monitor>')
|
||||
|
||||
mon.clear()
|
||||
mon.setTextScale(.5)
|
||||
|
||||
@@ -6,14 +6,14 @@ local Socket = require('socket')
|
||||
local Util = require('util')
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local network = _G.network
|
||||
local os = _G.os
|
||||
local colors = _G.colors
|
||||
local network = _G.network
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
UI:configure('multiMiner', ...)
|
||||
|
||||
local scanner = device.neuralInterface
|
||||
local scanner = peripheral.find('neuralInterface')
|
||||
if not scanner or not scanner.scan then
|
||||
error('Plethora scanner must be equipped')
|
||||
end
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
local args = {...}
|
||||
|
||||
if not args[1] then
|
||||
print("Usage:")
|
||||
print(shell.getRunningProgram() .. " <program> [program arguments, ...]")
|
||||
return
|
||||
end
|
||||
|
||||
local path = shell.resolveProgram(args[1]) or shell.resolve(args[1])
|
||||
|
||||
-- here be dragons
|
||||
if fs.exists(path) then
|
||||
local eshell = setmetatable({getRunningProgram=function() return path end}, {__index = shell})
|
||||
local env = setmetatable({shell=eshell}, {__index=_ENV})
|
||||
|
||||
local f = fs.open(path, "r")
|
||||
local d = f.readAll()
|
||||
f.close()
|
||||
|
||||
local func, e = load(d, fs.getName(path), nil, env)
|
||||
if not func then
|
||||
printError("Syntax error:")
|
||||
printError(" " .. e)
|
||||
else
|
||||
table.remove(args, 1)
|
||||
xpcall(function() func(unpack(args)) end, function(err)
|
||||
local trace = {}
|
||||
local i, hitEnd, _, e = 4, false
|
||||
repeat
|
||||
_, e = pcall(function() error("<tracemarker>", i) end)
|
||||
i = i + 1
|
||||
if e == "xpcall: <tracemarker>" then
|
||||
hitEnd = true
|
||||
break
|
||||
end
|
||||
table.insert(trace, e)
|
||||
until i > 10
|
||||
table.remove(trace)
|
||||
if err:match("^" .. trace[1]:match("^(.-:%d+)")) then table.remove(trace, 1) end
|
||||
printError("\nProgram has crashed! Stack trace:")
|
||||
printError(err)
|
||||
for i, v in ipairs(trace) do
|
||||
printError(" at " .. v:match("^(.-:%d+)"))
|
||||
end
|
||||
if not hitEnd then
|
||||
printError(" ...")
|
||||
end
|
||||
end)
|
||||
end
|
||||
else
|
||||
printError("program not found")
|
||||
end
|
||||
@@ -7,10 +7,10 @@ local sync = require('sync').sync
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local peripheral = _G.peripheral
|
||||
local shell = _ENV.shell
|
||||
|
||||
local context = {
|
||||
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
||||
@@ -108,7 +108,7 @@ local page = UI.Page {
|
||||
}
|
||||
|
||||
local function getPlayerName()
|
||||
local neural = device.neuralInterface
|
||||
local neural = peripheral.find('neuralInterface')
|
||||
|
||||
if neural and neural.getName then
|
||||
return neural.getName()
|
||||
|
||||
@@ -225,6 +225,7 @@ function Milo:eject(item, count)
|
||||
count = count - amount
|
||||
|
||||
Sound.play('ui.button.click')
|
||||
--Sound.play('entity.illusion_illager.death')
|
||||
turtle.emptyInventory()
|
||||
end
|
||||
return total
|
||||
@@ -324,6 +325,7 @@ function Milo:updateRecipe(result, recipe)
|
||||
recipe.result = nil
|
||||
end
|
||||
self.context.userRecipes[result] = recipe
|
||||
Util.backup(Craft.USER_RECIPES)
|
||||
Util.writeTable(Craft.USER_RECIPES, self.context.userRecipes)
|
||||
Craft.loadRecipes()
|
||||
end
|
||||
@@ -333,10 +335,12 @@ function Milo:saveMachineRecipe(recipe, result, machine)
|
||||
|
||||
-- save the recipe
|
||||
self.context.userRecipes[key] = recipe
|
||||
Util.backup(Craft.USER_RECIPES)
|
||||
Util.writeTable(Craft.USER_RECIPES, self.context.userRecipes)
|
||||
|
||||
-- save the machine association
|
||||
Craft.machineLookup[key] = machine
|
||||
Util.backup(Craft.MACHINE_LOOKUP)
|
||||
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||
|
||||
Craft.loadRecipes()
|
||||
@@ -391,6 +395,7 @@ function Milo:mergeResources(t)
|
||||
end
|
||||
|
||||
function Milo:saveResources()
|
||||
Util.backup(self.RESOURCE_FILE)
|
||||
Util.writeTable(self.RESOURCE_FILE, self.context.resources)
|
||||
end
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ function Storage:saveConfiguration()
|
||||
v.adapter = nil
|
||||
end
|
||||
|
||||
Util.backup('usr/config/storage')
|
||||
Config.update('storage', self.nodes)
|
||||
|
||||
for k,v in pairs(t) do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
local fs = _G.fs
|
||||
local peripheral = _G.peripheral
|
||||
local shell = _ENV.shell
|
||||
|
||||
if fs.exists('packages/milo/Milo.lua') then
|
||||
fs.delete('packages/milo/Milo.lua')
|
||||
@@ -9,6 +9,6 @@ end
|
||||
|
||||
fs.delete('packages/milo/apis/milo.lua')
|
||||
|
||||
if device.workbench then
|
||||
if peripheral.find('workbench') then
|
||||
shell.openForegroundTab('MiloLocal')
|
||||
end
|
||||
|
||||
@@ -3,12 +3,11 @@ local Event = require('event')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local args = { ... }
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local ni = device.neuralInterface
|
||||
local args = { ... }
|
||||
local colors = _G.colors
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local SHIELD_SLOT = 2
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
local context = args[1]
|
||||
|
||||
if not context.state.autostore then
|
||||
|
||||
@@ -2,12 +2,12 @@ local Config = require('config')
|
||||
local UI = require('ui')
|
||||
local itemDB = require('core.itemDB')
|
||||
|
||||
local args = { ... }
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local ni = device.neuralInterface
|
||||
local args = { ... }
|
||||
local colors = _G.colors
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local context = args[1]
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
|
||||
if not context.state.depositAll then
|
||||
context.state.depositAll = { }
|
||||
|
||||
@@ -2,9 +2,9 @@ local Milo = require('milo')
|
||||
local Sound = require('sound')
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
local device = _G.device
|
||||
local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local speakerNode = context.storage:getSingleNode('speaker')
|
||||
if speakerNode then
|
||||
@@ -50,8 +50,7 @@ function wizardPage:validate()
|
||||
end
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'speaker' and {
|
||||
return peripheral.getType(node.name) == 'speaker' and {
|
||||
name = 'Speaker',
|
||||
value = 'speaker',
|
||||
category = 'custom',
|
||||
|
||||
@@ -5,13 +5,13 @@ local Sound = require('sound')
|
||||
local Swarm = require('core.swarm')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local COLUMNS = 4
|
||||
|
||||
local gpt = GPS.getPoint() or error('GPS not found')
|
||||
local scanner = device.neuralInterface
|
||||
local scanner = peripheral.find('neuralInterface')
|
||||
if not scanner or not scanner.scan then
|
||||
error('Plethora scanner must be equipped')
|
||||
end
|
||||
|
||||
@@ -32,9 +32,7 @@ local parentMon
|
||||
|
||||
local defaultEnv = Util.shallowCopy(_ENV)
|
||||
defaultEnv.multishell = multishell
|
||||
if args[3] then
|
||||
parentMon = _G.device[args[3]]
|
||||
elseif args[2] then
|
||||
if args[2] then
|
||||
parentMon = peripheral.wrap(args[2]) or syntax()
|
||||
else
|
||||
parentMon = peripheral.find('monitor') or syntax()
|
||||
|
||||
@@ -4,11 +4,14 @@ local Project = require('neural.project')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local scanner = device.neuralInterface or device['plethora:scanner'] or peripheral.find('manipulator')
|
||||
if not scanner or not scanner.scan then
|
||||
local scanner =
|
||||
peripheral.find('neuralInterface') or
|
||||
peripheral.find('plethora:scanner') or
|
||||
peripheral.find('manipulator')
|
||||
|
||||
if not scanner or not scanner.scan then
|
||||
error('Plethora scanner must be equipped')
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ local Project = require('neural.project')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
local turtle = _G.turtle
|
||||
|
||||
@@ -13,9 +12,9 @@ local function equip(side, rawName)
|
||||
end
|
||||
|
||||
local target = nil
|
||||
local ni = device.neuralInterface
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
local sensor = ni or
|
||||
device['plethora:sensor'] or
|
||||
peripheral.find('plethora:sensor') or
|
||||
peripheral.find('manipulator') or
|
||||
equip('left', 'plethora:module:3')
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
local Interface = { }
|
||||
|
||||
local Angle = require('neural.angle')
|
||||
local Util = require('util')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local ni = device.neuralInterface or { }
|
||||
local ni = peripheral.find('neuralInterface') or { }
|
||||
for k,v in pairs(ni) do
|
||||
Interface[k] = v
|
||||
end
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
if not device.neuralInterface then
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
if not ni then
|
||||
error('Missing neural interface')
|
||||
elseif not device.neuralInterface.disableAI then
|
||||
_G.printError('Unable to disable AI')
|
||||
elseif not ni.disableAI then
|
||||
error('Missing kinetic augment')
|
||||
else
|
||||
device.neuralInterface.disableAI()
|
||||
ni.disableAI()
|
||||
end
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
if not device.neuralInterface then
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
if not ni then
|
||||
error('Missing neural interface')
|
||||
elseif not device.neuralInterface.getEquipment then
|
||||
elseif not ni.getEquipment then
|
||||
error('Missing introspection module')
|
||||
else
|
||||
device.neuralInterface.getEquipment().drop(6)
|
||||
ni.getEquipment().drop(6)
|
||||
end
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('gps')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local t = { }
|
||||
local ni = _G.device.neuralInterface or error('Neural Interface not found')
|
||||
local ni =
|
||||
peripheral.find('neuralInterface') or
|
||||
error('Neural Interface not found')
|
||||
|
||||
if not ni.getID then
|
||||
error('Missing Introspection Module')
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('gps')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
local shell = _ENV.shell
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
local fileName = args[1] or 'neural.tbl'
|
||||
|
||||
local t = Util.readTable(shell.resolve(fileName)) or error('Unable to read ' .. fileName)
|
||||
local ni = _G.device.neuralInterface
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
|
||||
local function walkTo(x, y, z)
|
||||
local pt = GPS.locate(2)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
--[[ Configuration Page ]]--
|
||||
local wizardPage = UI.WizardPage {
|
||||
@@ -64,8 +64,8 @@ function wizardPage:saveNode(node)
|
||||
end
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'monitor' and {
|
||||
local m = peripheral.getType(node.name)
|
||||
return m == 'monitor' and {
|
||||
name = 'Store Front',
|
||||
value = 'shop',
|
||||
category = 'display',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local Equipper = require('turtle.equipper')
|
||||
local Point = require('point')
|
||||
|
||||
local peripheral = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
local turtle = _G.turtle
|
||||
|
||||
local MAX_FUEL = turtle.getFuelLimit()
|
||||
|
||||
Reference in New Issue
Block a user