diff --git a/apis/blocks.lua b/apis/blocks.lua index 2077c5b..571b03a 100644 --- a/apis/blocks.lua +++ b/apis/blocks.lua @@ -64,7 +64,7 @@ function blockDB:lookup(id, dmg) if not id then return end - + return self.data[id .. ':' .. dmg] end @@ -136,12 +136,12 @@ function placementDB:addSubsForBlockType(id, dmg, bt) sub.extra) end end - + function placementDB:add(id, dmg, sid, sdmg, direction, extra) if direction and #direction == 0 then direction = nil end - + local entry = { oid = id, -- numeric ID odmg = dmg, -- dmg with placement info @@ -176,9 +176,9 @@ function blockTypeDB:addTemp(blockType, subs) end self.dirty = true end - + function blockTypeDB:load() - + blockTypeDB:addTemp('stairs', { { 0, nil, 0, 'east-up' }, { 1, nil, 0, 'west-up' }, @@ -575,7 +575,8 @@ function Blocks:init(args) placementDB:load2(blockDB, blockTypeDB) end --- for an ID / dmg (with placement info) - return the correct block (without the placment info embedded in the dmg) +-- for an ID / dmg (with placement info) +-- return the correct block (without the placment info embedded in the dmg) function Blocks:getPlaceableBlock(id, dmg) local p = placementDB:get({id, dmg}) diff --git a/apis/chestAdapter.lua b/apis/chestAdapter.lua index e23506a..5502967 100644 --- a/apis/chestAdapter.lua +++ b/apis/chestAdapter.lua @@ -13,7 +13,7 @@ local convertNames = { displayName = 'display_name', maxDamage = 'max_dmg', } -local keys = { +local keys = { 'damage', 'displayName', 'maxCount', @@ -31,7 +31,7 @@ local function safeString(text) local newText = {} for i = 4, #text do - local val = text:byte(i) + val = text:byte(i) newText[i - 3] = (val > 31 and val < 127) and val or 63 end return string.char(unpack(newText)) @@ -65,11 +65,11 @@ function ChestAdapter:init(args) Util.merge(self, chest) end end - + function ChestAdapter:isValid() return not not self.getAllStacks end - + function ChestAdapter:refresh(throttle) return self:listItems(throttle) end @@ -109,12 +109,11 @@ function ChestAdapter:getItemInfo(item) local key = table.concat({ item.name, item.damage, item.nbtHash }, ':') return self.cache[key] end - -function ChestAdapter:craft(id, dmg, qty) - return false + +function ChestAdapter:craft() end -function ChestAdapter:craftItems(items) +function ChestAdapter:craftItems() end function ChestAdapter:provide(item, qty, slot, direction) @@ -144,7 +143,7 @@ end function ChestAdapter:insert(slot, qty) local s, m = pcall(function() self.pullItem(self.direction, slot, qty) end) if not s and m then - sleep(1) + os.sleep(1) pcall(function() self.pullItem(self.direction, slot, qty) end) end end diff --git a/apis/chestAdapter18.lua b/apis/chestAdapter18.lua index 0dae1ea..25d043b 100644 --- a/apis/chestAdapter18.lua +++ b/apis/chestAdapter18.lua @@ -5,7 +5,7 @@ local Peripheral = require('peripheral') local ChestAdapter = class() -local keys = Util.transpose({ +local keys = Util.transpose({ 'damage', 'displayName', 'maxCount', @@ -22,7 +22,7 @@ function ChestAdapter:init(args) } Util.merge(self, defaults) Util.merge(self, args) - + local chest = Peripheral.getBySide(self.wrapSide) if not chest then chest = Peripheral.getByMethod('list') @@ -106,10 +106,10 @@ function ChestAdapter:getItemInfo(item) return self.cache[key] end -function ChestAdapter:craft(name, damage, qty) +function ChestAdapter:craft() end -function ChestAdapter:craftItems(items) +function ChestAdapter:craftItems() end function ChestAdapter:provide(item, qty, slot, direction) diff --git a/apis/meAdapter.lua b/apis/meAdapter.lua index d8ec367..1f3b7d9 100644 --- a/apis/meAdapter.lua +++ b/apis/meAdapter.lua @@ -3,7 +3,8 @@ local itemDB = require('itemDB') local Peripheral = require('peripheral') local Util = require('util') -local MEAdapter = class() +local os = _G.os +local peripheral = _G.peripheral local convertNames = { name = 'id', @@ -13,7 +14,7 @@ local convertNames = { displayName = 'display_name', maxDamage = 'max_dmg', } -local keys = { +local keys = { 'damage', 'displayName', 'maxCount', @@ -31,7 +32,7 @@ local function safeString(text) local newText = {} for i = 4, #text do - local val = text:byte(i) + val = text:byte(i) newText[i - 3] = (val > 31 and val < 127) and val or 63 end return string.char(unpack(newText)) @@ -48,6 +49,8 @@ local function convertItem(item) item.displayName = safeString(item.displayName) end +local MEAdapter = class() + function MEAdapter:init(args) local defaults = { items = { }, @@ -72,7 +75,7 @@ function MEAdapter:init(args) end end end - + function MEAdapter:isValid() return self.getAvailableItems and self.getAvailableItems() end @@ -102,9 +105,9 @@ function MEAdapter:listItems() self:refresh() return self.items end - + function MEAdapter:getItemInfo(item) - for key,i in pairs(self.items) do + for _,i in pairs(self.items) do if item.name == i.name and item.damage == i.damage and item.nbtHash == i.nbtHash then return i end @@ -123,7 +126,7 @@ function MEAdapter:isCPUAvailable() end end return available -end +end function MEAdapter:craft(item, count) @@ -133,7 +136,7 @@ function MEAdapter:craft(item, count) self:refresh() - local item = self:getItemInfo(item) + item = self:getItemInfo(item) if item and item.is_craftable then local cpus = self.getCraftingCPUs() or { } @@ -186,8 +189,8 @@ end function MEAdapter:isCrafting(item) for _,v in pairs(self:getJobList()) do - if v.name == item.name and - v.damage == item.damage and + if v.name == item.name and + v.damage == item.damage and v.nbtHash == item.nbtHash then return true end @@ -220,7 +223,7 @@ function MEAdapter:provide(item, count, slot, direction) return pcall(function() while count > 0 do local qty = math.min(count, 64) - local s, m = self.exportItem({ + local s = self.exportItem({ id = item.name, dmg = item.damage }, direction or self.direction, qty, slot) @@ -232,18 +235,14 @@ function MEAdapter:provide(item, count, slot, direction) end end) end - + function MEAdapter:insert(slot, count) local s, m = pcall(function() self.pullItem(self.direction, slot, count) end) if not s and m then - print('MEAdapter:pullItem') - print(m) - sleep(1) + os.sleep(1) s, m = pcall(function() self.pullItem(self.direction, slot, count) end) if not s and m then - print('MEAdapter:pullItem') - print(m) - read() + error(m) end end end diff --git a/apis/nameDB.lua b/apis/nameDB.lua index a5115bb..0b22bde 100644 --- a/apis/nameDB.lua +++ b/apis/nameDB.lua @@ -12,7 +12,7 @@ function nameDB:load() end for strId, block in pairs(blocks) do - local strId = 'minecraft:' .. strId + strId = 'minecraft:' .. strId if type(block.name) == 'string' then self.data[strId .. ':0'] = block.name else diff --git a/apis/refinedAdapter.lua b/apis/refinedAdapter.lua index 1977f30..e69b0b7 100644 --- a/apis/refinedAdapter.lua +++ b/apis/refinedAdapter.lua @@ -5,7 +5,7 @@ local itemDB = require('itemDB') local RefinedAdapter = class() -local keys = { +local keys = { 'damage', 'displayName', 'maxCount', @@ -109,8 +109,8 @@ end function RefinedAdapter:isCrafting(item) for _,task in pairs(self.getCraftingTasks()) do local output = task.getPattern().outputs[1] - if output.name == item.name and - output.damage == item.damage and + if output.name == item.name and + output.damage == item.damage and output.nbtHash == item.nbtHash then return true end @@ -125,18 +125,18 @@ function RefinedAdapter:craft(item, qty) end end -function RefinedAdapter:craftItems(items) +function RefinedAdapter:craftItems() return false end -function RefinedAdapter:provide(item, qty, slot) +function RefinedAdapter:provide() end - -function RefinedAdapter:extract(slot, qty) + +function RefinedAdapter:extract() -- self.pushItems(self.direction, slot, qty) end -function RefinedAdapter:insert(slot, qty) +function RefinedAdapter:insert() -- self.pullItems(self.direction, slot, qty) end diff --git a/apis/schematic.lua b/apis/schematic.lua index f7d08d9..5a76eb9 100644 --- a/apis/schematic.lua +++ b/apis/schematic.lua @@ -4,6 +4,11 @@ local DEFLATE = require('deflatelua') local UI = require('ui') local Point = require('point') +local bit = _G.bit +local fs = _G.fs +local term = _G.term +local turtle = _G.turtle + --[[ Loading and manipulating a schematic --]] @@ -24,7 +29,7 @@ end --[[ Credit to Orwell for the schematic file reader code http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/ - + Some parts of the file reader code was modified from the original --]] @@ -52,7 +57,7 @@ function Schematic:readname(h) local c = h:readbyte(h) if c == nil then return - end + end str = str .. string.char(c) end return str @@ -218,11 +223,11 @@ function DiskFile:close() end local MemoryFile = class() -function MemoryFile:init(args) +function MemoryFile:init() self.s = { } self.i = 1 end -function MemoryFile:open(filename) +function MemoryFile:open() self.i = 1 end function MemoryFile:close() end @@ -247,7 +252,7 @@ function Schematic:decompress(ifname, spinner) local mh = MemoryFile() DEFLATE.gunzip({ - input=function(...) spinner:spin() return ifh.read() end, + input=function() spinner:spin() return ifh.read() end, output=function(b) mh:write(b) end, disable_crc=true }) @@ -310,7 +315,7 @@ end function Schematic:load(filename) - local cursorX, cursorY = term.getCursorPos() + local _, cursorY = term.getCursorPos() local spinner = UI.Spinner({ x = UI.term.width, y = cursorY - 1 @@ -757,7 +762,7 @@ function Schematic:determineBlockPlacement(y) -- otherwise, the turtle must place the block from the same plane -- against another block -- if no block to place against (from side) then the turtle must place from - -- the other side + -- the other side -- -- Stair bug in 1.7 - placing a stair southward doesn't respect the turtle's direction -- all other directions are fine @@ -843,8 +848,6 @@ end -- set the order for block dependencies function Schematic:setPlacementOrder(spinner, placementChains) - local cursorX, cursorY = term.getCursorPos() - -- optimize for overlapping check for _,chain in pairs(placementChains) do for index,_ in pairs(chain.keys) do @@ -917,9 +920,9 @@ function Schematic:setPlacementOrder(spinner, placementChains) ]]-- local masterChain = table.remove(chains) - + --[[ it's something like this: - + A chain B chain result 1 1 2 -------- 2 2 @@ -1040,12 +1043,10 @@ v.info = 'Unplaceable' end term.clearLine() - - return t end function Schematic:optimizeRoute(spinner, y) - + local function getNearestNeighbor(p, pt, maxDistance) local key, block, heading local moves = maxDistance @@ -1146,7 +1147,6 @@ function Schematic:optimizeRoute(spinner, y) local maxDistance = self.width*self.length local plane, doors = extractPlane(y) - spinner:spin(percent) pt.index = 0 for i = 1, #plane do local b = getNearestNeighbor(plane, pt, maxDistance) diff --git a/apis/tableDB.lua b/apis/tableDB.lua index 5432206..a985522 100644 --- a/apis/tableDB.lua +++ b/apis/tableDB.lua @@ -11,14 +11,14 @@ function TableDB:init(args) Util.merge(defaults, args) Util.merge(self, defaults) end - + function TableDB:load() local t = Util.readTable(self.fileName) if t then self.data = t.data or t end end - + function TableDB:add(key, entry) if type(key) == 'table' then key = table.concat(key, ':') @@ -26,19 +26,19 @@ function TableDB:add(key, entry) self.data[key] = entry self.dirty = true end - + function TableDB:get(key) if type(key) == 'table' then key = table.concat(key, ':') end return self.data[key] end - + function TableDB:remove(key) self.data[key] = nil self.dirty = true end - + function TableDB:flush() if self.dirty then Util.writeTable(self.fileName, self.data) diff --git a/apps/Appstore.lua b/apps/Appstore.lua index 5fb217b..e2060d6 100644 --- a/apps/Appstore.lua +++ b/apps/Appstore.lua @@ -1,25 +1,28 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Ansi = require('ansi') -local Config = require('config') local SHA1 = require('sha1') local UI = require('ui') local Util = require('util') --- scrap this entire file. don't muck with standard apis +local fs = _G.fs +local http = _G.http +local multishell = _ENV.multishell +local os = _G.os +local shell = _ENV.shell local REGISTRY_DIR = 'usr/.registry' -- FIX SOMEDAY -function os.registerApp(app, key) +local function registerApp(app, key) app.key = SHA1.sha1(key) Util.writeTable(fs.combine(REGISTRY_DIR, app.key), app) os.queueEvent('os_register_app') end -function os.unregisterApp(key) +local function unregisterApp(key) local filename = fs.combine(REGISTRY_DIR, SHA1.sha1(key)) if fs.exists(filename) then @@ -29,7 +32,7 @@ function os.unregisterApp(key) end -local sandboxEnv = Util.shallowCopy(getfenv(1)) +local sandboxEnv = Util.shallowCopy(_ENV) setmetatable(sandboxEnv, { __index = _G }) multishell.setTitle(multishell.getCurrent(), 'App Store') @@ -243,7 +246,7 @@ function appPage:eventHandler(event) elseif event.type == 'uninstall' then if self.app.runOnly then - s,m = runApp(self.app, false, 'uninstall') + runApp(self.app, false, 'uninstall') else fs.delete(fs.combine(APP_DIR, self.app.name)) self.notification:success("Uninstalled " .. self.app.name, 3) @@ -251,7 +254,7 @@ function appPage:eventHandler(event) self.menuBar.removeButton:disable('Remove') self.menuBar:draw() - os.unregisterApp(self.app.creator .. '.' .. self.app.name) + unregisterApp(self.app.creator .. '.' .. self.app.name) end elseif event.type == 'install' then @@ -275,7 +278,7 @@ function appPage:eventHandler(event) category = 'Games' end - os.registerApp({ + registerApp({ run = fs.combine(APP_DIR, self.app.name), title = self.app.title, category = category, @@ -314,7 +317,7 @@ local categoryPage = UI.Page { function categoryPage:setCategory(source, name, index) self.grid.values = { } - for k,v in pairs(source.storeURLs) do + for _,v in pairs(source.storeURLs) do if index == 0 or index == v.catagory then table.insert(self.grid.values, v) end @@ -339,7 +342,7 @@ function categoryPage:setSource(source) end local buttons = { } - for k,v in Util.spairs(source.storeCatagoryNames, + for k,v in Util.spairs(source.storeCatagoryNames, function(a, b) return a:lower() < b:lower() end) do if v ~= 'Operating System' then diff --git a/apps/Events.lua b/apps/Events.lua index 3276b63..882d68c 100644 --- a/apps/Events.lua +++ b/apps/Events.lua @@ -1,9 +1,12 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Event = require('event') local UI = require('ui') local Util = require('util') +local multishell = _ENV.multishell +local os = _G.os + multishell.setTitle(multishell.getCurrent(), 'Events') UI:configure('Events', ...) diff --git a/apps/Peripherals.lua b/apps/Peripherals.lua index 11cb3af..9dbf6a3 100644 --- a/apps/Peripherals.lua +++ b/apps/Peripherals.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Ansi = require('ansi') local Event = require('event') @@ -6,6 +6,7 @@ local UI = require('ui') local Util = require('util') local colors = _G.colors +local multishell = _ENV.multishell local peripheral = _G.peripheral multishell.setTitle(multishell.getCurrent(), 'Devices') diff --git a/apps/Script.lua b/apps/Script.lua index 4436abb..f16fdea 100644 --- a/apps/Script.lua +++ b/apps/Script.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Config = require('config') local Event = require('event') @@ -6,6 +6,12 @@ local Socket = require('socket') local UI = require('ui') local Util = require('util') +local colors = _G.colors +local fs = _G.fs +local multishell = _ENV.multishell +local os = _G.os +local shell = _ENV.shell + local GROUPS_PATH = 'usr/groups' local SCRIPTS_PATH = 'usr/etc/scripts' @@ -26,7 +32,7 @@ if UI.term.width % 2 ~= 0 then width = width + 1 end -function processVariables(script) +local function processVariables(script) local fn = loadstring('return ' .. config.variables) if fn then @@ -40,7 +46,7 @@ function processVariables(script) return script end -function invokeScript(computer, scriptName) +local function invokeScript(computer, scriptName) local script = Util.readFile(scriptName) if not script then @@ -74,7 +80,7 @@ function invokeScript(computer, scriptName) socket:close() end -function runScript(computerOrGroup, scriptName) +local function runScript(computerOrGroup, scriptName) if computerOrGroup.id then invokeScript(computerOrGroup, scriptName) else @@ -208,14 +214,14 @@ local editorPage = UI.Page({ y = 3, }), right = UI.Button({ - text = '>', + text = '>', event = 'right', x = width - 2, y = 2, width = 3, }), left = UI.Button({ - text = '<', + text = '<', event = 'left', x = UI.term.width - width + 1, y = 2, @@ -459,11 +465,6 @@ function mainPage:eventHandler(event) elseif event.type == 'toggle' then config.showGroups = not config.showGroups - local text = 'Computers' - if config.showGroups then - text = 'Groups' - end --- self.statusBar.toggleButton.text = text self:draw() Config.update('script', config) diff --git a/apps/Turtles.lua b/apps/Turtles.lua index 769929a..9cfa5a9 100644 --- a/apps/Turtles.lua +++ b/apps/Turtles.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Config = require('config') local Event = require('event') @@ -8,6 +8,14 @@ local Terminal = require('terminal') local UI = require('ui') local Util = require('util') +local colors = _G.colors +local fs = _G.fs +local multishell = _ENV.multishell +local network = _G.network +local os = _G.os +local shell = _ENV.shell +local term = _G.term + multishell.setTitle(multishell.getCurrent(), 'Turtles') UI.Button.defaults.focusIndicator = ' ' UI:configure('Turtles', ...) @@ -27,15 +35,7 @@ local options = { local SCRIPTS_PATH = 'usr/etc/scripts' local nullTerm = Terminal.getNullTerm(term.current()) -local turtles = { } local socket -local policies = { - { label = 'none' }, - { label = 'digOnly' }, - { label = 'attackOnly' }, - { label = 'digAttack' }, - { label = 'turtleSafe' }, -} local page = UI.Page { coords = UI.Window { @@ -142,7 +142,7 @@ function page:enable(turtle) end function page:runFunction(script, nowrap) - for i = 1, 2 do + for _ = 1, 2 do if not socket then socket = Socket.connect(self.turtle.id, 161) end @@ -186,7 +186,7 @@ function page.coords:draw() if not t.point.gps then ind = 'REL' end - self:print(string.format('%s : %d,%d,%d\n Fuel: %s\n', + self:print(string.format('%s : %d,%d,%d\n Fuel: %s\n', ind, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel))) end end @@ -210,12 +210,6 @@ function page.tabs.inventory:draw() v.selected = true end if v.id then --- local item = itemDB:get({ v.id, v.dmg }) --- if item then --- v.id = item.displayName --- else --- v.id = v.id:gsub('.*:(.*)', '%1') --- end v.id = itemDB:getName(v) end end @@ -356,7 +350,7 @@ if not Util.getOptions(options, { ... }, true) then end if options.turtle.value >= 0 then - for i = 1, 10 do + for _ = 1, 10 do page.turtle = _G.network[options.turtle.value] if page.turtle then break diff --git a/apps/base64dl.lua b/apps/base64dl.lua index 203b4a1..a76f494 100644 --- a/apps/base64dl.lua +++ b/apps/base64dl.lua @@ -1,6 +1,10 @@ -requireInjector(getfenv(1)) +_G.requireInjector() -Base64 = require('base64') +local Base64 = require('base64') + +local http = _G.http +local os = _G.os +local shell = _ENV.shell local args = { ... } diff --git a/apps/chestManager.lua b/apps/chestManager.lua index 82d730e..f56d367 100644 --- a/apps/chestManager.lua +++ b/apps/chestManager.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local ChestAdapter = require('chestAdapter18') local Config = require('config') @@ -12,6 +12,11 @@ local Terminal = require('terminal') local UI = require('ui') local Util = require('util') +local device = _G.device +local multishell = _ENV.multishell +local peripheral = _G.peripheral +local term = _G.term + multishell.setTitle(multishell.getCurrent(), 'Resource Manager') -- 3 wide monitor (any side of turtle) @@ -58,6 +63,9 @@ end local RESOURCE_FILE = 'usr/config/resources.db' local RECIPES_FILE = 'usr/etc/recipes.db' +local colors = _G.colors +local turtle = _G.turtle + local craftingPaused = false local canCraft = not not duckAntenna or turtleChestAdapter:isValid() local recipes = Util.readTable(RECIPES_FILE) or { } @@ -97,18 +105,6 @@ local function getItemQuantity(items, item) return 0 end -local function getItemDetails(items, item) - local cItem = getItem(items, item) - if cItem then - return cItem - end - cItem = itemDB:get(itemDB:makeKey(item)) - if cItem then - return { count = 0, maxCount = cItem.maxCount } - end - return { count = 0, maxCount = 64 } -end - local function uniqueKey(item) return table.concat({ item.name, item.damage, item.nbtHash }, ':') end @@ -143,12 +139,12 @@ local function mergeResources(t) v.lname = v.displayName:lower() end end - + local function filterItems(t, filter) if filter then local r = {} filter = filter:lower() - for k,v in pairs(t) do + for _,v in pairs(t) do if string.find(v.lname, filter) then table.insert(r, v) end @@ -160,7 +156,6 @@ end local function sumItems3(ingredients, items, summedItems, count) - local canCraft = 0 for _,key in pairs(ingredients) do local item = splitKey(key) local summedItem = summedItems[key] @@ -205,7 +200,7 @@ local function addCraftingRequest(item, craftList, count) local key = uniqueKey(item) local request = craftList[key] if not craftList[key] then - request = { name = item.name, damage = item.damage, nbtHash = nbtHash, count = 0 } + request = { name = item.name, damage = item.damage, nbtHash = item.nbtHash, count = 0 } request.displayName = itemDB:getName(request) craftList[key] = request end @@ -238,7 +233,7 @@ local function craftItem(recipe, items, originalItem, craftList, count) local summedItems = { } sumItems3(recipe.ingredients, items, summedItems, math.ceil(count / recipe.count)) - for key,ingredient in pairs(summedItems) do + for _,ingredient in pairs(summedItems) do if not ingredient.recipe and ingredient.count < 0 then addCraftingRequest(ingredient, craftList, -ingredient.count) end @@ -270,7 +265,7 @@ local function craftItems(craftList, allItems) else local count = item.count while count >= 1 do -- try to request smaller quantities until successful - local s, m = pcall(function() + local s = pcall(function() item.status = '(no recipe)' if not controller:craft(item, count) then item.status = '(missing ingredients)' @@ -289,7 +284,7 @@ local function craftItems(craftList, allItems) end end -local function jobMonitor(jobList) +local function jobMonitor() local mon = Peripheral.getByType('monitor') @@ -368,7 +363,7 @@ local function watchResources(items) local craftList = { } local outputs = { } - for k, res in pairs(resources) do + for _,res in pairs(resources) do local item = getItemWithQty(items, res, res.ignoreDamage) if not item then item = { @@ -381,8 +376,8 @@ local function watchResources(items) end if res.limit and item.count > res.limit then - local s, m = inventoryAdapter:provide( - { name = item.name, damage = item.damage }, + inventoryAdapter:provide( + { name = item.name, damage = item.damage }, item.count - res.limit, nil, config.trashDirection) @@ -522,9 +517,9 @@ function itemPage:enable(item) local devices = self.form[6].choices Util.clear(devices) - for _,device in pairs(device) do - if device.setOutput then - table.insert(devices, { name = device.name, value = device.name }) + for _,dev in pairs(device) do + if dev.setOutput then + table.insert(devices, { name = dev.name, value = dev.name }) end end @@ -564,7 +559,7 @@ function itemPage:eventHandler(event) if filtered.auto ~= true then filtered.auto = nil end - + if filtered.rsControl ~= true then filtered.rsControl = nil filtered.rsSide = nil @@ -629,9 +624,6 @@ function listingPage.grid:getRowTextColor(row, selected) return colors.yellow end if row.has_recipe then - if selected then - return colors.cyan - end return colors.cyan end return UI.Grid:getRowTextColor(row, selected) @@ -705,7 +697,7 @@ function listingPage:eventHandler(event) self.grid:draw() end - elseif event.type == 'text_change' then + elseif event.type == 'text_change' then self.filter = event.text if #self.filter == 0 then self.filter = nil @@ -741,7 +733,7 @@ local function getTurtleInventory() if duckAntenna then local list = duckAntenna.getAllStacks(false) - for k,v in pairs(list) do + for _,v in pairs(list) do v.name = v.id v.damage = v.dmg v.displayName = v.display_name @@ -765,22 +757,12 @@ local function getTurtleInventory() return inventory end -local function filter(t, filter) - local keys = Util.keys(t) - for _,key in pairs(keys) do - if not Util.key(filter, key) then - t[key] = nil - end - end -end - local function learnRecipe(page) - local recipe = { } local ingredients = getTurtleInventory() if ingredients then turtle.select(1) if canCraft and turtle.craft() then - recipe = getTurtleInventory() + local recipe = getTurtleInventory() if recipe and recipe[1] then clearGrid() @@ -851,7 +833,7 @@ function learnPage:disable() craftingPaused = false UI.Dialog.disable(self) end - + function learnPage:eventHandler(event) if event.type == 'cancel' then UI:setPreviousPage() @@ -902,12 +884,11 @@ function craftPage:disable() craftingPaused = false UI.Dialog.disable(self) end - + function craftPage:eventHandler(event) if event.type == 'cancel' then UI:setPreviousPage() - elseif event.type == 'accept' then - + --elseif event.type == 'accept' then else return UI.Dialog.eventHandler(self, event) end diff --git a/apps/mirror.lua b/apps/mirror.lua index ab3c8c1..f2817d4 100644 --- a/apps/mirror.lua +++ b/apps/mirror.lua @@ -1,9 +1,12 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Terminal = require('terminal') +local shell = _ENV.shell +local term = _G.term + local args = { ... } -local mon = device[table.remove(args, 1) or 'monitor'] +local mon = _G.device[table.remove(args, 1) or 'monitor'] if not mon then error('mirror: Invalid device') end diff --git a/apps/mirrorClient.lua b/apps/mirrorClient.lua index 7152ee6..c3c6225 100644 --- a/apps/mirrorClient.lua +++ b/apps/mirrorClient.lua @@ -1,11 +1,13 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Event = require('event') local Logger = require('logger') local Socket = require('socket') -local Terminal = require('terminal') local Util = require('util') +local multishell = _ENV.multishell +local os = _G.os + Logger.setScreenLogging() local remoteId @@ -14,7 +16,7 @@ if #args == 1 then remoteId = tonumber(args[1]) else print('Enter host ID') - remoteId = tonumber(read()) + remoteId = tonumber(_G.read()) end if not remoteId then @@ -70,7 +72,7 @@ while true do while true do local e = Event.pullEvent() if e[1] == 'terminate' then - break + break end if not socket.connected then break diff --git a/apps/mirrorHost.lua b/apps/mirrorHost.lua index 8ddefee..dbbaf25 100644 --- a/apps/mirrorHost.lua +++ b/apps/mirrorHost.lua @@ -1,15 +1,18 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local Event = require('event') local Logger = require('logger') local Socket = require('socket') +local colors = _G.colors +local term = _G.term + Logger.setScreenLogging() local mon = term.current() local args = { ... } if args[1] then - mon = device[args[1]] + mon = _G.device[args[1]] end if not mon then diff --git a/apps/music.lua b/apps/music.lua index d9b791b..33a7eba 100644 --- a/apps/music.lua +++ b/apps/music.lua @@ -1,8 +1,14 @@ -require = requireInjector(getfenv(1)) +_G.requireInjector() local Event = require('event') local UI = require('ui') +local colors = _G.colors +local device = _G.device +local turtle = _G.turtle + +local multishell = _ENV.multishell + multishell.setTitle(multishell.getCurrent(), 'Music') local radio = device.drive or error('No drive attached') @@ -16,8 +22,6 @@ end UI:configure('Music', ...) -local monitor = UI.term - UI.Button.defaults.backgroundFocusColor = colors.gray local page = UI.Page({ @@ -146,12 +150,12 @@ function page:eventHandler(event) end end -function page:setVolume(volume, displayOnly) +function page:setVolume(volume) volume = math.min(volume, 15) volume = math.max(volume, 1) self.volume = volume volume = math.ceil(volume / 2) - + for i = 1, volume do self.volumeControls[i].backgroundColor = self.volumeControls[i].color @@ -224,7 +228,7 @@ end function page:updateStationName() local title = radio.getAudioTitle() - + if title then self.stationName.value = title self.stationName:draw() diff --git a/apps/mwm.lua b/apps/mwm.lua index b2e4bc8..2346ab5 100644 --- a/apps/mwm.lua +++ b/apps/mwm.lua @@ -1,9 +1,16 @@ local injector = requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())() -injector(getfenv(1)) +injector() local Canvas = require('ui.canvas') local Util = require('util') +local colors = _G.colors +local os = _G.os +local peripheral = _G.peripheral +local shell = _ENV.shell +local term = _G.term +local window = _G.window + local function syntax() printError('Syntax:') error('mwm sessionName [monitor]') @@ -18,7 +25,7 @@ local sessionFile = args[1] or syntax() local running local monitor -local defaultEnv = Util.shallowCopy(getfenv(1)) +local defaultEnv = Util.shallowCopy(_ENV) defaultEnv.multishell = multishell if args[2] then @@ -55,7 +62,7 @@ end local function getProcessAt(x, y) for k = #processes, 1, -1 do local process = processes[k] - if x >= process.x and + if x >= process.x and y >= process.y and x <= process.x + process.width - 1 and y <= process.y + process.height - 1 then @@ -356,7 +363,7 @@ function multishell.removeProcess(process) redraw() end -function multishell.saveSession(sessionFile) +function multishell.saveSession(filename) local t = { } for _,process in pairs(processes) do if process.path and not process.isShell then @@ -370,11 +377,11 @@ function multishell.saveSession(sessionFile) }) end end - Util.writeTable(sessionFile, t) + Util.writeTable(filename, t) end -function multishell.loadSession(sessionFile) - local config = Util.readTable(sessionFile) +function multishell.loadSession(filename) + local config = Util.readTable(filename) if config then for _,v in pairs(config) do multishell.openTab(v) diff --git a/apps/storageActivity.lua b/apps/storageActivity.lua index 11346bc..5065032 100644 --- a/apps/storageActivity.lua +++ b/apps/storageActivity.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() local ChestAdapter = require('chestAdapter18') local Event = require('event') @@ -7,6 +7,9 @@ local RefinedAdapter = require('refinedAdapter') local UI = require('ui') local Util = require('util') +local colors = _G.colors +local multishell = _ENV.multishell + local storage = RefinedAdapter() if not storage:isValid() then storage = MEAdapter({ auto = true }) @@ -73,7 +76,7 @@ function changedPage.grid:getDisplayValues(row) end function changedPage:eventHandler(event) - + if event.type == 'reset' then self.lastItems = nil self.grid:setValues({ }) @@ -102,22 +105,23 @@ end function changedPage:refresh() local t = storage:listItems() - + if not t or Util.empty(t) then self:clear() self:centeredWrite(math.ceil(self.height/2), 'Communication failure') return end - + for k,v in pairs(t) do t[k] = Util.shallowCopy(v) end - + if not self.lastItems then self.lastItems = t self.grid:setValues({ }) else - local changedItems = {} + local changedItems = { } + local found for _,v in pairs(self.lastItems) do found = false for k2,v2 in pairs(t) do @@ -141,12 +145,12 @@ function changedPage:refresh() end end -- No items left - for k,v in pairs(t) do + for _,v in pairs(t) do v.lastCount = 0 table.insert(changedItems, v) end - for k,v in pairs(changedItems) do + for _,v in pairs(changedItems) do v.change = v.count - v.lastCount end @@ -154,11 +158,11 @@ function changedPage:refresh() end self.grid:draw() end - + Event.onInterval(5, function() changedPage:refresh() changedPage:sync() end) - + UI:setPage(changedPage) UI:pullEvents() diff --git a/apps/treefarm.lua b/apps/treefarm.lua index cb0d74d..3475cf6 100644 --- a/apps/treefarm.lua +++ b/apps/treefarm.lua @@ -1,4 +1,4 @@ -requireInjector(getfenv(1)) +_G.requireInjector() --[[ Requirements: @@ -27,6 +27,10 @@ local Pathing = require('turtle.pathfind') local Point = require('point') local Util = require('util') +local os = _G.os +local read = _G.read +local turtle = _G.turtle + local FUEL_BASE = 0 local FUEL_DIRE = FUEL_BASE + 10 local FUEL_GOOD = FUEL_BASE + 2000 @@ -175,7 +179,7 @@ local function makeSingleCharcoal() local slots = turtle.getSummedInventory() - if not state.furnace or + if not state.furnace or slots[CHARCOAL] or not slots[OAK_LOG] or slots[OAK_LOG].count < 2 then @@ -195,13 +199,13 @@ local function makeCharcoal() local slots = turtle.getSummedInventory() - if not state.furnace or + if not state.furnace or not slots[CHARCOAL] or slots[CHARCOAL].count >= MIN_CHARCOAL then return true end - local function getLogSlot(slots) + local function getLogSlot() local maxslot = { count = 0 } for k,slot in pairs(slots) do if string.match(k, 'minecraft:log') then @@ -214,7 +218,8 @@ local function makeCharcoal() end repeat - local slots = turtle.getSummedInventory() + slots = turtle.getSummedInventory() + local charcoal = slots[CHARCOAL].count local slot = getLogSlot(slots) @@ -266,7 +271,7 @@ local function getCobblestone(count) turtle.select(1) turtle.digDown() turtle.down() - for i = 1, 4 do + for _ = 1, 4 do if inspect(turtle.inspect) == STONE then turtle.dig() end @@ -391,9 +396,9 @@ local function dropOffItems() if state.chest_1 then local slots = turtle.getSummedInventory() - if state.chest_1 and - slots[CHARCOAL] and - slots[CHARCOAL].count >= MIN_CHARCOAL and + if state.chest_1 and + slots[CHARCOAL] and + slots[CHARCOAL].count >= MIN_CHARCOAL and (turtle.getItemCount('minecraft:log') > 0 or turtle.getItemCount('minecraft:log2') > 0) then @@ -510,10 +515,10 @@ local function fell() local pts = Util.shallowCopy(state.trees) - local pt = table.remove(pts, math.random(1, #pts)) + local rpt = table.remove(pts, math.random(1, #pts)) -- give the pathfinder hints about what to avoid (state.trees) - if not turtle.faceAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) or + if not turtle.faceAgainst(rpt, { blocks = Util.shallowCopy(state.trees) }) or not string.match(inspect(turtle.inspect), 'minecraft:log') then return true end @@ -523,7 +528,7 @@ local function fell() local fuel = turtle.getFuelLevel() -- push this point to the start of this list - table.insert(pts, 1, pt) + table.insert(pts, 1, rpt) Point.eachClosest(turtle.point, pts, function(pt) if turtle.faceAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) and @@ -570,7 +575,7 @@ local function moreTrees() end) end -function getTurtleFacing(block) +local function getTurtleFacing(block) local directions = { [5] = 2, [3] = 3, @@ -586,7 +591,7 @@ function getTurtleFacing(block) return directions[bi.metadata] end -function saveTurtleFacing() +local function saveTurtleFacing() if not state.facing then setState('facing', getTurtleFacing(CHEST)) end @@ -600,9 +605,9 @@ local function findGround() local s, block = turtle.inspectDown() if not s then block = { name = 'minecraft:air', metadata = 0 } end - b = block.name .. ':' .. block.metadata + local b = block.name .. ':' .. block.metadata - if b == 'minecraft:dirt:0' or + if b == 'minecraft:dirt:0' or b == 'minecraft:grass:0' or block.name == 'minecraft:chest' then break @@ -719,7 +724,7 @@ local tasks = { { desc = 'Placing torches', fn = placeTorches }, { desc = 'Refueling', fn = refuel }, { desc = 'Dropping off items', fn = dropOffItems }, - { desc = 'Condensing', fn = turtle.condense }, + { desc = 'Condensing', fn = turtle.condense }, { desc = 'Sleeping', fn = updateClock }, } @@ -734,12 +739,12 @@ local s, m = turtle.run(function() turtle.status = task.desc turtle.select(1) if not task.fn() then - Util.filterInplace(tasks, function(v) return v.fn ~= task.fn end) + Util.filterInplace(tasks, function(v) return v.fn ~= task.fn end) end end end end) if not s then - error('Failed') + error(m or 'Failed') end diff --git a/etc/fstab.ignore b/etc/fstab.ignore new file mode 100644 index 0000000..7c8538b --- /dev/null +++ b/etc/fstab.ignore @@ -0,0 +1 @@ +forced fstab overwrite \ No newline at end of file