diff --git a/core/debugMonitor.lua b/core/debugMonitor.lua index 6b9b34f..d5bce6f 100644 --- a/core/debugMonitor.lua +++ b/core/debugMonitor.lua @@ -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 ') +local mon = args[1] and peripheral.wrap(args[1]) or + peripheral.find('monitor') or + error('Syntax: debug ') mon.clear() mon.setTextScale(.5) diff --git a/core/multiMiner.lua b/core/multiMiner.lua index e8af5ee..494a065 100644 --- a/core/multiMiner.lua +++ b/core/multiMiner.lua @@ -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 diff --git a/core/trace.lua b/core/trace.lua deleted file mode 100644 index ca79b6e..0000000 --- a/core/trace.lua +++ /dev/null @@ -1,52 +0,0 @@ -local args = {...} - -if not args[1] then - print("Usage:") - print(shell.getRunningProgram() .. " [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("", i) end) - i = i + 1 - if e == "xpcall: " 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 diff --git a/milo/MiloRemote.lua b/milo/MiloRemote.lua index 7ac1934..86b89e4 100644 --- a/milo/MiloRemote.lua +++ b/milo/MiloRemote.lua @@ -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() diff --git a/milo/apis/init.lua b/milo/apis/init.lua index a24b6d2..411e5e2 100644 --- a/milo/apis/init.lua +++ b/milo/apis/init.lua @@ -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 diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 7aea941..7ad745b 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -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 diff --git a/milo/autorun/milo.lua b/milo/autorun/milo.lua index 4a9a7a9..a36e8cf 100644 --- a/milo/autorun/milo.lua +++ b/milo/autorun/milo.lua @@ -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 diff --git a/milo/plugins/remote/autostore.lua b/milo/plugins/remote/autostore.lua index 8f5761f..bbc45b7 100644 --- a/milo/plugins/remote/autostore.lua +++ b/milo/plugins/remote/autostore.lua @@ -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 diff --git a/milo/plugins/remote/depositAll.lua b/milo/plugins/remote/depositAll.lua index bd4d917..289700a 100644 --- a/milo/plugins/remote/depositAll.lua +++ b/milo/plugins/remote/depositAll.lua @@ -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 = { } diff --git a/milo/plugins/speakerView.lua b/milo/plugins/speakerView.lua index c35b811..fb448a0 100644 --- a/milo/plugins/speakerView.lua +++ b/milo/plugins/speakerView.lua @@ -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', diff --git a/miners/findSwarm.lua b/miners/findSwarm.lua index cb5f715..f623a4f 100644 --- a/miners/findSwarm.lua +++ b/miners/findSwarm.lua @@ -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 diff --git a/monitor/mwm.lua b/monitor/mwm.lua index 0d2ef82..479c123 100644 --- a/monitor/mwm.lua +++ b/monitor/mwm.lua @@ -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() diff --git a/neural/Scanner.lua b/neural/Scanner.lua index 7af1d35..bb0c73d 100644 --- a/neural/Scanner.lua +++ b/neural/Scanner.lua @@ -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 diff --git a/neural/Sensor.lua b/neural/Sensor.lua index b200a8b..0ba3f97 100644 --- a/neural/Sensor.lua +++ b/neural/Sensor.lua @@ -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') diff --git a/neural/apis/interface.lua b/neural/apis/interface.lua index a149767..5989696 100644 --- a/neural/apis/interface.lua +++ b/neural/apis/interface.lua @@ -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 diff --git a/neural/disableAI.lua b/neural/disableAI.lua index f58470d..8e5aa26 100644 --- a/neural/disableAI.lua +++ b/neural/disableAI.lua @@ -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 diff --git a/neural/dropNeural.lua b/neural/dropNeural.lua index fe2ece7..6b4bc5f 100644 --- a/neural/dropNeural.lua +++ b/neural/dropNeural.lua @@ -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 diff --git a/neural/neuralRecorder.lua b/neural/neuralRecorder.lua index eac4da5..f19ee2e 100644 --- a/neural/neuralRecorder.lua +++ b/neural/neuralRecorder.lua @@ -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') diff --git a/neural/neuralReplay.lua b/neural/neuralReplay.lua index b2264ca..c90ca85 100644 --- a/neural/neuralReplay.lua +++ b/neural/neuralReplay.lua @@ -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) diff --git a/swshop/shopConfig.lua b/swshop/shopConfig.lua index 2b95a06..9bddc89 100644 --- a/swshop/shopConfig.lua +++ b/swshop/shopConfig.lua @@ -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', diff --git a/turtle/lavaRefuel.lua b/turtle/lavaRefuel.lua index 957136b..adfb72c 100644 --- a/turtle/lavaRefuel.lua +++ b/turtle/lavaRefuel.lua @@ -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()