From 86e0330100ca34692a06f04a743970a9a062db1f Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 3 Dec 2019 23:26:13 +0000 Subject: [PATCH 01/11] Lint bios and the rom (#321) We now use illuaminate[1]'s linting facilities to check the rom and bios.lua for a couple of common bugs and other problems. Right now this doesn't detect any especially important bugs, though it has caught lots of small things (unused variables, some noisy code). In the future, the linter will grow in scope and features, which should allow us to be stricter and catch most issues. As a fun aside, we started off with ~150 bugs, and illuaminate was able to fix all but 30 of them, which is pretty neat. [1]: https://github.com/SquidDev/illuaminate --- .editorconfig | 3 ++ .github/workflows/main-ci.yml | 15 +++++++++ illuaminate.sexp | 25 +++++++++++++++ .../assets/computercraft/lua/bios.lua | 26 ++++++++-------- .../lua/rom/apis/command/commands.lua | 4 +-- .../computercraft/lua/rom/apis/disk.lua | 2 +- .../assets/computercraft/lua/rom/apis/gps.lua | 10 +++--- .../computercraft/lua/rom/apis/help.lua | 4 +-- .../computercraft/lua/rom/apis/paintutils.lua | 4 +-- .../computercraft/lua/rom/apis/peripheral.lua | 16 +++++----- .../computercraft/lua/rom/apis/rednet.lua | 10 +++--- .../computercraft/lua/rom/apis/settings.lua | 2 +- .../computercraft/lua/rom/apis/term.lua | 2 +- .../computercraft/lua/rom/apis/textutils.lua | 16 +++++----- .../computercraft/lua/rom/apis/vector.lua | 6 ++-- .../computercraft/lua/rom/apis/window.lua | 2 +- .../lua/rom/programs/advanced/multishell.lua | 7 ++--- .../computercraft/lua/rom/programs/copy.lua | 2 +- .../computercraft/lua/rom/programs/delete.lua | 2 +- .../computercraft/lua/rom/programs/drive.lua | 4 +-- .../computercraft/lua/rom/programs/edit.lua | 11 +++---- .../lua/rom/programs/fun/advanced/paint.lua | 6 ++-- .../rom/programs/fun/advanced/redirection.lua | 10 +++--- .../lua/rom/programs/fun/adventure.lua | 31 +++++++++---------- .../computercraft/lua/rom/programs/fun/dj.lua | 2 +- .../lua/rom/programs/fun/worm.lua | 11 ++----- .../computercraft/lua/rom/programs/gps.lua | 4 +-- .../computercraft/lua/rom/programs/help.lua | 2 +- .../computercraft/lua/rom/programs/list.lua | 2 +- .../computercraft/lua/rom/programs/lua.lua | 4 +-- .../computercraft/lua/rom/programs/move.lua | 2 +- .../lua/rom/programs/pocket/falling.lua | 11 +++---- .../lua/rom/programs/rednet/chat.lua | 15 +++++---- .../lua/rom/programs/rednet/repeat.lua | 4 +-- .../lua/rom/programs/redstone.lua | 6 ++-- .../computercraft/lua/rom/programs/set.lua | 2 +- .../computercraft/lua/rom/programs/shell.lua | 12 +++---- .../lua/rom/programs/turtle/dance.lua | 4 +-- .../lua/rom/programs/turtle/excavate.lua | 9 +++--- .../lua/rom/programs/turtle/refuel.lua | 2 +- .../lua/rom/programs/turtle/tunnel.lua | 2 -- .../lua/rom/programs/turtle/turn.lua | 2 +- .../assets/computercraft/lua/rom/startup.lua | 2 +- 43 files changed, 173 insertions(+), 145 deletions(-) create mode 100644 illuaminate.sexp diff --git a/.editorconfig b/.editorconfig index f04c87852..f11468850 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,5 +11,8 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false +[*.sexp] +indent_size = 2 + [*.properties] insert_final_newline = false diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 16f34b3e2..0be633a53 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -4,6 +4,7 @@ on: [push, pull_request] jobs: build: + name: Build runs-on: ubuntu-latest steps: @@ -16,3 +17,17 @@ jobs: - name: Build with Gradle run: ./gradlew build --no-daemon + + lint-lua: + name: Lint Lua + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Lint Lua code + run: | + test -d bin || mkdir bin + test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate + chmod +x bin/illuaminate + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/illuaminate lint --github diff --git a/illuaminate.sexp b/illuaminate.sexp new file mode 100644 index 000000000..2271a01e5 --- /dev/null +++ b/illuaminate.sexp @@ -0,0 +1,25 @@ +; -*- mode: Lisp;-*- + +(sources + /src/main/resources/assets/computercraft/lua/bios.lua + /src/main/resources/assets/computercraft/lua/rom/) + +(at / + (linters + ;; It'd be nice to avoid this, but right now there's a lot of instances of it. + -var:set-loop + + ;; It's useful to name arguments for documentation, so we allow this. It'd + ;; be good to find a compromise in the future, but this works for now. + -var:unused-arg)) + +;; We disable the two global linters in bios.lua and the APIs. In the future +;; hopefully we'll get illuaminate to handle this. +(at + (/src/main/resources/assets/computercraft/lua/bios.lua + /src/main/resources/assets/computercraft/lua/rom/apis/) + (linters -var:set-global -var:unused-global)) + +;; These warnings are broken right now +(at completion.lua (linters -doc:malformed-type)) +(at (bios.lua worm.lua) (linters -control:unreachable)) diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index cebfe1fa3..e4b792538 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -184,7 +184,7 @@ function sleep( nTime ) expect(1, nTime, "number", "nil") local timer = os.startTimer( nTime or 0 ) repeat - local sEvent, param = os.pullEvent( "timer" ) + local _, param = os.pullEvent( "timer" ) until param == timer end @@ -233,7 +233,7 @@ function write( sText ) newLine() end term.write( text ) - text = string.sub( text, (w-x) + 2 ) + text = string.sub( text, w-x + 2 ) x,y = term.getCursorPos() end else @@ -332,7 +332,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) local _, cy = term.getCursorPos() term.setCursorPos( sx, cy ) - local sReplace = (_bClear and " ") or _sReplaceChar + local sReplace = _bClear and " " or _sReplaceChar if sReplace then term.write( string.rep( sReplace, math.max( #sLine - nScroll, 0 ) ) ) else @@ -544,7 +544,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) end end - local cx, cy = term.getCursorPos() + local _, cy = term.getCursorPos() term.setCursorBlink( false ) term.setCursorPos( w + 1, cy ) print() @@ -775,7 +775,7 @@ if http then if not ok then return ok, err end while true do - local event, url, ok, err = os.pullEvent( "http_check" ) + local _, url, ok, err = os.pullEvent( "http_check" ) if url == _url then return ok, err end end end @@ -808,8 +808,8 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs ) expect(3, bIncludeFiles, "boolean", "nil") expect(4, bIncludeDirs, "boolean", "nil") - bIncludeFiles = (bIncludeFiles ~= false) - bIncludeDirs = (bIncludeDirs ~= false) + bIncludeFiles = bIncludeFiles ~= false + bIncludeDirs = bIncludeDirs ~= false local sDir = sLocation local nStart = 1 local nSlash = string.find( sPath, "[/\\]", nStart ) @@ -836,9 +836,9 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs ) end if sDir ~= "" then if sPath == "" then - table.insert( tResults, (bIncludeDirs and "..") or "../" ) + table.insert( tResults, bIncludeDirs and ".." or "../" ) elseif sPath == "." then - table.insert( tResults, (bIncludeDirs and ".") or "./" ) + table.insert( tResults, bIncludeDirs and "." or "./" ) end end local tFiles = fs.list( sDir ) @@ -867,7 +867,7 @@ end -- Load APIs local bAPIError = false local tApis = fs.list( "rom/apis" ) -for n,sFile in ipairs( tApis ) do +for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis", sFile ) if not fs.isDir( sPath ) then @@ -881,7 +881,7 @@ end if turtle and fs.isDir( "rom/apis/turtle" ) then -- Load turtle APIs local tApis = fs.list( "rom/apis/turtle" ) - for n,sFile in ipairs( tApis ) do + for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/turtle", sFile ) if not fs.isDir( sPath ) then @@ -896,7 +896,7 @@ end if pocket and fs.isDir( "rom/apis/pocket" ) then -- Load pocket APIs local tApis = fs.list( "rom/apis/pocket" ) - for n,sFile in ipairs( tApis ) do + for _,sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/pocket", sFile ) if not fs.isDir( sPath ) then @@ -946,7 +946,7 @@ end -- Set default settings settings.set( "shell.allow_startup", true ) -settings.set( "shell.allow_disk_startup", (commands == nil) ) +settings.set( "shell.allow_disk_startup", commands == nil ) settings.set( "shell.autocomplete", true ) settings.set( "edit.autocomplete", true ) settings.set( "edit.default_extension", "lua" ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua index 849bf8e7c..7afd34bad 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua @@ -33,9 +33,9 @@ local tNonNBTJSONCommands = { [ "title" ] = true } local tCommands = native.list() -for n,sCommandName in ipairs(tCommands) do +for _,sCommandName in ipairs(tCommands) do if env[ sCommandName ] == nil then - local bJSONIsNBT = (tNonNBTJSONCommands[ sCommandName ] == nil) + local bJSONIsNBT = tNonNBTJSONCommands[ sCommandName ] == nil env[ sCommandName ] = function( ... ) local sCommand = collapseArgs( bJSONIsNBT, sCommandName, ... ) return native.exec( sCommand ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua index 637a48b07..2c5e6ec8b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua @@ -62,7 +62,7 @@ end function stopAudio( name ) if not name then - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do stopAudio( sName ) end else diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua index 08f698eb2..aab023209 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua @@ -13,7 +13,7 @@ local function trilaterate( A, B, C ) local d = a2b:length() local ex = a2b:normalize( ) local i = ex:dot( a2c ) - local ey = (a2c - (ex * i)):normalize() + local ey = (a2c - ex * i):normalize() local j = ey:dot( a2c ) local ez = ex:cross( ey ) @@ -24,13 +24,13 @@ local function trilaterate( A, B, C ) local x = (r1*r1 - r2*r2 + d*d) / (2*d) local y = (r1*r1 - r3*r3 - x*x + (x-i)*(x-i) + j*j) / (2*j) - local result = A.vPosition + (ex * x) + (ey * y) + local result = A.vPosition + ex * x + ey * y local zSquared = r1*r1 - x*x - y*y if zSquared > 0 then local z = math.sqrt( zSquared ) - local result1 = result + (ez * z) - local result2 = result - (ez * z) + local result1 = result + ez * z + local result2 = result - ez * z local rounded1, rounded2 = result1:round( 0.01 ), result2:round( 0.01 ) if rounded1.x ~= rounded2.x or rounded1.y ~= rounded2.y or rounded1.z ~= rounded2.z then @@ -66,7 +66,7 @@ function locate( _nTimeout, _bDebug ) -- Find a modem local sModemSide = nil - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua index b4e69921f..853ec09a0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua @@ -37,7 +37,7 @@ function topics() for sPath in string.gmatch(sPath, "[^:]+") do if fs.isDir( sPath ) then local tList = fs.list( sPath ) - for n,sFile in pairs( tList ) do + for _,sFile in pairs( tList ) do if string.sub( sFile, 1, 1 ) ~= "." then if not fs.isDir( fs.combine( sPath, sFile ) ) then if #sFile > 4 and sFile:sub(-4) == ".txt" then @@ -52,7 +52,7 @@ function topics() -- Sort and return local tItemList = {} - for sItem, b in pairs( tItems ) do + for sItem in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua index 0988945e0..5420b029d 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua @@ -147,8 +147,8 @@ function drawBox( startX, startY, endX, endY, nColour ) drawPixelInternal( x, maxY ) end - if (maxY - minY) >= 2 then - for y=(minY+1),(maxY-1) do + if maxY - minY >= 2 then + for y=minY+1,maxY-1 do drawPixelInternal( minX, y ) drawPixelInternal( maxX, y ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua index 3f4fdc150..ecfccbb53 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua @@ -4,12 +4,12 @@ local native = peripheral function getNames() local tResults = {} - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.isPresent( sSide ) then table.insert( tResults, sSide ) if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then local tRemote = native.call( sSide, "getNamesRemote" ) - for n,sName in ipairs( tRemote ) do + for _,sName in ipairs( tRemote ) do table.insert( tResults, sName ) end end @@ -23,7 +23,7 @@ function isPresent( _sSide ) if native.isPresent( _sSide ) then return true end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return true @@ -38,7 +38,7 @@ function getType( _sSide ) if native.isPresent( _sSide ) then return native.getType( _sSide ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getTypeRemote", _sSide ) @@ -53,7 +53,7 @@ function getMethods( _sSide ) if native.isPresent( _sSide ) then return native.getMethods( _sSide ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getMethodsRemote", _sSide ) @@ -69,7 +69,7 @@ function call( _sSide, _sMethod, ... ) if native.isPresent( _sSide ) then return native.call( _sSide, _sMethod, ... ) end - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "callRemote", _sSide, _sMethod, ... ) @@ -84,7 +84,7 @@ function wrap( _sSide ) if peripheral.isPresent( _sSide ) then local tMethods = peripheral.getMethods( _sSide ) local tResult = {} - for n,sMethod in ipairs( tMethods ) do + for _,sMethod in ipairs( tMethods ) do tResult[sMethod] = function( ... ) return peripheral.call( _sSide, sMethod, ... ) end @@ -98,7 +98,7 @@ function find( sType, fnFilter ) expect(1, sType, "string") expect(2, fnFilter, "function", "nil") local tResults = {} - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do if peripheral.getType( sName ) == sType then local wrapped = peripheral.wrap( sName ) if fnFilter == nil or fnFilter( sName, wrapped ) then diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua index 5af3a4706..e38084ad5 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua @@ -27,7 +27,7 @@ function close( sModem ) peripheral.call( sModem, "close", CHANNEL_BROADCAST ) else -- Close all modems - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then close( sModem ) end @@ -44,7 +44,7 @@ function isOpen( sModem ) end else -- Check if any modem is open - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then return true end @@ -79,10 +79,10 @@ function send( nRecipient, message, sProtocol ) sent = true else -- Send on all open modems, to the target and to repeaters - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then - peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage ); - peripheral.call( sModem, "transmit", CHANNEL_REPEAT, nReplyChannel, tMessage ); + peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage ) + peripheral.call( sModem, "transmit", CHANNEL_REPEAT, nReplyChannel, tMessage ) sent = true end end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua index d60510937..9f9ba9822 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua @@ -47,7 +47,7 @@ end function getNames() local result = {} - for k,v in pairs( tSettings ) do + for k in pairs( tSettings ) do result[ #result + 1 ] = k end table.sort(result) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua index e9ad00408..98db90be7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua @@ -1,6 +1,6 @@ local expect = dofile("rom/modules/main/cc/expect.lua").expect -local native = (term.native and term.native()) or term +local native = term.native and term.native() or term local redirectTarget = native local function wrap( _sFunction ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua index 447babb44..09130fbad 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua @@ -16,7 +16,7 @@ function slowWrite( sText, nRate ) term.setCursorPos( x, y ) sleep( nSleep ) local nLines = write( string.sub( sText, 1, n ) ) - local newX, newY = term.getCursorPos() + local _, newY = term.getCursorPos() y = newY - nLines end end @@ -54,11 +54,11 @@ local function makePagedScroll( _term, _nFreeLines ) local nativeScroll = _term.scroll local nFreeLines = _nFreeLines or 0 return function( _n ) - for n=1,_n do + for _=1,_n do nativeScroll( 1 ) if nFreeLines <= 0 then - local w,h = _term.getSize() + local _,h = _term.getSize() _term.setCursorPos( 1, h ) _term.write( "Press any key to continue" ) os.pullEvent( "key" ) @@ -123,7 +123,7 @@ local function tabulateCommon( bPaged, ... ) local nCols = math.floor( w / nMaxLen ) local nLines = 0 local function newLine() - if bPaged and nLines >= (h-3) then + if bPaged and nLines >= h-3 then pagedPrint() else print() @@ -133,14 +133,14 @@ local function tabulateCommon( bPaged, ... ) local function drawCols( _t ) local nCol = 1 - for n, s in ipairs( _t ) do + for _, s in ipairs( _t ) do if nCol > nCols then nCol = 1 newLine() end local cx, cy = term.getCursorPos() - cx = 1 + ((nCol - 1) * nMaxLen) + cx = 1 + (nCol - 1) * nMaxLen term.setCursorPos( cx, cy ) term.write( s ) @@ -148,7 +148,7 @@ local function tabulateCommon( bPaged, ... ) end print() end - for n, t in ipairs( tAll ) do + for _, t in ipairs( tAll ) do if type(t) == "table" then if #t > 0 then drawCols( t ) @@ -280,7 +280,7 @@ local function serializeJSONImpl( t, tTracking, bNBTStyle ) nObjectSize = nObjectSize + 1 end end - for n,v in ipairs(t) do + for _,v in ipairs(t) do local sEntry = serializeJSONImpl( v, tTracking, bNBTStyle ) if nArraySize == 0 then sArrayResult = sArrayResult .. sEntry diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua index 2fd2fbdb6..7a6db14b7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua @@ -54,9 +54,9 @@ local vector = { round = function( self, nTolerance ) nTolerance = nTolerance or 1.0 return vector.new( - math.floor( (self.x + (nTolerance * 0.5)) / nTolerance ) * nTolerance, - math.floor( (self.y + (nTolerance * 0.5)) / nTolerance ) * nTolerance, - math.floor( (self.z + (nTolerance * 0.5)) / nTolerance ) * nTolerance + math.floor( (self.x + nTolerance * 0.5) / nTolerance ) * nTolerance, + math.floor( (self.y + nTolerance * 0.5) / nTolerance ) * nTolerance, + math.floor( (self.z + nTolerance * 0.5) / nTolerance ) * nTolerance ) end, tostring = function( self ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua index 87ede5cbd..2f20220fc 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua @@ -49,7 +49,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) createEmptyLines( nWidth ) -- Setup - local bVisible = (bStartVisible ~= false) + local bVisible = bStartVisible ~= false local nCursorX = 1 local nCursorY = 1 local bCursorBlink = false diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua index 51c1c1753..b07cccf3c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua @@ -172,7 +172,6 @@ local function resizeWindows() end for n=1,#tProcesses do local tProcess = tProcesses[n] - local window = tProcess.window local x,y = tProcess.window.getCursorPos() if y > windowHeight then tProcess.window.scroll( y - windowHeight ) @@ -232,7 +231,7 @@ function multishell.launch( tProgramEnv, sProgramPath, ... ) expect(1, tProgramEnv, "table") expect(2, sProgramPath, "string") local previousTerm = term.current() - setMenuVisible( (#tProcesses + 1) >= 2 ) + setMenuVisible( #tProcesses + 1 >= 2 ) local nResult = launchProcess( false, tProgramEnv, sProgramPath, ... ) redrawMenu() term.redirect( previousTerm ) @@ -299,7 +298,7 @@ while #tProcesses > 0 do end else -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, button, x, (bShowMenu and y-1) or y ) + resumeProcess( nCurrentProcess, sEvent, button, x, bShowMenu and y-1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() @@ -319,7 +318,7 @@ while #tProcesses > 0 do end elseif not (bShowMenu and y == 1) then -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, p1, x, (bShowMenu and y-1) or y ) + resumeProcess( nCurrentProcess, sEvent, p1, x, bShowMenu and y-1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua index 70cde52a1..71ea68043 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for n,sFile in ipairs( tFiles ) do + for _,sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.copy( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua b/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua index e2d296805..91f2e0c23 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/delete.lua @@ -8,7 +8,7 @@ end for i = 1, args.n do local files = fs.find(shell.resolve(args[i])) if #files > 0 then - for n, file in ipairs(files) do + for _, file in ipairs(files) do local ok, err = pcall(fs.delete, file) if not ok then printError((err:gsub("^pcall: ", ""))) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua b/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua index c1a38e6dd..807cf88b4 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/drive.lua @@ -10,9 +10,9 @@ if fs.exists( sPath ) then write( fs.getDrive( sPath ) .. " (" ) local nSpace = fs.getFreeSpace( sPath ) if nSpace >= 1000 * 1000 then - print( (math.floor( nSpace / (100 * 1000) ) / 10) .. "MB remaining)" ) + print( math.floor( nSpace / (100 * 1000) ) / 10 .. "MB remaining)" ) elseif nSpace >= 1000 then - print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" ) + print( math.floor( nSpace / 100 ) / 10 .. "KB remaining)" ) else print( nSpace .. "B remaining)" ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua index e481dd9cd..2d7d9357e 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua @@ -95,7 +95,7 @@ local function save( _sPath ) local function innerSave() file, fileerr = fs.open( _sPath, "w" ) if file then - for n, sLine in ipairs( tLines ) do + for _, sLine in ipairs( tLines ) do file.write( sLine .. "\n" ) end else @@ -287,7 +287,7 @@ local tMenuFuncs = { if bReadOnly then sStatus = "Access denied" else - local ok, err, fileerr = save( sPath ) + local ok, _, fileerr = save( sPath ) if ok then sStatus="Saved to "..sPath else @@ -357,7 +357,7 @@ local tMenuFuncs = { term.redirect( printerTerminal ) local ok, error = pcall( function() term.scroll() - for n, sLine in ipairs( tLines ) do + for _, sLine in ipairs( tLines ) do print( sLine ) end end ) @@ -385,7 +385,7 @@ local tMenuFuncs = { end, Run = function() local sTempPath = "/.temp" - local ok, err = save( sTempPath ) + local ok = save( sTempPath ) if ok then local nTask = shell.openTab( sTempPath ) if nTask then @@ -411,7 +411,7 @@ local function doMenuItem( _n ) end local function setCursor( newX, newY ) - local oldX, oldY = x, y + local _, oldY = x, y x, y = newX, newY local screenX = x - scrollX local screenY = y - scrollY @@ -476,7 +476,6 @@ end while bRunning do local sEvent, param, param2, param3 = os.pullEvent() if sEvent == "key" then - local oldX, oldY = x, y if param == keys.up then -- Up if not bMenu then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua index bd0bb12b4..5011458ca 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua @@ -186,8 +186,8 @@ local function drawInterface() term.write("\127\127") -- Left and Right Selected Colours - for i=18,18 do - term.setCursorPos(w-1, i) + do + term.setCursorPos(w-1, 18) if leftColour ~= nil then term.setBackgroundColour( leftColour ) term.write(" ") @@ -269,7 +269,7 @@ local function accessMenu() for k,v in pairs(mChoices) do if selection==k then term.setTextColour(colours.yellow) - local ox,_ = term.getCursorPos() + local ox = term.getCursorPos() term.write("["..string.rep(" ",#v).."]") term.setCursorPos(ox+1,h) term.setTextColour(colours.white) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua index d58bb0a4a..232f6d863 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua @@ -66,8 +66,8 @@ local function printCentred( yc, stg ) end local function centerOrgin() - XOrgin = math.floor((TermW/2)-(SizeW/2)) - YOrgin = math.floor((TermH/2)-(SizeH/2)) + XOrgin = math.floor(TermW/2-SizeW/2) + YOrgin = math.floor(TermH/2-SizeH/2) end local function reMap() @@ -177,7 +177,6 @@ local function loadLevel(nNum) local sLevelD = sDir .. "/levels/" .. tostring(nNum)..".dat" if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end fLevel = fs.open(sLevelD,"r") - local Line = 0 local wl = true Blocks = tonumber(string.sub(fLevel.readLine(),1,1)) local xSize = string.len(fLevel.readLine())+2 @@ -557,7 +556,7 @@ function InterFace.render() elseif p3 == TermH and p2 >= TermW-4 and p2 <= TermW-3 then bPaused = not bPaused fSpeedS = false - Speed = (bPaused and 0) or nSpeed + Speed = bPaused and 0 or nSpeed if Speed > 0 then Tick = os.startTimer(Speed) else @@ -567,7 +566,7 @@ function InterFace.render() elseif p3 == TermH and p2 >= TermW-1 then bPaused = false fSpeedS = not fSpeedS - Speed = (fSpeedS and fSpeed) or nSpeed + Speed = fSpeedS and fSpeed or nSpeed Tick = os.startTimer(Speed) InterFace.drawBar() elseif p3-1 < YOrgin+SizeH+1 and p3-1 > YOrgin and @@ -596,7 +595,6 @@ local function startG(LevelN) drawStars() loadLevel(LevelN) centerOrgin() - local create = true drawMap() InterFace.drawBar() gRender("start") diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua index 61f373e8e..eef035301 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua @@ -342,7 +342,7 @@ local function getTimeOfDay() end local function isSunny() - return (getTimeOfDay() < 10) + return getTimeOfDay() < 10 end local function getRoom( x, y, z, dontCreate ) @@ -365,7 +365,7 @@ local function getRoom( x, y, z, dontCreate ) -- Add animals if math.random(1,3) == 1 then - for n = 1,math.random(1,2) do + for _ = 1,math.random(1,2) do local sAnimal = tAnimals[ math.random( 1, #tAnimals ) ] room.items[ sAnimal ] = items[ sAnimal ] end @@ -478,7 +478,7 @@ local function findItem( _tList, _sQuery ) return sItem end if tItem.aliases ~= nil then - for n, sAlias in pairs( tItem.aliases ) do + for _, sAlias in pairs( tItem.aliases ) do if sAlias == _sQuery then return sItem end @@ -613,7 +613,7 @@ local function doCommand( text ) end for sCommand, t in pairs( tMatches ) do - for n, sMatch in pairs( t ) do + for _, sMatch in pairs( t ) do local tCaptures = { string.match( text, "^" .. sMatch .. "$" ) } if #tCaptures ~= 0 then local fnCommand = commands[ sCommand ] @@ -679,7 +679,7 @@ function commands.look( _sTarget ) end if tItem then - print( tItem.desc or ("You see nothing special about "..sItem..".") ) + print( tItem.desc or "You see nothing special about "..sItem.."." ) else print( "You don't see any ".._sTarget.." here." ) end @@ -752,7 +752,7 @@ function commands.dig( _sDir, _sTool ) tTool = inventory[ sTool ] end - local bActuallyDigging = (room.exits[ _sDir ] ~= true) + local bActuallyDigging = room.exits[ _sDir ] ~= true if bActuallyDigging then if sTool == nil or tTool.toolType ~= "pick" then print( "You need to use a pickaxe to dig through stone." ) @@ -1021,7 +1021,7 @@ function commands.cbreak( _sItem, _sTool ) print( "The "..tItem.aliases[1].." dies." ) if tItem.drops then - for n, sDrop in pairs( tItem.drops ) do + for _, sDrop in pairs( tItem.drops ) do if not room.items[sDrop] then print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) room.items[sDrop] = items[sDrop] @@ -1037,7 +1037,7 @@ function commands.cbreak( _sItem, _sTool ) end if tItem.hitDrops then - for n, sDrop in pairs( tItem.hitDrops ) do + for _, sDrop in pairs( tItem.hitDrops ) do if not room.items[sDrop] then print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) room.items[sDrop] = items[sDrop] @@ -1071,18 +1071,17 @@ function commands.craft( _sItem ) return end - local room = getRoom( x,y,z ) local sItem = findItem( items, _sItem ) - local tRecipe = (sItem and tRecipes[ sItem ]) or nil + local tRecipe = sItem and tRecipes[ sItem ] or nil if tRecipe then - for n,sReq in ipairs( tRecipe ) do + for _,sReq in ipairs( tRecipe ) do if inventory[sReq] == nil then print( "You don't have the items you need to craft "..sItem.."." ) return end end - for n,sReq in ipairs( tRecipe ) do + for _,sReq in ipairs( tRecipe ) do inventory[sReq] = nil end inventory[ sItem ] = items[ sItem ] @@ -1223,7 +1222,7 @@ local function simulate() -- Spawn monsters if room.nMonsters < 2 and - ((h == 0 and not isSunny() and not room.items["a torch"]) or room.dark) and + (h == 0 and not isSunny() and not room.items["a torch"] or room.dark) and math.random(1,6) == 1 then local sMonster = tMonsters[ math.random(1,#tMonsters) ] @@ -1240,7 +1239,7 @@ local function simulate() -- Burn monsters if h == 0 and isSunny() then - for n,sMonster in ipairs( tMonsters ) do + for _,sMonster in ipairs( tMonsters ) do if room.items[sMonster] and items[sMonster].nocturnal then room.items[sMonster] = nil if sx == 0 and sy == 0 and sz == 0 and not room.dark then @@ -1258,10 +1257,10 @@ local function simulate() -- Make monsters attack local room = getRoom( x, y, z ) if nTimeInRoom >= 2 and not bNewMonstersThisRoom then - for n,sMonster in ipairs( tMonsters ) do + for _,sMonster in ipairs( tMonsters ) do if room.items[sMonster] then if math.random(1,4) == 1 and - not (y == 0 and isSunny() and (sMonster == "a spider")) then + not (y == 0 and isSunny() and sMonster == "a spider") then if sMonster == "a creeper" then if room.dark then print( "A creeper explodes." ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua index 4cc98a3ef..81775248b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua @@ -23,7 +23,7 @@ elseif sCommand == "play" or sCommand == nil then if sName == nil then -- No disc specified, pick one at random local tNames = {} - for n,sName in ipairs( peripheral.getNames() ) do + for _,sName in ipairs( peripheral.getNames() ) do if disk.isPresent( sName ) and disk.hasAudio( sName ) then table.insert( tNames, sName ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua index 33c7eed8f..58eb72fc0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua @@ -2,15 +2,13 @@ -- Display the start screen local w,h = term.getSize() -local titleColour, headingColour, textColour, wormColour, fruitColour +local headingColour, textColour, wormColour, fruitColour if term.isColour() then - titleColour = colours.red headingColour = colours.yellow textColour = colours.white wormColour = colours.green fruitColour = colours.red else - titleColour = colours.white headingColour = colours.white textColour = colours.white wormColour = colours.white @@ -27,8 +25,6 @@ end local xVel,yVel = 1,0 local xPos, yPos = math.floor(w/2), math.floor(h/2) local pxVel, pyVel = nil, nil - -local nLength = 1 local nExtraLength = 6 local bRunning = true @@ -103,7 +99,6 @@ local function drawMenu() end local function update( ) - local x,y = xPos,yPos if pxVel and pyVel then xVel, yVel = pxVel, pyVel pxVel, pyVel = nil, nil @@ -190,7 +185,7 @@ end drawMenu() drawFrontend() while true do - local e,key = os.pullEvent( "key" ) + local _,key = os.pullEvent( "key" ) if key == keys.up or key == keys.w then -- Up if nDifficulty > 1 then @@ -228,7 +223,7 @@ addFruit() -- Play the game local timer = os.startTimer(0) while bRunning do - local event, p1, p2 = os.pullEvent() + local event, p1 = os.pullEvent() if event == "timer" and p1 == timer then timer = os.startTimer(nInterval) update( false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua index fc1ae7614..77621de75 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua @@ -28,7 +28,7 @@ elseif sCommand == "host" then -- Find a modem local sModemSide = nil - for n,sSide in ipairs( rs.getSides() ) do + for _,sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break @@ -80,7 +80,7 @@ elseif sCommand == "host" then -- Print the number of requests handled nServed = nServed + 1 if nServed > 1 then - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos(1,y-1) end print( nServed.." GPS requests served" ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/help.lua b/src/main/resources/assets/computercraft/lua/rom/programs/help.lua index 2925cf72d..c8653616a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/help.lua @@ -14,7 +14,7 @@ if sTopic == "index" then end local sFile = help.lookup( sTopic ) -local file = ((sFile ~= nil) and io.open( sFile )) or nil +local file = sFile ~= nil and io.open( sFile ) or nil if file then local sContents = file:read("*a") file:close() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/list.lua b/src/main/resources/assets/computercraft/lua/rom/programs/list.lua index 14ed40439..f493d8ae5 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/list.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/list.lua @@ -18,7 +18,7 @@ local tFiles = {} local tDirs = {} local bShowHidden = settings.get( "list.show_hidden" ) -for n, sItem in pairs( tAll ) do +for _, sItem in pairs( tAll ) do if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then local sPath = fs.combine( sDir, sItem ) if fs.isDir( sPath ) then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua index e1a4cb0f2..50766b973 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua @@ -67,7 +67,7 @@ while bRunning do local nForcePrint = 0 local func, e = load( s, "=lua", "t", tEnv ) - local func2, e2 = load( "return _echo("..s..");", "=lua", "t", tEnv ) + local func2 = load( "return _echo("..s..");", "=lua", "t", tEnv ) if not func then if func2 then func = func2 @@ -84,7 +84,7 @@ while bRunning do local tResults = table.pack( pcall( func ) ) if tResults[1] then local n = 1 - while n < tResults.n or (n <= nForcePrint) do + while n < tResults.n or n <= nForcePrint do local value = tResults[ n + 1 ] if type( value ) == "table" then local metatable = getmetatable( value ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua index a794c90b9..5f12588e7 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for n,sFile in ipairs( tFiles ) do + for _,sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.move( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua index 3680b6b66..afecfa67b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua @@ -424,7 +424,7 @@ local function playGame() end if #rows>0 then - for i=1,4 do + for _=1,4 do sleep(.1) for r=1,#rows do r=rows[r] @@ -469,7 +469,6 @@ local function playGame() end local function blockFall() - local result = false if testBlockAt(curBlock,curX,curY+1,curRot) then pitBlock(curBlock,curX,curY,curRot) --detect rows that clear @@ -524,16 +523,16 @@ local function playGame() dropTimer=os.startTimer(dropSpeed) end if dx+dr~=0 then - if not testBlockAt(curBlock,curX+dx,curY+dy,(dr>0 and curRot%#curBlock+dr or curRot)) then + if not testBlockAt(curBlock,curX+dx,curY+dy,dr>0 and curRot%#curBlock+dr or curRot) then eraseBlockAt(curBlock,curX,curY,curRot) curX=curX+dx curY=curY+dy - curRot=dr==0 and curRot or (curRot%#curBlock+dr) + curRot=dr==0 and curRot or curRot%#curBlock+dr drawBlockAt(curBlock,curX,curY,curRot) end end elseif e[1]=="term_resize" then - local w,h=term.getSize() + local _,h=term.getSize() if h==20 then heightAdjust=0 else @@ -617,7 +616,7 @@ local function runMenu() level=math.max(level-1,1) drawMenu() elseif key>=keys.one and key<=keys.nine and selected==1 then - level=(key-keys.one) + 1 + level=key-keys.one + 1 drawMenu() elseif key==keys.up or key==keys.w then selected=selected-1 diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua index 329f15db8..2bf5404ee 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua @@ -9,7 +9,7 @@ end local sOpenedModem = nil local function openModem() - for n,sModem in ipairs( peripheral.getNames() ) do + for _,sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then if not rednet.isOpen( sModem ) then rednet.open( sModem ) @@ -94,7 +94,7 @@ if sCommand == "host" then end local function printUsers() - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nUsers == 1 then @@ -108,7 +108,7 @@ if sCommand == "host" then local ok, error = pcall( function() parallel.waitForAny( function() while true do - local sEvent, timer = os.pullEvent( "timer" ) + local _, timer = os.pullEvent( "timer" ) local nUserID = tPingPongTimer[ timer ] if nUserID and tUsers[ nUserID ] then local tUser = tUsers[ nUserID ] @@ -148,7 +148,7 @@ if sCommand == "host" then ["users"] = function( tUser, sContent ) send( "* Connected Users:", tUser.nUserID ) local sUsers = "*" - for nUserID, tUser in pairs( tUsers ) do + for _, tUser in pairs( tUsers ) do sUsers = sUsers .. " " .. tUser.sUsername end send( sUsers, tUser.nUserID ) @@ -156,7 +156,7 @@ if sCommand == "host" then ["help"] = function( tUser, sContent ) send( "* Available commands:", tUser.nUserID ) local sCommands = "*" - for sCommand, fnCommand in pairs( tCommands ) do + for sCommand in pairs( tCommands ) do sCommands = sCommands .. " /" .. sCommand end send( sCommands.." /logout", tUser.nUserID ) @@ -297,8 +297,7 @@ elseif sCommand == "join" then promptWindow.restoreCursor() local function drawTitle() - local x,y = titleWindow.getCursorPos() - local w,h = titleWindow.getSize() + local w = titleWindow.getSize() local sTitle = sUsername.." on "..sHostname titleWindow.setTextColour( highlightColour ) titleWindow.setCursorPos( math.floor( w/2 - string.len(sTitle)/2 ), 1 ) @@ -410,7 +409,7 @@ elseif sCommand == "join" then term.redirect( parentTerm ) -- Print error notice - local w,h = term.getSize() + local _,h = term.getSize() term.setCursorPos( 1, h ) term.clearLine() term.setCursorBlink( false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua index c8fdc89b8..452ffb587 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua @@ -1,7 +1,7 @@ -- Find modems local tModems = {} -for n,sModem in ipairs( peripheral.getNames() ) do +for _,sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then table.insert( tModems, sModem ) end @@ -59,7 +59,7 @@ local ok, error = pcall( function() -- Log the event nTransmittedMessages = nTransmittedMessages + 1 - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nTransmittedMessages == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua index 8a6d2db86..ff38a89ef 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua @@ -17,7 +17,7 @@ if sCommand == "probe" then local count = 0 local bundledCount = 0 - for n,sSide in ipairs( redstone.getSides() ) do + for _,sSide in ipairs( redstone.getSides() ) do if redstone.getBundledInput( sSide ) > 0 then bundledCount = bundledCount + 1 end @@ -39,7 +39,7 @@ if sCommand == "probe" then if bundledCount > 0 then print() print( "Bundled inputs:" ) - for i,sSide in ipairs( redstone.getSides() ) do + for _,sSide in ipairs( redstone.getSides() ) do local nInput = redstone.getBundledInput( sSide ) if nInput ~= 0 then write( sSide..": " ) @@ -69,7 +69,7 @@ elseif sCommand == "pulse" then local sSide = tArgs[2] local nCount = tonumber( tArgs[3] ) or 1 local nPeriod = tonumber( tArgs[4] ) or 0.5 - for n=1,nCount do + for _=1,nCount do redstone.setOutput( sSide, true ) sleep( nPeriod / 2 ) redstone.setOutput( sSide, false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua index 9acad56c2..94ef6b621 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua @@ -2,7 +2,7 @@ local tArgs = { ... } if #tArgs == 0 then -- "set" - local x,y = term.getCursorPos() + local _,y = term.getCursorPos() local tSettings = {} for n,sName in ipairs( settings.getNames() ) do tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua index 3c15e04b3..13c4b90c0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua @@ -9,10 +9,10 @@ if multishell then end local bExit = false -local sDir = (parentShell and parentShell.dir()) or "" -local sPath = (parentShell and parentShell.path()) or ".:/rom/programs" -local tAliases = (parentShell and parentShell.aliases()) or {} -local tCompletionInfo = (parentShell and parentShell.getCompletionInfo()) or {} +local sDir = parentShell and parentShell.dir() or "" +local sPath = parentShell and parentShell.path() or ".:/rom/programs" +local tAliases = parentShell and parentShell.aliases() or {} +local tCompletionInfo = parentShell and parentShell.getCompletionInfo() or {} local tProgramStack = {} local shell = {} @@ -287,7 +287,7 @@ function shell.programs( _bIncludeHidden ) -- Sort and return local tItemList = {} - for sItem, b in pairs( tItems ) do + for sItem in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) @@ -304,7 +304,7 @@ local function completeProgram( sLine ) local tSeen = {} -- Add aliases - for sAlias, sCommand in pairs( tAliases ) do + for sAlias in pairs( tAliases ) do if #sAlias > #sLine and string.sub( sAlias, 1, #sLine ) == sLine then local sResult = string.sub( sAlias, #sLine + 1 ) if not tSeen[ sResult ] then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua index 6f32a1df0..246992f78 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua @@ -81,7 +81,7 @@ textutils.slowWrite( "Preparing to get down." ) textutils.slowPrint( "..", 0.75 ) local sAudio = nil -for n,sName in pairs( peripheral.getNames() ) do +for _,sName in pairs( peripheral.getNames() ) do if disk.hasAudio( sName ) then disk.playAudio( sName ) print( "Jamming to "..disk.getAudioTitle( sName ) ) @@ -95,7 +95,7 @@ print( "Press any key to stop the groove" ) parallel.waitForAny( function() while not bEnd do - local event, key = os.pullEvent("key") + local _, key = os.pullEvent("key") if key ~= keys.escape then return end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua index 677e43678..5e7f32274 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua @@ -81,7 +81,7 @@ local function collect() if nTotalItems > collected then collected = nTotalItems if math.fmod(collected + unloaded, 50) == 0 then - print( "Mined "..(collected + unloaded).." items." ) + print( "Mined "..collected + unloaded.." items." ) end end @@ -98,9 +98,8 @@ function refuel( ammount ) return true end - local needed = ammount or (xPos + zPos + depth + 2) + local needed = ammount or xPos + zPos + depth + 2 if turtle.getFuelLevel() < needed then - local fueled = false for n=1,16 do if turtle.getItemCount(n) > 0 then turtle.select(n) @@ -292,7 +291,7 @@ local alternate = 0 local done = false while not done do for n=1,size do - for m=1,size-1 do + for _=1,size-1 do if not tryForwards() then done = true break @@ -354,4 +353,4 @@ if reseal then turtle.placeDown() end -print( "Mined "..(collected + unloaded).." items total." ) +print( "Mined "..collected + unloaded.." items total." ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua index d9f606f8c..fa69de01c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua @@ -23,7 +23,7 @@ end if turtle.getFuelLevel() ~= "unlimited" then for n = 1, 16 do -- Stop if we've reached the limit, or are fully refuelled. - if (nLimit and nLimit <= 0) or turtle.getFuelLevel() >= turtle.getFuelLimit() then + if nLimit and nLimit <= 0 or turtle.getFuelLevel() >= turtle.getFuelLimit() then break end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua index 9345a6225..9bf4e2665 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua @@ -15,8 +15,6 @@ if length < 1 then print( "Tunnel length must be positive" ) return end - -local depth = 0 local collected = 0 local function collect() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua index 4ab6151ec..df90142d2 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/turn.lua @@ -31,7 +31,7 @@ while nArg <= #tArgs do local fnHandler = tHandlers[string.lower(sDirection)] if fnHandler then - for n=1,nDistance do + for _=1,nDistance do fnHandler( nArg ) end else diff --git a/src/main/resources/assets/computercraft/lua/rom/startup.lua b/src/main/resources/assets/computercraft/lua/rom/startup.lua index e6b396b39..af8ff4fbc 100644 --- a/src/main/resources/assets/computercraft/lua/rom/startup.lua +++ b/src/main/resources/assets/computercraft/lua/rom/startup.lua @@ -163,7 +163,7 @@ if settings.get( "shell.allow_startup" ) then tUserStartups = findStartups( "/" ) end if settings.get( "shell.allow_disk_startup" ) then - for n,sName in pairs( peripheral.getNames() ) do + for _,sName in pairs( peripheral.getNames() ) do if disk.isPresent( sName ) and disk.hasData( sName ) then local startups = findStartups( disk.getMountPath( sName ) ) if startups then From fa70ebcac248c2360b58a014a38b8334eeb75838 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 7 Dec 2019 10:33:47 +0000 Subject: [PATCH 02/11] Fix spacing on all of the rom (#323) --- illuaminate.sexp | 3 +- .../assets/computercraft/lua/bios.lua | 34 +- .../computercraft/lua/rom/apis/colors.lua | 6 +- .../computercraft/lua/rom/apis/colours.lua | 2 +- .../lua/rom/apis/command/commands.lua | 6 +- .../computercraft/lua/rom/apis/disk.lua | 2 +- .../assets/computercraft/lua/rom/apis/gps.lua | 14 +- .../computercraft/lua/rom/apis/help.lua | 12 +- .../assets/computercraft/lua/rom/apis/io.lua | 6 +- .../computercraft/lua/rom/apis/keys.lua | 86 +-- .../computercraft/lua/rom/apis/paintutils.lua | 26 +- .../computercraft/lua/rom/apis/parallel.lua | 4 +- .../computercraft/lua/rom/apis/peripheral.lua | 16 +- .../computercraft/lua/rom/apis/rednet.lua | 10 +- .../computercraft/lua/rom/apis/settings.lua | 4 +- .../computercraft/lua/rom/apis/term.lua | 8 +- .../computercraft/lua/rom/apis/textutils.lua | 38 +- .../lua/rom/apis/turtle/turtle.lua | 2 +- .../computercraft/lua/rom/apis/vector.lua | 14 +- .../computercraft/lua/rom/apis/window.lua | 20 +- .../lua/rom/programs/advanced/multishell.lua | 26 +- .../computercraft/lua/rom/programs/alias.lua | 2 +- .../computercraft/lua/rom/programs/apis.lua | 2 +- .../lua/rom/programs/command/exec.lua | 6 +- .../computercraft/lua/rom/programs/copy.lua | 2 +- .../computercraft/lua/rom/programs/edit.lua | 94 +-- .../computercraft/lua/rom/programs/eject.lua | 2 +- .../lua/rom/programs/fun/advanced/paint.lua | 92 +-- .../rom/programs/fun/advanced/redirection.lua | 294 ++++---- .../lua/rom/programs/fun/adventure.lua | 132 ++-- .../computercraft/lua/rom/programs/fun/dj.lua | 8 +- .../lua/rom/programs/fun/hello.lua | 2 +- .../lua/rom/programs/fun/worm.lua | 84 +-- .../computercraft/lua/rom/programs/gps.lua | 16 +- .../lua/rom/programs/http/pastebin.lua | 20 +- .../computercraft/lua/rom/programs/id.lua | 10 +- .../computercraft/lua/rom/programs/label.lua | 12 +- .../computercraft/lua/rom/programs/lua.lua | 2 +- .../computercraft/lua/rom/programs/mkdir.lua | 4 +- .../lua/rom/programs/monitor.lua | 6 +- .../computercraft/lua/rom/programs/motd.lua | 4 +- .../computercraft/lua/rom/programs/move.lua | 2 +- .../lua/rom/programs/peripherals.lua | 2 +- .../lua/rom/programs/pocket/falling.lua | 630 +++++++++--------- .../lua/rom/programs/rednet/chat.lua | 40 +- .../lua/rom/programs/rednet/repeat.lua | 10 +- .../lua/rom/programs/redstone.lua | 10 +- .../computercraft/lua/rom/programs/set.lua | 6 +- .../computercraft/lua/rom/programs/shell.lua | 22 +- .../computercraft/lua/rom/programs/time.lua | 2 +- .../lua/rom/programs/turtle/craft.lua | 2 +- .../lua/rom/programs/turtle/dance.lua | 6 +- .../lua/rom/programs/turtle/excavate.lua | 38 +- .../lua/rom/programs/turtle/go.lua | 2 +- .../lua/rom/programs/turtle/refuel.lua | 2 +- .../lua/rom/programs/turtle/tunnel.lua | 10 +- .../lua/rom/programs/turtle/turn.lua | 4 +- .../lua/rom/programs/turtle/unequip.lua | 2 +- .../assets/computercraft/lua/rom/startup.lua | 22 +- src/test/resources/test-rom/mcfly.lua | 38 +- .../resources/test-rom/spec/apis/gps_spec.lua | 2 +- .../resources/test-rom/spec/apis/io_spec.lua | 6 +- .../resources/test-rom/spec/base_spec.lua | 2 +- .../spec/modules/cc/shell/completion_spec.lua | 2 +- .../spec/programs/command/commands_spec.lua | 2 +- .../spec/programs/command/exec_spec.lua | 6 +- .../test-rom/spec/programs/edit_spec.lua | 1 - .../spec/programs/http/pastebin_spec.lua | 4 +- .../test-rom/spec/programs/http/wget_spec.lua | 2 +- .../test-rom/spec/programs/id_spec.lua | 2 +- .../test-rom/spec/programs/motd_spec.lua | 4 +- .../spec/programs/pocket/equip_spec.lua | 4 +- .../spec/programs/pocket/unequip_spec.lua | 4 +- .../test-rom/spec/programs/set_spec.lua | 8 +- .../test-rom/spec/programs/time_spec.lua | 2 +- .../spec/programs/turtle/craft_spec.lua | 4 +- .../spec/programs/turtle/equip_spec.lua | 6 +- .../spec/programs/turtle/refuel_spec.lua | 6 +- .../spec/programs/turtle/unequip_spec.lua | 12 +- .../resources/test-rom/spec/test_helpers.lua | 2 +- 80 files changed, 1032 insertions(+), 1032 deletions(-) diff --git a/illuaminate.sexp b/illuaminate.sexp index 2271a01e5..b4deb17bd 100644 --- a/illuaminate.sexp +++ b/illuaminate.sexp @@ -2,7 +2,8 @@ (sources /src/main/resources/assets/computercraft/lua/bios.lua - /src/main/resources/assets/computercraft/lua/rom/) + /src/main/resources/assets/computercraft/lua/rom/ + /src/test/resources/test-rom) (at / (linters diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index e4b792538..4a30d22da 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -93,7 +93,7 @@ if _VERSION == "Lua 5.1" then bxor = bit32.bxor, brshift = bit32.arshift, blshift = bit32.lshift, - blogic_rshift = bit32.rshift + blogic_rshift = bit32.rshift, } end end @@ -191,8 +191,8 @@ end function write( sText ) expect(1, sText, "string", "number") - local w,h = term.getSize() - local x,y = term.getCursorPos() + local w, h = term.getSize() + local x, y = term.getCursorPos() local nLinesPrinted = 0 local function newLine() @@ -212,7 +212,7 @@ function write( sText ) if whitespace then -- Print whitespace term.write( whitespace ) - x,y = term.getCursorPos() + x, y = term.getCursorPos() sText = string.sub( sText, string.len(whitespace) + 1 ) end @@ -233,8 +233,8 @@ function write( sText ) newLine() end term.write( text ) - text = string.sub( text, w-x + 2 ) - x,y = term.getCursorPos() + text = string.sub( text, w - x + 2 ) + x, y = term.getCursorPos() end else -- Print a word normally @@ -242,7 +242,7 @@ function write( sText ) newLine() end term.write( text ) - x,y = term.getCursorPos() + x, y = term.getCursorPos() end end end @@ -613,10 +613,10 @@ function os.loadAPI( _sPath ) expect(1, _sPath, "string") local sName = fs.getName( _sPath ) if sName:sub(-4) == ".lua" then - sName = sName:sub(1,-5) + sName = sName:sub(1, -5) end if tAPIsLoading[sName] == true then - printError( "API "..sName.." is already being loaded" ) + printError( "API " .. sName .. " is already being loaded" ) return false end tAPIsLoading[sName] = true @@ -636,7 +636,7 @@ function os.loadAPI( _sPath ) end local tAPI = {} - for k,v in pairs( tEnv ) do + for k, v in pairs( tEnv ) do if k ~= "_ENV" then tAPI[k] = v end @@ -680,7 +680,7 @@ if http then local methods = { GET = true, POST = true, HEAD = true, - OPTIONS = true, PUT = true, DELETE = true + OPTIONS = true, PUT = true, DELETE = true, } local function checkKey( options, key, ty, opt ) @@ -842,7 +842,7 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs ) end end local tFiles = fs.list( sDir ) - for n=1,#tFiles do + for n = 1, #tFiles do local sFile = tFiles[n] if #sFile >= #sName and string.sub( sFile, 1, #sName ) == sName then local bIsDir = fs.isDir( fs.combine( sDir, sFile ) ) @@ -867,7 +867,7 @@ end -- Load APIs local bAPIError = false local tApis = fs.list( "rom/apis" ) -for _,sFile in ipairs( tApis ) do +for _, sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis", sFile ) if not fs.isDir( sPath ) then @@ -881,7 +881,7 @@ end if turtle and fs.isDir( "rom/apis/turtle" ) then -- Load turtle APIs local tApis = fs.list( "rom/apis/turtle" ) - for _,sFile in ipairs( tApis ) do + for _, sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/turtle", sFile ) if not fs.isDir( sPath ) then @@ -896,7 +896,7 @@ end if pocket and fs.isDir( "rom/apis/pocket" ) then -- Load pocket APIs local tApis = fs.list( "rom/apis/pocket" ) - for _,sFile in ipairs( tApis ) do + for _, sFile in ipairs( tApis ) do if string.sub( sFile, 1, 1 ) ~= "." then local sPath = fs.combine( "rom/apis/pocket", sFile ) if not fs.isDir( sPath ) then @@ -925,7 +925,7 @@ if commands and fs.isDir( "rom/apis/command" ) then end end return nil - end + end, } setmetatable( commands, tCaseInsensitiveMetatable ) setmetatable( commands.async, tCaseInsensitiveMetatable ) @@ -941,7 +941,7 @@ if bAPIError then print( "Press any key to continue" ) os.pullEvent( "key" ) term.clear() - term.setCursorPos( 1,1 ) + term.setCursorPos( 1, 1 ) end -- Set default settings diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/colors.lua b/src/main/resources/assets/computercraft/lua/rom/apis/colors.lua index 969f984e5..b2e665268 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/colors.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/colors.lua @@ -23,7 +23,7 @@ function combine( ... ) for i = 1, select('#', ...) do local c = select(i, ...) expect(i, c, "number") - r = bit32.bor(r,c) + r = bit32.bor(r, c) end return r end @@ -50,8 +50,8 @@ function packRGB( r, g, b ) expect(2, g, "number") expect(3, b, "number") return - bit32.band( r * 255, 0xFF ) * 2^16 + - bit32.band( g * 255, 0xFF ) * 2^8 + + bit32.band( r * 255, 0xFF ) * 2 ^ 16 + + bit32.band( g * 255, 0xFF ) * 2 ^ 8 + bit32.band( b * 255, 0xFF ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/colours.lua b/src/main/resources/assets/computercraft/lua/rom/apis/colours.lua index 59202ebc5..fa17c6cb3 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/colours.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/colours.lua @@ -1,6 +1,6 @@ -- Colours (for lovers of british spelling) local colours = _ENV -for k,v in pairs(colors) do +for k, v in pairs(colors) do colours[k] = v end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua index 7afd34bad..caf86f5cf 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/command/commands.lua @@ -22,7 +22,7 @@ end -- Put native functions into the environment local env = _ENV -for k,v in pairs( native ) do +for k, v in pairs( native ) do env[k] = v end @@ -30,10 +30,10 @@ end local tAsync = {} local tNonNBTJSONCommands = { [ "tellraw" ] = true, - [ "title" ] = true + [ "title" ] = true, } local tCommands = native.list() -for _,sCommandName in ipairs(tCommands) do +for _, sCommandName in ipairs(tCommands) do if env[ sCommandName ] == nil then local bJSONIsNBT = tNonNBTJSONCommands[ sCommandName ] == nil env[ sCommandName ] = function( ... ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua index 2c5e6ec8b..7a0dbad39 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua @@ -62,7 +62,7 @@ end function stopAudio( name ) if not name then - for _,sName in ipairs( peripheral.getNames() ) do + for _, sName in ipairs( peripheral.getNames() ) do stopAudio( sName ) end else diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua index aab023209..5b556eb09 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua @@ -21,12 +21,12 @@ local function trilaterate( A, B, C ) local r2 = B.nDistance local r3 = C.nDistance - local x = (r1*r1 - r2*r2 + d*d) / (2*d) - local y = (r1*r1 - r3*r3 - x*x + (x-i)*(x-i) + j*j) / (2*j) + local x = (r1 * r1 - r2 * r2 + d * d) / (2 * d) + local y = (r1 * r1 - r3 * r3 - x * x + (x - i) * (x - i) + j * j) / (2 * j) local result = A.vPosition + ex * x + ey * y - local zSquared = r1*r1 - x*x - y*y + local zSquared = r1 * r1 - x * x - y * y if zSquared > 0 then local z = math.sqrt( zSquared ) local result1 = result + ez * z @@ -66,7 +66,7 @@ function locate( _nTimeout, _bDebug ) -- Find a modem local sModemSide = nil - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break @@ -109,7 +109,7 @@ function locate( _nTimeout, _bDebug ) if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance } if _bDebug then - print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) ) + print( tFix.nDistance .. " metres from " .. tostring( tFix.vPosition ) ) end if tFix.nDistance == 0 then pos1, pos2 = tFix.vPosition, nil @@ -148,12 +148,12 @@ function locate( _nTimeout, _bDebug ) if pos1 and pos2 then if _bDebug then print( "Ambiguous position" ) - print( "Could be "..pos1.x..","..pos1.y..","..pos1.z.." or "..pos2.x..","..pos2.y..","..pos2.z ) + print( "Could be " .. pos1.x .. "," .. pos1.y .. "," .. pos1.z .. " or " .. pos2.x .. "," .. pos2.y .. "," .. pos2.z ) end return nil elseif pos1 then if _bDebug then - print( "Position is "..pos1.x..","..pos1.y..","..pos1.z ) + print( "Position is " .. pos1.x .. "," .. pos1.y .. "," .. pos1.z ) end return pos1.x, pos1.y, pos1.z else diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua index 853ec09a0..ded20f2f3 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/help.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/help.lua @@ -18,8 +18,8 @@ function lookup( _sTopic ) sPath = fs.combine( sPath, _sTopic ) if fs.exists( sPath ) and not fs.isDir( sPath ) then return sPath - elseif fs.exists( sPath..".txt" ) and not fs.isDir( sPath..".txt" ) then - return sPath..".txt" + elseif fs.exists( sPath .. ".txt" ) and not fs.isDir( sPath .. ".txt" ) then + return sPath .. ".txt" end end @@ -30,18 +30,18 @@ end function topics() -- Add index local tItems = { - [ "index" ] = true + [ "index" ] = true, } -- Add topics from the path for sPath in string.gmatch(sPath, "[^:]+") do if fs.isDir( sPath ) then local tList = fs.list( sPath ) - for _,sFile in pairs( tList ) do + for _, sFile in pairs( tList ) do if string.sub( sFile, 1, 1 ) ~= "." then if not fs.isDir( fs.combine( sPath, sFile ) ) then if #sFile > 4 and sFile:sub(-4) == ".txt" then - sFile = sFile:sub(1,-5) + sFile = sFile:sub(1, -5) end tItems[ sFile ] = true end @@ -63,7 +63,7 @@ function completeTopic( sText ) expect(1, sText, "string") local tTopics = topics() local tResults = {} - for n=1,#tTopics do + for n = 1, #tTopics do local sTopic = tTopics[n] if #sTopic > #sText and string.sub( sTopic, 1, #sText ) == sText then table.insert( tResults, string.sub( sTopic, #sText + 1 ) ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/io.lua b/src/main/resources/assets/computercraft/lua/rom/apis/io.lua index efbc13b40..779d7e26d 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/io.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/io.lua @@ -129,11 +129,11 @@ handleMetatable = { } local defaultInput = setmetatable({ - _handle = { readLine = _G.read } + _handle = { readLine = _G.read }, }, handleMetatable) local defaultOutput = setmetatable({ - _handle = { write = _G.write } + _handle = { write = _G.write }, }, handleMetatable) local defaultError = setmetatable({ @@ -147,7 +147,7 @@ local defaultError = setmetatable({ _G.write(...) if term.isColour() then term.setTextColour(oldColour) end end, - } + }, }, handleMetatable) local currentInput = defaultInput diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua b/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua index 8411883cf..c3ab42605 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua @@ -4,49 +4,49 @@ local expect = dofile("rom/modules/main/cc/expect.lua").expect local tKeys = { - nil, "one", "two", "three", "four", -- 1 - "five", "six", "seven", "eight", "nine", -- 6 - "zero", "minus", "equals", "backspace","tab", -- 11 - "q", "w", "e", "r", "t", -- 16 - "y", "u", "i", "o", "p", -- 21 - "leftBracket","rightBracket","enter","leftCtrl","a", -- 26 - "s", "d", "f", "g", "h", -- 31 - "j", "k", "l", "semiColon","apostrophe", -- 36 - "grave", "leftShift","backslash","z", "x", -- 41 - "c", "v", "b", "n", "m", -- 46 - "comma", "period", "slash", "rightShift","multiply", -- 51 - "leftAlt", "space", "capsLock", "f1", "f2", -- 56 - "f3", "f4", "f5", "f6", "f7", -- 61 - "f8", "f9", "f10", "numLock", "scrollLock", -- 66 - "numPad7", "numPad8", "numPad9", "numPadSubtract","numPad4", -- 71 - "numPad5", "numPad6", "numPadAdd","numPad1", "numPad2", -- 76 - "numPad3", "numPad0", "numPadDecimal",nil, nil, -- 81 - nil, "f11", "f12", nil, nil, -- 86 - nil, nil, nil, nil, nil, -- 91 - nil, nil, nil, nil, "f13", -- 96 - "f14", "f15", nil, nil, nil, -- 101 - nil, nil, nil, nil, nil, -- 106 - nil, "kana", nil, nil, nil, -- 111 - nil, nil, nil, nil, nil, -- 116 - "convert", nil, "noconvert",nil, "yen", -- 121 - nil, nil, nil, nil, nil, -- 126 - nil, nil, nil, nil, nil, -- 131 - nil, nil, nil, nil, nil, -- 136 - "numPadEquals",nil, nil, "circumflex","at", -- 141 - "colon", "underscore","kanji", "stop", "ax", -- 146 - nil, nil, nil, nil, nil, -- 151 - "numPadEnter","rightCtrl",nil, nil, nil, -- 156 - nil, nil, nil, nil, nil, -- 161 - nil, nil, nil, nil, nil, -- 166 - nil, nil, nil, nil, nil, -- 171 - nil, nil, nil, "numPadComma",nil, -- 176 - "numPadDivide",nil, nil, "rightAlt", nil, -- 181 - nil, nil, nil, nil, nil, -- 186 - nil, nil, nil, nil, nil, -- 191 - nil, "pause", nil, "home", "up", -- 196 - "pageUp", nil, "left", nil, "right", -- 201 - nil, "end", "down", "pageDown", "insert", -- 206 - "delete" -- 211 + nil, "one", "two", "three", "four", -- 1 + "five", "six", "seven", "eight", "nine", -- 6 + "zero", "minus", "equals", "backspace", "tab", -- 11 + "q", "w", "e", "r", "t", -- 16 + "y", "u", "i", "o", "p", -- 21 + "leftBracket", "rightBracket", "enter", "leftCtrl", "a", -- 26 + "s", "d", "f", "g", "h", -- 31 + "j", "k", "l", "semiColon", "apostrophe", -- 36 + "grave", "leftShift", "backslash", "z", "x", -- 41 + "c", "v", "b", "n", "m", -- 46 + "comma", "period", "slash", "rightShift", "multiply", -- 51 + "leftAlt", "space", "capsLock", "f1", "f2", -- 56 + "f3", "f4", "f5", "f6", "f7", -- 61 + "f8", "f9", "f10", "numLock", "scrollLock", -- 66 + "numPad7", "numPad8", "numPad9", "numPadSubtract", "numPad4", -- 71 + "numPad5", "numPad6", "numPadAdd", "numPad1", "numPad2", -- 76 + "numPad3", "numPad0", "numPadDecimal", nil, nil, -- 81 + nil, "f11", "f12", nil, nil, -- 86 + nil, nil, nil, nil, nil, -- 91 + nil, nil, nil, nil, "f13", -- 96 + "f14", "f15", nil, nil, nil, -- 101 + nil, nil, nil, nil, nil, -- 106 + nil, "kana", nil, nil, nil, -- 111 + nil, nil, nil, nil, nil, -- 116 + "convert", nil, "noconvert", nil, "yen", -- 121 + nil, nil, nil, nil, nil, -- 126 + nil, nil, nil, nil, nil, -- 131 + nil, nil, nil, nil, nil, -- 136 + "numPadEquals", nil, nil, "circumflex", "at", -- 141 + "colon", "underscore", "kanji", "stop", "ax", -- 146 + nil, nil, nil, nil, nil, -- 151 + "numPadEnter", "rightCtrl", nil, nil, nil, -- 156 + nil, nil, nil, nil, nil, -- 161 + nil, nil, nil, nil, nil, -- 166 + nil, nil, nil, nil, nil, -- 171 + nil, nil, nil, "numPadComma", nil, -- 176 + "numPadDivide", nil, nil, "rightAlt", nil, -- 181 + nil, nil, nil, nil, nil, -- 186 + nil, nil, nil, nil, nil, -- 191 + nil, "pause", nil, "home", "up", -- 196 + "pageUp", nil, "left", nil, "right", -- 201 + nil, "end", "down", "pageDown", "insert", -- 206 + "delete", -- 211 } local keys = _ENV diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua index 5420b029d..d725367d0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua @@ -6,14 +6,14 @@ local function drawPixelInternal( xPos, yPos ) end local tColourLookup = {} -for n=1,16 do - tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1) +for n = 1, 16 do + tColourLookup[ string.byte( "0123456789abcdef", n, n ) ] = 2 ^ (n - 1) end local function parseLine( tImageArg, sLine ) local tLine = {} - for x=1,sLine:len() do - tLine[x] = tColourLookup[ string.byte(sLine,x,x) ] or 0 + for x = 1, sLine:len() do + tLine[x] = tColourLookup[ string.byte(sLine, x, x) ] or 0 end table.insert( tImageArg, tLine ) end @@ -89,7 +89,7 @@ function drawLine( startX, startY, endX, endY, nColour ) if xDiff > math.abs(yDiff) then local y = minY local dy = yDiff / xDiff - for x=minX,maxX do + for x = minX, maxX do drawPixelInternal( x, math.floor( y + 0.5 ) ) y = y + dy end @@ -97,12 +97,12 @@ function drawLine( startX, startY, endX, endY, nColour ) local x = minX local dx = xDiff / yDiff if maxY >= minY then - for y=minY,maxY do + for y = minY, maxY do drawPixelInternal( math.floor( x + 0.5 ), y ) x = x + dx end else - for y=minY,maxY,-1 do + for y = minY, maxY, -1 do drawPixelInternal( math.floor( x + 0.5 ), y ) x = x - dx end @@ -142,13 +142,13 @@ function drawBox( startX, startY, endX, endY, nColour ) maxY = startY end - for x=minX,maxX do + for x = minX, maxX do drawPixelInternal( x, minY ) drawPixelInternal( x, maxY ) end if maxY - minY >= 2 then - for y=minY+1,maxY-1 do + for y = minY + 1, maxY - 1 do drawPixelInternal( minX, y ) drawPixelInternal( maxX, y ) end @@ -187,8 +187,8 @@ function drawFilledBox( startX, startY, endX, endY, nColour ) maxY = startY end - for x=minX,maxX do - for y=minY,maxY do + for x = minX, maxX do + for y = minY, maxY do drawPixelInternal( x, y ) end end @@ -198,9 +198,9 @@ function drawImage( tImage, xPos, yPos ) expect(1, tImage, "table") expect(2, xPos, "number") expect(3, yPos, "number") - for y=1,#tImage do + for y = 1, #tImage do local tLine = tImage[y] - for x=1,#tLine do + for x = 1, #tLine do if tLine[x] > 0 then term.setBackgroundColor( tLine[x] ) drawPixelInternal( x + xPos - 1, y + yPos - 1 ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/parallel.lua b/src/main/resources/assets/computercraft/lua/rom/apis/parallel.lua index 7aad3519d..43b832c8b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/parallel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/parallel.lua @@ -21,7 +21,7 @@ local function runUntilLimit( _routines, _limit ) local tFilters = {} local eventData = { n = 0 } while true do - for n=1,count do + for n = 1, count do local r = _routines[n] if r then if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then @@ -41,7 +41,7 @@ local function runUntilLimit( _routines, _limit ) end end end - for n=1,count do + for n = 1, count do local r = _routines[n] if r and coroutine.status( r ) == "dead" then _routines[n] = nil diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua index ecfccbb53..a398d696f 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua @@ -4,12 +4,12 @@ local native = peripheral function getNames() local tResults = {} - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if native.isPresent( sSide ) then table.insert( tResults, sSide ) if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then local tRemote = native.call( sSide, "getNamesRemote" ) - for _,sName in ipairs( tRemote ) do + for _, sName in ipairs( tRemote ) do table.insert( tResults, sName ) end end @@ -23,7 +23,7 @@ function isPresent( _sSide ) if native.isPresent( _sSide ) then return true end - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return true @@ -38,7 +38,7 @@ function getType( _sSide ) if native.isPresent( _sSide ) then return native.getType( _sSide ) end - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getTypeRemote", _sSide ) @@ -53,7 +53,7 @@ function getMethods( _sSide ) if native.isPresent( _sSide ) then return native.getMethods( _sSide ) end - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "getMethodsRemote", _sSide ) @@ -69,7 +69,7 @@ function call( _sSide, _sMethod, ... ) if native.isPresent( _sSide ) then return native.call( _sSide, _sMethod, ... ) end - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.call( sSide, "isPresentRemote", _sSide ) then return native.call( sSide, "callRemote", _sSide, _sMethod, ... ) @@ -84,7 +84,7 @@ function wrap( _sSide ) if peripheral.isPresent( _sSide ) then local tMethods = peripheral.getMethods( _sSide ) local tResult = {} - for _,sMethod in ipairs( tMethods ) do + for _, sMethod in ipairs( tMethods ) do tResult[sMethod] = function( ... ) return peripheral.call( _sSide, sMethod, ... ) end @@ -98,7 +98,7 @@ function find( sType, fnFilter ) expect(1, sType, "string") expect(2, fnFilter, "function", "nil") local tResults = {} - for _,sName in ipairs( peripheral.getNames() ) do + for _, sName in ipairs( peripheral.getNames() ) do if peripheral.getType( sName ) == sType then local wrapped = peripheral.wrap( sName ) if fnFilter == nil or fnFilter( sName, wrapped ) then diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua index e38084ad5..d6bf5d668 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua @@ -10,7 +10,7 @@ local tHostnames = {} function open( sModem ) expect(1, sModem, "string") if peripheral.getType( sModem ) ~= "modem" then - error( "No such modem: "..sModem, 2 ) + error( "No such modem: " .. sModem, 2 ) end peripheral.call( sModem, "open", os.getComputerID() ) peripheral.call( sModem, "open", CHANNEL_BROADCAST ) @@ -21,13 +21,13 @@ function close( sModem ) if sModem then -- Close a specific modem if peripheral.getType( sModem ) ~= "modem" then - error( "No such modem: "..sModem, 2 ) + error( "No such modem: " .. sModem, 2 ) end peripheral.call( sModem, "close", os.getComputerID() ) peripheral.call( sModem, "close", CHANNEL_BROADCAST ) else -- Close all modems - for _,sModem in ipairs( peripheral.getNames() ) do + for _, sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then close( sModem ) end @@ -44,7 +44,7 @@ function isOpen( sModem ) end else -- Check if any modem is open - for _,sModem in ipairs( peripheral.getNames() ) do + for _, sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then return true end @@ -79,7 +79,7 @@ function send( nRecipient, message, sProtocol ) sent = true else -- Send on all open modems, to the target and to repeaters - for _,sModem in ipairs( peripheral.getNames() ) do + for _, sModem in ipairs( peripheral.getNames() ) do if isOpen( sModem ) then peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage ) peripheral.call( sModem, "transmit", CHANNEL_REPEAT, nReplyChannel, tMessage ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua index 9f9ba9822..54da34a32 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua @@ -17,7 +17,7 @@ local copy function copy( value ) if type(value) == "table" then local result = {} - for k,v in pairs(value) do + for k, v in pairs(value) do result[k] = copy(v) end return result @@ -69,7 +69,7 @@ function load( sPath ) return false end - for k,v in pairs(tFile) do + for k, v in pairs(tFile) do if type(k) == "string" and (type(v) == "string" or type(v) == "number" or type(v) == "boolean" or type(v) == "table") then set( k, v ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua index 98db90be7..706bd16f6 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/term.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/term.lua @@ -16,11 +16,11 @@ term.redirect = function( target ) if target == term or target == _G.term then error( "term is not a recommended redirect target, try term.current() instead", 2 ) end - for k,v in pairs( native ) do + for k, v in pairs( native ) do if type( k ) == "string" and type( v ) == "function" then if type( target[k] ) ~= "function" then target[k] = function() - error( "Redirect object is missing method "..k..".", 2 ) + error( "Redirect object is missing method " .. k .. ".", 2 ) end end end @@ -48,13 +48,13 @@ for _, method in ipairs { "nativePaletteColor", "nativePaletteColour"} do native[method] = nil end -for k,v in pairs( native ) do +for k, v in pairs( native ) do if type( k ) == "string" and type( v ) == "function" and term[k] == nil then term[k] = wrap( k ) end end local env = _ENV -for k,v in pairs( term ) do +for k, v in pairs( term ) do env[k] = v end diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua index 09130fbad..5044d9dc3 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua @@ -9,10 +9,10 @@ function slowWrite( sText, nRate ) local nSleep = 1 / nRate sText = tostring( sText ) - local x,y = term.getCursorPos() + local x, y = term.getCursorPos() local len = string.len( sText ) - for n=1,len do + for n = 1, len do term.setCursorPos( x, y ) sleep( nSleep ) local nLines = write( string.sub( sText, 1, n ) ) @@ -42,7 +42,7 @@ function formatTime( nTime, bTwentyFourHour ) end local nHour = math.floor(nTime) - local nMinute = math.floor((nTime - nHour)*60) + local nMinute = math.floor((nTime - nHour) * 60) if sTOD then return string.format( "%d:%02d %s", nHour, nMinute, sTOD ) else @@ -54,11 +54,11 @@ local function makePagedScroll( _term, _nFreeLines ) local nativeScroll = _term.scroll local nFreeLines = _nFreeLines or 0 return function( _n ) - for _=1,_n do + for _ = 1, _n do nativeScroll( 1 ) if nFreeLines <= 0 then - local _,h = _term.getSize() + local _, h = _term.getSize() _term.setCursorPos( 1, h ) _term.write( "Press any key to continue" ) os.pullEvent( "key" ) @@ -76,7 +76,7 @@ function pagedPrint( _sText, _nFreeLines ) -- Setup a redirector local oldTerm = term.current() local newTerm = {} - for k,v in pairs( oldTerm ) do + for k, v in pairs( oldTerm ) do newTerm[k] = v end newTerm.scroll = makePagedScroll( oldTerm, _nFreeLines ) @@ -108,13 +108,13 @@ local function tabulateCommon( bPaged, ... ) expect(i, tAll[i], "number", "table") end - local w,h = term.getSize() + local w, h = term.getSize() local nMaxLen = w / 8 for n, t in ipairs( tAll ) do if type(t) == "table" then for nu, sItem in pairs(t) do if type( sItem ) ~= "string" then - error( "bad argument #"..n.."."..nu.." (expected string, got " .. type( sItem ) .. ")", 3 ) + error( "bad argument #" .. n .. "." .. nu .. " (expected string, got " .. type( sItem ) .. ")", 3 ) end nMaxLen = math.max( string.len( sItem ) + 1, nMaxLen ) end @@ -123,7 +123,7 @@ local function tabulateCommon( bPaged, ... ) local nCols = math.floor( w / nMaxLen ) local nLines = 0 local function newLine() - if bPaged and nLines >= h-3 then + if bPaged and nLines >= h - 3 then pagedPrint() else print() @@ -207,11 +207,11 @@ local function serializeImpl( t, tTracking, sIndent ) local sResult = "{\n" local sSubIndent = sIndent .. " " local tSeen = {} - for k,v in ipairs(t) do + for k, v in ipairs(t) do tSeen[k] = true sResult = sResult .. sSubIndent .. serializeImpl( v, tTracking, sSubIndent ) .. ",\n" end - for k,v in pairs(t) do + for k, v in pairs(t) do if not tSeen[k] then local sEntry if type(k) == "string" and not g_tLuaKeywords[k] and string.match( k, "^[%a_][%a%d_]*$" ) then @@ -233,7 +233,7 @@ local function serializeImpl( t, tTracking, sIndent ) return tostring(t) else - error( "Cannot serialize type "..sType, 0 ) + error( "Cannot serialize type " .. sType, 0 ) end end @@ -241,7 +241,7 @@ end empty_json_array = setmetatable({}, { __newindex = function() error("attempt to mutate textutils.empty_json_array", 2) - end + end, }) local function serializeJSONImpl( t, tTracking, bNBTStyle ) @@ -264,7 +264,7 @@ local function serializeJSONImpl( t, tTracking, bNBTStyle ) local sArrayResult = "[" local nObjectSize = 0 local nArraySize = 0 - for k,v in pairs(t) do + for k, v in pairs(t) do if type(k) == "string" then local sEntry if bNBTStyle then @@ -280,7 +280,7 @@ local function serializeJSONImpl( t, tTracking, bNBTStyle ) nObjectSize = nObjectSize + 1 end end - for _,v in ipairs(t) do + for _, v in ipairs(t) do local sEntry = serializeJSONImpl( v, tTracking, bNBTStyle ) if nArraySize == 0 then sArrayResult = sArrayResult .. sEntry @@ -305,7 +305,7 @@ local function serializeJSONImpl( t, tTracking, bNBTStyle ) return tostring(t) else - error( "Cannot serialize type "..sType, 0 ) + error( "Cannot serialize type " .. sType, 0 ) end end @@ -317,7 +317,7 @@ end function unserialize( s ) expect(1, s, "string") - local func = load( "return "..s, "unserialize", "t", {} ) + local func = load( "return " .. s, "unserialize", "t", {} ) if func then local ok, result = pcall( func ) if ok then @@ -346,7 +346,7 @@ function urlEncode( str ) else -- Non-ASCII (encode as UTF-8) return - string.format("%%%02X", 192 + bit32.band( bit32.arshift(n,6), 31 ) ) .. + string.format("%%%02X", 192 + bit32.band( bit32.arshift(n, 6), 31 ) ) .. string.format("%%%02X", 128 + bit32.band( n, 63 ) ) end end ) @@ -393,7 +393,7 @@ function complete( sSearchText, tSearchTable ) local tResults = {} local tSeen = {} while tTable do - for k,v in pairs( tTable ) do + for k, v in pairs( tTable ) do if not tSeen[k] and type(k) == "string" then if string.find( k, sPart, 1, true ) == 1 then if not g_tLuaKeywords[k] and string.match( k, "^[%a_][%a%d_]*$" ) then diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/turtle/turtle.lua b/src/main/resources/assets/computercraft/lua/rom/apis/turtle/turtle.lua index 069f73b8d..c471212a4 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/turtle/turtle.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/turtle/turtle.lua @@ -20,7 +20,7 @@ end -- Put commands into environment table local env = _ENV -for k,v in pairs( native ) do +for k, v in pairs( native ) do if k == "equipLeft" or k == "equipRight" then env[k] = function( ... ) local result, err = v( ... ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua index 7a6db14b7..4d6c159f9 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua @@ -36,17 +36,17 @@ local vector = { ) end, dot = function( self, o ) - return self.x*o.x + self.y*o.y + self.z*o.z + return self.x * o.x + self.y * o.y + self.z * o.z end, cross = function( self, o ) return vector.new( - self.y*o.z - self.z*o.y, - self.z*o.x - self.x*o.z, - self.x*o.y - self.y*o.x + self.y * o.z - self.z * o.y, + self.z * o.x - self.x * o.z, + self.x * o.y - self.y * o.x ) end, length = function( self ) - return math.sqrt( self.x*self.x + self.y*self.y + self.z*self.z ) + return math.sqrt( self.x * self.x + self.y * self.y + self.z * self.z ) end, normalize = function( self ) return self:mul( 1 / self:length() ) @@ -60,7 +60,7 @@ local vector = { ) end, tostring = function( self ) - return self.x..","..self.y..","..self.z + return self.x .. "," .. self.y .. "," .. self.z end, } @@ -78,7 +78,7 @@ function new( x, y, z ) local v = { x = tonumber(x) or 0, y = tonumber(y) or 0, - z = tonumber(z) or 0 + z = tonumber(z) or 0, } setmetatable( v, vmetatable ) return v diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua index 2f20220fc..0e24b7696 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua @@ -39,8 +39,8 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local tEmptyColorLines = {} local function createEmptyLines( nWidth ) sEmptySpaceLine = string_rep( " ", nWidth ) - for n=0,15 do - local nColor = 2^n + for n = 0, 15 do + local nColor = 2 ^ n local sHex = tHex[nColor] tEmptyColorLines[nColor] = string_rep( sHex, nWidth ) end @@ -61,7 +61,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local sEmptyText = sEmptySpaceLine local sEmptyTextColor = tEmptyColorLines[ nTextColor ] local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ] - for y=1,nHeight do + for y = 1, nHeight do tLines[y] = { text = sEmptyText, textColor = sEmptyTextColor, @@ -69,7 +69,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) } end - for i=0,15 do + for i = 0, 15 do local c = 2 ^ i tPalette[c] = { parent.getPaletteColour( c ) } end @@ -100,13 +100,13 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) end local function redraw() - for n=1,nHeight do + for n = 1, nHeight do redrawLine( n ) end end local function updatePalette() - for k,v in pairs( tPalette ) do + for k, v in pairs( tPalette ) do parent.setPaletteColour( k, v[1], v[2], v[3] ) end end @@ -204,7 +204,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local sEmptyText = sEmptySpaceLine local sEmptyTextColor = tEmptyColorLines[ nTextColor ] local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ] - for y=1,nHeight do + for y = 1, nHeight do tLines[y] = { text = sEmptyText, textColor = sEmptyTextColor, @@ -351,7 +351,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local sEmptyText = sEmptySpaceLine local sEmptyTextColor = tEmptyColorLines[ nTextColor ] local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ] - for newY=1,nHeight do + for newY = 1, nHeight do local y = newY + n if y >= 1 and y <= nHeight then tNewLines[newY] = tLines[y] @@ -451,12 +451,12 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local sEmptyText = sEmptySpaceLine local sEmptyTextColor = tEmptyColorLines[ nTextColor ] local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ] - for y=1,nNewHeight do + for y = 1, nNewHeight do if y > nHeight then tNewLines[y] = { text = sEmptyText, textColor = sEmptyTextColor, - backgroundColor = sEmptyBackgroundColor + backgroundColor = sEmptyBackgroundColor, } else local tOldLine = tLines[y] diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua index b07cccf3c..757691e27 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua @@ -2,7 +2,7 @@ local expect = dofile("rom/modules/main/cc/expect.lua").expect -- Setup process switching local parentTerm = term.current() -local w,h = parentTerm.getSize() +local w, h = parentTerm.getSize() local tProcesses = {} local nCurrentProcess = nil @@ -55,7 +55,7 @@ local function launchProcess( bFocus, tProgramEnv, sProgramPath, ... ) local tProcess = {} tProcess.sTitle = fs.getName( sProgramPath ) if bShowMenu then - tProcess.window = window.create( parentTerm, 1, 2, w, h-1, false ) + tProcess.window = window.create( parentTerm, 1, 2, w, h - 1, false ) else tProcess.window = window.create( parentTerm, 1, 1, w, h, false ) end @@ -102,7 +102,7 @@ end local function cullProcesses() local culled = false - for n=#tProcesses,1,-1 do + for n = #tProcesses, 1, -1 do culled = culled or cullProcess( n ) end return culled @@ -132,7 +132,7 @@ local function redrawMenu() parentTerm.write( "<" ) nCharCount = 1 end - for n=nScrollPos,#tProcesses do + for n = nScrollPos, #tProcesses do if n == nCurrentProcess then parentTerm.setTextColor( menuMainTextColor ) parentTerm.setBackgroundColor( menuMainBgColor ) @@ -165,14 +165,14 @@ local function resizeWindows() local windowY, windowHeight if bShowMenu then windowY = 2 - windowHeight = h-1 + windowHeight = h - 1 else windowY = 1 windowHeight = h end - for n=1,#tProcesses do + for n = 1, #tProcesses do local tProcess = tProcesses[n] - local x,y = tProcess.window.getCursorPos() + local x, y = tProcess.window.getCursorPos() if y > windowHeight then tProcess.window.scroll( y - windowHeight ) tProcess.window.setCursorPos( x, windowHeight ) @@ -257,7 +257,7 @@ while #tProcesses > 0 do local sEvent = tEventData[1] if sEvent == "term_resize" then -- Resize event - w,h = parentTerm.getSize() + w, h = parentTerm.getSize() resizeWindows() redrawMenu() @@ -286,7 +286,7 @@ while #tProcesses > 0 do if nScrollPos ~= 1 then tabStart = 2 end - for n=nScrollPos,#tProcesses do + for n = nScrollPos, #tProcesses do local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1 if x >= tabStart and x <= tabEnd then selectProcess( n ) @@ -298,7 +298,7 @@ while #tProcesses > 0 do end else -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, button, x, bShowMenu and y-1 or y ) + resumeProcess( nCurrentProcess, sEvent, button, x, bShowMenu and y - 1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() @@ -318,7 +318,7 @@ while #tProcesses > 0 do end elseif not (bShowMenu and y == 1) then -- Passthrough to current process - resumeProcess( nCurrentProcess, sEvent, p1, x, bShowMenu and y-1 or y ) + resumeProcess( nCurrentProcess, sEvent, p1, x, bShowMenu and y - 1 or y ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() @@ -329,7 +329,7 @@ while #tProcesses > 0 do -- Other event -- Passthrough to all processes local nLimit = #tProcesses -- Storing this ensures any new things spawned don't get the event - for n=1,nLimit do + for n = 1, nLimit do resumeProcess( n, table.unpack( tEventData, 1, tEventData.n ) ) end if cullProcesses() then @@ -341,7 +341,7 @@ while #tProcesses > 0 do if bWindowsResized then -- Pass term_resize to all processes local nLimit = #tProcesses -- Storing this ensures any new things spawned don't get the event - for n=1,nLimit do + for n = 1, nLimit do resumeProcess( n, "term_resize" ) end bWindowsResized = false diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/alias.lua b/src/main/resources/assets/computercraft/lua/rom/programs/alias.lua index 6d7c3ff99..c4f8c5ffe 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/alias.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/alias.lua @@ -19,7 +19,7 @@ else local tAliases = shell.aliases() local tList = {} for sAlias, sCommand in pairs( tAliases ) do - table.insert( tList, sAlias..":"..sCommand ) + table.insert( tList, sAlias .. ":" .. sCommand ) end table.sort( tList ) textutils.pagedTabulate( tList ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/apis.lua b/src/main/resources/assets/computercraft/lua/rom/programs/apis.lua index 9a734d891..7ef16e96f 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/apis.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/apis.lua @@ -1,6 +1,6 @@ local tApis = {} -for k,v in pairs( _G ) do +for k, v in pairs( _G ) do if type(k) == "string" and type(v) == "table" and k ~= "_G" then table.insert( tApis, k ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/command/exec.lua b/src/main/resources/assets/computercraft/lua/rom/programs/command/exec.lua index 76aebc086..c54b3f567 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/command/exec.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/command/exec.lua @@ -18,7 +18,7 @@ local function printSuccess( text ) end local sCommand = string.lower( tArgs[1] ) -for n=2,#tArgs do +for n = 2, #tArgs do sCommand = sCommand .. " " .. tArgs[n] end @@ -26,14 +26,14 @@ local bResult, tOutput = commands.exec( sCommand ) if bResult then printSuccess( "Success" ) if #tOutput > 0 then - for n=1,#tOutput do + for n = 1, #tOutput do print( tOutput[n] ) end end else printError( "Failed" ) if #tOutput > 0 then - for n=1,#tOutput do + for n = 1, #tOutput do print( tOutput[n] ) end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua index 71ea68043..c8d66459b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/copy.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for _,sFile in ipairs( tFiles ) do + for _, sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.copy( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua index 2d7d9357e..bfa682843 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua @@ -21,9 +21,9 @@ if not fs.exists( sPath ) and not string.find( sPath, "%." ) then end end -local x,y = 1,1 -local w,h = term.getSize() -local scrollX, scrollY = 0,0 +local x, y = 1, 1 +local w, h = term.getSize() +local scrollX, scrollY = 0, 0 local tLines = {} local bRunning = true @@ -99,7 +99,7 @@ local function save( _sPath ) file.write( sLine .. "\n" ) end else - error( "Failed to open ".._sPath ) + error( "Failed to open " .. _sPath ) end end @@ -130,7 +130,7 @@ local tKeywords = { ["return"] = true, ["then"] = true, ["true"] = true, - ["until"]= true, + ["until"] = true, ["while"] = true, } @@ -214,7 +214,7 @@ end local function redrawText() local cursorX, cursorY = x, y - for y=1,h-1 do + for y = 1, h - 1 do term.setCursorPos( 1 - scrollX, y ) term.clearLine() @@ -248,7 +248,7 @@ local function redrawMenu() term.clearLine() -- Draw line numbers - term.setCursorPos( w - string.len( "Ln "..y ) + 1, h ) + term.setCursorPos( w - string.len( "Ln " .. y ) + 1, h ) term.setTextColour( highlightColour ) term.write( "Ln " ) term.setTextColour( textColour ) @@ -258,7 +258,7 @@ local function redrawMenu() if bMenu then -- Draw menu term.setTextColour( textColour ) - for nItem,sItem in pairs( tMenuItems ) do + for nItem, sItem in pairs( tMenuItems ) do if nItem == nMenuItem then term.setTextColour( highlightColour ) term.write( "[" ) @@ -268,7 +268,7 @@ local function redrawMenu() term.write( "]" ) term.setTextColour( textColour ) else - term.write( " "..sItem.." " ) + term.write( " " .. sItem .. " " ) end end else @@ -289,12 +289,12 @@ local tMenuFuncs = { else local ok, _, fileerr = save( sPath ) if ok then - sStatus="Saved to "..sPath + sStatus = "Saved to " .. sPath else if fileerr then - sStatus="Error saving to "..fileerr + sStatus = "Error saving to " .. fileerr else - sStatus="Error saving to "..sPath + sStatus = "Error saving to " .. sPath end end end @@ -326,7 +326,7 @@ local tMenuFuncs = { } printerTerminal.scroll = function() if nPage == 1 then - printer.setPageTitle( sName.." (page "..nPage..")" ) + printer.setPageTitle( sName .. " (page " .. nPage .. ")" ) end while not printer.newPage() do @@ -349,7 +349,7 @@ local tMenuFuncs = { if nPage == 1 then printer.setPageTitle( sName ) else - printer.setPageTitle( sName.." (page "..nPage..")" ) + printer.setPageTitle( sName .. " (page " .. nPage .. ")" ) end end @@ -374,7 +374,7 @@ local tMenuFuncs = { bMenu = true if nPage > 1 then - sStatus = "Printed "..nPage.." Pages" + sStatus = "Printed " .. nPage .. " Pages" else sStatus = "Printed 1 Page" end @@ -391,14 +391,14 @@ local tMenuFuncs = { if nTask then shell.switchTab( nTask ) else - sStatus="Error starting Task" + sStatus = "Error starting Task" end fs.delete( sTempPath ) else - sStatus="Error saving to "..sTempPath + sStatus = "Error saving to " .. sTempPath end redrawMenu() - end + end, } local function doMenuItem( _n ) @@ -431,9 +431,9 @@ local function setCursor( newX, newY ) scrollY = y - 1 screenY = 1 bRedraw = true - elseif screenY > h-1 then - scrollY = y - (h-1) - screenY = h-1 + elseif screenY > h - 1 then + scrollY = y - (h - 1) + screenY = h - 1 bRedraw = true end @@ -456,7 +456,7 @@ load(sPath) term.setBackgroundColour( bgColour ) term.clear() -term.setCursorPos(x,y) +term.setCursorPos(x, y) term.setCursorBlink( true ) recomplete() @@ -526,7 +526,7 @@ while bRunning do else -- Indent line local sLine = tLines[y] - tLines[y] = string.sub(sLine,1,x-1) .. " " .. string.sub(sLine,x) + tLines[y] = string.sub(sLine, 1, x - 1) .. " " .. string.sub(sLine, x) setCursor( x + 4, y ) end end @@ -566,7 +566,7 @@ while bRunning do if not bMenu then -- Move cursor to the beginning if x > 1 then - setCursor(1,y) + setCursor(1, y) end end @@ -586,8 +586,8 @@ while bRunning do if x > 1 then -- Move cursor left setCursor( x - 1, y ) - elseif x==1 and y>1 then - setCursor( string.len( tLines[y-1] ) + 1, y - 1 ) + elseif x == 1 and y > 1 then + setCursor( string.len( tLines[y - 1] ) + 1, y - 1 ) end else -- Move menu left @@ -608,7 +608,7 @@ while bRunning do elseif nCompletion and x == string.len(tLines[y]) + 1 then -- Accept autocomplete acceptCompletion() - elseif x==nLimit and y<#tLines then + elseif x == nLimit and y < #tLines then -- Go to next line setCursor( 1, y + 1 ) end @@ -627,12 +627,12 @@ while bRunning do local nLimit = string.len( tLines[y] ) + 1 if x < nLimit then local sLine = tLines[y] - tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1) + tLines[y] = string.sub(sLine, 1, x - 1) .. string.sub(sLine, x + 1) recomplete() redrawLine(y) - elseif y<#tLines then - tLines[y] = tLines[y] .. tLines[y+1] - table.remove( tLines, y+1 ) + elseif y < #tLines then + tLines[y] = tLines[y] .. tLines[y + 1] + table.remove( tLines, y + 1 ) recomplete() redrawText() end @@ -644,17 +644,17 @@ while bRunning do if x > 1 then -- Remove character local sLine = tLines[y] - if x > 4 and string.sub(sLine,x-4,x-1) == " " and not string.sub(sLine, 1, x - 1):find("%S") then - tLines[y] = string.sub(sLine,1,x-5) .. string.sub(sLine,x) + if x > 4 and string.sub(sLine, x - 4, x - 1) == " " and not string.sub(sLine, 1, x - 1):find("%S") then + tLines[y] = string.sub(sLine, 1, x - 5) .. string.sub(sLine, x) setCursor( x - 4, y ) else - tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x) + tLines[y] = string.sub(sLine, 1, x - 2) .. string.sub(sLine, x) setCursor( x - 1, y ) end elseif y > 1 then -- Remove newline - local sPrevLen = string.len( tLines[y-1] ) - tLines[y-1] = tLines[y-1] .. tLines[y] + local sPrevLen = string.len( tLines[y - 1] ) + tLines[y - 1] = tLines[y - 1] .. tLines[y] table.remove( tLines, y ) setCursor( sPrevLen + 1, y - 1 ) redrawText() @@ -666,12 +666,12 @@ while bRunning do if not bMenu and not bReadOnly then -- Newline local sLine = tLines[y] - local _,spaces=string.find(sLine,"^[ ]+") + local _, spaces = string.find(sLine, "^[ ]+") if not spaces then - spaces=0 + spaces = 0 end - tLines[y] = string.sub(sLine,1,x-1) - table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) ) + tLines[y] = string.sub(sLine, 1, x - 1) + table.insert( tLines, y + 1, string.rep(' ', spaces) .. string.sub(sLine, x) ) setCursor( spaces + 1, y + 1 ) redrawText() @@ -697,13 +697,13 @@ while bRunning do if not bMenu and not bReadOnly then -- Input text local sLine = tLines[y] - tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x) + tLines[y] = string.sub(sLine, 1, x - 1) .. param .. string.sub(sLine, x) setCursor( x + 1, y ) elseif bMenu then -- Select menu items - for n,sMenuItem in ipairs( tMenuItems ) do - if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then + for n, sMenuItem in ipairs( tMenuItems ) do + if string.lower(string.sub(sMenuItem, 1, 1)) == string.lower(param) then doMenuItem( n ) break end @@ -720,7 +720,7 @@ while bRunning do end -- Input text local sLine = tLines[y] - tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x) + tLines[y] = string.sub(sLine, 1, x - 1) .. param .. string.sub(sLine, x) setCursor( x + string.len( param ), y ) end @@ -728,7 +728,7 @@ while bRunning do if not bMenu then if param == 1 then -- Left click - local cx,cy = param2, param3 + local cx, cy = param2, param3 if cy < h then local newY = math.min( math.max( scrollY + cy, 1 ), #tLines ) local newX = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[newY] ) + 1 ) @@ -749,7 +749,7 @@ while bRunning do elseif param == 1 then -- Scroll down - local nMaxScroll = #tLines - (h-1) + local nMaxScroll = #tLines - (h - 1) if scrollY < nMaxScroll then -- Move cursor down scrollY = scrollY + 1 @@ -760,7 +760,7 @@ while bRunning do end elseif sEvent == "term_resize" then - w,h = term.getSize() + w, h = term.getSize() setCursor( x, y ) redrawMenu() redrawText() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/eject.lua b/src/main/resources/assets/computercraft/lua/rom/programs/eject.lua index 1e0e8b7af..ad47bbd99 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/eject.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/eject.lua @@ -11,7 +11,7 @@ local sDrive = tArgs[1] -- Check the disk exists local bPresent = disk.isPresent( sDrive ) if not bPresent then - print( "Nothing in "..sDrive.." drive" ) + print( "Nothing in " .. sDrive .. " drive" ) return end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua index 5011458ca..2e77847e0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua @@ -6,7 +6,7 @@ ------------ -- The width and height of the terminal -local w,h = term.getSize() +local w, h = term.getSize() -- The selected colours on the left and right mouse button, and the colour of the canvas local leftColour, rightColour = colours.white, nil @@ -16,7 +16,7 @@ local canvasColour = colours.black local canvas = {} -- The menu options -local mChoices = { "Save","Exit" } +local mChoices = { "Save", "Exit" } -- The message displayed in the footer bar local fMessage = "Press Ctrl to access menu" @@ -86,8 +86,8 @@ end returns: the colour number of the hex value ]] local tColourLookup = {} -for n=1,16 do - tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1) +for n = 1, 16 do + tColourLookup[ string.byte( "0123456789abcdef", n, n ) ] = 2 ^ (n - 1) end local function getColourOf( char ) -- Values not in the hex table are transparent (canvas coloured) @@ -106,8 +106,8 @@ local function load(path) local sLine = file.readLine() while sLine do local line = {} - for x=1,w-2 do - line[x] = getColourOf( string.byte(sLine,x,x) ) + for x = 1, w - 2 do + line[x] = getColourOf( string.byte(sLine, x, x) ) end table.insert( canvas, line ) sLine = file.readLine() @@ -136,10 +136,10 @@ local function save(path) -- Encode (and trim) local tLines = {} local nLastLine = 0 - for y=1,h-1 do + for y = 1, h - 1 do local sLine = "" local nLastChar = 0 - for x=1,w-2 do + for x = 1, w - 2 do local c = getCharOf( getCanvasPixel( x, y ) ) sLine = sLine .. c if c ~= " " then @@ -154,7 +154,7 @@ local function save(path) end -- Save out - for n=1,nLastLine do + for n = 1, nLastLine do file.writeLine( tLines[ n ] ) end file.close() @@ -174,20 +174,20 @@ local function drawInterface() term.write(fMessage) -- Colour Picker - for i=1,16 do - term.setCursorPos(w-1, i) - term.setBackgroundColour( 2^(i-1) ) + for i = 1, 16 do + term.setCursorPos(w - 1, i) + term.setBackgroundColour( 2 ^ (i - 1) ) term.write(" ") end - term.setCursorPos(w-1, 17) + term.setCursorPos(w - 1, 17) term.setBackgroundColour( canvasColour ) term.setTextColour( colours.grey ) term.write("\127\127") -- Left and Right Selected Colours do - term.setCursorPos(w-1, 18) + term.setCursorPos(w - 1, 18) if leftColour ~= nil then term.setBackgroundColour( leftColour ) term.write(" ") @@ -208,8 +208,8 @@ local function drawInterface() -- Padding term.setBackgroundColour( canvasColour ) - for i=20,h-1 do - term.setCursorPos(w-1, i) + for i = 20, h - 1 do + term.setCursorPos(w - 1, i) term.write(" ") end end @@ -237,7 +237,7 @@ end returns: nil ]] local function drawCanvasLine( y ) - for x = 1, w-2 do + for x = 1, w - 2 do drawCanvasPixel( x, y ) end end @@ -247,7 +247,7 @@ end returns: nil ]] local function drawCanvas() - for y = 1, h-1 do + for y = 1, h - 1 do drawCanvasLine( y ) end end @@ -263,25 +263,25 @@ local function accessMenu() term.setBackgroundColour(colours.black) while true do -- Draw the menu - term.setCursorPos(1,h) + term.setCursorPos(1, h) term.clearLine() term.setTextColour(colours.white) - for k,v in pairs(mChoices) do - if selection==k then + for k, v in pairs(mChoices) do + if selection == k then term.setTextColour(colours.yellow) local ox = term.getCursorPos() - term.write("["..string.rep(" ",#v).."]") - term.setCursorPos(ox+1,h) + term.write("[" .. string.rep(" ", #v) .. "]") + term.setCursorPos(ox + 1, h) term.setTextColour(colours.white) term.write(v) - term.setCursorPos(term.getCursorPos()+1,h) + term.setCursorPos(term.getCursorPos() + 1, h) else - term.write(" "..v.." ") + term.write(" " .. v .. " ") end end -- Handle input in the menu - local id,key = os.pullEvent("key") + local id, key = os.pullEvent("key") if id == "key" then -- S and E are shortcuts if key == keys.s then @@ -308,23 +308,23 @@ local function accessMenu() elseif key == keys.enter then -- Select an option - if mChoices[selection]=="Save" then + if mChoices[selection] == "Save" then if bReadOnly then fMessage = "Access denied" return false end local success, err = save(sPath) if success then - fMessage = "Saved to "..sPath + fMessage = "Saved to " .. sPath else if err then - fMessage = "Error saving to "..err + fMessage = "Error saving to " .. err else - fMessage = "Error saving to "..sPath + fMessage = "Error saving to " .. sPath end end return false - elseif mChoices[selection]=="Exit" then + elseif mChoices[selection] == "Exit" then return true end elseif key == keys.leftCtrl or keys == keys.rightCtrl then @@ -343,19 +343,19 @@ end local function handleEvents() local programActive = true while programActive do - local id,p1,p2,p3 = os.pullEvent() - if id=="mouse_click" or id=="mouse_drag" then - if p2 >= w-1 and p3 >= 1 and p3 <= 17 then + local id, p1, p2, p3 = os.pullEvent() + if id == "mouse_click" or id == "mouse_drag" then + if p2 >= w - 1 and p3 >= 1 and p3 <= 17 then if id ~= "mouse_drag" then -- Selecting an items in the colour picker if p3 <= 16 then - if p1==1 then - leftColour = 2^(p3-1) + if p1 == 1 then + leftColour = 2 ^ (p3 - 1) else - rightColour = 2^(p3-1) + rightColour = 2 ^ (p3 - 1) end else - if p1==1 then + if p1 == 1 then leftColour = nil else rightColour = nil @@ -364,12 +364,12 @@ local function handleEvents() --drawCanvas() drawInterface() end - elseif p2 < w-1 and p3 <= h-1 then + elseif p2 < w - 1 and p3 <= h - 1 then -- Clicking on the canvas local paintColour = nil - if p1==1 then + if p1 == 1 then paintColour = leftColour - elseif p1==2 then + elseif p1 == 2 then paintColour = rightColour end if not canvas[p3] then @@ -379,13 +379,13 @@ local function handleEvents() drawCanvasPixel( p2, p3 ) end - elseif id=="key" then - if p1==keys.leftCtrl or p1==keys.rightCtrl then + elseif id == "key" then + if p1 == keys.leftCtrl or p1 == keys.rightCtrl then programActive = not accessMenu() drawInterface() end - elseif id=="term_resize" then - w,h = term.getSize() + elseif id == "term_resize" then + w, h = term.getSize() drawCanvas() drawInterface() end @@ -404,4 +404,4 @@ handleEvents() term.setBackgroundColour(colours.black) term.setTextColour(colours.white) term.clear() -term.setCursorPos(1,1) +term.setCursorPos(1, 1) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua index 232f6d863..a84117bdb 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua @@ -3,12 +3,12 @@ --Clearing Screen-- --Vars-- -local TermW,TermH = term.getSize() +local TermW, TermH = term.getSize() local sLevelTitle local tScreen local oScreen -local SizeW,SizeH +local SizeW, SizeH local aExits local fExit local nSpeed @@ -18,14 +18,14 @@ local fSpeedS local bPaused local Tick local Blocks -local XOrgin,YOrgin +local XOrgin, YOrgin local fLevel local function reset() sLevelTitle = "" tScreen = {} oScreen = {} - SizeW,SizeH = TermW,TermH + SizeW, SizeH = TermW, TermH aExits = 0 fExit = "nop" nSpeed = 0.6 @@ -35,7 +35,7 @@ local function reset() bPaused = false Tick = os.startTimer(Speed) Blocks = 0 - XOrgin,YOrgin = 1,1 + XOrgin, YOrgin = 1, 1 term.setBackgroundColor(colors.black) term.setTextColor(colors.white) @@ -61,21 +61,21 @@ local tArgs = { ... } --Functions-- local function printCentred( yc, stg ) local xc = math.floor((TermW - string.len(stg)) / 2) + 1 - term.setCursorPos(xc,yc) + term.setCursorPos(xc, yc) term.write( stg ) end local function centerOrgin() - XOrgin = math.floor(TermW/2-SizeW/2) - YOrgin = math.floor(TermH/2-SizeH/2) + XOrgin = math.floor(TermW / 2 - SizeW / 2) + YOrgin = math.floor(TermH / 2 - SizeH / 2) end local function reMap() tScreen = nil tScreen = {} - for x=1,SizeW do + for x = 1, SizeW do tScreen[x] = {} - for y=1,SizeH do + for y = 1, SizeH do tScreen[x][y] = { space = true, wall = false, ground = false, robot = "zz", start = "zz", exit = "zz" } end end @@ -83,7 +83,7 @@ end local function tablecopy(t) local t2 = {} - for k,v in pairs(t) do + for k, v in pairs(t) do t2[k] = v end return t2 @@ -92,17 +92,17 @@ end local function buMap() oScreen = nil oScreen = {} - for x=1,SizeW do + for x = 1, SizeW do oScreen[x] = {} - for y=1,SizeH do + for y = 1, SizeH do oScreen[x][y] = tablecopy(tScreen[x][y]) end end end -local function addRobot(x,y,side,color) +local function addRobot(x, y, side, color) local obj = tScreen[x][y] - local data = side..color + local data = side .. color if obj.wall == nil and obj.robot == nil then tScreen[x][y].robot = data else @@ -112,9 +112,9 @@ local function addRobot(x,y,side,color) end end -local function addStart(x,y,side,color) +local function addStart(x, y, side, color) local obj = tScreen[x][y] - local data = side..color + local data = side .. color if obj.wall == nil and obj.space == nil then tScreen[x][y].start = data else @@ -122,10 +122,10 @@ local function addStart(x,y,side,color) obj.space = nil tScreen[x][y].start = data end - aExits = aExits+1 + aExits = aExits + 1 end -local function addGround(x,y) +local function addGround(x, y) local obj = tScreen[x][y] if obj.space == nil and obj.exit == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then tScreen[x][y].ground = true @@ -139,7 +139,7 @@ local function addGround(x,y) end end -local function addExit(x,y,cl) +local function addExit(x, y, cl) local obj = tScreen[x][y] if obj.space == nil and obj.ground == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then tScreen[x][y].exit = cl @@ -153,10 +153,10 @@ local function addExit(x,y,cl) end end -local function addWall(x,y) +local function addWall(x, y) local obj = tScreen[x][y] if obj == nil then - return error("Here X"..x.." Y"..y) + return error("Here X" .. x .. " Y" .. y) end if obj.space == nil and obj.exit == nil and obj.ground == nil and obj.robot == nil and obj.start == nil then tScreen[x][y].wall = true @@ -171,15 +171,15 @@ local function addWall(x,y) end local function loadLevel(nNum) - sLevelTitle = "Level "..nNum + sLevelTitle = "Level " .. nNum if nNum == nil then return error("nNum == nil") end local sDir = fs.getDir( shell.getRunningProgram() ) - local sLevelD = sDir .. "/levels/" .. tostring(nNum)..".dat" - if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end - fLevel = fs.open(sLevelD,"r") + local sLevelD = sDir .. "/levels/" .. tostring(nNum) .. ".dat" + if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : " .. sLevelD) end + fLevel = fs.open(sLevelD, "r") local wl = true - Blocks = tonumber(string.sub(fLevel.readLine(),1,1)) - local xSize = string.len(fLevel.readLine())+2 + Blocks = tonumber(string.sub(fLevel.readLine(), 1, 1)) + local xSize = string.len(fLevel.readLine()) + 2 local Lines = 3 while wl do local wLine = fLevel.readLine() @@ -187,43 +187,43 @@ local function loadLevel(nNum) fLevel.close() wl = false else - xSize = math.max(string.len(wLine)+2,xSize) + xSize = math.max(string.len(wLine) + 2, xSize) Lines = Lines + 1 end end - SizeW,SizeH = xSize,Lines + SizeW, SizeH = xSize, Lines reMap() - fLevel = fs.open(sLevelD,"r") + fLevel = fs.open(sLevelD, "r") fLevel.readLine() - for Line=2,Lines-1 do + for Line = 2, Lines - 1 do local sLine = fLevel.readLine() local chars = string.len(sLine) for char = 1, chars do - local el = string.sub(sLine,char,char) + local el = string.sub(sLine, char, char) if el == "8" then - addGround(char+1,Line) + addGround(char + 1, Line) elseif el == "0" then - addStart(char+1,Line,"a","a") + addStart(char + 1, Line, "a", "a") elseif el == "1" then - addStart(char+1,Line,"b","a") + addStart(char + 1, Line, "b", "a") elseif el == "2" then - addStart(char+1,Line,"c","a") + addStart(char + 1, Line, "c", "a") elseif el == "3" then - addStart(char+1,Line,"d","a") + addStart(char + 1, Line, "d", "a") elseif el == "4" then - addStart(char+1,Line,"a","b") + addStart(char + 1, Line, "a", "b") elseif el == "5" then - addStart(char+1,Line,"b","b") + addStart(char + 1, Line, "b", "b") elseif el == "6" then - addStart(char+1,Line,"c","b") + addStart(char + 1, Line, "c", "b") elseif el == "9" then - addStart(char+1,Line,"d","b") + addStart(char + 1, Line, "d", "b") elseif el == "b" then - addExit(char+1,Line,"a") + addExit(char + 1, Line, "a") elseif el == "e" then - addExit(char+1,Line,"b") + addExit(char + 1, Line, "b") elseif el == "7" then - addWall(char+1,Line) + addWall(char + 1, Line) end end end @@ -232,29 +232,29 @@ end local function drawStars() --CCR Background By : RamiLego-- - local cStar,cStarG,crStar,crStarB = colors.lightGray,colors.gray,".","*" - local DStar,BStar,nStar,gStar = 14,10,16,3 - local TermW,TermH = term.getSize() + local cStar, cStarG, crStar, crStarB = colors.lightGray, colors.gray, ".", "*" + local DStar, BStar, nStar, gStar = 14, 10, 16, 3 + local TermW, TermH = term.getSize() term.clear() - term.setCursorPos(1,1) - for x=1,TermW do - for y=1,TermH do - local StarT = math.random(1,30) + term.setCursorPos(1, 1) + for x = 1, TermW do + for y = 1, TermH do + local StarT = math.random(1, 30) if StarT == DStar then - term.setCursorPos(x,y) + term.setCursorPos(x, y) term.setTextColor(cStar) write(crStar) elseif StarT == BStar then - term.setCursorPos(x,y) + term.setCursorPos(x, y) term.setTextColor(cStar) write(crStarB) elseif StarT == nStar then - term.setCursorPos(x,y) + term.setCursorPos(x, y) term.setTextColor(cStarG) write(crStar) elseif StarT == gStar then - term.setCursorPos(x,y) + term.setCursorPos(x, y) term.setTextColor(cStarG) write(crStarB) end @@ -263,15 +263,15 @@ local function drawStars() end local function drawMap() - for x=1,SizeW do - for y=1,SizeH do + for x = 1, SizeW do + for y = 1, SizeH do local obj = tScreen[x][y] if obj.ground == true then - paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cG) + paintutils.drawPixel(XOrgin + x, YOrgin + y + 1, cG) end if obj.wall == true then - paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cW) + paintutils.drawPixel(XOrgin + x, YOrgin + y + 1, cW) end local ex = tostring(tScreen[x][y].exit) @@ -289,13 +289,13 @@ local function drawMap() end term.setBackgroundColor(cG) term.setTextColor(ex) - term.setCursorPos(XOrgin+x,YOrgin+y+1) + term.setCursorPos(XOrgin + x, YOrgin + y + 1) print("X") end local st = tostring(tScreen[x][y].start) if not(st == "zz" or st == "nil") then - local Cr = string.sub(st,2,2) + local Cr = string.sub(st, 2, 2) if Cr == "a" then Cr = cR1 elseif Cr == "b" then @@ -310,9 +310,9 @@ local function drawMap() term.setTextColor(Cr) term.setBackgroundColor(cG) - term.setCursorPos(XOrgin+x,YOrgin+y+1) + term.setCursorPos(XOrgin + x, YOrgin + y + 1) - local sSide = string.sub(st,1,1) + local sSide = string.sub(st, 1, 1) if sSide == "a" then print("^") elseif sSide == "b" then @@ -327,12 +327,12 @@ local function drawMap() end if obj.space == true then - paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cS) + paintutils.drawPixel(XOrgin + x, YOrgin + y + 1, cS) end local rb = tostring(tScreen[x][y].robot) if not(rb == "zz" or rb == "nil") then - local Cr = string.sub(rb,2,2) + local Cr = string.sub(rb, 2, 2) if Cr == "a" then Cr = cR1 elseif Cr == "b" then @@ -346,8 +346,8 @@ local function drawMap() end term.setBackgroundColor(Cr) term.setTextColor(colors.white) - term.setCursorPos(XOrgin+x,YOrgin+y+1) - local sSide = string.sub(rb,1,1) + term.setCursorPos(XOrgin + x, YOrgin + y + 1) + local sSide = string.sub(rb, 1, 1) if sSide == "a" then print("^") elseif sSide == "b" then @@ -364,7 +364,7 @@ local function drawMap() end end -local function isBrick(x,y) +local function isBrick(x, y) local brb = tostring(tScreen[x][y].robot) local bobj = oScreen[x][y] if (brb == "zz" or brb == "nil") and not bobj.wall == true then @@ -376,134 +376,134 @@ end local function gRender(sContext) if sContext == "start" then - for x=1,SizeW do - for y=1,SizeH do + for x = 1, SizeW do + for y = 1, SizeH do local st = tostring(tScreen[x][y].start) if not(st == "zz" or st == "nil") then - local Cr = string.sub(st,2,2) - local sSide = string.sub(st,1,1) - addRobot(x,y,sSide,Cr) + local Cr = string.sub(st, 2, 2) + local sSide = string.sub(st, 1, 1) + addRobot(x, y, sSide, Cr) end end end elseif sContext == "tick" then buMap() - for x=1,SizeW do - for y=1,SizeH do + for x = 1, SizeW do + for y = 1, SizeH do local rb = tostring(oScreen[x][y].robot) if not(rb == "zz" or rb == "nil") then - local Cr = string.sub(rb,2,2) - local sSide = string.sub(rb,1,1) + local Cr = string.sub(rb, 2, 2) + local sSide = string.sub(rb, 1, 1) local sobj = oScreen[x][y] if sobj.space == true then tScreen[x][y].robot = "zz" if not sSide == "g" then - addRobot(x,y,"g",Cr) + addRobot(x, y, "g", Cr) end elseif sobj.exit == Cr then if sSide == "a" or sSide == "b" or sSide == "c" or sSide == "d" then tScreen[x][y].robot = "zz" - addRobot(x,y,"g",Cr) - aExits = aExits-1 + addRobot(x, y, "g", Cr) + aExits = aExits - 1 end elseif sSide == "a" then - local obj = isBrick(x,y-1) + local obj = isBrick(x, y - 1) tScreen[x][y].robot = "zz" if not obj == true then - addRobot(x,y-1,sSide,Cr) + addRobot(x, y - 1, sSide, Cr) else - local obj2 = isBrick(x-1,y) - local obj3 = isBrick(x+1,y) + local obj2 = isBrick(x - 1, y) + local obj3 = isBrick(x + 1, y) if not obj2 == true and not obj3 == true then if Cr == "a" then - addRobot(x,y,"d",Cr) + addRobot(x, y, "d", Cr) elseif Cr == "b" then - addRobot(x,y,"b",Cr) + addRobot(x, y, "b", Cr) end elseif obj == true and obj2 == true and obj3 == true then - addRobot(x,y,"c",Cr) + addRobot(x, y, "c", Cr) else if obj3 == true then - addRobot(x,y,"d",Cr) + addRobot(x, y, "d", Cr) elseif obj2 == true then - addRobot(x,y,"b",Cr) + addRobot(x, y, "b", Cr) end end end elseif sSide == "b" then - local obj = isBrick(x+1,y) + local obj = isBrick(x + 1, y) tScreen[x][y].robot = "zz" if not obj == true then - addRobot(x+1,y,sSide,Cr) + addRobot(x + 1, y, sSide, Cr) else - local obj2 = isBrick(x,y-1) - local obj3 = isBrick(x,y+1) + local obj2 = isBrick(x, y - 1) + local obj3 = isBrick(x, y + 1) if not obj2 == true and not obj3 == true then if Cr == "a" then - addRobot(x,y,"a",Cr) + addRobot(x, y, "a", Cr) elseif Cr == "b" then - addRobot(x,y,"c",Cr) + addRobot(x, y, "c", Cr) end elseif obj == true and obj2 == true and obj3 == true then - addRobot(x,y,"d",Cr) + addRobot(x, y, "d", Cr) else if obj3 == true then - addRobot(x,y,"a",Cr) + addRobot(x, y, "a", Cr) elseif obj2 == true then - addRobot(x,y,"c",Cr) + addRobot(x, y, "c", Cr) end end end elseif sSide == "c" then - local obj = isBrick(x,y+1) + local obj = isBrick(x, y + 1) tScreen[x][y].robot = "zz" if not obj == true then - addRobot(x,y+1,sSide,Cr) + addRobot(x, y + 1, sSide, Cr) else - local obj2 = isBrick(x-1,y) - local obj3 = isBrick(x+1,y) + local obj2 = isBrick(x - 1, y) + local obj3 = isBrick(x + 1, y) if not obj2 == true and not obj3 == true then if Cr == "a" then - addRobot(x,y,"b",Cr) + addRobot(x, y, "b", Cr) elseif Cr == "b" then - addRobot(x,y,"d",Cr) + addRobot(x, y, "d", Cr) end elseif obj == true and obj2 == true and obj3 == true then - addRobot(x,y,"a",Cr) + addRobot(x, y, "a", Cr) else if obj3 == true then - addRobot(x,y,"d",Cr) + addRobot(x, y, "d", Cr) elseif obj2 == true then - addRobot(x,y,"b",Cr) + addRobot(x, y, "b", Cr) end end end elseif sSide == "d" then - local obj = isBrick(x-1,y) + local obj = isBrick(x - 1, y) tScreen[x][y].robot = "zz" if not obj == true then - addRobot(x-1,y,sSide,Cr) + addRobot(x - 1, y, sSide, Cr) else - local obj2 = isBrick(x,y-1) - local obj3 = isBrick(x,y+1) + local obj2 = isBrick(x, y - 1) + local obj3 = isBrick(x, y + 1) if not obj2 == true and not obj3 == true then if Cr == "a" then - addRobot(x,y,"c",Cr) + addRobot(x, y, "c", Cr) elseif Cr == "b" then - addRobot(x,y,"a",Cr) + addRobot(x, y, "a", Cr) end elseif obj == true and obj2 == true and obj3 == true then - addRobot(x,y,"b",Cr) + addRobot(x, y, "b", Cr) else if obj3 == true then - addRobot(x,y,"a",Cr) + addRobot(x, y, "a", Cr) elseif obj2 == true then - addRobot(x,y,"c",Cr) + addRobot(x, y, "c", Cr) end end end else - addRobot(x,y,sSide,"g") + addRobot(x, y, sSide, "g") end end end @@ -514,15 +514,15 @@ end function InterFace.drawBar() term.setBackgroundColor( colors.black ) term.setTextColor( InterFace.cTitle ) - printCentred( 1, " "..sLevelTitle.." " ) + printCentred( 1, " " .. sLevelTitle .. " " ) - term.setCursorPos(1,1) + term.setCursorPos(1, 1) term.setBackgroundColor( cW ) write( " " ) term.setBackgroundColor( colors.black ) - write( " x "..tostring(Blocks).." " ) + write( " x " .. tostring(Blocks) .. " " ) - term.setCursorPos( TermW-8,TermH ) + term.setCursorPos( TermW - 8, TermH ) term.setBackgroundColor( colors.black ) term.setTextColour(InterFace.cSpeedD) write(" <<" ) @@ -539,7 +539,7 @@ function InterFace.drawBar() end write(" >>") - term.setCursorPos( TermW-1, 1 ) + term.setCursorPos( TermW - 1, 1 ) term.setBackgroundColor( colors.black ) term.setTextColour( InterFace.cExit ) write(" X") @@ -547,13 +547,13 @@ function InterFace.drawBar() end function InterFace.render() - local id,p1,p2,p3 = os.pullEvent() + local id, p1, p2, p3 = os.pullEvent() if id == "mouse_click" then if p3 == 1 and p2 == TermW then return "end" - elseif p3 == TermH and p2 >= TermW-7 and p2 <= TermW-6 then + elseif p3 == TermH and p2 >= TermW - 7 and p2 <= TermW - 6 then return "retry" - elseif p3 == TermH and p2 >= TermW-4 and p2 <= TermW-3 then + elseif p3 == TermH and p2 >= TermW - 4 and p2 <= TermW - 3 then bPaused = not bPaused fSpeedS = false Speed = bPaused and 0 or nSpeed @@ -563,19 +563,19 @@ function InterFace.render() Tick = nil end InterFace.drawBar() - elseif p3 == TermH and p2 >= TermW-1 then + elseif p3 == TermH and p2 >= TermW - 1 then bPaused = false fSpeedS = not fSpeedS Speed = fSpeedS and fSpeed or nSpeed Tick = os.startTimer(Speed) InterFace.drawBar() - elseif p3-1 < YOrgin+SizeH+1 and p3-1 > YOrgin and - p2 < XOrgin+SizeW+1 and p2 > XOrgin then - local eobj = tScreen[p2-XOrgin][p3-YOrgin-1] - local erobj = tostring(tScreen[p2-XOrgin][p3-YOrgin-1].robot) + elseif p3 - 1 < YOrgin + SizeH + 1 and p3 - 1 > YOrgin and + p2 < XOrgin + SizeW + 1 and p2 > XOrgin then + local eobj = tScreen[p2 - XOrgin][p3 - YOrgin - 1] + local erobj = tostring(tScreen[p2 - XOrgin][p3 - YOrgin - 1].robot) if (erobj == "zz" or erobj == "nil") and not eobj.wall == true and not eobj.space == true and Blocks > 0 then - addWall(p2-XOrgin,p3-YOrgin-1) - Blocks = Blocks-1 + addWall(p2 - XOrgin, p3 - YOrgin - 1) + Blocks = Blocks - 1 InterFace.drawBar() drawMap() end @@ -635,17 +635,17 @@ if ok and not sStartLevel then term.clear() drawStars() term.setTextColor( colors.red ) - printCentred( TermH/2 - 1, " REDIRECTION " ) - printCentred( TermH/2 - 0, " ComputerCraft Edition " ) + printCentred( TermH / 2 - 1, " REDIRECTION " ) + printCentred( TermH / 2 - 0, " ComputerCraft Edition " ) term.setTextColor( colors.yellow ) - printCentred( TermH/2 + 2, " Click to Begin " ) + printCentred( TermH / 2 + 2, " Click to Begin " ) os.pullEvent( "mouse_click" ) end ) end --Game-- if ok then - ok,err = pcall( function() + ok, err = pcall( function() local nLevel if sStartLevel then nLevel = tonumber( sStartLevel ) @@ -668,18 +668,18 @@ if ok then drawStars() term.setTextColor( colors.red ) if TermW >= 40 then - printCentred( TermH/2 - 1, " Thank you for playing Redirection " ) - printCentred( TermH/2 - 0, " ComputerCraft Edition " ) - printCentred( TermH/2 + 2, " Check out the full game: " ) + printCentred( TermH / 2 - 1, " Thank you for playing Redirection " ) + printCentred( TermH / 2 - 0, " ComputerCraft Edition " ) + printCentred( TermH / 2 + 2, " Check out the full game: " ) term.setTextColor( colors.yellow ) - printCentred( TermH/2 + 3, " http://www.redirectiongame.com " ) + printCentred( TermH / 2 + 3, " http://www.redirectiongame.com " ) else - printCentred( TermH/2 - 2, " Thank you for " ) - printCentred( TermH/2 - 1, " playing Redirection " ) - printCentred( TermH/2 - 0, " ComputerCraft Edition " ) - printCentred( TermH/2 + 2, " Check out the full game: " ) + printCentred( TermH / 2 - 2, " Thank you for " ) + printCentred( TermH / 2 - 1, " playing Redirection " ) + printCentred( TermH / 2 - 0, " ComputerCraft Edition " ) + printCentred( TermH / 2 + 2, " Check out the full game: " ) term.setTextColor( colors.yellow ) - printCentred( TermH/2 + 3, " www.redirectiongame.com " ) + printCentred( TermH / 2 + 3, " www.redirectiongame.com " ) end parallel.waitForAll( function() sleep(2) end, @@ -689,7 +689,7 @@ if ok then end --Clear and exit-- -term.setCursorPos(1,1) +term.setCursorPos(1, 1) term.setTextColor(colors.white) term.setBackgroundColor(colors.black) term.clear() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua index eef035301..17c2b9a2b 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/adventure.lua @@ -112,7 +112,7 @@ local items = { desc = "A perfect handle for torches or a pickaxe.", }, ["a crafting table"] = { - aliases = { "crafting table", "craft table", "work bench", "workbench", "crafting bench", "table", }, + aliases = { "crafting table", "craft table", "work bench", "workbench", "crafting bench", "table" }, desc = "It's a crafting table. I shouldn't tell you this, but these don't actually do anything in this game, you can craft tools whenever you like.", }, ["a furnace"] = { @@ -270,7 +270,7 @@ local tAnimals = { } local tMonsters = { - "a creeper", "a skeleton", "a zombie", "a spider" + "a creeper", "a skeleton", "a zombie", "a spider", } local tRecipes = { @@ -309,8 +309,8 @@ local tGoWest = { local nGoWest = 0 local bRunning = true -local tMap = { { {}, }, } -local x,y,z = 0,0,0 +local tMap = { { {} } } +local x, y, z = 0, 0, 0 local inventory = { ["no tea"] = items["no tea"], } @@ -338,7 +338,7 @@ local tDayCycle = { } local function getTimeOfDay() - return math.fmod( math.floor(nTurn/3), #tDayCycle ) + 1 + return math.fmod( math.floor(nTurn / 3), #tDayCycle ) + 1 end local function isSunny() @@ -364,21 +364,21 @@ local function getRoom( x, y, z, dontCreate ) room.trees = hasTrees( room.nBiome ) -- Add animals - if math.random(1,3) == 1 then - for _ = 1,math.random(1,2) do + if math.random(1, 3) == 1 then + for _ = 1, math.random(1, 2) do local sAnimal = tAnimals[ math.random( 1, #tAnimals ) ] room.items[ sAnimal ] = items[ sAnimal ] end end -- Add surface ore - if math.random(1,5) == 1 or hasStone( room.nBiome ) then + if math.random(1, 5) == 1 or hasStone( room.nBiome ) then room.items[ "some stone" ] = items[ "some stone" ] end - if math.random(1,8) == 1 then + if math.random(1, 8) == 1 then room.items[ "some coal" ] = items[ "some coal" ] end - if math.random(1,8) == 1 and hasRivers( room.nBiome ) then + if math.random(1, 8) == 1 and hasRivers( room.nBiome ) then room.items[ "a river" ] = items[ "a river" ] end @@ -389,7 +389,7 @@ local function getRoom( x, y, z, dontCreate ) ["east"] = true, ["west"] = true, } - if math.random(1,8) == 1 then + if math.random(1, 8) == 1 then room.exits["down"] = true room.items["a cave entrance"] = items["a cave entrance"] end @@ -404,7 +404,7 @@ local function getRoom( x, y, z, dontCreate ) room.exits[sDir] = true end else - if math.random(1,3) == 1 then + if math.random(1, 3) == 1 then room.exits[sDir] = true end end @@ -431,13 +431,13 @@ local function getRoom( x, y, z, dontCreate ) -- Add ores room.items[ "some stone" ] = items[ "some stone" ] - if math.random(1,3) == 1 then + if math.random(1, 3) == 1 then room.items[ "some coal" ] = items[ "some coal" ] end - if math.random(1,8) == 1 then + if math.random(1, 8) == 1 then room.items[ "some iron" ] = items[ "some iron" ] end - if y == -3 and math.random(1,15) == 1 then + if y == -3 and math.random(1, 15) == 1 then room.items[ "some diamond" ] = items[ "some diamond" ] end @@ -634,7 +634,7 @@ function commands.wait() end function commands.look( _sTarget ) - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) if room.dark then print( "It is pitch dark." ) return @@ -648,7 +648,7 @@ function commands.look( _sTarget ) else io.write( "You are underground. " ) if next( room.exits ) ~= nil then - print( "You can travel "..itemize( room.exits ).."." ) + print( "You can travel " .. itemize( room.exits ) .. "." ) else print() end @@ -679,16 +679,16 @@ function commands.look( _sTarget ) end if tItem then - print( tItem.desc or "You see nothing special about "..sItem.."." ) + print( tItem.desc or "You see nothing special about " .. sItem .. "." ) else - print( "You don't see any ".._sTarget.." here." ) + print( "You don't see any " .. _sTarget .. " here." ) end end end end function commands.go( _sDir ) - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) if _sDir == nil then print( "Go where?" ) return @@ -735,7 +735,7 @@ function commands.go( _sDir ) end function commands.dig( _sDir, _sTool ) - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) if _sDir == nil then print( "Dig where?" ) return @@ -746,7 +746,7 @@ function commands.dig( _sDir, _sTool ) if _sTool ~= nil then sTool = findItem( inventory, _sTool ) if not sTool then - print( "You're not carrying a ".._sTool.."." ) + print( "You're not carrying a " .. _sTool .. "." ) return end tTool = inventory[ sTool ] @@ -827,10 +827,10 @@ function commands.dig( _sDir, _sTool ) _sDir == "up" and y == 0 then inventory[ "some dirt" ] = items[ "some dirt" ] inventory[ "some stone" ] = items[ "some stone" ] - print( "You dig ".._sDir.." using "..sTool.." and collect some dirt and stone." ) + print( "You dig " .. _sDir .. " using " .. sTool .. " and collect some dirt and stone." ) else inventory[ "some stone" ] = items[ "some stone" ] - print( "You dig ".._sDir.." using "..sTool.." and collect some stone." ) + print( "You dig " .. _sDir .. " using " .. sTool .. " and collect some stone." ) end end @@ -848,7 +848,7 @@ function commands.drop( _sItem ) return end - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) local sItem = findItem( inventory, _sItem ) if sItem then local tItem = inventory[ sItem ] @@ -860,7 +860,7 @@ function commands.drop( _sItem ) print( "Dropped." ) end else - print( "You don't have a ".._sItem.."." ) + print( "You don't have a " .. _sItem .. "." ) end end @@ -871,7 +871,7 @@ function commands.place( _sItem ) end if _sItem == "torch" or _sItem == "a torch" then - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) if inventory["some torches"] or inventory["a torch"] then inventory["a torch"] = nil room.items["a torch"] = items["a torch"] @@ -898,12 +898,12 @@ function commands.take( _sItem ) return end - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) local sItem = findItem( room.items, _sItem ) if sItem then local tItem = room.items[ sItem ] if tItem.heavy == true then - print( "You can't carry "..sItem.."." ) + print( "You can't carry " .. sItem .. "." ) elseif tItem.ore == true then print( "You need to mine this ore." ) else @@ -923,7 +923,7 @@ function commands.take( _sItem ) end end else - print( "You don't see a ".._sItem.." here." ) + print( "You don't see a " .. _sItem .. " here." ) end end @@ -933,7 +933,7 @@ function commands.mine( _sItem, _sTool ) return end if _sTool == nil then - print( "Mine ".._sItem.." with what?" ) + print( "Mine " .. _sItem .. " with what?" ) return end commands.cbreak( _sItem, _sTool ) @@ -957,12 +957,12 @@ function commands.cbreak( _sItem, _sTool ) if _sTool ~= nil then sTool = findItem( inventory, _sTool ) if sTool == nil then - print( "You're not carrying a ".._sTool.."." ) + print( "You're not carrying a " .. _sTool .. "." ) return end end - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) if _sItem == "tree" or _sItem == "trees" or _sItem == "a tree" then print( "The tree breaks into blocks of wood, which you pick up." ) inventory[ "some wood" ] = items[ "some wood" ] @@ -990,18 +990,18 @@ function commands.cbreak( _sItem, _sTool ) local tTool = inventory[ sTool ] if tTool.tool then if tTool.toolLevel < tItem.toolLevel then - print( sTool .." is not strong enough to break this ore." ) + print( sTool .. " is not strong enough to break this ore." ) elseif tTool.toolType ~= tItem.toolType then print( "You need a different kind of tool to break this ore." ) else - print( "The ore breaks, dropping "..sItem..", which you pick up." ) + print( "The ore breaks, dropping " .. sItem .. ", which you pick up." ) inventory[ sItem ] = items[ sItem ] if tItem.infinite ~= true then room.items[ sItem ] = nil end end else - print( "You can't break "..sItem.." with "..sTool..".") + print( "You can't break " .. sItem .. " with " .. sTool .. ".") end elseif tItem.creature == true then @@ -1018,12 +1018,12 @@ function commands.cbreak( _sItem, _sTool ) local tChances = { 0.2, 0.4, 0.55, 0.8, 1 } if math.random() <= tChances[ toolLevel + 1 ] then room.items[ sItem ] = nil - print( "The "..tItem.aliases[1].." dies." ) + print( "The " .. tItem.aliases[1] .. " dies." ) if tItem.drops then for _, sDrop in pairs( tItem.drops ) do if not room.items[sDrop] then - print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) + print( "The " .. tItem.aliases[1] .. " dropped " .. sDrop .. "." ) room.items[sDrop] = items[sDrop] end end @@ -1033,23 +1033,23 @@ function commands.cbreak( _sItem, _sTool ) room.nMonsters = room.nMonsters - 1 end else - print( "The "..tItem.aliases[1].." is injured by your blow." ) + print( "The " .. tItem.aliases[1] .. " is injured by your blow." ) end if tItem.hitDrops then for _, sDrop in pairs( tItem.hitDrops ) do if not room.items[sDrop] then - print( "The "..tItem.aliases[1].." dropped "..sDrop.."." ) + print( "The " .. tItem.aliases[1] .. " dropped " .. sDrop .. "." ) room.items[sDrop] = items[sDrop] end end end else - print( "You can't break "..sItem.."." ) + print( "You can't break " .. sItem .. "." ) end else - print( "You don't see a ".._sItem.." here." ) + print( "You don't see a " .. _sItem .. " here." ) end end @@ -1074,14 +1074,14 @@ function commands.craft( _sItem ) local sItem = findItem( items, _sItem ) local tRecipe = sItem and tRecipes[ sItem ] or nil if tRecipe then - for _,sReq in ipairs( tRecipe ) do + for _, sReq in ipairs( tRecipe ) do if inventory[sReq] == nil then - print( "You don't have the items you need to craft "..sItem.."." ) + print( "You don't have the items you need to craft " .. sItem .. "." ) return end end - for _,sReq in ipairs( tRecipe ) do + for _, sReq in ipairs( tRecipe ) do inventory[sReq] = nil end inventory[ sItem ] = items[ sItem ] @@ -1090,7 +1090,7 @@ function commands.craft( _sItem ) end print( "Crafted." ) else - print( "You don't know how to make "..(sItem or _sItem).."." ) + print( "You don't know how to make " .. (sItem or _sItem) .. "." ) end end @@ -1115,12 +1115,12 @@ function commands.build( _sThing, _sMaterial ) else sMaterial = findItem( inventory, _sMaterial ) if not sMaterial then - print( "You don't have any ".._sMaterial ) + print( "You don't have any " .. _sMaterial ) return end if inventory[sMaterial].material ~= true then - print( sMaterial.." is not a good building material." ) + print( sMaterial .. " is not a good building material." ) return end end @@ -1130,12 +1130,12 @@ function commands.build( _sThing, _sMaterial ) alias = string.match( _sThing, "a ([%a ]+)" ) end - local room = getRoom( x,y,z ) + local room = getRoom( x, y, z ) inventory[sMaterial] = nil room.items[ _sThing ] = { heavy = true, aliases = { alias }, - desc = "As you look at your creation (made from "..sMaterial.."), you feel a swelling sense of pride.", + desc = "As you look at your creation (made from " .. sMaterial .. "), you feel a swelling sense of pride.", } print( "Your construction is complete." ) @@ -1158,7 +1158,7 @@ function commands.eat( _sItem ) local sItem = findItem( inventory, _sItem ) if not sItem then - print( "You don't have any ".._sItem.."." ) + print( "You don't have any " .. _sItem .. "." ) return end @@ -1172,7 +1172,7 @@ function commands.eat( _sItem ) bInjured = false end else - print( "You can't eat "..sItem.."." ) + print( "You can't eat " .. sItem .. "." ) end end @@ -1195,7 +1195,7 @@ function commands.badinput() "That doesn't make any sense.", "What?", } - print( tResponses[ math.random(1,#tResponses) ] ) + print( tResponses[ math.random(1, #tResponses) ] ) end function commands.noinput() @@ -1206,16 +1206,16 @@ function commands.noinput() "Don't be shy.", "Use your words.", } - print( tResponses[ math.random(1,#tResponses) ] ) + print( tResponses[ math.random(1, #tResponses) ] ) end local function simulate() local bNewMonstersThisRoom = false -- Spawn monsters in nearby rooms - for sx = -2,2 do - for sy = -1,1 do - for sz = -2,2 do + for sx = -2, 2 do + for sy = -1, 1 do + for sz = -2, 2 do local h = y + sy if h >= -3 and h <= 0 then local room = getRoom( x + sx, h, z + sz ) @@ -1223,15 +1223,15 @@ local function simulate() -- Spawn monsters if room.nMonsters < 2 and (h == 0 and not isSunny() and not room.items["a torch"] or room.dark) and - math.random(1,6) == 1 then + math.random(1, 6) == 1 then - local sMonster = tMonsters[ math.random(1,#tMonsters) ] + local sMonster = tMonsters[ math.random(1, #tMonsters) ] if room.items[ sMonster ] == nil then room.items[ sMonster ] = items[ sMonster ] room.nMonsters = room.nMonsters + 1 if sx == 0 and sy == 0 and sz == 0 and not room.dark then - print( "From the shadows, "..sMonster.." appears." ) + print( "From the shadows, " .. sMonster .. " appears." ) bNewMonstersThisRoom = true end end @@ -1239,11 +1239,11 @@ local function simulate() -- Burn monsters if h == 0 and isSunny() then - for _,sMonster in ipairs( tMonsters ) do + for _, sMonster in ipairs( tMonsters ) do if room.items[sMonster] and items[sMonster].nocturnal then room.items[sMonster] = nil if sx == 0 and sy == 0 and sz == 0 and not room.dark then - print( "With the sun high in the sky, the "..items[sMonster].aliases[1].." bursts into flame and dies." ) + print( "With the sun high in the sky, the " .. items[sMonster].aliases[1] .. " bursts into flame and dies." ) end room.nMonsters = room.nMonsters - 1 end @@ -1257,9 +1257,9 @@ local function simulate() -- Make monsters attack local room = getRoom( x, y, z ) if nTimeInRoom >= 2 and not bNewMonstersThisRoom then - for _,sMonster in ipairs( tMonsters ) do + for _, sMonster in ipairs( tMonsters ) do if room.items[sMonster] then - if math.random(1,4) == 1 and + if math.random(1, 4) == 1 and not (y == 0 and isSunny() and sMonster == "a spider") then if sMonster == "a creeper" then if room.dark then @@ -1271,9 +1271,9 @@ local function simulate() room.nMonsters = room.nMonsters - 1 else if room.dark then - print( "A "..items[sMonster].aliases[1].." attacks you." ) + print( "A " .. items[sMonster].aliases[1] .. " attacks you." ) else - print( "The "..items[sMonster].aliases[1].." attacks you." ) + print( "The " .. items[sMonster].aliases[1] .. " attacks you." ) end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua index 81775248b..78b259fe0 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/dj.lua @@ -23,7 +23,7 @@ elseif sCommand == "play" or sCommand == nil then if sName == nil then -- No disc specified, pick one at random local tNames = {} - for _,sName in ipairs( peripheral.getNames() ) do + for _, sName in ipairs( peripheral.getNames() ) do if disk.isPresent( sName ) and disk.hasAudio( sName ) then table.insert( tNames, sName ) end @@ -32,15 +32,15 @@ elseif sCommand == "play" or sCommand == nil then print( "No Music Discs in attached disk drives" ) return end - sName = tNames[ math.random(1,#tNames) ] + sName = tNames[ math.random(1, #tNames) ] end -- Play the disc if disk.isPresent( sName ) and disk.hasAudio( sName ) then - print( "Playing "..disk.getAudioTitle( sName ) ) + print( "Playing " .. disk.getAudioTitle( sName ) ) disk.playAudio( sName ) else - print( "No Music Disc in disk drive: "..sName ) + print( "No Music Disc in disk drive: " .. sName ) return end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/hello.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/hello.lua index c1118bd9f..d22399410 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/hello.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/hello.lua @@ -1,5 +1,5 @@ if term.isColour() then - term.setTextColour( 2^math.random(0,15) ) + term.setTextColour( 2 ^ math.random(0, 15) ) end textutils.slowPrint( "Hello World!" ) term.setTextColour( colours.white ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua index 58eb72fc0..cc55288fb 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua @@ -1,6 +1,6 @@ -- Display the start screen -local w,h = term.getSize() +local w, h = term.getSize() local headingColour, textColour, wormColour, fruitColour if term.isColour() then @@ -17,27 +17,27 @@ end local function printCentred( y, s ) local x = math.floor((w - string.len(s)) / 2) - term.setCursorPos(x,y) + term.setCursorPos(x, y) --term.clearLine() term.write( s ) end -local xVel,yVel = 1,0 -local xPos, yPos = math.floor(w/2), math.floor(h/2) +local xVel, yVel = 1, 0 +local xPos, yPos = math.floor(w / 2), math.floor(h / 2) local pxVel, pyVel = nil, nil local nExtraLength = 6 local bRunning = true -local tailX,tailY = xPos,yPos +local tailX, tailY = xPos, yPos local nScore = 0 local nDifficulty = 2 local nSpeed, nInterval -- Setup the screen local screen = {} -for x=1,w do +for x = 1, w do screen[x] = {} - for y=1,h do + for y = 1, h do screen[x][y] = {} end end @@ -54,17 +54,17 @@ local tFruits = { "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", - "@", "$", "%", "#", "&", "!", "?", "+", "*", "~" + "@", "$", "%", "#", "&", "!", "?", "+", "*", "~", } local function addFruit() while true do - local x = math.random(1,w) - local y = math.random(2,h) + local x = math.random(1, w) + local y = math.random(2, h) local fruit = screen[x][y] if fruit.snake == nil and fruit.wall == nil and fruit.fruit == nil then screen[x][y] = { fruit = true } - term.setCursorPos(x,y) + term.setCursorPos(x, y) term.setBackgroundColour( fruitColour ) term.write(" ") term.setBackgroundColour( colours.black ) @@ -80,19 +80,19 @@ end local function drawMenu() term.setTextColour( headingColour ) - term.setCursorPos(1,1) + term.setCursorPos(1, 1) term.write( "SCORE " ) term.setTextColour( textColour ) - term.setCursorPos(7,1) + term.setCursorPos(7, 1) term.write( tostring(nScore) ) term.setTextColour( headingColour ) - term.setCursorPos(w-11,1) + term.setCursorPos(w - 11, 1) term.write( "DIFFICULTY ") term.setTextColour( textColour ) - term.setCursorPos(w,1) + term.setCursorPos(w, 1) term.write( tostring(nDifficulty or "?") ) term.setTextColour( colours.white ) @@ -108,7 +108,7 @@ local function update( ) if nExtraLength == 0 then local tail = screen[tailX][tailY] screen[tailX][tailY] = {} - term.setCursorPos(tailX,tailY) + term.setCursorPos(tailX, tailY) term.write(" ") tailX = tail.nextX tailY = tail.nextY @@ -149,7 +149,7 @@ local function update( ) end - term.setCursorPos(xPos,yPos) + term.setCursorPos(xPos, yPos) term.setBackgroundColour( wormColour ) term.write(" ") term.setBackgroundColour( colours.black ) @@ -164,20 +164,20 @@ local function drawFrontend() --printCentred( math.floor(h/2) - 4, " W O R M " ) term.setTextColour( headingColour ) - printCentred( math.floor(h/2) - 3, "" ) - printCentred( math.floor(h/2) - 2, " SELECT DIFFICULTY " ) - printCentred( math.floor(h/2) - 1, "" ) + printCentred( math.floor(h / 2) - 3, "" ) + printCentred( math.floor(h / 2) - 2, " SELECT DIFFICULTY " ) + printCentred( math.floor(h / 2) - 1, "" ) - printCentred( math.floor(h/2) + 0, " " ) - printCentred( math.floor(h/2) + 1, " " ) - printCentred( math.floor(h/2) + 2, " " ) - printCentred( math.floor(h/2) - 1 + nDifficulty, " [ ] " ) + printCentred( math.floor(h / 2) + 0, " " ) + printCentred( math.floor(h / 2) + 1, " " ) + printCentred( math.floor(h / 2) + 2, " " ) + printCentred( math.floor(h / 2) - 1 + nDifficulty, " [ ] " ) term.setTextColour( textColour ) - printCentred( math.floor(h/2) + 0, "EASY" ) - printCentred( math.floor(h/2) + 1, "MEDIUM" ) - printCentred( math.floor(h/2) + 2, "HARD" ) - printCentred( math.floor(h/2) + 3, "" ) + printCentred( math.floor(h / 2) + 0, "EASY" ) + printCentred( math.floor(h / 2) + 1, "MEDIUM" ) + printCentred( math.floor(h / 2) + 2, "HARD" ) + printCentred( math.floor(h / 2) + 3, "" ) term.setTextColour( colours.white ) end @@ -185,7 +185,7 @@ end drawMenu() drawFrontend() while true do - local _,key = os.pullEvent( "key" ) + local _, key = os.pullEvent( "key" ) if key == keys.up or key == keys.w then -- Up if nDifficulty > 1 then @@ -233,23 +233,23 @@ while bRunning do if key == keys.up or key == keys.w then -- Up if yVel == 0 then - pxVel,pyVel = 0,-1 + pxVel, pyVel = 0, -1 end elseif key == keys.down or key == keys.s then -- Down if yVel == 0 then - pxVel,pyVel = 0,1 + pxVel, pyVel = 0, 1 end elseif key == keys.left or key == keys.a then -- Left if xVel == 0 then - pxVel,pyVel = -1,0 + pxVel, pyVel = -1, 0 end elseif key == keys.right or key == keys.d then -- Right if xVel == 0 then - pxVel,pyVel = 1,0 + pxVel, pyVel = 1, 0 end end @@ -258,25 +258,25 @@ end -- Display the gameover screen term.setTextColour( headingColour ) -printCentred( math.floor(h/2) - 2, " " ) -printCentred( math.floor(h/2) - 1, " G A M E O V E R " ) +printCentred( math.floor(h / 2) - 2, " " ) +printCentred( math.floor(h / 2) - 1, " G A M E O V E R " ) term.setTextColour( textColour ) -printCentred( math.floor(h/2) + 0, " " ) -printCentred( math.floor(h/2) + 1, " FINAL SCORE "..nScore.." " ) -printCentred( math.floor(h/2) + 2, " " ) +printCentred( math.floor(h / 2) + 0, " " ) +printCentred( math.floor(h / 2) + 1, " FINAL SCORE " .. nScore .. " " ) +printCentred( math.floor(h / 2) + 2, " " ) term.setTextColour( colours.white ) local timer = os.startTimer(2.5) repeat - local e,p = os.pullEvent() + local e, p = os.pullEvent() if e == "timer" and p == timer then term.setTextColour( textColour ) - printCentred( math.floor(h/2) + 2, " PRESS ANY KEY " ) - printCentred( math.floor(h/2) + 3, " " ) + printCentred( math.floor(h / 2) + 2, " PRESS ANY KEY " ) + printCentred( math.floor(h / 2) + 3, " " ) term.setTextColour( colours.white ) end until e == "char" term.clear() -term.setCursorPos(1,1) +term.setCursorPos(1, 1) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua index 77621de75..c5556c079 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/gps.lua @@ -28,7 +28,7 @@ elseif sCommand == "host" then -- Find a modem local sModemSide = nil - for _,sSide in ipairs( rs.getSides() ) do + for _, sSide in ipairs( rs.getSides() ) do if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then sModemSide = sSide break @@ -41,7 +41,7 @@ elseif sCommand == "host" then end -- Determine position - local x,y,z + local x, y, z if #tArgs >= 4 then -- Position is manually specified x = tonumber(tArgs[2]) @@ -51,10 +51,10 @@ elseif sCommand == "host" then printUsage() return end - print( "Position is "..x..","..y..","..z ) + print( "Position is " .. x .. "," .. y .. "," .. z ) else -- Position is to be determined using locate - x,y,z = gps.locate( 2, true ) + x, y, z = gps.locate( 2, true ) if x == nil then print( "Run \"gps host \" to set position manually" ) return @@ -63,7 +63,7 @@ elseif sCommand == "host" then -- Open a channel local modem = peripheral.wrap( sModemSide ) - print( "Opening channel on modem "..sModemSide ) + print( "Opening channel on modem " .. sModemSide ) modem.open( gps.CHANNEL_GPS ) -- Serve requests indefinately @@ -80,10 +80,10 @@ elseif sCommand == "host" then -- Print the number of requests handled nServed = nServed + 1 if nServed > 1 then - local _,y = term.getCursorPos() - term.setCursorPos(1,y-1) + local _, y = term.getCursorPos() + term.setCursorPos(1, y - 1) end - print( nServed.." GPS requests served" ) + print( nServed .. " GPS requests served" ) end end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/http/pastebin.lua b/src/main/resources/assets/computercraft/lua/rom/programs/http/pastebin.lua index e31edd7f1..3e28a2f7a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/http/pastebin.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/http/pastebin.lua @@ -46,9 +46,9 @@ local function get(url) write( "Connecting to pastebin.com... " ) -- Add a cache buster so that spam protection is re-checked - local cacheBuster = ("%x"):format(math.random(0, 2^30)) + local cacheBuster = ("%x"):format(math.random(0, 2 ^ 30)) local response, err = http.get( - "https://pastebin.com/raw/"..textutils.urlEncode( paste ).."?cb="..cacheBuster + "https://pastebin.com/raw/" .. textutils.urlEncode( paste ) .. "?cb=" .. cacheBuster ) if response then @@ -93,11 +93,11 @@ if sCommand == "put" then local key = "0ec2eb25b6166c0c27a394ae118ad829" local response = http.post( "https://pastebin.com/api/api_post.php", - "api_option=paste&".. - "api_dev_key="..key.."&".. - "api_paste_format=lua&".. - "api_paste_name="..textutils.urlEncode(sName).."&".. - "api_paste_code="..textutils.urlEncode(sText) + "api_option=paste&" .. + "api_dev_key=" .. key .. "&" .. + "api_paste_format=lua&" .. + "api_paste_name=" .. textutils.urlEncode(sName) .. "&" .. + "api_paste_code=" .. textutils.urlEncode(sText) ) if response then @@ -107,8 +107,8 @@ if sCommand == "put" then response.close() local sCode = string.match( sResponse, "[^/]+$" ) - print( "Uploaded as "..sResponse ) - print( "Run \"pastebin get "..sCode.."\" to download anywhere" ) + print( "Uploaded as " .. sResponse ) + print( "Run \"pastebin get " .. sCode .. "\" to download anywhere" ) else print( "Failed." ) @@ -137,7 +137,7 @@ elseif sCommand == "get" then file.write( res ) file.close() - print( "Downloaded as "..sFile ) + print( "Downloaded as " .. sFile ) end elseif sCommand == "run" then local sCode = tArgs[2] diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/id.lua b/src/main/resources/assets/computercraft/lua/rom/programs/id.lua index bacf2851e..439fc9f3c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/id.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/id.lua @@ -6,24 +6,24 @@ if #tArgs > 0 then end if sDrive == nil then - print( "This is computer #"..os.getComputerID() ) + print( "This is computer #" .. os.getComputerID() ) local label = os.getComputerLabel() if label then - print( "This computer is labelled \""..label.."\"" ) + print( "This computer is labelled \"" .. label .. "\"" ) end else local bData = disk.hasData( sDrive ) if not bData then - print( "No disk in drive "..sDrive ) + print( "No disk in drive " .. sDrive ) return end - print( "The disk is #"..disk.getID( sDrive ) ) + print( "The disk is #" .. disk.getID( sDrive ) ) local label = disk.getLabel( sDrive ) if label then - print( "The disk is labelled \""..label.."\"" ) + print( "The disk is labelled \"" .. label .. "\"" ) end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/label.lua b/src/main/resources/assets/computercraft/lua/rom/programs/label.lua index cee4179b4..ea23277a9 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/label.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/label.lua @@ -14,11 +14,11 @@ local function checkDrive( sDrive ) -- Check the disk exists local bData = disk.hasData( sDrive ) if not bData then - print( "No disk in "..sDrive.." drive" ) + print( "No disk in " .. sDrive .. " drive" ) return false end else - print( "No disk drive named "..sDrive ) + print( "No disk drive named " .. sDrive ) return false end return true @@ -29,7 +29,7 @@ local function get( sDrive ) if checkDrive( sDrive ) then local sLabel = disk.getLabel( sDrive ) if sLabel then - print( "Disk label is \""..sLabel.."\"" ) + print( "Disk label is \"" .. sLabel .. "\"" ) else print( "No Disk label" ) end @@ -37,7 +37,7 @@ local function get( sDrive ) else local sLabel = os.getComputerLabel() if sLabel then - print( "Computer label is \""..sLabel.."\"" ) + print( "Computer label is \"" .. sLabel .. "\"" ) else print( "No Computer label" ) end @@ -50,7 +50,7 @@ local function set( sDrive, sText ) disk.setLabel( sDrive, sText ) local sLabel = disk.getLabel( sDrive ) if sLabel then - print( "Disk label set to \""..sLabel.."\"" ) + print( "Disk label set to \"" .. sLabel .. "\"" ) else print( "Disk label cleared" ) end @@ -59,7 +59,7 @@ local function set( sDrive, sText ) os.setComputerLabel( sText ) local sLabel = os.getComputerLabel() if sLabel then - print( "Computer label set to \""..sLabel.."\"" ) + print( "Computer label set to \"" .. sLabel .. "\"" ) else print( "Computer label cleared" ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua index 50766b973..3535b19df 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/lua.lua @@ -67,7 +67,7 @@ while bRunning do local nForcePrint = 0 local func, e = load( s, "=lua", "t", tEnv ) - local func2 = load( "return _echo("..s..");", "=lua", "t", tEnv ) + local func2 = load( "return _echo(" .. s .. ");", "=lua", "t", tEnv ) if not func then if func2 then func = func2 diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/mkdir.lua b/src/main/resources/assets/computercraft/lua/rom/programs/mkdir.lua index ad3d5a059..3bdb5e840 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/mkdir.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/mkdir.lua @@ -8,9 +8,9 @@ end for _, v in ipairs( tArgs ) do local sNewDir = shell.resolve( v ) if fs.exists( sNewDir ) and not fs.isDir( sNewDir ) then - printError( v..": Destination exists" ) + printError( v .. ": Destination exists" ) elseif fs.isReadOnly( sNewDir ) then - printError( v..": Access denied" ) + printError( v .. ": Access denied" ) else fs.makeDir( sNewDir ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/monitor.lua b/src/main/resources/assets/computercraft/lua/rom/programs/monitor.lua index 985cc0246..16afddd29 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/monitor.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/monitor.lua @@ -11,18 +11,18 @@ end local sName = tArgs[1] if peripheral.getType( sName ) ~= "monitor" then - print( "No monitor named ".. sName ) + print( "No monitor named " .. sName ) return end local sProgram = tArgs[2] local sPath = shell.resolveProgram( sProgram ) if sPath == nil then - print( "No such program: "..sProgram ) + print( "No such program: " .. sProgram ) return end -print( "Running "..sProgram.." on monitor "..sName ) +print( "Running " .. sProgram .. " on monitor " .. sName ) local monitor = peripheral.wrap( sName ) local previousTerm = term.redirect( monitor ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/motd.lua b/src/main/resources/assets/computercraft/lua/rom/programs/motd.lua index 317938b31..a7142fb85 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/motd.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/motd.lua @@ -3,7 +3,7 @@ local tMotd = {} for sPath in string.gmatch(settings.get( "motd.path" ), "[^:]+") do if fs.exists(sPath) then for sLine in io.lines(sPath) do - table.insert(tMotd,sLine) + table.insert(tMotd, sLine) end end end @@ -11,5 +11,5 @@ end if #tMotd == 0 then print("missingno") else - print(tMotd[math.random(1,#tMotd)]) + print(tMotd[math.random(1, #tMotd)]) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua index 5f12588e7..5b2dd6266 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/move.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/move.lua @@ -9,7 +9,7 @@ local sSource = shell.resolve( tArgs[1] ) local sDest = shell.resolve( tArgs[2] ) local tFiles = fs.find( sSource ) if #tFiles > 0 then - for _,sFile in ipairs( tFiles ) do + for _, sFile in ipairs( tFiles ) do if fs.isDir( sDest ) then fs.move( sFile, fs.combine( sDest, fs.getName(sFile) ) ) elseif #tFiles == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/peripherals.lua b/src/main/resources/assets/computercraft/lua/rom/programs/peripherals.lua index b5b5e65f3..33b7e9c9a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/peripherals.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/peripherals.lua @@ -1,7 +1,7 @@ local tPeripherals = peripheral.getNames() print( "Attached Peripherals:" ) if #tPeripherals > 0 then - for n=1,#tPeripherals do + for n = 1, #tPeripherals do local sPeripheral = tPeripherals[n] print( sPeripheral .. " (" .. peripheral.getType( sPeripheral ) .. ")" ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua index afecfa67b..bdc922e4f 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/pocket/falling.lua @@ -4,178 +4,178 @@ This version written by Gopher, at the request of Dan200, for ComputerCraft v1.6. No particular rights are reserved. --]] -local function colorass(c,bw) +local function colorass(c, bw) return term.isColor() and c or bw end -local block_s1= { +local block_s1 = { { - { 1,0,0,0, }, - { 1,1,0,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 1, 0, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,0,0, }, - { 0,1,1,0, }, - { 1,1,0,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 0, 1, 1, 0 }, + { 1, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","{}"), - fg=colorass(colors.blue,colors.black), - bg=colorass(colors.cyan,colors.white), + ch = colorass(" ", "{}"), + fg = colorass(colors.blue, colors.black), + bg = colorass(colors.cyan, colors.white), } -local block_s2= { +local block_s2 = { { - { 0,1,0,0, }, - { 1,1,0,0, }, - { 1,0,0,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 1, 1, 0, 0 }, + { 1, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,0,0, }, - { 1,1,0,0, }, - { 0,1,1,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","{}"), - fg=colorass(colors.green,colors.black), - bg=colorass(colors.lime,colors.white), + ch = colorass(" ", "{}"), + fg = colorass(colors.green, colors.black), + bg = colorass(colors.lime, colors.white), } local block_line = { { - { 0,1,0,0, }, - { 0,1,0,0, }, - { 0,1,0,0, }, - { 0,1,0,0, }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, }, { - { 0,0,0,0, }, - { 1,1,1,1, }, - { 0,0,0,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 1, 1, 1, 1 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","[]"), - fg=colorass(colors.pink,colors.black), - bg=colorass(colors.red,colors.white), + ch = colorass(" ", "[]"), + fg = colorass(colors.pink, colors.black), + bg = colorass(colors.red, colors.white), } local block_square = { { - { 1,1,0,0, }, - { 1,1,0,0, }, - { 0,0,0,0, }, - { 0,0,0,0, }, + { 1, 1, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","[]"), - fg=colorass(colors.lightBlue,colors.black), - bg=colorass(colors.blue,colors.white), + ch = colorass(" ", "[]"), + fg = colorass(colors.lightBlue, colors.black), + bg = colorass(colors.blue, colors.white), } local block_L1 = { { - { 1,1,0,0, }, - { 0,1,0,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 1, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,0,0, }, - { 1,1,1,0, }, - { 1,0,0,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 1, 1, 1, 0 }, + { 1, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,1,0,0, }, - { 0,1,0,0, }, - { 0,1,1,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,1,0, }, - { 1,1,1,0, }, - { 0,0,0,0, }, - { 0,0,0,0, }, + { 0, 0, 1, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","()"), - fg=colorass(colors.orange,colors.black), - bg=colorass(colors.yellow,colors.white), + ch = colorass(" ", "()"), + fg = colorass(colors.orange, colors.black), + bg = colorass(colors.yellow, colors.white), } local block_L2 = { { - { 0,1,0,0, }, - { 0,1,0,0, }, - { 1,1,0,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,0,0, }, - { 1,1,1,0, }, - { 0,0,1,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 1, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,1,1,0, }, - { 0,1,0,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 0, 1, 1, 0 }, + { 0, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 1,0,0,0, }, - { 1,1,1,0, }, - { 0,0,0,0, }, - { 0,0,0,0, }, + { 1, 0, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","()"), - fg=colorass(colors.brown,colors.black), - bg=colorass(colors.orange,colors.white), + ch = colorass(" ", "()"), + fg = colorass(colors.brown, colors.black), + bg = colorass(colors.orange, colors.white), } local block_T = { { - { 0,1,0,0, }, - { 1,1,0,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,0,0,0, }, - { 1,1,1,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 0, 0, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,1,0,0, }, - { 0,1,1,0, }, - { 0,1,0,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 0, 1, 1, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, }, { - { 0,1,0,0, }, - { 1,1,1,0, }, - { 0,0,0,0, }, - { 0,0,0,0, }, + { 0, 1, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, }, - ch=colorass(" ","<>"), - fg=colorass(colors.cyan,colors.black), - bg=colorass(colors.purple,colors.white), + ch = colorass(" ", "<>"), + fg = colorass(colors.cyan, colors.black), + bg = colorass(colors.purple, colors.white), } -local blocks={ block_line, block_square, block_s1, block_s2, block_L1, block_L2, block_T} +local blocks = { block_line, block_square, block_s1, block_s2, block_L1, block_L2, block_T} -local points={4,10,30,120} +local points = {4, 10, 30, 120} -local function lpad(text,amt) - text=tostring(text) - return string.rep(" ",amt-#text)..text +local function lpad(text, amt) + text = tostring(text) + return string.rep(" ", amt - #text) .. text end -local width,height=term.getSize() +local width, height = term.getSize() -if height<19 or width<26 then +if height < 19 or width < 26 then print("Your screen is too small to play :(") return end -local speedsByLevel={ +local speedsByLevel = { 1.2, 1.0, .8, @@ -187,23 +187,23 @@ local speedsByLevel={ .2, .15, .1, - .05,} + .05, } -local level=1 +local level = 1 local function playGame() - local score=0 - local lines=0 - local initialLevel=level - local next=blocks[math.random(1,#blocks)] + local score = 0 + local lines = 0 + local initialLevel = level + local next = blocks[math.random(1, #blocks)] - local pit={} + local pit = {} - local heightAdjust=0 + local heightAdjust = 0 - if height<=19 then - heightAdjust=1 + if height <= 19 then + heightAdjust = 1 end @@ -215,56 +215,56 @@ local function playGame() term.setTextColor(colors.black) term.setBackgroundColor(colorass(colors.lightGray, colors.white)) - term.setCursorPos(22,2) + term.setCursorPos(22, 2) term.write("Score") --score - term.setCursorPos(22,5) + term.setCursorPos(22, 5) term.write("Level") --level - term.setCursorPos(22,8) + term.setCursorPos(22, 8) term.write("Lines") --lines - term.setCursorPos(22,12) + term.setCursorPos(22, 12) term.write("Next") --next - term.setCursorPos(21,1) + term.setCursorPos(21, 1) term.write(" ") - term.setCursorPos(21,2) + term.setCursorPos(21, 2) term.write(" ") --score - term.setCursorPos(21,3) + term.setCursorPos(21, 3) term.write(" ") - term.setCursorPos(21,4) + term.setCursorPos(21, 4) term.write(" ") - term.setCursorPos(21,5) + term.setCursorPos(21, 5) term.write(" ") --level - term.setCursorPos(21,6) + term.setCursorPos(21, 6) term.write(" ") - term.setCursorPos(21,7) + term.setCursorPos(21, 7) term.write(" ") - term.setCursorPos(21,8) + term.setCursorPos(21, 8) term.write(" ") --lines - term.setCursorPos(21,9) + term.setCursorPos(21, 9) term.write(" ") - term.setCursorPos(21,10) + term.setCursorPos(21, 10) term.write(" ") - term.setCursorPos(21,11) + term.setCursorPos(21, 11) term.write(" ") - term.setCursorPos(21,12) + term.setCursorPos(21, 12) term.write(" ") --next - term.setCursorPos(26,12) + term.setCursorPos(26, 12) term.write(" ") --next - term.setCursorPos(21,13) + term.setCursorPos(21, 13) term.write(" ") - term.setCursorPos(21,14) + term.setCursorPos(21, 14) term.write(" ") - term.setCursorPos(21,15) + term.setCursorPos(21, 15) term.write(" ") - term.setCursorPos(21,16) + term.setCursorPos(21, 16) term.write(" ") - term.setCursorPos(21,17) + term.setCursorPos(21, 17) term.write(" ") - term.setCursorPos(21,18) + term.setCursorPos(21, 18) term.write(" ") - term.setCursorPos(21,19) + term.setCursorPos(21, 19) term.write(" ") - term.setCursorPos(21,20) + term.setCursorPos(21, 20) term.write(" ") end @@ -272,47 +272,47 @@ local function playGame() term.setTextColor(colors.white) term.setBackgroundColor(colors.black) - term.setCursorPos(22,3) - term.write(lpad(score,5)) --score - term.setCursorPos(22,6) - term.write(lpad(level,5)) --level - term.setCursorPos(22,9) - term.write(lpad(lines,5)) --lines + term.setCursorPos(22, 3) + term.write(lpad(score, 5)) --score + term.setCursorPos(22, 6) + term.write(lpad(level, 5)) --level + term.setCursorPos(22, 9) + term.write(lpad(lines, 5)) --lines end - local function drawBlockAt(block,xp,yp,rot) + local function drawBlockAt(block, xp, yp, rot) term.setTextColor(block.fg) term.setBackgroundColor(block.bg) - for y=1,4 do - for x=1,4 do - if block[rot][y][x]==1 then - term.setCursorPos((xp+x)*2-3,yp+y-1-heightAdjust) + for y = 1, 4 do + for x = 1, 4 do + if block[rot][y][x] == 1 then + term.setCursorPos((xp + x) * 2 - 3, yp + y - 1 - heightAdjust) term.write(block.ch) end end end end - local function eraseBlockAt(block,xp,yp,rot) + local function eraseBlockAt(block, xp, yp, rot) term.setTextColor(colors.white) term.setBackgroundColor(colors.black) - for y=1,4 do - for x=1,4 do - if block[rot][y][x]==1 then - term.setCursorPos((xp+x)*2-3,yp+y-1-heightAdjust) + for y = 1, 4 do + for x = 1, 4 do + if block[rot][y][x] == 1 then + term.setCursorPos((xp + x) * 2 - 3, yp + y - 1 - heightAdjust) term.write(" ") end end end end - local function testBlockAt(block,xp,yp,rot) - for y=1,4 do - local ty=yp+y-1 - for x=1,4 do - local tx=xp+x-1 - if block[rot][y][x]==1 then - if tx>10 or tx<1 or ty>20 or pit[ty][tx]~=0 then + local function testBlockAt(block, xp, yp, rot) + for y = 1, 4 do + local ty = yp + y - 1 + for x = 1, 4 do + local tx = xp + x - 1 + if block[rot][y][x] == 1 then + if tx > 10 or tx < 1 or ty > 20 or pit[ty][tx] ~= 0 then return true end end @@ -320,11 +320,11 @@ local function playGame() end end - local function pitBlock(block,xp,yp,rot) - for y=1,4 do - for x=1,4 do - if block[rot][y][x]==1 then - pit[yp+y-1][xp+x-1]=block + local function pitBlock(block, xp, yp, rot) + for y = 1, 4 do + for x = 1, 4 do + if block[rot][y][x] == 1 then + pit[yp + y - 1][xp + x - 1] = block end end end @@ -332,10 +332,10 @@ local function playGame() local function clearPit() - for row=1,20 do - pit[row]={} - for col=1,10 do - pit[row][col]=0 + for row = 1, 20 do + pit[row] = {} + for col = 1, 10 do + pit[row][col] = 0 end end end @@ -350,24 +350,24 @@ local function playGame() - local halt=false - local dropSpeed=speedsByLevel[math.min(level,12)] + local halt = false + local dropSpeed = speedsByLevel[math.min(level, 12)] - local curBlock=next - next=blocks[math.random(1,7)] + local curBlock = next + next = blocks[math.random(1, 7)] - local curX, curY, curRot=4, 1, 1 - local dropTimer=os.startTimer(dropSpeed) + local curX, curY, curRot = 4, 1, 1 + local dropTimer = os.startTimer(dropSpeed) - drawBlockAt(next,11.5,15+heightAdjust,1) - drawBlockAt(curBlock,curX,curY,curRot) + drawBlockAt(next, 11.5, 15 + heightAdjust, 1) + drawBlockAt(curBlock, curX, curY, curRot) local function redrawPit() - for r=1+heightAdjust,20 do - term.setCursorPos(1,r-heightAdjust) - for c=1,10 do - if pit[r][c]==0 then + for r = 1 + heightAdjust, 20 do + term.setCursorPos(1, r - heightAdjust) + for c = 1, 10 do + if pit[r][c] == 0 then term.setTextColor(colors.black) term.setBackgroundColor(colors.black) term.write(" ") @@ -381,8 +381,8 @@ local function playGame() end local function hidePit() - for r=1+heightAdjust,20 do - term.setCursorPos(1,r-heightAdjust) + for r = 1 + heightAdjust, 20 do + term.setCursorPos(1, r - heightAdjust) term.setTextColor(colors.black) term.setBackgroundColor(colors.black) term.write(" ") @@ -390,56 +390,56 @@ local function playGame() end local function msgBox(message) - local x=math.floor((17-#message)/2) - term.setBackgroundColor(colorass(colors.lightGray,colors.white)) + local x = math.floor((17 - #message) / 2) + term.setBackgroundColor(colorass(colors.lightGray, colors.white)) term.setTextColor(colors.black) - term.setCursorPos(x,9) - term.write("+"..string.rep("-",#message+2).."+") - term.setCursorPos(x,10) + term.setCursorPos(x, 9) + term.write("+" .. string.rep("-", #message + 2) .. "+") + term.setCursorPos(x, 10) term.write("|") - term.setCursorPos(x+#message+3,10) + term.setCursorPos(x + #message + 3, 10) term.write("|") - term.setCursorPos(x,11) - term.write("+"..string.rep("-",#message+2).."+") + term.setCursorPos(x, 11) + term.write("+" .. string.rep("-", #message + 2) .. "+") term.setTextColor(colors.white) term.setBackgroundColor(colors.black) - term.setCursorPos(x+1,10) - term.write(" "..message.." ") + term.setCursorPos(x + 1, 10) + term.write(" " .. message .. " ") end local function clearRows() - local rows={} - for r=1,20 do - local count=0 - for c=1,10 do - if pit[r][c]~=0 then - count=count+1 + local rows = {} + for r = 1, 20 do + local count = 0 + for c = 1, 10 do + if pit[r][c] ~= 0 then + count = count + 1 else break end end - if count==10 then - rows[#rows+1]=r + if count == 10 then + rows[#rows + 1] = r end end - if #rows>0 then - for _=1,4 do + if #rows > 0 then + for _ = 1, 4 do sleep(.1) - for r=1,#rows do - r=rows[r] - term.setCursorPos(1,r-heightAdjust) - for c=1,10 do + for r = 1, #rows do + r = rows[r] + term.setCursorPos(1, r - heightAdjust) + for c = 1, 10 do term.setTextColor(pit[r][c].bg) term.setBackgroundColor(pit[r][c].fg) term.write(pit[r][c].ch) end end sleep(.1) - for r=1,#rows do - r=rows[r] - term.setCursorPos(1,r-heightAdjust) - for c=1,10 do + for r = 1, #rows do + r = rows[r] + term.setCursorPos(1, r - heightAdjust) + for c = 1, 10 do term.setTextColor(pit[r][c].fg) term.setBackgroundColor(pit[r][c].bg) term.write(pit[r][c].ch) @@ -448,154 +448,154 @@ local function playGame() end --now remove the rows and drop everythign else term.setBackgroundColor(colors.black) - for r=1,#rows do - r=rows[r] - term.setCursorPos(1,r-heightAdjust) + for r = 1, #rows do + r = rows[r] + term.setCursorPos(1, r - heightAdjust) term.write(" ") end sleep(.25) - for r=1,#rows do - table.remove(pit,rows[r]) - table.insert(pit,1,{0,0,0,0,0,0,0,0,0,0}) + for r = 1, #rows do + table.remove(pit, rows[r]) + table.insert(pit, 1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) end redrawPit() - lines=lines+#rows - score=score+points[#rows]*math.min(level,20) - level=math.floor(lines/10)+initialLevel - dropSpeed=speedsByLevel[math.min(level,12)] + lines = lines + #rows + score = score + points[#rows] * math.min(level, 20) + level = math.floor(lines / 10) + initialLevel + dropSpeed = speedsByLevel[math.min(level, 12)] updateNumbers() end sleep(.25) end local function blockFall() - if testBlockAt(curBlock,curX,curY+1,curRot) then - pitBlock(curBlock,curX,curY,curRot) + if testBlockAt(curBlock, curX, curY + 1, curRot) then + pitBlock(curBlock, curX, curY, curRot) --detect rows that clear clearRows() - curBlock=next - curX=4 - curY=1 - curRot=1 - if testBlockAt(curBlock,curX,curY,curRot) then - halt=true + curBlock = next + curX = 4 + curY = 1 + curRot = 1 + if testBlockAt(curBlock, curX, curY, curRot) then + halt = true end - drawBlockAt(curBlock,curX,curY,curRot) - eraseBlockAt(next,11.5,15+heightAdjust,1) - next=blocks[math.random(1,7)] - drawBlockAt(next,11.5,15+heightAdjust,1) + drawBlockAt(curBlock, curX, curY, curRot) + eraseBlockAt(next, 11.5, 15 + heightAdjust, 1) + next = blocks[math.random(1, 7)] + drawBlockAt(next, 11.5, 15 + heightAdjust, 1) return true else - eraseBlockAt(curBlock,curX,curY,curRot) - curY=curY+1 - drawBlockAt(curBlock,curX,curY,curRot) + eraseBlockAt(curBlock, curX, curY, curRot) + curY = curY + 1 + drawBlockAt(curBlock, curX, curY, curRot) return false end end while not halt do - local e={os.pullEvent()} - if e[1]=="timer" then - if e[2]==dropTimer then + local e = {os.pullEvent()} + if e[1] == "timer" then + if e[2] == dropTimer then blockFall() - dropTimer=os.startTimer(dropSpeed) + dropTimer = os.startTimer(dropSpeed) end - elseif e[1]=="key" then - local key=e[2] - local dx,dy,dr=0,0,0 - if key==keys.left or key==keys.a then - dx=-1 - elseif key==keys.right or key==keys.d then - dx=1 - elseif key==keys.up or key==keys.w then - dr=1 - elseif key==keys.down or key==keys.s then + elseif e[1] == "key" then + local key = e[2] + local dx, dy, dr = 0, 0, 0 + if key == keys.left or key == keys.a then + dx = -1 + elseif key == keys.right or key == keys.d then + dx = 1 + elseif key == keys.up or key == keys.w then + dr = 1 + elseif key == keys.down or key == keys.s then while not blockFall() do end - dropTimer=os.startTimer(dropSpeed) - elseif key==keys.space then + dropTimer = os.startTimer(dropSpeed) + elseif key == keys.space then hidePit() msgBox("Paused") - while ({os.pullEvent("key")})[2]~=keys.space do end + while ({os.pullEvent("key")})[2] ~= keys.space do end redrawPit() - drawBlockAt(curBlock,curX,curY,curRot) - dropTimer=os.startTimer(dropSpeed) + drawBlockAt(curBlock, curX, curY, curRot) + dropTimer = os.startTimer(dropSpeed) end - if dx+dr~=0 then - if not testBlockAt(curBlock,curX+dx,curY+dy,dr>0 and curRot%#curBlock+dr or curRot) then - eraseBlockAt(curBlock,curX,curY,curRot) - curX=curX+dx - curY=curY+dy - curRot=dr==0 and curRot or curRot%#curBlock+dr - drawBlockAt(curBlock,curX,curY,curRot) + if dx + dr ~= 0 then + if not testBlockAt(curBlock, curX + dx, curY + dy, dr > 0 and curRot % #curBlock + dr or curRot) then + eraseBlockAt(curBlock, curX, curY, curRot) + curX = curX + dx + curY = curY + dy + curRot = dr == 0 and curRot or curRot % #curBlock + dr + drawBlockAt(curBlock, curX, curY, curRot) end end - elseif e[1]=="term_resize" then - local _,h=term.getSize() - if h==20 then - heightAdjust=0 + elseif e[1] == "term_resize" then + local _, h = term.getSize() + if h == 20 then + heightAdjust = 0 else - heightAdjust=1 + heightAdjust = 1 end redrawPit() - drawBlockAt(curBlock,curX,curY,curRot) + drawBlockAt(curBlock, curX, curY, curRot) end end msgBox("Game Over!") while true do - local _,k=os.pullEvent("key") - if k==keys.space or k==keys.enter then + local _, k = os.pullEvent("key") + if k == keys.space or k == keys.enter then break end end - level = math.min(level,9) + level = math.min(level, 9) end -local selected=1 -local playersDetected=false +local selected = 1 +local playersDetected = false local function drawMenu() term.setBackgroundColor(colors.black) - term.setTextColor(colorass(colors.red,colors.white)) + term.setTextColor(colorass(colors.red, colors.white)) term.clear() - local cx,cy=math.floor(width/2),math.floor(height/2) + local cx, cy = math.floor(width / 2), math.floor(height / 2) - term.setCursorPos(cx-6,cy-2) + term.setCursorPos(cx - 6, cy - 2) term.write("F A L L I N G") if playersDetected then - if selected==0 then - term.setTextColor(colorass(colors.blue,colors.black)) - term.setBackgroundColor(colorass(colors.gray,colors.white)) + if selected == 0 then + term.setTextColor(colorass(colors.blue, colors.black)) + term.setBackgroundColor(colorass(colors.gray, colors.white)) else - term.setTextColor(colorass(colors.lightBlue,colors.white)) + term.setTextColor(colorass(colors.lightBlue, colors.white)) term.setBackgroundColor(colors.black) end - term.setCursorPos(cx-12,cy) + term.setCursorPos(cx - 12, cy) term.write(" Play head-to-head game! ") end - term.setCursorPos(cx-10,cy+1) - if selected==1 then - term.setTextColor(colorass(colors.blue,colors.black)) - term.setBackgroundColor(colorass(colors.lightGray,colors.white)) + term.setCursorPos(cx - 10, cy + 1) + if selected == 1 then + term.setTextColor(colorass(colors.blue, colors.black)) + term.setBackgroundColor(colorass(colors.lightGray, colors.white)) else - term.setTextColor(colorass(colors.lightBlue,colors.white)) + term.setTextColor(colorass(colors.lightBlue, colors.white)) term.setBackgroundColor(colors.black) end term.write(" Play from level: <" .. level .. "> ") - term.setCursorPos(cx-3,cy+3) - if selected==2 then - term.setTextColor(colorass(colors.blue,colors.black)) - term.setBackgroundColor(colorass(colors.lightGray,colors.white)) + term.setCursorPos(cx - 3, cy + 3) + if selected == 2 then + term.setTextColor(colorass(colors.blue, colors.black)) + term.setBackgroundColor(colorass(colors.lightGray, colors.white)) else - term.setTextColor(colorass(colors.lightBlue,colors.white)) + term.setTextColor(colorass(colors.lightBlue, colors.white)) term.setBackgroundColor(colors.black) end term.write(" Quit ") @@ -606,28 +606,28 @@ local function runMenu() drawMenu() while true do - local event={os.pullEvent()} - if event[1]=="key" then - local key=event[2] - if key==keys.right or key==keys.d and selected==1 then - level=math.min(level+1,9) + local event = {os.pullEvent()} + if event[1] == "key" then + local key = event[2] + if key == keys.right or key == keys.d and selected == 1 then + level = math.min(level + 1, 9) drawMenu() - elseif key==keys.left or key==keys.a and selected==1 then - level=math.max(level-1,1) + elseif key == keys.left or key == keys.a and selected == 1 then + level = math.max(level - 1, 1) drawMenu() - elseif key>=keys.one and key<=keys.nine and selected==1 then - level=key-keys.one + 1 + elseif key >= keys.one and key <= keys.nine and selected == 1 then + level = key - keys.one + 1 drawMenu() - elseif key==keys.up or key==keys.w then - selected=selected-1 - if selected==0 then - selected=2 + elseif key == keys.up or key == keys.w then + selected = selected - 1 + if selected == 0 then + selected = 2 end drawMenu() - elseif key==keys.down or key==keys.s then - selected=selected%2+1 + elseif key == keys.down or key == keys.s then + selected = selected % 2 + 1 drawMenu() - elseif key==keys.enter or key==keys.space then + elseif key == keys.enter or key == keys.space then break --begin play! end end @@ -636,7 +636,7 @@ end while true do runMenu() - if selected==2 then + if selected == 2 then break end @@ -647,4 +647,4 @@ end term.setTextColor(colors.white) term.setBackgroundColor(colors.black) term.clear() -term.setCursorPos(1,1) +term.setCursorPos(1, 1) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua index 2bf5404ee..3a772804a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua @@ -9,7 +9,7 @@ end local sOpenedModem = nil local function openModem() - for _,sModem in ipairs( peripheral.getNames() ) do + for _, sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then if not rednet.isOpen( sModem ) then rednet.open( sModem ) @@ -94,7 +94,7 @@ if sCommand == "host" then end local function printUsers() - local _,y = term.getCursorPos() + local _, y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nUsers == 1 then @@ -114,7 +114,7 @@ if sCommand == "host" then local tUser = tUsers[ nUserID ] if tUser then if not tUser.bPingPonged then - send( "* "..tUser.sUsername.." has timed out" ) + send( "* " .. tUser.sUsername .. " has timed out" ) tUsers[ nUserID ] = nil nUsers = nUsers - 1 printUsers() @@ -131,7 +131,7 @@ if sCommand == "host" then tCommands = { ["me"] = function( tUser, sContent ) if string.len(sContent) > 0 then - send( "* "..tUser.sUsername.." "..sContent ) + send( "* " .. tUser.sUsername .. " " .. sContent ) else send( "* Usage: /me [words]", tUser.nUserID ) end @@ -140,7 +140,7 @@ if sCommand == "host" then if string.len(sContent) > 0 then local sOldName = tUser.sUsername tUser.sUsername = sContent - send( "* "..sOldName.." is now known as "..tUser.sUsername ) + send( "* " .. sOldName .. " is now known as " .. tUser.sUsername ) else send( "* Usage: /nick [nickname]", tUser.nUserID ) end @@ -159,7 +159,7 @@ if sCommand == "host" then for sCommand in pairs( tCommands ) do sCommands = sCommands .. " /" .. sCommand end - send( sCommands.." /logout", tUser.nUserID ) + send( sCommands .. " /logout", tUser.nUserID ) end, } @@ -177,7 +177,7 @@ if sCommand == "host" then } nUsers = nUsers + 1 printUsers() - send( "* "..sUsername.." has joined the chat" ) + send( "* " .. sUsername .. " has joined the chat" ) ping( nUserID ) end @@ -187,7 +187,7 @@ if sCommand == "host" then local tUser = tUsers[ nUserID ] if tUser and tUser.nID == nSenderID then if tMessage.sType == "logout" then - send( "* "..tUser.sUsername.." has left the chat" ) + send( "* " .. tUser.sUsername .. " has left the chat" ) tUsers[ nUserID ] = nil nUsers = nUsers - 1 printUsers() @@ -199,13 +199,13 @@ if sCommand == "host" then if sCommand then local fnCommand = tCommands[ sCommand ] if fnCommand then - local sContent = string.sub( sMessage, string.len(sCommand)+3 ) + local sContent = string.sub( sMessage, string.len(sCommand) + 3 ) fnCommand( tUser, sContent ) else - send( "* Unrecognised command: /"..sCommand, tUser.nUserID ) + send( "* Unrecognised command: /" .. sCommand, tUser.nUserID ) end else - send( "<"..tUser.sUsername.."> "..tMessage.sText ) + send( "<" .. tUser.sUsername .. "> " .. tMessage.sText ) end end @@ -284,12 +284,12 @@ elseif sCommand == "join" then end -- Handle messages - local w,h = term.getSize() + local w, h = term.getSize() local parentTerm = term.current() local titleWindow = window.create( parentTerm, 1, 1, w, 1, true ) - local historyWindow = window.create( parentTerm, 1, 2, w, h-2, true ) + local historyWindow = window.create( parentTerm, 1, 2, w, h - 2, true ) local promptWindow = window.create( parentTerm, 1, h, w, 1, true ) - historyWindow.setCursorPos( 1, h-2 ) + historyWindow.setCursorPos( 1, h - 2 ) term.clear() term.setTextColour( textColour ) @@ -298,9 +298,9 @@ elseif sCommand == "join" then local function drawTitle() local w = titleWindow.getSize() - local sTitle = sUsername.." on "..sHostname + local sTitle = sUsername .. " on " .. sHostname titleWindow.setTextColour( highlightColour ) - titleWindow.setCursorPos( math.floor( w/2 - string.len(sTitle)/2 ), 1 ) + titleWindow.setCursorPos( math.floor( w / 2 - string.len(sTitle) / 2 ), 1 ) titleWindow.clearLine() titleWindow.write( sTitle ) promptWindow.restoreCursor() @@ -347,9 +347,9 @@ elseif sCommand == "join" then end elseif sEvent == "term_resize" then - local w,h = parentTerm.getSize() + local w, h = parentTerm.getSize() titleWindow.reposition( 1, 1, w, 1 ) - historyWindow.reposition( 1, 2, w, h-2 ) + historyWindow.reposition( 1, 2, w, h - 2 ) promptWindow.reposition( 1, h, w, 1 ) end @@ -384,7 +384,7 @@ elseif sCommand == "join" then function() local tSendHistory = {} while true do - promptWindow.setCursorPos( 1,1 ) + promptWindow.setCursorPos( 1, 1 ) promptWindow.clearLine() promptWindow.setTextColor( highlightColour ) promptWindow.write( ": ") @@ -409,7 +409,7 @@ elseif sCommand == "join" then term.redirect( parentTerm ) -- Print error notice - local _,h = term.getSize() + local _, h = term.getSize() term.setCursorPos( 1, h ) term.clearLine() term.setCursorBlink( false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua index 452ffb587..c6bad5634 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/repeat.lua @@ -1,7 +1,7 @@ -- Find modems local tModems = {} -for _,sModem in ipairs( peripheral.getNames() ) do +for _, sModem in ipairs( peripheral.getNames() ) do if peripheral.getType( sModem ) == "modem" then table.insert( tModems, sModem ) end @@ -16,14 +16,14 @@ else end local function open( nChannel ) - for n=1,#tModems do + for n = 1, #tModems do local sModem = tModems[n] peripheral.call( sModem, "open", nChannel ) end end local function close( nChannel ) - for n=1,#tModems do + for n = 1, #tModems do local sModem = tModems[n] peripheral.call( sModem, "close", nChannel ) end @@ -51,7 +51,7 @@ local ok, error = pcall( function() tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = tMessage.nMessageID -- Send on all other open modems, to the target and to other repeaters - for n=1,#tModems do + for n = 1, #tModems do local sOtherModem = tModems[n] peripheral.call( sOtherModem, "transmit", rednet.CHANNEL_REPEAT, nReplyChannel, tMessage ) peripheral.call( sOtherModem, "transmit", tMessage.nRecipient, nReplyChannel, tMessage ) @@ -59,7 +59,7 @@ local ok, error = pcall( function() -- Log the event nTransmittedMessages = nTransmittedMessages + 1 - local _,y = term.getCursorPos() + local _, y = term.getCursorPos() term.setCursorPos( 1, y - 1 ) term.clearLine() if nTransmittedMessages == 1 then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua index ff38a89ef..ff7f87a48 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/redstone.lua @@ -17,7 +17,7 @@ if sCommand == "probe" then local count = 0 local bundledCount = 0 - for _,sSide in ipairs( redstone.getSides() ) do + for _, sSide in ipairs( redstone.getSides() ) do if redstone.getBundledInput( sSide ) > 0 then bundledCount = bundledCount + 1 end @@ -39,12 +39,12 @@ if sCommand == "probe" then if bundledCount > 0 then print() print( "Bundled inputs:" ) - for _,sSide in ipairs( redstone.getSides() ) do + for _, sSide in ipairs( redstone.getSides() ) do local nInput = redstone.getBundledInput( sSide ) if nInput ~= 0 then - write( sSide..": " ) + write( sSide .. ": " ) local count = 0 - for sColour,nColour in pairs( colors ) do + for sColour, nColour in pairs( colors ) do if type( nColour ) == "number" and colors.test( nInput, nColour ) then if count > 0 then write( ", " ) @@ -69,7 +69,7 @@ elseif sCommand == "pulse" then local sSide = tArgs[2] local nCount = tonumber( tArgs[3] ) or 1 local nPeriod = tonumber( tArgs[4] ) or 0.5 - for _=1,nCount do + for _ = 1, nCount do redstone.setOutput( sSide, true ) sleep( nPeriod / 2 ) redstone.setOutput( sSide, false ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua index 94ef6b621..f2bacabcc 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/set.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/set.lua @@ -2,12 +2,12 @@ local tArgs = { ... } if #tArgs == 0 then -- "set" - local _,y = term.getCursorPos() + local _, y = term.getCursorPos() local tSettings = {} - for n,sName in ipairs( settings.getNames() ) do + for n, sName in ipairs( settings.getNames() ) do tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) end - textutils.pagedPrint(table.concat(tSettings,"\n"),y-3) + textutils.pagedPrint(table.concat(tSettings, "\n"), y - 3) elseif #tArgs == 1 then -- "set foo" diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua index 13c4b90c0..5628f0c6f 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua @@ -33,9 +33,9 @@ local function createShellEnv( sDir ) } package.path = "?;?.lua;?/init.lua;/rom/modules/main/?;/rom/modules/main/?.lua;/rom/modules/main/?/init.lua" if turtle then - package.path = package.path..";/rom/modules/turtle/?;/rom/modules/turtle/?.lua;/rom/modules/turtle/?/init.lua" + package.path = package.path .. ";/rom/modules/turtle/?;/rom/modules/turtle/?.lua;/rom/modules/turtle/?/init.lua" elseif command then - package.path = package.path..";/rom/modules/command/?;/rom/modules/command/?.lua;/rom/modules/command/?/init.lua" + package.path = package.path .. ";/rom/modules/command/?;/rom/modules/command/?.lua;/rom/modules/command/?/init.lua" end package.config = "/\n;\n?\n!\n-" package.preload = {} @@ -52,7 +52,7 @@ local function createShellEnv( sDir ) local sError = "" for pattern in string.gmatch(package.path, "[^;]+") do local sPath = string.gsub(pattern, "%?", fname) - if sPath:sub(1,1) ~= "/" then + if sPath:sub(1, 1) ~= "/" then sPath = fs.combine(sDir, sPath) end if fs.exists(sPath) and not fs.isDir(sPath) then @@ -70,7 +70,7 @@ local function createShellEnv( sDir ) end end return nil, sError - end + end, } local sentinel = {} @@ -125,7 +125,7 @@ local function run( _sCommand, ... ) if multishell then local sTitle = fs.getName( sPath ) if sTitle:sub(-4) == ".lua" then - sTitle = sTitle:sub(1,-5) + sTitle = sTitle:sub(1, -5) end multishell.setTitle( multishell.getCurrent(), sTitle ) end @@ -140,7 +140,7 @@ local function run( _sCommand, ... ) if #tProgramStack > 0 then local sTitle = fs.getName( tProgramStack[#tProgramStack] ) if sTitle:sub(-4) == ".lua" then - sTitle = sTitle:sub(1,-5) + sTitle = sTitle:sub(1, -5) end multishell.setTitle( multishell.getCurrent(), sTitle ) else @@ -272,12 +272,12 @@ function shell.programs( _bIncludeHidden ) sPath = shell.resolve( sPath ) if fs.isDir( sPath ) then local tList = fs.list( sPath ) - for n=1,#tList do + for n = 1, #tList do local sFile = tList[n] if not fs.isDir( fs.combine( sPath, sFile ) ) and (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then if #sFile > 4 and sFile:sub(-4) == ".lua" then - sFile = sFile:sub(1,-5) + sFile = sFile:sub(1, -5) end tItems[ sFile ] = true end @@ -326,7 +326,7 @@ local function completeProgram( sLine ) -- Add programs from the path local tPrograms = shell.programs() - for n=1,#tPrograms do + for n = 1, #tPrograms do local sProgram = tPrograms[n] if #sProgram > #sLine and string.sub( sProgram, 1, #sLine ) == sLine then local sResult = string.sub( sProgram, #sLine + 1 ) @@ -366,7 +366,7 @@ function shell.complete( sLine ) return { " " } else local tResults = completeProgram( sBit ) - for n=1,#tResults do + for n = 1, #tResults do local sResult = tResults[n] local sPath = shell.resolveProgram( sBit .. sResult ) if tCompletionInfo[ sPath ] then @@ -397,7 +397,7 @@ function shell.setCompletionFunction( sProgram, fnComplete ) expect(1, sProgram, "string") expect(2, fnComplete, "function") tCompletionInfo[ sProgram ] = { - fnComplete = fnComplete + fnComplete = fnComplete, } end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/time.lua b/src/main/resources/assets/computercraft/lua/rom/programs/time.lua index ff5fac8f2..ccd83d4ec 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/time.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/time.lua @@ -1,3 +1,3 @@ local nTime = os.time() local nDay = os.day() -print( "The time is "..textutils.formatTime( nTime, false ).." on Day "..nDay ) +print( "The time is " .. textutils.formatTime( nTime, false ) .. " on Day " .. nDay ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/craft.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/craft.lua index 8b273c2d6..8b8923e71 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/craft.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/craft.lua @@ -29,7 +29,7 @@ if turtle.craft( nLimit ) then end if nCrafted > 1 then - print( nCrafted.." items crafted" ) + print( nCrafted .. " items crafted" ) elseif nCrafted == 1 then print( "1 item crafted" ) else diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua index 246992f78..696c15747 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/dance.lua @@ -81,10 +81,10 @@ textutils.slowWrite( "Preparing to get down." ) textutils.slowPrint( "..", 0.75 ) local sAudio = nil -for _,sName in pairs( peripheral.getNames() ) do +for _, sName in pairs( peripheral.getNames() ) do if disk.hasAudio( sName ) then disk.playAudio( sName ) - print( "Jamming to "..disk.getAudioTitle( sName ) ) + print( "Jamming to " .. disk.getAudioTitle( sName ) ) sAudio = sName break end @@ -103,7 +103,7 @@ parallel.waitForAny( end, function() while true do - local fnMove = tMoves[math.random(1,#tMoves)] + local fnMove = tMoves[math.random(1, #tMoves)] fnMove() end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua index 5e7f32274..2edc5b1fa 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/excavate.lua @@ -20,15 +20,15 @@ local depth = 0 local unloaded = 0 local collected = 0 -local xPos,zPos = 0,0 -local xDir,zDir = 0,1 +local xPos, zPos = 0, 0 +local xDir, zDir = 0, 1 local goTo -- Filled in further down local refuel -- Filled in further down local function unload( _bKeepOneFuelStack ) print( "Unloading items..." ) - for n=1,16 do + for n = 1, 16 do local nCount = turtle.getItemCount(n) if nCount > 0 then turtle.select(n) @@ -48,11 +48,11 @@ local function unload( _bKeepOneFuelStack ) end local function returnSupplies() - local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir + local x, y, z, xd, zd = xPos, depth, zPos, xDir, zDir print( "Returning to surface..." ) - goTo( 0,0,0,0,-1 ) + goTo( 0, 0, 0, 0, -1 ) - local fuelNeeded = 2*(x+y+z) + 1 + local fuelNeeded = 2 * (x + y + z) + 1 if not refuel( fuelNeeded ) then unload( true ) print( "Waiting for fuel" ) @@ -64,13 +64,13 @@ local function returnSupplies() end print( "Resuming mining..." ) - goTo( x,y,z,xd,zd ) + goTo( x, y, z, xd, zd ) end local function collect() local bFull = true local nTotalItems = 0 - for n=1,16 do + for n = 1, 16 do local nCount = turtle.getItemCount(n) if nCount == 0 then bFull = false @@ -81,7 +81,7 @@ local function collect() if nTotalItems > collected then collected = nTotalItems if math.fmod(collected + unloaded, 50) == 0 then - print( "Mined "..collected + unloaded.." items." ) + print( "Mined " .. collected + unloaded .. " items." ) end end @@ -100,7 +100,7 @@ function refuel( ammount ) local needed = ammount or xPos + zPos + depth + 2 if turtle.getFuelLevel() < needed then - for n=1,16 do + for n = 1, 16 do if turtle.getItemCount(n) > 0 then turtle.select(n) if turtle.refuel(1) then @@ -176,7 +176,7 @@ local function tryDown() depth = depth + 1 if math.fmod( depth, 10 ) == 0 then - print( "Descended "..depth.." metres." ) + print( "Descended " .. depth .. " metres." ) end return true @@ -290,8 +290,8 @@ end local alternate = 0 local done = false while not done do - for n=1,size do - for _=1,size-1 do + for n = 1, size do + for _ = 1, size - 1 do if not tryForwards() then done = true break @@ -300,8 +300,8 @@ while not done do if done then break end - if n 1 then - if math.fmod(size,2) == 0 then + if math.fmod(size, 2) == 0 then turnRight() else if alternate == 0 then @@ -344,13 +344,13 @@ end print( "Returning to surface..." ) -- Return to where we started -goTo( 0,0,0,0,-1 ) +goTo( 0, 0, 0, 0, -1 ) unload( false ) -goTo( 0,0,0,0,1 ) +goTo( 0, 0, 0, 0, 1 ) -- Seal the hole if reseal then turtle.placeDown() end -print( "Mined "..collected + unloaded.." items total." ) +print( "Mined " .. collected + unloaded .. " items total." ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/go.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/go.lua index c84120ce0..c8b43b0e9 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/go.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/go.lua @@ -50,7 +50,7 @@ while nArg <= #tArgs do end end else - print( "No such direction: "..sDirection ) + print( "No such direction: " .. sDirection ) print( "Try: forward, back, up, down" ) return end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua index fa69de01c..77f796196 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/refuel.lua @@ -36,7 +36,7 @@ if turtle.getFuelLevel() ~= "unlimited" then end end end - print( "Fuel level is "..turtle.getFuelLevel() ) + print( "Fuel level is " .. turtle.getFuelLevel() ) if turtle.getFuelLevel() == turtle.getFuelLimit() then print( "Fuel limit reached" ) end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua index 9bf4e2665..50183d013 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/turtle/tunnel.lua @@ -20,7 +20,7 @@ local collected = 0 local function collect() collected = collected + 1 if math.fmod(collected, 25) == 0 then - print( "Mined "..collected.." items." ) + print( "Mined " .. collected .. " items." ) end end @@ -67,7 +67,7 @@ local function refuel() end local function tryRefuel() - for n=1,16 do + for n = 1, 16 do if turtle.getItemCount(n) > 0 then turtle.select(n) if turtle.refuel(1) then @@ -139,7 +139,7 @@ end print( "Tunnelling..." ) -for n=1,length do +for n = 1, length do turtle.placeDown() tryDigUp() turtle.turnLeft() @@ -153,7 +153,7 @@ for n=1,length do tryDig() turtle.turnLeft() - if n 0 then info = info .. (" Skipped %d pending test(s)."):format(test_status.pending) diff --git a/src/test/resources/test-rom/spec/apis/gps_spec.lua b/src/test/resources/test-rom/spec/apis/gps_spec.lua index 8d61a5c37..1e0a49f87 100644 --- a/src/test/resources/test-rom/spec/apis/gps_spec.lua +++ b/src/test/resources/test-rom/spec/apis/gps_spec.lua @@ -2,7 +2,7 @@ describe("The gps library", function() describe("gps.locate", function() it("validates arguments", function() stub(_G, "commands", { getBlockPosition = function() - end }) + end, }) gps.locate() gps.locate(1) diff --git a/src/test/resources/test-rom/spec/apis/io_spec.lua b/src/test/resources/test-rom/spec/apis/io_spec.lua index 9dad5f7ec..484588014 100644 --- a/src/test/resources/test-rom/spec/apis/io_spec.lua +++ b/src/test/resources/test-rom/spec/apis/io_spec.lua @@ -60,10 +60,10 @@ describe("The io library", function() expect(io.output():seek()):equal(0) assert(io.write("alo alo")) - expect(io.output():seek()):equal(#("alo alo")) - expect(io.output():seek("cur", -3)):equal(#("alo alo") - 3) + expect(io.output():seek()):equal(#"alo alo") + expect(io.output():seek("cur", -3)):equal(#"alo alo" - 3) assert(io.write("joao")) - expect(io.output():seek("end"):equal(#("alo joao"))) + expect(io.output():seek("end"):equal(#"alo joao")) expect(io.output():seek("set")):equal(0) diff --git a/src/test/resources/test-rom/spec/base_spec.lua b/src/test/resources/test-rom/spec/base_spec.lua index 43de8239d..8ce2213bf 100644 --- a/src/test/resources/test-rom/spec/base_spec.lua +++ b/src/test/resources/test-rom/spec/base_spec.lua @@ -70,7 +70,7 @@ describe("The Lua base library", function() it("does not prefix for unnamed chunks", function() local info = debug.getinfo(loadstring("return 1"), "S") - expect(info):matches { short_src = '[string "return 1"]', source = "return 1", } + expect(info):matches { short_src = '[string "return 1"]', source = "return 1" } end) it("does not prefix when already prefixed", function() diff --git a/src/test/resources/test-rom/spec/modules/cc/shell/completion_spec.lua b/src/test/resources/test-rom/spec/modules/cc/shell/completion_spec.lua index 7f7fd0a40..ffcd3b7f3 100644 --- a/src/test/resources/test-rom/spec/modules/cc/shell/completion_spec.lua +++ b/src/test/resources/test-rom/spec/modules/cc/shell/completion_spec.lua @@ -5,7 +5,7 @@ describe("cc.shell.completion", function() it("completes both", function() expect(c.dirOrFile(shell, "rom/")):same { "apis/", "apis", "autorun/", "autorun", "help/", "help", - "modules/", "modules", "motd.txt", "programs/", "programs", "startup.lua" + "modules/", "modules", "motd.txt", "programs/", "programs", "startup.lua", } end) diff --git a/src/test/resources/test-rom/spec/programs/command/commands_spec.lua b/src/test/resources/test-rom/spec/programs/command/commands_spec.lua index d7261b9d1..6c9d87cdc 100644 --- a/src/test/resources/test-rom/spec/programs/command/commands_spec.lua +++ b/src/test/resources/test-rom/spec/programs/command/commands_spec.lua @@ -10,7 +10,7 @@ describe("The commands program", function() it("lists commands", function() local pagedTabulate = stub(textutils, "pagedTabulate", function(x) print(table.unpack(x)) end) stub(_G, "commands", { - list = function() return { "computercraft" } end + list = function() return { "computercraft" } end, }) expect(capture(stub, "/rom/programs/command/commands.lua")) diff --git a/src/test/resources/test-rom/spec/programs/command/exec_spec.lua b/src/test/resources/test-rom/spec/programs/command/exec_spec.lua index 869222b2c..0c12b18a7 100644 --- a/src/test/resources/test-rom/spec/programs/command/exec_spec.lua +++ b/src/test/resources/test-rom/spec/programs/command/exec_spec.lua @@ -15,7 +15,7 @@ describe("The exec program", function() it("runs a command", function() stub(_G, "commands", { - exec = function() return true, {"Hello World!"} end + exec = function() return true, {"Hello World!"} end, }) expect(capture(stub, "/rom/programs/command/exec.lua computercraft")) @@ -23,8 +23,8 @@ describe("The exec program", function() end) it("reports command failures", function() - stub(_G,"commands",{ - exec = function() return false, {"Hello World!"} end + stub(_G, "commands", { + exec = function() return false, {"Hello World!"} end, }) expect(capture(stub, "/rom/programs/command/exec.lua computercraft")) diff --git a/src/test/resources/test-rom/spec/programs/edit_spec.lua b/src/test/resources/test-rom/spec/programs/edit_spec.lua index 137c39c83..7ca0b04f2 100644 --- a/src/test/resources/test-rom/spec/programs/edit_spec.lua +++ b/src/test/resources/test-rom/spec/programs/edit_spec.lua @@ -1,5 +1,4 @@ local capture = require "test_helpers".capture_program -local testFile = require "test_helpers".testFile describe("The edit program", function() diff --git a/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua b/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua index eb55f53d4..5b13d59a9 100644 --- a/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua +++ b/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua @@ -17,7 +17,7 @@ describe("The pastebin program", function() local tHeader = {} tHeader["Content-Type"] = "text/plain; charset=utf-8" return tHeader - end + end, } end, post = function() @@ -28,7 +28,7 @@ describe("The pastebin program", function() close = function() end, } - end + end, }) end diff --git a/src/test/resources/test-rom/spec/programs/http/wget_spec.lua b/src/test/resources/test-rom/spec/programs/http/wget_spec.lua index b6b88b34b..75d82c671 100644 --- a/src/test/resources/test-rom/spec/programs/http/wget_spec.lua +++ b/src/test/resources/test-rom/spec/programs/http/wget_spec.lua @@ -14,7 +14,7 @@ describe("The wget program", function() close = function() end, } - end + end, }) end diff --git a/src/test/resources/test-rom/spec/programs/id_spec.lua b/src/test/resources/test-rom/spec/programs/id_spec.lua index a4e4657d3..73206e7fb 100644 --- a/src/test/resources/test-rom/spec/programs/id_spec.lua +++ b/src/test/resources/test-rom/spec/programs/id_spec.lua @@ -6,6 +6,6 @@ describe("The id program", function() local id = os.getComputerID() expect(capture(stub, "id")) - :matches { ok = true, output = "This is computer #"..id.."\n", error = "" } + :matches { ok = true, output = "This is computer #" .. id .. "\n", error = "" } end) end) diff --git a/src/test/resources/test-rom/spec/programs/motd_spec.lua b/src/test/resources/test-rom/spec/programs/motd_spec.lua index 052cd8fa4..3781e2e16 100644 --- a/src/test/resources/test-rom/spec/programs/motd_spec.lua +++ b/src/test/resources/test-rom/spec/programs/motd_spec.lua @@ -3,10 +3,10 @@ local capture = require "test_helpers".capture_program describe("The motd program", function() it("displays MODT", function() - local file = fs.open("/modt_check.txt","w") + local file = fs.open("/modt_check.txt", "w") file.write("Hello World!") file.close() - settings.set("motd.path","/modt_check.txt") + settings.set("motd.path", "/modt_check.txt") expect(capture(stub, "motd")) :matches { ok = true, output = "Hello World!\n", error = "" } diff --git a/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua b/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua index 0c3fb3183..32144051b 100644 --- a/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua +++ b/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua @@ -9,7 +9,7 @@ describe("The pocket equip program", function() it("can equip an upgrade", function() stub(_G, "pocket", { - equipBack = function() return true end + equipBack = function() return true end, }) expect(capture(stub, "/rom/programs/pocket/equip.lua")) @@ -18,7 +18,7 @@ describe("The pocket equip program", function() it("handles when an upgrade cannot be equipped", function() stub(_G, "pocket", { - equipBack = function() return false, "Cannot equip this item." end + equipBack = function() return false, "Cannot equip this item." end, }) expect(capture(stub, "/rom/programs/pocket/equip.lua")) diff --git a/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua b/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua index 85a1e640f..9cb0f7481 100644 --- a/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua +++ b/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua @@ -9,7 +9,7 @@ describe("The pocket unequip program", function() it("unequips an upgrade", function() stub(_G, "pocket", { - unequipBack = function() return true end + unequipBack = function() return true end, }) expect(capture(stub, "/rom/programs/pocket/unequip.lua")) @@ -18,7 +18,7 @@ describe("The pocket unequip program", function() it("handles when an upgrade cannot be equipped", function() stub(_G, "pocket", { - unequipBack = function() return false, "Nothing to remove." end + unequipBack = function() return false, "Nothing to remove." end, }) expect(capture(stub, "/rom/programs/pocket/unequip.lua")) diff --git a/src/test/resources/test-rom/spec/programs/set_spec.lua b/src/test/resources/test-rom/spec/programs/set_spec.lua index dc81dcfe3..64dba1447 100644 --- a/src/test/resources/test-rom/spec/programs/set_spec.lua +++ b/src/test/resources/test-rom/spec/programs/set_spec.lua @@ -4,8 +4,8 @@ describe("The set program", function() it("displays all settings", function() settings.clear() - settings.set("Test","Hello World!") - settings.set("123",456) + settings.set("Test", "Hello World!") + settings.set("123", 456) expect(capture(stub, "set")) :matches { ok = true, output = '"123" is 456\n"Test" is "Hello World!"\n', error = "" } @@ -13,8 +13,8 @@ describe("The set program", function() it("displays a single settings", function() settings.clear() - settings.set("Test","Hello World!") - settings.set("123",456) + settings.set("Test", "Hello World!") + settings.set("123", 456) expect(capture(stub, "set Test")) :matches { ok = true, output = '"Test" is "Hello World!"\n', error = "" } diff --git a/src/test/resources/test-rom/spec/programs/time_spec.lua b/src/test/resources/test-rom/spec/programs/time_spec.lua index 8ec10044e..e9c1eff31 100644 --- a/src/test/resources/test-rom/spec/programs/time_spec.lua +++ b/src/test/resources/test-rom/spec/programs/time_spec.lua @@ -7,6 +7,6 @@ describe("The time program", function() local day = os.day() expect(capture(stub, "time")) - :matches { ok = true, output = "The time is "..time.." on Day "..day.."\n", error = "" } + :matches { ok = true, output = "The time is " .. time .. " on Day " .. day .. "\n", error = "" } end) end) diff --git a/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua b/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua index 43b7ea982..11934b7ec 100644 --- a/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua +++ b/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua @@ -39,7 +39,7 @@ describe("The craft program", function() it("craft a single item", function() local item_count = 2 - stub(_G,"turtle",{ + stub(_G, "turtle", { craft = function() item_count = 1 return true @@ -54,7 +54,7 @@ describe("The craft program", function() it("crafts no items", function() local item_count = 2 - stub(_G,"turtle",{ + stub(_G, "turtle", { craft = function() item_count = 1 return false diff --git a/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua b/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua index 2e637fc82..09284f8a6 100644 --- a/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua +++ b/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua @@ -29,7 +29,7 @@ describe("The turtle equip program", function() end) it("swaps existing upgrades", function() - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return 1 end, equipLeft = function() return true end, @@ -45,7 +45,7 @@ describe("The turtle equip program", function() describe("equips a new upgrade", function() local function setup() local item_count = 1 - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return item_count end, equipLeft = function() @@ -73,7 +73,7 @@ describe("The turtle equip program", function() end) it("handles when an upgrade cannot be equipped", function() - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return 1 end, equipLeft = function() return false end, diff --git a/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua b/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua index 3b6283260..986d028c1 100644 --- a/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua +++ b/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua @@ -17,7 +17,7 @@ describe("The refuel program", function() end, getFuelLimit = function() return fuel_limit - end + end, }) end @@ -49,13 +49,13 @@ describe("The refuel program", function() end) it("reports when the fuel limit is reached", function() - setup_turtle(0,5,5) + setup_turtle(0, 5, 5) expect(capture(stub, "/rom/programs/turtle/refuel.lua 5")) :matches { ok = true, output = "Fuel level is 5\nFuel limit reached\n", error = "" } end) it("reports when the fuel level is unlimited", function() - setup_turtle("unlimited",5,5) + setup_turtle("unlimited", 5, 5) expect(capture(stub, "/rom/programs/turtle/refuel.lua 5")) :matches { ok = true, output = "Fuel level is unlimited\n", error = "" } end) diff --git a/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua b/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua index 1cb97b440..eea58f78f 100644 --- a/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua +++ b/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua @@ -17,11 +17,11 @@ describe("The turtle unequip program", function() end) it("says when nothing was unequipped", function() - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return 0 end, equipRight = function() return true end, - equipLeft = function() return true end + equipLeft = function() return true end, }) expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) @@ -32,7 +32,7 @@ describe("The turtle unequip program", function() it("unequips a upgrade", function() local item_count = 0 - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return item_count end, equipRight = function() @@ -42,7 +42,7 @@ describe("The turtle unequip program", function() equipLeft = function() item_count = 1 return true - end + end, }) expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) @@ -53,11 +53,11 @@ describe("The turtle unequip program", function() end) it("fails when the turtle is full", function() - stub(_G,"turtle",{ + stub(_G, "turtle", { select = function() end, getItemCount = function() return 1 end, equipRight = function() return true end, - equipLeft = function() return true end + equipLeft = function() return true end, }) expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) diff --git a/src/test/resources/test-rom/spec/test_helpers.lua b/src/test/resources/test-rom/spec/test_helpers.lua index 6ffe3942d..74b94b7e2 100644 --- a/src/test/resources/test-rom/spec/test_helpers.lua +++ b/src/test/resources/test-rom/spec/test_helpers.lua @@ -37,7 +37,7 @@ local function capture_program(stub, program, ...) output = table.concat(output), error = table.concat(error), combined = table.concat(combined), - ok = ok + ok = ok, } end From b0397ed3c533a011e52b32d6e03a2accd3477ecb Mon Sep 17 00:00:00 2001 From: Jared Allard Date: Sun, 8 Dec 2019 09:10:58 -0800 Subject: [PATCH 03/11] Add support for HTTP PATCH and TRACE (#324) --- .github/workflows/main-ci.yml | 2 +- src/main/resources/assets/computercraft/lua/bios.lua | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 0be633a53..649c36da6 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -30,4 +30,4 @@ jobs: test -d bin || mkdir bin test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate chmod +x bin/illuaminate - GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/illuaminate lint --github + bin/illuaminate lint diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index 4a30d22da..42ae840f1 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -681,6 +681,7 @@ if http then local methods = { GET = true, POST = true, HEAD = true, OPTIONS = true, PUT = true, DELETE = true, + PATCH = true, TRACE = true, } local function checkKey( options, key, ty, opt ) From 03b6d2f1aba131fdaa3e28a0f50ae769d76c296b Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 10 Dec 2019 18:54:43 +0000 Subject: [PATCH 04/11] Replace string.len with # --- .luacheckrc | 35 ----------------- illuaminate.sexp | 10 +++-- .../assets/computercraft/lua/bios.lua | 14 +++---- .../computercraft/lua/rom/apis/textutils.lua | 6 +-- .../lua/rom/programs/advanced/multishell.lua | 2 +- .../computercraft/lua/rom/programs/edit.lua | 38 +++++++++---------- .../lua/rom/programs/fun/advanced/paint.lua | 2 +- .../rom/programs/fun/advanced/redirection.lua | 8 ++-- .../lua/rom/programs/fun/worm.lua | 2 +- .../lua/rom/programs/rednet/chat.lua | 10 ++--- 10 files changed, 47 insertions(+), 80 deletions(-) delete mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc deleted file mode 100644 index 3bf2c2c41..000000000 --- a/.luacheckrc +++ /dev/null @@ -1,35 +0,0 @@ -std = "max" - -ignore = { - -- Allow access to undefined globals or their fields. In the future we'll - -- define all of CC's globals within this file - '113', '143', - - -- FIXME: Ignore unused arguments and loop variables - '212', '213', - - -- Disable line is too long for now. It would be possible to clean - -- this up in the future. - '631', -} - --- Only run the linter on ROM and bios for now, as the treasure disks --- are largely unsupported. -include_files = { - 'src/main/resources/assets/computercraft/lua/rom', - 'src/main/resources/assets/computercraft/lua/bios.lua', - 'src/test/resources/test-rom', -} - -files['src/main/resources/assets/computercraft/lua/bios.lua'] = { - -- Allow declaring and mutating globals - allow_defined_top = true, - ignore = { '112', '121', '122', '131', '142' }, -} - -files['src/main/resources/assets/computercraft/lua/rom/apis'] = { - -- APIs may define globals on the top level. We'll ignore unused globals, - -- as obviously they may be used outside that API. - allow_defined_top = true, - ignore = { '131' }, -} diff --git a/illuaminate.sexp b/illuaminate.sexp index b4deb17bd..b37f34928 100644 --- a/illuaminate.sexp +++ b/illuaminate.sexp @@ -7,20 +7,22 @@ (at / (linters - ;; It'd be nice to avoid this, but right now there's a lot of instances of it. + ;; It'd be nice to avoid this, but right now there's a lot of instances of + ;; it. -var:set-loop ;; It's useful to name arguments for documentation, so we allow this. It'd ;; be good to find a compromise in the future, but this works for now. -var:unused-arg)) -;; We disable the two global linters in bios.lua and the APIs. In the future +;; We disable the unused global linter in bios.lua and the APIs. In the future ;; hopefully we'll get illuaminate to handle this. (at (/src/main/resources/assets/computercraft/lua/bios.lua /src/main/resources/assets/computercraft/lua/rom/apis/) - (linters -var:set-global -var:unused-global)) + (linters -var:unused-global) + (lint + (allow-toplevel-global true))) ;; These warnings are broken right now -(at completion.lua (linters -doc:malformed-type)) (at (bios.lua worm.lua) (linters -control:unreachable)) diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index 42ae840f1..0cceccf99 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -207,13 +207,13 @@ function write( sText ) end -- Print the line with proper word wrapping - while string.len(sText) > 0 do + while #sText > 0 do local whitespace = string.match( sText, "^[ \t]+" ) if whitespace then -- Print whitespace term.write( whitespace ) x, y = term.getCursorPos() - sText = string.sub( sText, string.len(whitespace) + 1 ) + sText = string.sub( sText, #whitespace + 1 ) end local newline = string.match( sText, "^\n" ) @@ -225,10 +225,10 @@ function write( sText ) local text = string.match( sText, "^[^ \t\n]+" ) if text then - sText = string.sub( sText, string.len(text) + 1 ) - if string.len(text) > w then + sText = string.sub( sText, #text + 1 ) + if #text > w then -- Print a multiline word - while string.len( text ) > 0 do + while #text > 0 do if x > w then newLine() end @@ -238,7 +238,7 @@ function write( sText ) end else -- Print a word normally - if x + string.len(text) - 1 > w then + if x + #text - 1 > w then newLine() end term.write( text ) @@ -299,7 +299,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault ) local tCompletions local nCompletion local function recomplete() - if _fnComplete and nPos == string.len(sLine) then + if _fnComplete and nPos == #sLine then tCompletions = _fnComplete( sLine ) if tCompletions and #tCompletions > 0 then nCompletion = 1 diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua index 5044d9dc3..38360ea71 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/textutils.lua @@ -10,7 +10,7 @@ function slowWrite( sText, nRate ) sText = tostring( sText ) local x, y = term.getCursorPos() - local len = string.len( sText ) + local len = #sText for n = 1, len do term.setCursorPos( x, y ) @@ -116,7 +116,7 @@ local function tabulateCommon( bPaged, ... ) if type( sItem ) ~= "string" then error( "bad argument #" .. n .. "." .. nu .. " (expected string, got " .. type( sItem ) .. ")", 3 ) end - nMaxLen = math.max( string.len( sItem ) + 1, nMaxLen ) + nMaxLen = math.max( #sItem + 1, nMaxLen ) end end end @@ -388,7 +388,7 @@ function complete( sSearchText, tSearchTable ) end local sPart = string.sub( sSearchText, nStart ) - local nPartLength = string.len( sPart ) + local nPartLength = #sPart local tResults = {} local tSeen = {} diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua index 757691e27..75dd3b3da 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell.lua @@ -287,7 +287,7 @@ while #tProcesses > 0 do tabStart = 2 end for n = nScrollPos, #tProcesses do - local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1 + local tabEnd = tabStart + #tProcesses[n].sTitle + 1 if x >= tabStart and x <= tabEnd then selectProcess( n ) redrawMenu() diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua index bfa682843..5e6cfee1c 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/edit.lua @@ -62,7 +62,7 @@ end table.insert( tMenuItems, "Exit" ) local sStatus = "Press Ctrl to access menu" -if string.len( sStatus ) > w - 5 then +if #sStatus > w - 5 then sStatus = "Press Ctrl for menu" end @@ -144,13 +144,13 @@ local function tryWrite( sLine, regex, colour ) end term.write( match ) term.setTextColour( textColour ) - return string.sub( sLine, string.len(match) + 1 ) + return string.sub( sLine, #match + 1 ) end return nil end local function writeHighlighted( sLine ) - while string.len(sLine) > 0 do + while #sLine > 0 do sLine = tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or tryWrite( sLine, "^%-%-.*", commentColour ) or @@ -188,7 +188,7 @@ end local function recomplete() local sLine = tLines[y] - if not bMenu and not bReadOnly and x == string.len(sLine) + 1 then + if not bMenu and not bReadOnly and x == #sLine + 1 then tCompletions = complete( sLine ) if tCompletions and #tCompletions > 0 then nCompletion = 1 @@ -248,7 +248,7 @@ local function redrawMenu() term.clearLine() -- Draw line numbers - term.setCursorPos( w - string.len( "Ln " .. y ) + 1, h ) + term.setCursorPos( w - #( "Ln " .. y ) + 1, h ) term.setTextColour( highlightColour ) term.write( "Ln " ) term.setTextColour( textColour ) @@ -468,7 +468,7 @@ local function acceptCompletion() -- Append the completion local sCompletion = tCompletions[ nCompletion ] tLines[y] = tLines[y] .. sCompletion - setCursor( x + string.len( sCompletion ), y ) + setCursor( x + #sCompletion , y ) end end @@ -490,7 +490,7 @@ while bRunning do elseif y > 1 then -- Move cursor up setCursor( - math.min( x, string.len( tLines[y - 1] ) + 1 ), + math.min( x, #tLines[y - 1] + 1 ), y - 1 ) end @@ -511,7 +511,7 @@ while bRunning do elseif y < #tLines then -- Move cursor down setCursor( - math.min( x, string.len( tLines[y + 1] ) + 1 ), + math.min( x, #tLines[y + 1] + 1 ), y + 1 ) end @@ -520,7 +520,7 @@ while bRunning do elseif param == keys.tab then -- Tab if not bMenu and not bReadOnly then - if nCompletion and x == string.len(tLines[y]) + 1 then + if nCompletion and x == #tLines[y] + 1 then -- Accept autocomplete acceptCompletion() else @@ -542,7 +542,7 @@ while bRunning do newY = 1 end setCursor( - math.min( x, string.len( tLines[newY] ) + 1 ), + math.min( x, #tLines[newY] + 1 ), newY ) end @@ -557,7 +557,7 @@ while bRunning do else newY = #tLines end - local newX = math.min( x, string.len( tLines[newY] ) + 1 ) + local newX = math.min( x, #tLines[newY] + 1 ) setCursor( newX, newY ) end @@ -574,7 +574,7 @@ while bRunning do -- End if not bMenu then -- Move cursor to the end - local nLimit = string.len( tLines[y] ) + 1 + local nLimit = #tLines[y] + 1 if x < nLimit then setCursor( nLimit, y ) end @@ -587,7 +587,7 @@ while bRunning do -- Move cursor left setCursor( x - 1, y ) elseif x == 1 and y > 1 then - setCursor( string.len( tLines[y - 1] ) + 1, y - 1 ) + setCursor( #tLines[y - 1] + 1, y - 1 ) end else -- Move menu left @@ -601,11 +601,11 @@ while bRunning do elseif param == keys.right then -- Right if not bMenu then - local nLimit = string.len( tLines[y] ) + 1 + local nLimit = #tLines[y] + 1 if x < nLimit then -- Move cursor right setCursor( x + 1, y ) - elseif nCompletion and x == string.len(tLines[y]) + 1 then + elseif nCompletion and x == #tLines[y] + 1 then -- Accept autocomplete acceptCompletion() elseif x == nLimit and y < #tLines then @@ -624,7 +624,7 @@ while bRunning do elseif param == keys.delete then -- Delete if not bMenu and not bReadOnly then - local nLimit = string.len( tLines[y] ) + 1 + local nLimit = #tLines[y] + 1 if x < nLimit then local sLine = tLines[y] tLines[y] = string.sub(sLine, 1, x - 1) .. string.sub(sLine, x + 1) @@ -653,7 +653,7 @@ while bRunning do end elseif y > 1 then -- Remove newline - local sPrevLen = string.len( tLines[y - 1] ) + local sPrevLen = #tLines[y - 1] tLines[y - 1] = tLines[y - 1] .. tLines[y] table.remove( tLines, y ) setCursor( sPrevLen + 1, y - 1 ) @@ -721,7 +721,7 @@ while bRunning do -- Input text local sLine = tLines[y] tLines[y] = string.sub(sLine, 1, x - 1) .. param .. string.sub(sLine, x) - setCursor( x + string.len( param ), y ) + setCursor( x + #param , y ) end elseif sEvent == "mouse_click" then @@ -731,7 +731,7 @@ while bRunning do local cx, cy = param2, param3 if cy < h then local newY = math.min( math.max( scrollY + cy, 1 ), #tLines ) - local newX = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[newY] ) + 1 ) + local newX = math.min( math.max( scrollX + cx, 1 ), #tLines[newY] + 1 ) setCursor( newX, newY ) end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua index 2e77847e0..758e82074 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/paint.lua @@ -148,7 +148,7 @@ local function save(path) end sLine = string.sub( sLine, 1, nLastChar ) tLines[y] = sLine - if string.len( sLine ) > 0 then + if #sLine > 0 then nLastLine = y end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua index a84117bdb..fc6e0f038 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/advanced/redirection.lua @@ -60,7 +60,7 @@ local tArgs = { ... } --Functions-- local function printCentred( yc, stg ) - local xc = math.floor((TermW - string.len(stg)) / 2) + 1 + local xc = math.floor((TermW - #stg) / 2) + 1 term.setCursorPos(xc, yc) term.write( stg ) end @@ -179,7 +179,7 @@ local function loadLevel(nNum) fLevel = fs.open(sLevelD, "r") local wl = true Blocks = tonumber(string.sub(fLevel.readLine(), 1, 1)) - local xSize = string.len(fLevel.readLine()) + 2 + local xSize = #fLevel.readLine() + 2 local Lines = 3 while wl do local wLine = fLevel.readLine() @@ -187,7 +187,7 @@ local function loadLevel(nNum) fLevel.close() wl = false else - xSize = math.max(string.len(wLine) + 2, xSize) + xSize = math.max(#wLine + 2, xSize) Lines = Lines + 1 end end @@ -197,7 +197,7 @@ local function loadLevel(nNum) fLevel.readLine() for Line = 2, Lines - 1 do local sLine = fLevel.readLine() - local chars = string.len(sLine) + local chars = #sLine for char = 1, chars do local el = string.sub(sLine, char, char) if el == "8" then diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua index cc55288fb..507763cb4 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/fun/worm.lua @@ -16,7 +16,7 @@ else end local function printCentred( y, s ) - local x = math.floor((w - string.len(s)) / 2) + local x = math.floor((w - #s) / 2) term.setCursorPos(x, y) --term.clearLine() term.write( s ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua index 3a772804a..58a513f36 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/rednet/chat.lua @@ -130,14 +130,14 @@ if sCommand == "host" then local tCommands tCommands = { ["me"] = function( tUser, sContent ) - if string.len(sContent) > 0 then + if #sContent > 0 then send( "* " .. tUser.sUsername .. " " .. sContent ) else send( "* Usage: /me [words]", tUser.nUserID ) end end, ["nick"] = function( tUser, sContent ) - if string.len(sContent) > 0 then + if #sContent > 0 then local sOldName = tUser.sUsername tUser.sUsername = sContent send( "* " .. sOldName .. " is now known as " .. tUser.sUsername ) @@ -199,7 +199,7 @@ if sCommand == "host" then if sCommand then local fnCommand = tCommands[ sCommand ] if fnCommand then - local sContent = string.sub( sMessage, string.len(sCommand) + 3 ) + local sContent = string.sub( sMessage, #sCommand + 3 ) fnCommand( tUser, sContent ) else send( "* Unrecognised command: /" .. sCommand, tUser.nUserID ) @@ -300,7 +300,7 @@ elseif sCommand == "join" then local w = titleWindow.getSize() local sTitle = sUsername .. " on " .. sHostname titleWindow.setTextColour( highlightColour ) - titleWindow.setCursorPos( math.floor( w / 2 - string.len(sTitle) / 2 ), 1 ) + titleWindow.setCursorPos( math.floor( w / 2 - #sTitle / 2 ), 1 ) titleWindow.clearLine() titleWindow.write( sTitle ) promptWindow.restoreCursor() @@ -321,7 +321,7 @@ elseif sCommand == "join" then term.setTextColour( highlightColour ) write( sUsernameBit ) term.setTextColour( textColour ) - write( string.sub( sMessage, string.len( sUsernameBit ) + 1 ) ) + write( string.sub( sMessage, #sUsernameBit + 1 ) ) else write( sMessage ) end From 3a5d50e572263d96695c7dea61abea02e7a542f3 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 18 Dec 2019 15:29:24 +0000 Subject: [PATCH 05/11] Basic Minetweaker support (#327) This provides the following methods: - dan200.computercraft.turtle.removeUpgrade(id: String) - dan200.computercraft.turtle.removeUpgrade(stack: IItemStack) - dan200.computercraft.turtle.addTool(id: String, craftItem: IItemStack[, toolItem: IItemStack][, kind: string]) While it's pretty minimal, it should allow for a reasonable amount of functionality. Closes #327 and #97. --- build.gradle | 7 +- .../computercraft/shared/TurtleUpgrades.java | 109 ++++++++++++------ .../crafttweaker/TurtleTweaker.java | 70 +++++++++++ .../crafttweaker/actions/AddTurtleTool.java | 96 +++++++++++++++ .../crafttweaker/actions/IAction.java | 32 +++++ .../actions/RemoveTurtleUpgradeByItem.java | 50 ++++++++ .../actions/RemoveTurtleUpgradeByName.java | 49 ++++++++ .../shared/turtle/items/ItemTurtleBase.java | 12 +- .../shared/turtle/upgrades/TurtleAxe.java | 6 + .../shared/turtle/upgrades/TurtleHoe.java | 5 + .../shared/turtle/upgrades/TurtleShovel.java | 5 + .../shared/turtle/upgrades/TurtleSword.java | 6 + .../shared/turtle/upgrades/TurtleTool.java | 8 +- 13 files changed, 409 insertions(+), 46 deletions(-) create mode 100644 src/main/java/dan200/computercraft/shared/integration/crafttweaker/TurtleTweaker.java create mode 100644 src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/AddTurtleTool.java create mode 100644 src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/IAction.java create mode 100644 src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByItem.java create mode 100644 src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByName.java diff --git a/build.gradle b/build.gradle index 4632fcf19..a10121df1 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,10 @@ name "Amadornes" url "https://maven.amadornes.com/" } + maven { + name "CraftTweaker" + url "https://maven.blamejared.com/" + } } configurations { @@ -70,9 +74,10 @@ dependencies { checkstyle "com.puppycrawl.tools:checkstyle:8.25" + deobfProvided "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.554" + deobfProvided "MCMultiPart2:MCMultiPart:2.5.3" deobfProvided "mezz.jei:jei_1.12.2:4.15.0.269:api" deobfProvided "pl.asie:Charset-Lib:0.5.4.6" - deobfProvided "MCMultiPart2:MCMultiPart:2.5.3" runtime "mezz.jei:jei_1.12.2:4.15.0.269" diff --git a/src/main/java/dan200/computercraft/shared/TurtleUpgrades.java b/src/main/java/dan200/computercraft/shared/TurtleUpgrades.java index 921be39d9..ad62ff310 100644 --- a/src/main/java/dan200/computercraft/shared/TurtleUpgrades.java +++ b/src/main/java/dan200/computercraft/shared/TurtleUpgrades.java @@ -19,12 +19,35 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; +import java.util.stream.Stream; public final class TurtleUpgrades { + public static class Wrapper + { + final ITurtleUpgrade upgrade; + final int legacyId; + final String id; + final String modId; + boolean enabled; + + public Wrapper( ITurtleUpgrade upgrade ) + { + ModContainer mc = Loader.instance().activeModContainer(); + + this.upgrade = upgrade; + this.legacyId = upgrade.getLegacyUpgradeID(); + this.id = upgrade.getUpgradeID().toString(); + this.modId = mc != null && mc.getModId() != null ? mc.getModId() : null; + this.enabled = true; + } + } + + private static ITurtleUpgrade[] vanilla; + private static final Map upgrades = new HashMap<>(); private static final Int2ObjectMap legacyUpgrades = new Int2ObjectOpenHashMap<>(); - private static final IdentityHashMap upgradeOwners = new IdentityHashMap<>(); + private static final IdentityHashMap wrappers = new IdentityHashMap<>(); private TurtleUpgrades() {} @@ -35,9 +58,7 @@ public static void register( @Nonnull ITurtleUpgrade upgrade ) int id = upgrade.getLegacyUpgradeID(); if( id >= 0 && id < 64 ) { - String message = getMessage( upgrade, "Legacy UpgradeID '" + id + "' is reserved by ComputerCraft" ); - ComputerCraft.log.error( message ); - throw new RuntimeException( message ); + throw registrationError( upgrade, "Legacy Upgrade ID '" + id + "' is reserved by ComputerCraft" ); } registerInternal( upgrade ); @@ -47,58 +68,63 @@ static void registerInternal( ITurtleUpgrade upgrade ) { Objects.requireNonNull( upgrade, "upgrade cannot be null" ); + Wrapper wrapper = new Wrapper( upgrade ); + // Check conditions - int legacyId = upgrade.getLegacyUpgradeID(); + int legacyId = wrapper.legacyId; if( legacyId >= 0 ) { if( legacyId >= Short.MAX_VALUE ) { - String message = getMessage( upgrade, "UpgradeID '" + legacyId + "' is out of range" ); - ComputerCraft.log.error( message ); - throw new RuntimeException( message ); + throw registrationError( upgrade, "Upgrade ID '" + legacyId + "' is out of range" ); } ITurtleUpgrade existing = legacyUpgrades.get( legacyId ); if( existing != null ) { - String message = getMessage( upgrade, "UpgradeID '" + legacyId + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" ); - ComputerCraft.log.error( message ); - throw new RuntimeException( message ); + throw registrationError( upgrade, "Upgrade ID '" + legacyId + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" ); } } - String id = upgrade.getUpgradeID().toString(); + String id = wrapper.id; ITurtleUpgrade existing = upgrades.get( id ); if( existing != null ) { - String message = getMessage( upgrade, "UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" ); - ComputerCraft.log.error( message ); - throw new RuntimeException( message ); + throw registrationError( upgrade, "Upgrade '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" ); } // Register if( legacyId >= 0 ) legacyUpgrades.put( legacyId, upgrade ); upgrades.put( id, upgrade ); - - ModContainer mc = Loader.instance().activeModContainer(); - if( mc != null && mc.getModId() != null ) upgradeOwners.put( upgrade, mc.getModId() ); + wrappers.put( upgrade, wrapper ); } - private static String getMessage( ITurtleUpgrade upgrade, String rest ) + private static RuntimeException registrationError( ITurtleUpgrade upgrade, String rest ) { - return "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. " + rest; + String message = "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. " + rest; + ComputerCraft.log.error( message ); + throw new IllegalArgumentException( message ); } + @Nullable public static ITurtleUpgrade get( String id ) { return upgrades.get( id ); } + @Nullable public static ITurtleUpgrade get( int id ) { return legacyUpgrades.get( id ); } + @Nullable + public static String getOwner( @Nonnull ITurtleUpgrade upgrade ) + { + Wrapper wrapper = wrappers.get( upgrade ); + return wrapper != null ? wrapper.modId : null; + } + public static ITurtleUpgrade get( @Nonnull ItemStack stack ) { if( stack.isEmpty() ) return null; @@ -115,25 +141,24 @@ public static ITurtleUpgrade get( @Nonnull ItemStack stack ) return null; } - public static Iterable getVanillaUpgrades() + public static Stream getVanillaUpgrades() { - List vanilla = new ArrayList<>(); - vanilla.add( ComputerCraft.TurtleUpgrades.diamondPickaxe ); - vanilla.add( ComputerCraft.TurtleUpgrades.diamondAxe ); - vanilla.add( ComputerCraft.TurtleUpgrades.diamondSword ); - vanilla.add( ComputerCraft.TurtleUpgrades.diamondShovel ); - vanilla.add( ComputerCraft.TurtleUpgrades.diamondHoe ); - vanilla.add( ComputerCraft.TurtleUpgrades.craftingTable ); - vanilla.add( ComputerCraft.TurtleUpgrades.wirelessModem ); - vanilla.add( ComputerCraft.TurtleUpgrades.advancedModem ); - vanilla.add( ComputerCraft.TurtleUpgrades.speaker ); - return vanilla; - } + if( vanilla == null ) + { + vanilla = new ITurtleUpgrade[] { + ComputerCraft.TurtleUpgrades.diamondPickaxe, + ComputerCraft.TurtleUpgrades.diamondAxe, + ComputerCraft.TurtleUpgrades.diamondSword, + ComputerCraft.TurtleUpgrades.diamondShovel, + ComputerCraft.TurtleUpgrades.diamondHoe, + ComputerCraft.TurtleUpgrades.craftingTable, + ComputerCraft.TurtleUpgrades.wirelessModem, + ComputerCraft.TurtleUpgrades.advancedModem, + ComputerCraft.TurtleUpgrades.speaker, + }; + } - @Nullable - public static String getOwner( @Nonnull ITurtleUpgrade upgrade ) - { - return upgradeOwners.get( upgrade ); + return Arrays.stream( vanilla ).filter( x -> x != null && wrappers.get( x ).enabled ); } public static Iterable getUpgrades() @@ -145,4 +170,14 @@ public static boolean suitableForFamily( ComputerFamily family, ITurtleUpgrade u { return true; } + + public static void disable( ITurtleUpgrade upgrade ) + { + Wrapper wrapper = wrappers.get( upgrade ); + if( !wrapper.enabled ) return; + + wrapper.enabled = false; + upgrades.remove( wrapper.id ); + if( wrapper.legacyId >= 0 ) legacyUpgrades.remove( wrapper.legacyId ); + } } diff --git a/src/main/java/dan200/computercraft/shared/integration/crafttweaker/TurtleTweaker.java b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/TurtleTweaker.java new file mode 100644 index 000000000..8f1439233 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/TurtleTweaker.java @@ -0,0 +1,70 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.integration.crafttweaker; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenDoc; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.minecraft.CraftTweakerMC; +import dan200.computercraft.ComputerCraft; +import dan200.computercraft.shared.integration.crafttweaker.actions.AddTurtleTool; +import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByItem; +import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByName; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenRegister +@ZenClass( "dan200.computercraft.turtle" ) +@ModOnly( ComputerCraft.MOD_ID ) +public class TurtleTweaker +{ + @ZenMethod + @ZenDoc( "Remove a turtle upgrade with the given id" ) + public static void removeUpgrade( String upgrade ) + { + CraftTweakerAPI.apply( new RemoveTurtleUpgradeByName( upgrade ) ); + } + + @ZenMethod + @ZenDoc( "Remove a turtle upgrade crafted with the given item stack" ) + public static void removeUpgrade( IItemStack stack ) + { + CraftTweakerAPI.apply( new RemoveTurtleUpgradeByItem( CraftTweakerMC.getItemStack( stack ) ) ); + } + + @ZenMethod + @ZenDoc( "Add a new turtle tool with the given id, which crafts and acts using the given stack." ) + public static void addTool( String id, IItemStack stack ) + { + addTool( id, stack, stack, "tool" ); + } + + @ZenMethod + @ZenDoc( "Add a new turtle tool with the given id, which is crafted with one item, and uses another." ) + public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack ) + { + addTool( id, craftingStack, toolStack, "tool" ); + } + + @ZenMethod + @ZenDoc( "Add a new turtle tool with the given id, which crafts and acts using the given stack. You may also" + + "specify a 'kind' of tool, which limits what blocks the turtle can break (for instance, an 'axe' may only break wood)." ) + public static void addTool( String id, IItemStack stack, String kind ) + { + addTool( id, stack, stack, kind ); + } + + @ZenMethod + @ZenDoc( "Add a new turtle tool with the given id, which is crafted with one item, and uses another. You may also" + + "specify a 'kind' of tool, which limits what blocks the turtle can break (for instance, an 'axe' may only break wood)." ) + public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack, String kind ) + { + CraftTweakerAPI.apply( new AddTurtleTool( id, CraftTweakerMC.getItemStack( craftingStack ), CraftTweakerMC.getItemStack( toolStack ), kind ) ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/AddTurtleTool.java b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/AddTurtleTool.java new file mode 100644 index 000000000..3b34cf5d7 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/AddTurtleTool.java @@ -0,0 +1,96 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.integration.crafttweaker.actions; + +import dan200.computercraft.ComputerCraft; +import dan200.computercraft.shared.TurtleUpgrades; +import dan200.computercraft.shared.turtle.upgrades.*; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * Register a new turtle tool. + */ +public class AddTurtleTool implements IAction +{ + private interface Factory + { + TurtleTool create( ResourceLocation location, ItemStack craftItem, ItemStack toolItem ); + } + + private static final Map kinds = new HashMap<>(); + + static + { + kinds.put( "tool", TurtleTool::new ); + kinds.put( "axe", TurtleAxe::new ); + kinds.put( "hoe", TurtleHoe::new ); + kinds.put( "shovel", TurtleShovel::new ); + kinds.put( "sword", TurtleSword::new ); + } + + private final String id; + private final ItemStack craftItem; + private final ItemStack toolItem; + private final String kind; + + public AddTurtleTool( String id, ItemStack craftItem, ItemStack toolItem, String kind ) + { + this.id = id; + this.craftItem = craftItem; + this.toolItem = toolItem; + this.kind = kind; + } + + @Override + public void apply() + { + Factory factory = kinds.get( kind ); + if( factory == null ) + { + ComputerCraft.log.error( "Unknown turtle upgrade kind '{}' (this should have been rejected by verify!)", kind ); + return; + } + + try + { + TurtleUpgrades.register( factory.create( new ResourceLocation( id ), craftItem, toolItem ) ); + } + catch( RuntimeException e ) + { + ComputerCraft.log.error( "Registration of turtle tool failed", e ); + } + } + + @Override + public String describe() + { + return String.format( "Add new turtle %s '%s' (crafted with '%s', uses a '%s')", kind, id, craftItem, toolItem ); + } + + public Optional getValidationProblem() + { + if( craftItem.isEmpty() ) return Optional.of( "Crafting item stack is empty." ); + if( craftItem.hasTagCompound() && !craftItem.getTagCompound().isEmpty() ) + { + return Optional.of( "Crafting item has NBT." ); + } + if( toolItem.isEmpty() ) return Optional.of( "Tool item stack is empty." ); + if( !kinds.containsKey( kind ) ) return Optional.of( String.format( "Unknown kind '%s'.", kind ) ); + + if( TurtleUpgrades.get( id ) != null ) + { + return Optional.of( String.format( "An upgrade with the same name ('%s') has already been registered.", id ) ); + } + + return Optional.empty(); + } +} diff --git a/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/IAction.java b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/IAction.java new file mode 100644 index 000000000..d726c7090 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/IAction.java @@ -0,0 +1,32 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.integration.crafttweaker.actions; + +import java.util.Optional; + +/** + * An extension of {@link IAction} with a single validation function, rather than two. + */ +public interface IAction extends crafttweaker.IAction +{ + default Optional getValidationProblem() + { + return Optional.empty(); + } + + @Override + default boolean validate() + { + return !getValidationProblem().isPresent(); + } + + @Override + default String describeInvalid() + { + return getValidationProblem().orElse( "No problems found." ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByItem.java b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByItem.java new file mode 100644 index 000000000..939e72592 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByItem.java @@ -0,0 +1,50 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.integration.crafttweaker.actions; + +import dan200.computercraft.api.turtle.ITurtleUpgrade; +import dan200.computercraft.shared.TurtleUpgrades; +import net.minecraft.item.ItemStack; + +import java.util.Optional; + +/** + * Removes a turtle upgrade crafted with the given stack. + */ +public class RemoveTurtleUpgradeByItem implements IAction +{ + private final ItemStack stack; + + public RemoveTurtleUpgradeByItem( ItemStack stack ) + { + this.stack = stack; + } + + @Override + public void apply() + { + ITurtleUpgrade upgrade = TurtleUpgrades.get( stack ); + if( upgrade != null ) TurtleUpgrades.disable( upgrade ); + } + + @Override + public String describe() + { + return String.format( "Remove turtle upgrades crafted with '%s'", stack ); + } + + @Override + public Optional getValidationProblem() + { + if( TurtleUpgrades.get( stack ) == null ) + { + return Optional.of( String.format( "Unknown turtle upgrade crafted with '%s'.", stack ) ); + } + + return Optional.empty(); + } +} diff --git a/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByName.java b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByName.java new file mode 100644 index 000000000..ce41a17d9 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/integration/crafttweaker/actions/RemoveTurtleUpgradeByName.java @@ -0,0 +1,49 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.integration.crafttweaker.actions; + +import dan200.computercraft.api.turtle.ITurtleUpgrade; +import dan200.computercraft.shared.TurtleUpgrades; + +import java.util.Optional; + +/** + * Removes a turtle upgrade with the given id. + */ +public class RemoveTurtleUpgradeByName implements IAction +{ + private final String id; + + public RemoveTurtleUpgradeByName( String id ) + { + this.id = id; + } + + @Override + public void apply() + { + ITurtleUpgrade upgrade = TurtleUpgrades.get( id ); + if( upgrade != null ) TurtleUpgrades.disable( upgrade ); + } + + @Override + public String describe() + { + return String.format( "Remove turtle upgrade '%s'", id ); + } + + @Override + public Optional getValidationProblem() + { + if( TurtleUpgrades.get( id ) == null ) + { + return Optional.of( String.format( "Unknown turtle upgrade '%s'.", id ) ); + } + + return Optional.empty(); + } +} diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java index 6234d0b62..3fdf3a01a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java @@ -48,13 +48,11 @@ public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList TurtleUpgrades.suitableForFamily( family, x ) ) + .map( x -> TurtleItemFactory.create( -1, null, -1, family, null, x, 0, null ) ) + .filter( x -> !x.isEmpty() && x.getItem() == this ) + .forEach( list::add ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java index c623a2066..02342eb8a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java @@ -7,6 +7,7 @@ package dan200.computercraft.shared.turtle.upgrades; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; public class TurtleAxe extends TurtleTool @@ -21,6 +22,11 @@ public TurtleAxe( ResourceLocation id, int legacyId, Item item ) super( id, legacyId, item ); } + public TurtleAxe( ResourceLocation id, ItemStack craftItem, ItemStack toolItem ) + { + super( id, craftItem, toolItem ); + } + @Override protected float getDamageMultiplier() { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java index 4e6a2de00..e29a17d46 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java @@ -35,6 +35,11 @@ public TurtleHoe( ResourceLocation id, int legacyId, Item item ) super( id, legacyId, item ); } + public TurtleHoe( ResourceLocation id, ItemStack craftItem, ItemStack toolItem ) + { + super( id, craftItem, toolItem ); + } + @Override protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java index 4e1c44689..face19e6d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java @@ -35,6 +35,11 @@ public TurtleShovel( ResourceLocation id, int legacyId, Item item ) super( id, legacyId, item ); } + public TurtleShovel( ResourceLocation id, ItemStack craftItem, ItemStack toolItem ) + { + super( id, craftItem, toolItem ); + } + @Override protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java index 8f5f13619..853def832 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java @@ -10,6 +10,7 @@ import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -26,6 +27,11 @@ public TurtleSword( ResourceLocation id, int legacyId, Item item ) super( id, legacyId, item ); } + public TurtleSword( ResourceLocation id, ItemStack craftItem, ItemStack toolItem ) + { + super( id, craftItem, toolItem ); + } + @Override protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index d7c40e27a..cf6b09ac7 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -62,6 +62,12 @@ public TurtleTool( ResourceLocation id, int legacyID, Item item ) this.item = new ItemStack( item, 1, 0 ); } + public TurtleTool( ResourceLocation id, ItemStack craftItem, ItemStack toolItem ) + { + super( id, -1, TurtleUpgradeType.Tool, craftItem ); + this.item = toolItem; + } + @Nonnull @Override @SideOnly( Side.CLIENT ) @@ -76,7 +82,7 @@ public Pair getModel( ITurtleAccess turtle, @Nonnull Turt ); Minecraft mc = Minecraft.getMinecraft(); return Pair.of( - mc.getRenderItem().getItemModelMesher().getItemModel( item ), + mc.getRenderItem().getItemModelMesher().getItemModel( getCraftingItem() ), transform ); } From d254c6464bbc2cdf786cea2892ff17d24c86df6c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 23 Dec 2019 15:43:48 +0100 Subject: [PATCH 06/11] Add more MOTD messages again (#241) --- .../assets/computercraft/lua/rom/motd.txt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/computercraft/lua/rom/motd.txt b/src/main/resources/assets/computercraft/lua/rom/motd.txt index d81dc2fd0..d82c3a995 100644 --- a/src/main/resources/assets/computercraft/lua/rom/motd.txt +++ b/src/main/resources/assets/computercraft/lua/rom/motd.txt @@ -1,7 +1,7 @@ View the source code at https://github.com/SquidDev-CC/CC-Tweaked View the documentation at https://wiki.computercraft.cc Visit the forum at https://forums.computercraft.cc -You can disable these messages by running "set motd.enable false" +You can disable these messages by running "set motd.enable false". You can create directories with "mkdir". Want to see hidden files? Run "set list.show_hidden true". Run "list" or "ls" to see all files in a directory. @@ -13,3 +13,22 @@ Use the "edit" program to create and edit your programs. You can copy files with "copy" or "cp". You can use "wget run " to run a program from the internet. You can use "wget" to download a file from the internet. +On an advanced computer you can use "fg" or "bg" to run multiple programs at the same time. +Use "type" to see if a path is a file or a directory. +Get a list of all programs with "programs". +Use an advanced computer to use colours and the mouse. +With a speaker you can play sounds. +Use "motd" to print the Message of the Day. +You can disable the startup from a computer with "set shell.allow_startup false". +You can disable the startup from a disk with "set shell.allow_disk_startup false". +Programs that are placed in the "startup" folder in the root of a computer are started on boot. +Use a modem to connect with other computers. +With the "gps" program you can get the position of a computer. +Use "monitor" to run a program on a attached monitor. +View all attached peripherals with "peripherals". +Use "time" to see the in-game time. +You can set the label of a computer with "label set". +A computer needs a label to keep its files if it got destroyed. +You can disable auto completion in the shell with "set shell.autocomplete false". +You can disable auto completion in edit with "set edit.autocomplete false". +Feeling creative? Use a printer to print a book! From 4d18234714b7bb61e20aef48c37f2ee2351b7b23 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 23 Dec 2019 17:17:32 +0000 Subject: [PATCH 07/11] Use a fake network handler too It appears that WB opens containers manually, and thus all of our stubs network stubs are entirely ignored. Thus the only solution here is to stub out the whole network handler code. Thankfully this is simple enough - we do the same for Plethora and 1.14. Fixes #328 --- .../shared/turtle/core/TurtlePlayer.java | 3 + .../shared/util/FakeNetHandler.java | 234 ++++++++++++++++++ 2 files changed, 237 insertions(+) create mode 100644 src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java index 6bd90717e..50284741e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java @@ -8,6 +8,7 @@ import com.mojang.authlib.GameProfile; import dan200.computercraft.api.turtle.ITurtleAccess; +import dan200.computercraft.shared.util.FakeNetHandler; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.entity.Entity; @@ -46,11 +47,13 @@ public class TurtlePlayer extends FakePlayer public TurtlePlayer( World world ) { super( (WorldServer) world, DEFAULT_PROFILE ); + connection = new FakeNetHandler( this ); } private TurtlePlayer( ITurtleAccess turtle ) { super( (WorldServer) turtle.getWorld(), getProfile( turtle.getOwningPlayer() ) ); + connection = new FakeNetHandler( this ); setState( turtle ); } diff --git a/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java b/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java new file mode 100644 index 000000000..a99e53e09 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java @@ -0,0 +1,234 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.util; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.network.*; +import net.minecraft.network.play.client.*; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.common.util.FakePlayer; + +import javax.annotation.Nonnull; +import javax.crypto.SecretKey; + +public class FakeNetHandler extends NetHandlerPlayServer +{ + public static class FakeNetworkManager extends NetworkManager + { + private INetHandler handler; + + public FakeNetworkManager() + { + super( EnumPacketDirection.CLIENTBOUND ); + } + + @Override + public void channelActive( ChannelHandlerContext context ) + { + } + + @Override + public void setConnectionState( @Nonnull EnumConnectionState state ) + { + } + + @Override + public void channelInactive( ChannelHandlerContext context ) + { + } + + @Override + public void exceptionCaught( ChannelHandlerContext context, @Nonnull Throwable e ) + { + } + + @Override + public void setNetHandler( INetHandler handler ) + { + this.handler = handler; + } + + @Override + public void processReceivedPackets() + { + } + + @Override + public void closeChannel( @Nonnull ITextComponent channel ) + { + } + + @Override + public boolean isLocalChannel() + { + return false; + } + + + @Override + public void enableEncryption( SecretKey key ) + { + } + + @Override + public boolean isChannelOpen() + { + return false; + } + + @Nonnull + @Override + public INetHandler getNetHandler() + { + return handler; + } + + @Nonnull + @Override + public ITextComponent getExitMessage() + { + return null; + } + + @Override + public void disableAutoRead() + { + } + + @Nonnull + @Override + public Channel channel() + { + return null; + } + } + + + public FakeNetHandler( FakePlayer player ) + { + this( player.server, player ); + } + + public FakeNetHandler( MinecraftServer server, FakePlayer player ) + { + super( server, new FakeNetworkManager(), player ); + } + + @Override + public void processInput( CPacketInput packet ) + { + } + + @Override + public void processPlayer( CPacketPlayer packet ) + { + } + + @Override + public void setPlayerLocation( double x, double y, double z, float yaw, float pitch ) + { + } + + @Override + public void processPlayerDigging( CPacketPlayerDigging packet ) + { + } + + @Override + public void onDisconnect( @Nonnull ITextComponent chat ) + { + } + + @Override + @SuppressWarnings( "rawtypes" ) + public void sendPacket( @Nonnull final Packet packet ) + { + + } + + @Override + public void processHeldItemChange( CPacketHeldItemChange packet ) + { + } + + @Override + public void processChatMessage( @Nonnull CPacketChatMessage packet ) + { + } + + @Override + public void processEntityAction( CPacketEntityAction packet ) + { + } + + @Override + public void processUseEntity( CPacketUseEntity packet ) + { + } + + @Override + public void processClientStatus( CPacketClientStatus packet ) + { + } + + @Override + public void processCloseWindow( @Nonnull CPacketCloseWindow packet ) + { + } + + @Override + public void processClickWindow( CPacketClickWindow packet ) + { + } + + @Override + public void processEnchantItem( CPacketEnchantItem packet ) + { + } + + @Override + public void processCreativeInventoryAction( @Nonnull CPacketCreativeInventoryAction packet ) + { + } + + @Override + public void processConfirmTransaction( @Nonnull CPacketConfirmTransaction packet ) + { + } + + @Override + public void processUpdateSign( CPacketUpdateSign packet ) + { + } + + @Override + public void processKeepAlive( @Nonnull CPacketKeepAlive packet ) + { + } + + @Override + public void processPlayerAbilities( CPacketPlayerAbilities packet ) + { + } + + @Override + public void processTabComplete( CPacketTabComplete packet ) + { + } + + @Override + public void processClientSettings( @Nonnull CPacketClientSettings packet ) + { + } + + @Override + public void processCustomPayload( CPacketCustomPayload packetIn ) + { + } +} From da41c651281da30ede3a4efa76ad41fd74eb4c23 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 23 Dec 2019 18:54:19 +0000 Subject: [PATCH 08/11] Update proguard configuration - Remove redundant preservation of cobalt lib constructors. We use lambdas now, so this is no longer needed. - Fix Java crypto lib not being included. --- build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a10121df1..3ada5933e 100644 --- a/build.gradle +++ b/build.gradle @@ -137,6 +137,7 @@ task proguard(type: ProGuardTask, dependsOn: jar) { // Add the main runtime jar and all non-shadowed dependencies libraryjars "${System.getProperty('java.home')}/lib/rt.jar" + libraryjars "${System.getProperty('java.home')}/lib/jce.jar" doFirst { sourceSets.main.compileClasspath .filter { !it.name.contains("Cobalt") } @@ -151,9 +152,6 @@ task proguard(type: ProGuardTask, dependsOn: jar) { // Preserve ComputerCraft classes - we only want to strip shadowed files. keep 'class dan200.computercraft.** { *; }' - - // Preserve the constructors in Cobalt library class, as we init them via reflection - keepclassmembers 'class org.squiddev.cobalt.lib.** { (...); }' } task proguardMove(dependsOn: proguard) { From ae928c4397b055cbdb0dc78a0877b01336b3b9a2 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 23 Dec 2019 18:59:36 +0000 Subject: [PATCH 09/11] Make http domain configuration a little clearer --- .../dan200/computercraft/shared/Config.java | 24 ++++++++++--------- .../assets/computercraft/lang/de_de.lang | 4 ++-- .../assets/computercraft/lang/en_us.lang | 4 ++-- .../assets/computercraft/lang/es_es.lang | 4 ++-- .../assets/computercraft/lang/fr_fr.lang | 4 ++-- .../assets/computercraft/lang/it_it.lang | 4 ++-- .../assets/computercraft/lang/pt_br.lang | 4 ++-- .../assets/computercraft/lang/sv_se.lang | 4 ++-- .../assets/computercraft/lang/zh_cn.lang | 4 ++-- 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index ffb176c72..cd5840100 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -54,8 +54,8 @@ public final class Config private static Property httpEnable; private static Property httpWebsocketEnable; - private static Property httpWhitelist; - private static Property httpBlacklist; + private static Property httpAllowedDomains; + private static Property httpBlockedDomains; private static Property httpTimeout; private static Property httpMaxRequests; @@ -163,8 +163,10 @@ public static void load( File configFile ) { // HTTP renameProperty( CATEGORY_GENERAL, "http_enable", CATEGORY_HTTP, "enabled" ); renameProperty( CATEGORY_GENERAL, "http_websocket_enable", CATEGORY_HTTP, "websocket_enabled" ); - renameProperty( CATEGORY_GENERAL, "http_whitelist", CATEGORY_HTTP, "whitelist" ); - renameProperty( CATEGORY_GENERAL, "http_blacklist", CATEGORY_HTTP, "blacklist" ); + renameProperty( CATEGORY_GENERAL, "http_whitelist", CATEGORY_HTTP, "allowed_domains" ); + renameProperty( CATEGORY_GENERAL, "http_blacklist", CATEGORY_HTTP, "blocked_domains" ); + renameProperty( CATEGORY_HTTP, "whitelist", CATEGORY_HTTP, "allowed_domains" ); + renameProperty( CATEGORY_HTTP, "blacklist", CATEGORY_HTTP, "blocked_domains" ); config.getCategory( CATEGORY_HTTP ) .setComment( "Controls the HTTP API" ); @@ -176,15 +178,15 @@ public static void load( File configFile ) httpWebsocketEnable = config.get( CATEGORY_HTTP, "websocket_enabled", ComputerCraft.http_websocket_enable ); httpWebsocketEnable.setComment( "Enable use of http websockets. This requires the \"http_enable\" option to also be true." ); - httpWhitelist = config.get( CATEGORY_HTTP, "whitelist", DEFAULT_HTTP_WHITELIST ); - httpWhitelist.setComment( "A list of wildcards for domains or IP ranges that can be accessed through the " + + httpAllowedDomains = config.get( CATEGORY_HTTP, "allowed_domains", DEFAULT_HTTP_WHITELIST ); + httpAllowedDomains.setComment( "A list of wildcards for domains or IP ranges that can be accessed through the " + "\"http\" API on Computers.\n" + "Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com\" will restrict access to " + "just subdomains of pastebin.com.\n" + "You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." ); - httpBlacklist = config.get( CATEGORY_HTTP, "blacklist", DEFAULT_HTTP_BLACKLIST ); - httpBlacklist.setComment( "A list of wildcards for domains or IP ranges that cannot be accessed through the " + + httpBlockedDomains = config.get( CATEGORY_HTTP, "blocked_domains", DEFAULT_HTTP_BLACKLIST ); + httpBlockedDomains.setComment( "A list of wildcards for domains or IP ranges that cannot be accessed through the " + "\"http\" API on Computers.\n" + "If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block " + "access to all subdomains of github.com.\n" + @@ -220,7 +222,7 @@ public static void load( File configFile ) setOrder( CATEGORY_HTTP, - httpEnable, httpWebsocketEnable, httpWhitelist, httpBlacklist, + httpEnable, httpWebsocketEnable, httpAllowedDomains, httpBlockedDomains, httpTimeout, httpMaxRequests, httpMaxDownload, httpMaxUpload, httpMaxWebsockets, httpMaxWebsocketMessage ); } @@ -441,8 +443,8 @@ public static void sync() // HTTP ComputerCraft.http_enable = httpEnable.getBoolean(); ComputerCraft.http_websocket_enable = httpWebsocketEnable.getBoolean(); - ComputerCraft.http_whitelist = new AddressPredicate( httpWhitelist.getStringList() ); - ComputerCraft.http_blacklist = new AddressPredicate( httpBlacklist.getStringList() ); + ComputerCraft.http_whitelist = new AddressPredicate( httpAllowedDomains.getStringList() ); + ComputerCraft.http_blacklist = new AddressPredicate( httpBlockedDomains.getStringList() ); ComputerCraft.httpTimeout = Math.max( 0, httpTimeout.getInt() ); ComputerCraft.httpMaxRequests = Math.max( 1, httpMaxRequests.getInt() ); diff --git a/src/main/resources/assets/computercraft/lang/de_de.lang b/src/main/resources/assets/computercraft/lang/de_de.lang index 7460a071c..6fabe4002 100644 --- a/src/main/resources/assets/computercraft/lang/de_de.lang +++ b/src/main/resources/assets/computercraft/lang/de_de.lang @@ -168,8 +168,8 @@ gui.computercraft:config.execution.max_main_computer_time=Computer Servertick Ze gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=HTTP-API aktivieren gui.computercraft:config.http.websocket_enabled=Websockets aktivieren -gui.computercraft:config.http.whitelist=HTTP-Whitelist -gui.computercraft:config.http.blacklist=HTTP-Blacklist +gui.computercraft:config.http.allowed_domains=HTTP-Whitelist +gui.computercraft:config.http.blocked_domains=HTTP-Blacklist gui.computercraft:config.http.timeout=Zeitüberschreitung gui.computercraft:config.http.max_requests=Maximale Anzahl gleichzeitiger Anfragen diff --git a/src/main/resources/assets/computercraft/lang/en_us.lang b/src/main/resources/assets/computercraft/lang/en_us.lang index d00875c37..99cadd868 100644 --- a/src/main/resources/assets/computercraft/lang/en_us.lang +++ b/src/main/resources/assets/computercraft/lang/en_us.lang @@ -168,8 +168,8 @@ gui.computercraft:config.execution.max_main_computer_time=Server tick computer t gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=Enable the HTTP API gui.computercraft:config.http.websocket_enabled=Enable websockets -gui.computercraft:config.http.whitelist=HTTP whitelist -gui.computercraft:config.http.blacklist=HTTP blacklist +gui.computercraft:config.http.allowed_domains=Allowed domains +gui.computercraft:config.http.blocked_domains=Blocked domains gui.computercraft:config.http.timeout=Timeout gui.computercraft:config.http.max_requests=Maximum concurrent requests diff --git a/src/main/resources/assets/computercraft/lang/es_es.lang b/src/main/resources/assets/computercraft/lang/es_es.lang index fa2129634..b8c352bb1 100644 --- a/src/main/resources/assets/computercraft/lang/es_es.lang +++ b/src/main/resources/assets/computercraft/lang/es_es.lang @@ -57,8 +57,8 @@ gui.computercraft:config.default_computer_settings=Configuración de Ordenador p gui.computercraft:config.log_computer_errors=Grabar errores periféricos gui.computercraft:config.http.enabled=Habilitar API de HTTP -gui.computercraft:config.http.whitelist=Lista blanca de HTTP -gui.computercraft:config.http.blacklist=Lista negra de HTTP +gui.computercraft:config.http.allowed_domains=Lista blanca de HTTP +gui.computercraft:config.http.blocked_domains=Lista negra de HTTP gui.computercraft:config.peripheral.command_block_enabled=Habilitar bloque de comandos periférico gui.computercraft:config.peripheral.modem_range=Rango del módem (Por defecto) diff --git a/src/main/resources/assets/computercraft/lang/fr_fr.lang b/src/main/resources/assets/computercraft/lang/fr_fr.lang index e1f151235..b21567e47 100644 --- a/src/main/resources/assets/computercraft/lang/fr_fr.lang +++ b/src/main/resources/assets/computercraft/lang/fr_fr.lang @@ -57,8 +57,8 @@ gui.computercraft:config.default_computer_settings=Configuration d'Ordinateur pa gui.computercraft:config.log_computer_errors=Journal d'erreur périphériques gui.computercraft:config.http.enabled=Permettre l'API HTTP -gui.computercraft:config.http.whitelist=HTTP liste blanche -gui.computercraft:config.http.blacklist=HTTP liste noire +gui.computercraft:config.http.allowed_domains=HTTP liste blanche +gui.computercraft:config.http.blocked_domains=HTTP liste noire gui.computercraft:config.peripheral.command_block_enabled=Permettre l'accès d'un Bloc de Commande par périphérique gui.computercraft:config.peripheral.modem_range=Portée d'un Modem (par défaut) diff --git a/src/main/resources/assets/computercraft/lang/it_it.lang b/src/main/resources/assets/computercraft/lang/it_it.lang index 6be7df879..931118f9c 100644 --- a/src/main/resources/assets/computercraft/lang/it_it.lang +++ b/src/main/resources/assets/computercraft/lang/it_it.lang @@ -63,8 +63,8 @@ gui.computercraft:config.execution.computer_threads=Threads computer gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=Attiva l'API HTTP gui.computercraft:config.http.websocket_enabled=Attiva websocket -gui.computercraft:config.http.whitelist=Lista bianca HTTP -gui.computercraft:config.http.blacklist=Lista nera HTTP +gui.computercraft:config.http.allowed_domains=Lista bianca HTTP +gui.computercraft:config.http.blocked_domains=Lista nera HTTP gui.computercraft:config.http.timeout=Tempo di scadenza gui.computercraft:config.http.max_requests=Richieste correnti massime diff --git a/src/main/resources/assets/computercraft/lang/pt_br.lang b/src/main/resources/assets/computercraft/lang/pt_br.lang index d9706ffa5..2cf77ebf5 100644 --- a/src/main/resources/assets/computercraft/lang/pt_br.lang +++ b/src/main/resources/assets/computercraft/lang/pt_br.lang @@ -63,8 +63,8 @@ gui.computercraft:config.execution.computer_threads=Threads por computador gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=Habilitar a biblioteca de HTTP gui.computercraft:config.http.websocket_enabled=Habilitar websockets -gui.computercraft:config.http.whitelist=Lista de endereços autorizados -gui.computercraft:config.http.blacklist=Lista de endereços proíbidos +gui.computercraft:config.http.allowed_domains=Lista de endereços autorizados +gui.computercraft:config.http.blocked_domains=Lista de endereços proíbidos gui.computercraft:config.http.timeout=Tempo limite para conexões gui.computercraft:config.http.max_requests=Limite de conexões paralelas diff --git a/src/main/resources/assets/computercraft/lang/sv_se.lang b/src/main/resources/assets/computercraft/lang/sv_se.lang index ad4dc0ceb..b90379225 100644 --- a/src/main/resources/assets/computercraft/lang/sv_se.lang +++ b/src/main/resources/assets/computercraft/lang/sv_se.lang @@ -63,8 +63,8 @@ gui.computercraft:config.execution.computer_threads=Dator trådar gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=Aktivera HTTP API gui.computercraft:config.http.websocket_enabled=Aktivera websockets -gui.computercraft:config.http.whitelist=HTTP vitlista -gui.computercraft:config.http.blacklist=HTTP svartlista +gui.computercraft:config.http.allowed_domains=HTTP vitlista +gui.computercraft:config.http.blocked_domains=HTTP svartlista gui.computercraft:config.http.timeout=Timeout gui.computercraft:config.http.max_requests=Maximalt antal samgående förfrågningar diff --git a/src/main/resources/assets/computercraft/lang/zh_cn.lang b/src/main/resources/assets/computercraft/lang/zh_cn.lang index 56b9aa106..86c43c33f 100644 --- a/src/main/resources/assets/computercraft/lang/zh_cn.lang +++ b/src/main/resources/assets/computercraft/lang/zh_cn.lang @@ -168,8 +168,8 @@ gui.computercraft:config.execution.max_main_computer_time=服务器计算机tick gui.computercraft:config.http=HTTP gui.computercraft:config.http.enabled=启用HTTP API gui.computercraft:config.http.websocket_enabled=启用websockets -gui.computercraft:config.http.whitelist=HTTP白名单 -gui.computercraft:config.http.blacklist=HTTP黑名单 +gui.computercraft:config.http.allowed_domains=HTTP白名单 +gui.computercraft:config.http.blocked_domains=HTTP黑名单 gui.computercraft:config.http.timeout=Timeout gui.computercraft:config.http.max_requests=最大并发请求数 From e59c043fb68da1c0e993f55b5e57901a5be3b4ce Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 23 Dec 2019 21:34:03 +0000 Subject: [PATCH 10/11] Fix a couple of comments to use the new config names --- src/main/java/dan200/computercraft/shared/Config.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index cd5840100..8c80af4ba 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -172,8 +172,8 @@ public static void load( File configFile ) .setComment( "Controls the HTTP API" ); httpEnable = config.get( CATEGORY_HTTP, "enabled", ComputerCraft.http_enable ); - httpEnable.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" and \"http_blacklist\" for " + - "more fine grained control than this)" ); + httpEnable.setComment( "Enable the \"http\" API on Computers (see \"allowed_domains\" and \"blocked_domains\" " + + "for more fine grained control than this)" ); httpWebsocketEnable = config.get( CATEGORY_HTTP, "websocket_enabled", ComputerCraft.http_websocket_enable ); httpWebsocketEnable.setComment( "Enable use of http websockets. This requires the \"http_enable\" option to also be true." ); @@ -188,7 +188,7 @@ public static void load( File configFile ) httpBlockedDomains = config.get( CATEGORY_HTTP, "blocked_domains", DEFAULT_HTTP_BLACKLIST ); httpBlockedDomains.setComment( "A list of wildcards for domains or IP ranges that cannot be accessed through the " + "\"http\" API on Computers.\n" + - "If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block " + + "If this is empty then all explicitly allowed domains will be accessible. Example: \"*.github.com\" will block " + "access to all subdomains of github.com.\n" + "You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." ); From 0dde859582ede3ac4a77148f4604709fb2ded1c6 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 23 Dec 2019 22:10:32 +0000 Subject: [PATCH 11/11] Bump version --- gradle.properties | 2 +- .../assets/computercraft/lua/rom/help/changelog.txt | 9 +++++++++ .../assets/computercraft/lua/rom/help/whatsnew.txt | 9 +++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index d3002e82e..c23effa6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Mod properties -mod_version=1.85.2 +mod_version=1.86.0 # Minecraft properties mc_version=1.12.2 diff --git a/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt b/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt index 99140820e..dec1fec52 100644 --- a/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt +++ b/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt @@ -1,3 +1,12 @@ +# New features in CC: Tweaked 1.86.0 + +* Add PATCH and TRACE HTTP methods. (jaredallard) +* Add more MOTD messages. (JakobDev) +* Allow removing and adding turtle upgrades via CraftTweaker. + +And several bug fixes: +* Fix crash when interacting with Wearable Backpacks. + # New features in CC: Tweaked 1.85.2 * Fix crashes when using the mouse with advanced computers. diff --git a/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt b/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt index b1a6d0cff..3d8051511 100644 --- a/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt +++ b/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt @@ -1,5 +1,10 @@ -New features in CC: Tweaked 1.85.2 +New features in CC: Tweaked 1.86.0 -* Fix crashes when using the mouse with advanced computers. +* Add PATCH and TRACE HTTP methods. (jaredallard) +* Add more MOTD messages. (JakobDev) +* Allow removing and adding turtle upgrades via CraftTweaker. + +And several bug fixes: +* Fix crash when interacting with Wearable Backpacks. Type "help changelog" to see the full version history.