mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-25 14:43:02 +00:00
Replaced tabs with spaces in all lua files
This commit is contained in:
parent
b86708aaf8
commit
f5edb32be9
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
if not shell.openTab then
|
if not shell.openTab then
|
||||||
printError( "Requires multishell" )
|
printError( "Requires multishell" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
if not shell.openTab then
|
if not shell.openTab then
|
||||||
printError( "Requires multishell" )
|
printError( "Requires multishell" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 2 then
|
if #tArgs > 2 then
|
||||||
print( "Usage: alias <alias> <program>" )
|
print( "Usage: alias <alias> <program>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sAlias = tArgs[1]
|
local sAlias = tArgs[1]
|
||||||
local sProgram = tArgs[2]
|
local sProgram = tArgs[2]
|
||||||
|
|
||||||
if sAlias and sProgram then
|
if sAlias and sProgram then
|
||||||
-- Set alias
|
-- Set alias
|
||||||
shell.setAlias( sAlias, sProgram )
|
shell.setAlias( sAlias, sProgram )
|
||||||
elseif sAlias then
|
elseif sAlias then
|
||||||
-- Clear alias
|
-- Clear alias
|
||||||
shell.clearAlias( sAlias )
|
shell.clearAlias( sAlias )
|
||||||
else
|
else
|
||||||
-- List aliases
|
-- List aliases
|
||||||
local tAliases = shell.aliases()
|
local tAliases = shell.aliases()
|
||||||
local tList = {}
|
local tList = {}
|
||||||
for sAlias, sCommand in pairs( tAliases ) do
|
for sAlias, sCommand in pairs( tAliases ) do
|
||||||
table.insert( tList, sAlias )
|
table.insert( tList, sAlias )
|
||||||
end
|
end
|
||||||
table.sort( tList )
|
table.sort( tList )
|
||||||
textutils.pagedTabulate( tList )
|
textutils.pagedTabulate( tList )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
local tApis = {}
|
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
|
if type(k) == "string" and type(v) == "table" and k ~= "_G" then
|
||||||
table.insert( tApis, k )
|
table.insert( tApis, k )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert( tApis, "shell" )
|
table.insert( tApis, "shell" )
|
||||||
table.sort( tApis )
|
table.sort( tApis )
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: cd <path>" )
|
print( "Usage: cd <path>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sNewDir = shell.resolve( tArgs[1] )
|
local sNewDir = shell.resolve( tArgs[1] )
|
||||||
if fs.isDir( sNewDir ) then
|
if fs.isDir( sNewDir ) then
|
||||||
shell.setDir( sNewDir )
|
shell.setDir( sNewDir )
|
||||||
else
|
else
|
||||||
print( "Not a directory" )
|
print( "Not a directory" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 2 then
|
if #tArgs < 2 then
|
||||||
print( "Usage: cp <source> <destination>" )
|
print( "Usage: cp <source> <destination>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sSource = shell.resolve( tArgs[1] )
|
local sSource = shell.resolve( tArgs[1] )
|
||||||
@ -21,4 +21,4 @@ if #tFiles > 0 then
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
printError( "No matching files" )
|
printError( "No matching files" )
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: rm <path>" )
|
print( "Usage: rm <path>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sPath = shell.resolve( tArgs[1] )
|
local sPath = shell.resolve( tArgs[1] )
|
||||||
@ -13,4 +13,4 @@ if #tFiles > 0 then
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
printError( "No matching files" )
|
printError( "No matching files" )
|
||||||
end
|
end
|
||||||
|
@ -3,19 +3,19 @@ local tArgs = { ... }
|
|||||||
-- Get where a directory is mounted
|
-- Get where a directory is mounted
|
||||||
local sPath = shell.dir()
|
local sPath = shell.dir()
|
||||||
if tArgs[1] ~= nil then
|
if tArgs[1] ~= nil then
|
||||||
sPath = shell.resolve( tArgs[1] )
|
sPath = shell.resolve( tArgs[1] )
|
||||||
end
|
end
|
||||||
|
|
||||||
if fs.exists( sPath ) then
|
if fs.exists( sPath ) then
|
||||||
write( fs.getDrive( sPath ) .. " (" )
|
write( fs.getDrive( sPath ) .. " (" )
|
||||||
local nSpace = fs.getFreeSpace( sPath )
|
local nSpace = fs.getFreeSpace( sPath )
|
||||||
if nSpace >= 1000 * 1000 then
|
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
|
elseif nSpace >= 1000 then
|
||||||
print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" )
|
print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" )
|
||||||
else
|
else
|
||||||
print( nSpace .. "B remaining)" )
|
print( nSpace .. "B remaining)" )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "No such path" )
|
print( "No such path" )
|
||||||
end
|
end
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,8 @@
|
|||||||
-- Get arguments
|
-- Get arguments
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs == 0 then
|
if #tArgs == 0 then
|
||||||
print( "Usage: eject <drive>" )
|
print( "Usage: eject <drive>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sDrive = tArgs[1]
|
local sDrive = tArgs[1]
|
||||||
@ -11,8 +11,8 @@ local sDrive = tArgs[1]
|
|||||||
-- Check the disk exists
|
-- Check the disk exists
|
||||||
local bPresent = disk.isPresent( sDrive )
|
local bPresent = disk.isPresent( sDrive )
|
||||||
if not bPresent then
|
if not bPresent then
|
||||||
print( "Nothing in "..sDrive.." drive" )
|
print( "Nothing in "..sDrive.." drive" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
disk.eject( sDrive )
|
disk.eject( sDrive )
|
||||||
|
@ -27,21 +27,21 @@ local fMessage = "Press Ctrl to access menu"
|
|||||||
|
|
||||||
-- Determine if we can even run this
|
-- Determine if we can even run this
|
||||||
if not term.isColour() then
|
if not term.isColour() then
|
||||||
print("Requires an Advanced Computer")
|
print("Requires an Advanced Computer")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Determines if the file exists, and can be edited on this computer
|
-- Determines if the file exists, and can be edited on this computer
|
||||||
local tArgs = {...}
|
local tArgs = {...}
|
||||||
if #tArgs == 0 then
|
if #tArgs == 0 then
|
||||||
print("Usage: paint <path>")
|
print("Usage: paint <path>")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local sPath = shell.resolve(tArgs[1])
|
local sPath = shell.resolve(tArgs[1])
|
||||||
local bReadOnly = fs.isReadOnly(sPath)
|
local bReadOnly = fs.isReadOnly(sPath)
|
||||||
if fs.exists(sPath) and fs.isDir(sPath) then
|
if fs.exists(sPath) and fs.isDir(sPath) then
|
||||||
print("Cannot edit a directory.")
|
print("Cannot edit a directory.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------
|
---------------
|
||||||
@ -56,327 +56,327 @@ local function getCanvasPixel( x, y )
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Converts a colour value to a text character
|
Converts a colour value to a text character
|
||||||
params: colour = the number to convert to a hex value
|
params: colour = the number to convert to a hex value
|
||||||
returns: a string representing the chosen colour
|
returns: a string representing the chosen colour
|
||||||
]]
|
]]
|
||||||
local function getCharOf( colour )
|
local function getCharOf( colour )
|
||||||
-- Incorrect values always convert to nil
|
-- Incorrect values always convert to nil
|
||||||
if type(colour) == "number" then
|
if type(colour) == "number" then
|
||||||
local value = math.floor( math.log(colour) / math.log(2) ) + 1
|
local value = math.floor( math.log(colour) / math.log(2) ) + 1
|
||||||
if value >= 1 and value <= 16 then
|
if value >= 1 and value <= 16 then
|
||||||
return string.sub( "0123456789abcdef", value, value )
|
return string.sub( "0123456789abcdef", value, value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return " "
|
return " "
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Converts a text character to colour value
|
Converts a text character to colour value
|
||||||
params: char = the char (from string.byte) to convert to number
|
params: char = the char (from string.byte) to convert to number
|
||||||
returns: the colour number of the hex value
|
returns: the colour number of the hex value
|
||||||
]]
|
]]
|
||||||
local tColourLookup = {}
|
local tColourLookup = {}
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
|
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
|
||||||
end
|
end
|
||||||
local function getColourOf( char )
|
local function getColourOf( char )
|
||||||
-- Values not in the hex table are transparent (canvas coloured)
|
-- Values not in the hex table are transparent (canvas coloured)
|
||||||
return tColourLookup[char]
|
return tColourLookup[char]
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Loads the file into the canvas
|
Loads the file into the canvas
|
||||||
params: path = the path of the file to open
|
params: path = the path of the file to open
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function load(path)
|
local function load(path)
|
||||||
-- Load the file
|
-- Load the file
|
||||||
if fs.exists(path) then
|
if fs.exists(path) then
|
||||||
local file = fs.open(sPath, "r")
|
local file = fs.open(sPath, "r")
|
||||||
local sLine = file.readLine()
|
local sLine = file.readLine()
|
||||||
while sLine do
|
while sLine do
|
||||||
local line = {}
|
local line = {}
|
||||||
for x=1,w-2 do
|
for x=1,w-2 do
|
||||||
line[x] = getColourOf( string.byte(sLine,x,x) )
|
line[x] = getColourOf( string.byte(sLine,x,x) )
|
||||||
end
|
end
|
||||||
table.insert( canvas, line )
|
table.insert( canvas, line )
|
||||||
sLine = file.readLine()
|
sLine = file.readLine()
|
||||||
end
|
end
|
||||||
file.close()
|
file.close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Saves the current canvas to file
|
Saves the current canvas to file
|
||||||
params: path = the path of the file to save
|
params: path = the path of the file to save
|
||||||
returns: true if save was successful, false otherwise
|
returns: true if save was successful, false otherwise
|
||||||
]]
|
]]
|
||||||
local function save(path)
|
local function save(path)
|
||||||
-- Open file
|
-- Open file
|
||||||
local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))
|
local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))
|
||||||
if not fs.exists(sDir) then
|
if not fs.exists(sDir) then
|
||||||
fs.makeDir(sDir)
|
fs.makeDir(sDir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local file = fs.open( path, "w" )
|
local file = fs.open( path, "w" )
|
||||||
if not file then
|
if not file then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Encode (and trim)
|
-- Encode (and trim)
|
||||||
local tLines = {}
|
local tLines = {}
|
||||||
local nLastLine = 0
|
local nLastLine = 0
|
||||||
for y=1,h-1 do
|
for y=1,h-1 do
|
||||||
local sLine = ""
|
local sLine = ""
|
||||||
local nLastChar = 0
|
local nLastChar = 0
|
||||||
for x=1,w-2 do
|
for x=1,w-2 do
|
||||||
local c = getCharOf( getCanvasPixel( x, y ) )
|
local c = getCharOf( getCanvasPixel( x, y ) )
|
||||||
sLine = sLine .. c
|
sLine = sLine .. c
|
||||||
if c ~= " " then
|
if c ~= " " then
|
||||||
nLastChar = x
|
nLastChar = x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sLine = string.sub( sLine, 1, nLastChar )
|
sLine = string.sub( sLine, 1, nLastChar )
|
||||||
tLines[y] = sLine
|
tLines[y] = sLine
|
||||||
if string.len( sLine ) > 0 then
|
if string.len( sLine ) > 0 then
|
||||||
nLastLine = y
|
nLastLine = y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save out
|
-- Save out
|
||||||
for n=1,nLastLine do
|
for n=1,nLastLine do
|
||||||
file.writeLine( tLines[ n ] )
|
file.writeLine( tLines[ n ] )
|
||||||
end
|
end
|
||||||
file.close()
|
file.close()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Draws colour picker sidebar, the pallette and the footer
|
Draws colour picker sidebar, the pallette and the footer
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function drawInterface()
|
local function drawInterface()
|
||||||
-- Footer
|
-- Footer
|
||||||
term.setCursorPos(1, h)
|
term.setCursorPos(1, h)
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
term.write(fMessage)
|
term.write(fMessage)
|
||||||
|
|
||||||
-- Colour Picker
|
-- Colour Picker
|
||||||
for i=1,16 do
|
for i=1,16 do
|
||||||
term.setCursorPos(w-1, i)
|
term.setCursorPos(w-1, i)
|
||||||
term.setBackgroundColour( 2^(i-1) )
|
term.setBackgroundColour( 2^(i-1) )
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(w-1, 17)
|
term.setCursorPos(w-1, 17)
|
||||||
term.setBackgroundColour( canvasColour )
|
term.setBackgroundColour( canvasColour )
|
||||||
term.setTextColour( colours.grey )
|
term.setTextColour( colours.grey )
|
||||||
term.write("\127\127")
|
term.write("\127\127")
|
||||||
|
|
||||||
-- Left and Right Selected Colours
|
-- Left and Right Selected Colours
|
||||||
for i=18,18 do
|
for i=18,18 do
|
||||||
term.setCursorPos(w-1, i)
|
term.setCursorPos(w-1, i)
|
||||||
if leftColour ~= nil then
|
if leftColour ~= nil then
|
||||||
term.setBackgroundColour( leftColour )
|
term.setBackgroundColour( leftColour )
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
else
|
else
|
||||||
term.setBackgroundColour( canvasColour )
|
term.setBackgroundColour( canvasColour )
|
||||||
term.setTextColour( colours.grey )
|
term.setTextColour( colours.grey )
|
||||||
term.write("\127")
|
term.write("\127")
|
||||||
end
|
end
|
||||||
if rightColour ~= nil then
|
if rightColour ~= nil then
|
||||||
term.setBackgroundColour( rightColour )
|
term.setBackgroundColour( rightColour )
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
else
|
else
|
||||||
term.setBackgroundColour( canvasColour )
|
term.setBackgroundColour( canvasColour )
|
||||||
term.setTextColour( colours.grey )
|
term.setTextColour( colours.grey )
|
||||||
term.write("\127")
|
term.write("\127")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Padding
|
-- Padding
|
||||||
term.setBackgroundColour( canvasColour )
|
term.setBackgroundColour( canvasColour )
|
||||||
for i=20,h-1 do
|
for i=20,h-1 do
|
||||||
term.setCursorPos(w-1, i)
|
term.setCursorPos(w-1, i)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Converts a single pixel of a single line of the canvas and draws it
|
Converts a single pixel of a single line of the canvas and draws it
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function drawCanvasPixel( x, y )
|
local function drawCanvasPixel( x, y )
|
||||||
local pixel = getCanvasPixel( x, y )
|
local pixel = getCanvasPixel( x, y )
|
||||||
if pixel then
|
if pixel then
|
||||||
term.setBackgroundColour( pixel or canvasColour )
|
term.setBackgroundColour( pixel or canvasColour )
|
||||||
term.setCursorPos(x, y)
|
term.setCursorPos(x, y)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
else
|
else
|
||||||
term.setBackgroundColour( canvasColour )
|
term.setBackgroundColour( canvasColour )
|
||||||
term.setTextColour( colours.grey )
|
term.setTextColour( colours.grey )
|
||||||
term.setCursorPos(x, y)
|
term.setCursorPos(x, y)
|
||||||
term.write("\127")
|
term.write("\127")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Converts each colour in a single line of the canvas and draws it
|
Converts each colour in a single line of the canvas and draws it
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function drawCanvasLine( y )
|
local function drawCanvasLine( y )
|
||||||
for x = 1, w-2 do
|
for x = 1, w-2 do
|
||||||
drawCanvasPixel( x, y )
|
drawCanvasPixel( x, y )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Converts each colour in the canvas and draws it
|
Converts each colour in the canvas and draws it
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function drawCanvas()
|
local function drawCanvas()
|
||||||
for y = 1, h-1 do
|
for y = 1, h-1 do
|
||||||
drawCanvasLine( y )
|
drawCanvasLine( y )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Draws menu options and handles input from within the menu.
|
Draws menu options and handles input from within the menu.
|
||||||
returns: true if the program is to be exited; false otherwise
|
returns: true if the program is to be exited; false otherwise
|
||||||
]]
|
]]
|
||||||
local function accessMenu()
|
local function accessMenu()
|
||||||
-- Selected menu option
|
-- Selected menu option
|
||||||
local selection = 1
|
local selection = 1
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
while true do
|
while true do
|
||||||
-- Draw the menu
|
-- Draw the menu
|
||||||
term.setCursorPos(1,h)
|
term.setCursorPos(1,h)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
for k,v in pairs(mChoices) do
|
for k,v in pairs(mChoices) do
|
||||||
if selection==k then
|
if selection==k then
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
local ox,_ = term.getCursorPos()
|
local ox,_ = term.getCursorPos()
|
||||||
term.write("["..string.rep(" ",#v).."]")
|
term.write("["..string.rep(" ",#v).."]")
|
||||||
term.setCursorPos(ox+1,h)
|
term.setCursorPos(ox+1,h)
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
term.write(v)
|
term.write(v)
|
||||||
term.setCursorPos(term.getCursorPos()+1,h)
|
term.setCursorPos(term.getCursorPos()+1,h)
|
||||||
else
|
else
|
||||||
term.write(" "..v.." ")
|
term.write(" "..v.." ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle input in the menu
|
-- Handle input in the menu
|
||||||
local id,key = os.pullEvent("key")
|
local id,key = os.pullEvent("key")
|
||||||
if id == "key" then
|
if id == "key" then
|
||||||
-- S and E are shortcuts
|
-- S and E are shortcuts
|
||||||
if key == keys.s then
|
if key == keys.s then
|
||||||
selection = 1
|
selection = 1
|
||||||
key = keys.enter
|
key = keys.enter
|
||||||
elseif key == keys.e then
|
elseif key == keys.e then
|
||||||
selection = 2
|
selection = 2
|
||||||
key = keys.enter
|
key = keys.enter
|
||||||
end
|
end
|
||||||
|
|
||||||
if key == keys.right then
|
if key == keys.right then
|
||||||
-- Move right
|
-- Move right
|
||||||
selection = selection + 1
|
selection = selection + 1
|
||||||
if selection > #mChoices then
|
if selection > #mChoices then
|
||||||
selection = 1
|
selection = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif key == keys.left and selection > 1 then
|
elseif key == keys.left and selection > 1 then
|
||||||
-- Move left
|
-- Move left
|
||||||
selection = selection - 1
|
selection = selection - 1
|
||||||
if selection < 1 then
|
if selection < 1 then
|
||||||
selection = #mChoices
|
selection = #mChoices
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif key == keys.enter then
|
elseif key == keys.enter then
|
||||||
-- Select an option
|
-- Select an option
|
||||||
if mChoices[selection]=="Save" then
|
if mChoices[selection]=="Save" then
|
||||||
if bReadOnly then
|
if bReadOnly then
|
||||||
fMessage = "Access Denied"
|
fMessage = "Access Denied"
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local success = save(sPath)
|
local success = save(sPath)
|
||||||
if success then
|
if success then
|
||||||
fMessage = "Saved to "..sPath
|
fMessage = "Saved to "..sPath
|
||||||
else
|
else
|
||||||
fMessage = "Error saving to "..sPath
|
fMessage = "Error saving to "..sPath
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
elseif mChoices[selection]=="Exit" then
|
elseif mChoices[selection]=="Exit" then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif key == keys.leftCtrl or keys == keys.rightCtrl then
|
elseif key == keys.leftCtrl or keys == keys.rightCtrl then
|
||||||
-- Cancel the menu
|
-- Cancel the menu
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Runs the main thread of execution. Draws the canvas and interface, and handles
|
Runs the main thread of execution. Draws the canvas and interface, and handles
|
||||||
mouse and key events.
|
mouse and key events.
|
||||||
returns: nil
|
returns: nil
|
||||||
]]
|
]]
|
||||||
local function handleEvents()
|
local function handleEvents()
|
||||||
local programActive = true
|
local programActive = true
|
||||||
while programActive do
|
while programActive do
|
||||||
local id,p1,p2,p3 = os.pullEvent()
|
local id,p1,p2,p3 = os.pullEvent()
|
||||||
if id=="mouse_click" or id=="mouse_drag" then
|
if id=="mouse_click" or id=="mouse_drag" then
|
||||||
if p2 >= w-1 and p3 >= 1 and p3 <= 17 then
|
if p2 >= w-1 and p3 >= 1 and p3 <= 17 then
|
||||||
if id ~= "mouse_drag" then
|
if id ~= "mouse_drag" then
|
||||||
-- Selecting an items in the colour picker
|
-- Selecting an items in the colour picker
|
||||||
if p3 <= 16 then
|
if p3 <= 16 then
|
||||||
if p1==1 then
|
if p1==1 then
|
||||||
leftColour = 2^(p3-1)
|
leftColour = 2^(p3-1)
|
||||||
else
|
else
|
||||||
rightColour = 2^(p3-1)
|
rightColour = 2^(p3-1)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if p1==1 then
|
if p1==1 then
|
||||||
leftColour = nil
|
leftColour = nil
|
||||||
else
|
else
|
||||||
rightColour = nil
|
rightColour = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--drawCanvas()
|
--drawCanvas()
|
||||||
drawInterface()
|
drawInterface()
|
||||||
end
|
end
|
||||||
elseif p2 < w-1 and p3 <= h-1 then
|
elseif p2 < w-1 and p3 <= h-1 then
|
||||||
-- Clicking on the canvas
|
-- Clicking on the canvas
|
||||||
local paintColour = nil
|
local paintColour = nil
|
||||||
if p1==1 then
|
if p1==1 then
|
||||||
paintColour = leftColour
|
paintColour = leftColour
|
||||||
elseif p1==2 then
|
elseif p1==2 then
|
||||||
paintColour = rightColour
|
paintColour = rightColour
|
||||||
end
|
end
|
||||||
if not canvas[p3] then
|
if not canvas[p3] then
|
||||||
canvas[p3] = {}
|
canvas[p3] = {}
|
||||||
end
|
end
|
||||||
canvas[p3][p2] = paintColour
|
canvas[p3][p2] = paintColour
|
||||||
|
|
||||||
drawCanvasPixel( p2, p3 )
|
drawCanvasPixel( p2, p3 )
|
||||||
end
|
end
|
||||||
elseif id=="key" then
|
elseif id=="key" then
|
||||||
if p1==keys.leftCtrl or p1==keys.rightCtrl then
|
if p1==keys.leftCtrl or p1==keys.rightCtrl then
|
||||||
programActive = not accessMenu()
|
programActive = not accessMenu()
|
||||||
drawInterface()
|
drawInterface()
|
||||||
end
|
end
|
||||||
elseif id=="term_resize" then
|
elseif id=="term_resize" then
|
||||||
w,h = term.getSize()
|
w,h = term.getSize()
|
||||||
drawCanvas()
|
drawCanvas()
|
||||||
drawInterface()
|
drawInterface()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Init
|
-- Init
|
||||||
|
@ -60,25 +60,25 @@ local tArgs = { ... }
|
|||||||
|
|
||||||
--Functions--
|
--Functions--
|
||||||
local function printCentred( yc, stg )
|
local function printCentred( yc, stg )
|
||||||
local xc = math.floor((TermW - string.len(stg)) / 2) + 1
|
local xc = math.floor((TermW - string.len(stg)) / 2) + 1
|
||||||
term.setCursorPos(xc,yc)
|
term.setCursorPos(xc,yc)
|
||||||
term.write( stg )
|
term.write( stg )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function centerOrgin()
|
local function centerOrgin()
|
||||||
XOrgin = math.floor((TermW/2)-(SizeW/2))
|
XOrgin = math.floor((TermW/2)-(SizeW/2))
|
||||||
YOrgin = math.floor((TermH/2)-(SizeH/2))
|
YOrgin = math.floor((TermH/2)-(SizeH/2))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reMap()
|
local function reMap()
|
||||||
tScreen = nil
|
tScreen = nil
|
||||||
tScreen = {}
|
tScreen = {}
|
||||||
for x=1,SizeW do
|
for x=1,SizeW do
|
||||||
tScreen[x] = {}
|
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" }
|
tScreen[x][y] = { space = true, wall = false, ground = false, robot = "zz", start = "zz", exit = "zz" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tablecopy(t)
|
local function tablecopy(t)
|
||||||
@ -90,305 +90,305 @@ local function tablecopy(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function buMap()
|
local function buMap()
|
||||||
oScreen = nil
|
oScreen = nil
|
||||||
oScreen = {}
|
oScreen = {}
|
||||||
for x=1,SizeW do
|
for x=1,SizeW do
|
||||||
oScreen[x] = {}
|
oScreen[x] = {}
|
||||||
for y=1,SizeH do
|
for y=1,SizeH do
|
||||||
oScreen[x][y] = tablecopy(tScreen[x][y])
|
oScreen[x][y] = tablecopy(tScreen[x][y])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addRobot(x,y,side,color)
|
local function addRobot(x,y,side,color)
|
||||||
local obj = tScreen[x][y]
|
local obj = tScreen[x][y]
|
||||||
local data = side..color
|
local data = side..color
|
||||||
if obj.wall == nil and obj.robot == nil then
|
if obj.wall == nil and obj.robot == nil then
|
||||||
tScreen[x][y].robot = data
|
tScreen[x][y].robot = data
|
||||||
else
|
else
|
||||||
obj.wall = nil
|
obj.wall = nil
|
||||||
obj.robot = "zz"
|
obj.robot = "zz"
|
||||||
tScreen[x][y].robot = data
|
tScreen[x][y].robot = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addStart(x,y,side,color)
|
local function addStart(x,y,side,color)
|
||||||
local obj = tScreen[x][y]
|
local obj = tScreen[x][y]
|
||||||
local data = side..color
|
local data = side..color
|
||||||
if obj.wall == nil and obj.space == nil then
|
if obj.wall == nil and obj.space == nil then
|
||||||
tScreen[x][y].start = data
|
tScreen[x][y].start = data
|
||||||
else
|
else
|
||||||
obj.wall = nil
|
obj.wall = nil
|
||||||
obj.space = nil
|
obj.space = nil
|
||||||
tScreen[x][y].start = data
|
tScreen[x][y].start = data
|
||||||
end
|
end
|
||||||
aExits = aExits+1
|
aExits = aExits+1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addGround(x,y)
|
local function addGround(x,y)
|
||||||
local obj = tScreen[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
|
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
|
tScreen[x][y].ground = true
|
||||||
else
|
else
|
||||||
obj.space = nil
|
obj.space = nil
|
||||||
obj.exit = "zz"
|
obj.exit = "zz"
|
||||||
obj.wall = nil
|
obj.wall = nil
|
||||||
obj.robot = "zz"
|
obj.robot = "zz"
|
||||||
obj.start = "zz"
|
obj.start = "zz"
|
||||||
tScreen[x][y].ground = true
|
tScreen[x][y].ground = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addExit(x,y,cl)
|
local function addExit(x,y,cl)
|
||||||
local obj = tScreen[x][y]
|
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
|
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
|
tScreen[x][y].exit = cl
|
||||||
else
|
else
|
||||||
obj.space = nil
|
obj.space = nil
|
||||||
obj.ground = nil
|
obj.ground = nil
|
||||||
obj.wall = nil
|
obj.wall = nil
|
||||||
obj.robot = "zz"
|
obj.robot = "zz"
|
||||||
obj.start = "zz"
|
obj.start = "zz"
|
||||||
tScreen[x][y].exit = cl
|
tScreen[x][y].exit = cl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addWall(x,y)
|
local function addWall(x,y)
|
||||||
local obj = tScreen[x][y]
|
local obj = tScreen[x][y]
|
||||||
if obj == nil then
|
if obj == nil then
|
||||||
return error("Here X"..x.." Y"..y)
|
return error("Here X"..x.." Y"..y)
|
||||||
end
|
end
|
||||||
if obj.space == nil and obj.exit == nil and obj.ground == nil and obj.robot == nil and obj.start == nil then
|
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
|
tScreen[x][y].wall = true
|
||||||
else
|
else
|
||||||
obj.space = nil
|
obj.space = nil
|
||||||
obj.exit = nil
|
obj.exit = nil
|
||||||
obj.ground = nil
|
obj.ground = nil
|
||||||
obj.robot = nil
|
obj.robot = nil
|
||||||
obj.start = nil
|
obj.start = nil
|
||||||
tScreen[x][y].wall = true
|
tScreen[x][y].wall = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadLevel(nNum)
|
local function loadLevel(nNum)
|
||||||
sLevelTitle = "Level "..nNum
|
sLevelTitle = "Level "..nNum
|
||||||
if nNum == nil then return error("nNum == nil") end
|
if nNum == nil then return error("nNum == nil") end
|
||||||
local sDir = fs.getDir( shell.getRunningProgram() )
|
local sDir = fs.getDir( shell.getRunningProgram() )
|
||||||
local sLevelD = sDir .. "/levels/" .. tostring(nNum)
|
local sLevelD = sDir .. "/levels/" .. tostring(nNum)
|
||||||
if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end
|
if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end
|
||||||
fLevel = fs.open(sLevelD,"r")
|
fLevel = fs.open(sLevelD,"r")
|
||||||
local Line = 0
|
local Line = 0
|
||||||
local wl = true
|
local wl = true
|
||||||
Blocks = tonumber(string.sub(fLevel.readLine(),1,1))
|
Blocks = tonumber(string.sub(fLevel.readLine(),1,1))
|
||||||
local xSize = string.len(fLevel.readLine())+2
|
local xSize = string.len(fLevel.readLine())+2
|
||||||
local Lines = 3
|
local Lines = 3
|
||||||
while wl do
|
while wl do
|
||||||
local wLine = fLevel.readLine()
|
local wLine = fLevel.readLine()
|
||||||
if wLine == nil then
|
if wLine == nil then
|
||||||
fLevel.close()
|
fLevel.close()
|
||||||
wl = false
|
wl = false
|
||||||
else
|
else
|
||||||
xSize = math.max(string.len(wLine)+2,xSize)
|
xSize = math.max(string.len(wLine)+2,xSize)
|
||||||
Lines = Lines + 1
|
Lines = Lines + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
SizeW,SizeH = xSize,Lines
|
SizeW,SizeH = xSize,Lines
|
||||||
reMap()
|
reMap()
|
||||||
fLevel = fs.open(sLevelD,"r")
|
fLevel = fs.open(sLevelD,"r")
|
||||||
fLevel.readLine()
|
fLevel.readLine()
|
||||||
for Line=2,Lines-1 do
|
for Line=2,Lines-1 do
|
||||||
sLine = fLevel.readLine()
|
sLine = fLevel.readLine()
|
||||||
local chars = string.len(sLine)
|
local chars = string.len(sLine)
|
||||||
for char = 1, chars do
|
for char = 1, chars do
|
||||||
local el = string.sub(sLine,char,char)
|
local el = string.sub(sLine,char,char)
|
||||||
if el == "8" then
|
if el == "8" then
|
||||||
addGround(char+1,Line)
|
addGround(char+1,Line)
|
||||||
elseif el == "0" then
|
elseif el == "0" then
|
||||||
addStart(char+1,Line,"a","a")
|
addStart(char+1,Line,"a","a")
|
||||||
elseif el == "1" then
|
elseif el == "1" then
|
||||||
addStart(char+1,Line,"b","a")
|
addStart(char+1,Line,"b","a")
|
||||||
elseif el == "2" then
|
elseif el == "2" then
|
||||||
addStart(char+1,Line,"c","a")
|
addStart(char+1,Line,"c","a")
|
||||||
elseif el == "3" then
|
elseif el == "3" then
|
||||||
addStart(char+1,Line,"d","a")
|
addStart(char+1,Line,"d","a")
|
||||||
elseif el == "4" then
|
elseif el == "4" then
|
||||||
addStart(char+1,Line,"a","b")
|
addStart(char+1,Line,"a","b")
|
||||||
elseif el == "5" then
|
elseif el == "5" then
|
||||||
addStart(char+1,Line,"b","b")
|
addStart(char+1,Line,"b","b")
|
||||||
elseif el == "6" then
|
elseif el == "6" then
|
||||||
addStart(char+1,Line,"c","b")
|
addStart(char+1,Line,"c","b")
|
||||||
elseif el == "9" then
|
elseif el == "9" then
|
||||||
addStart(char+1,Line,"d","b")
|
addStart(char+1,Line,"d","b")
|
||||||
elseif el == "b" then
|
elseif el == "b" then
|
||||||
addExit(char+1,Line,"a")
|
addExit(char+1,Line,"a")
|
||||||
elseif el == "e" then
|
elseif el == "e" then
|
||||||
addExit(char+1,Line,"b")
|
addExit(char+1,Line,"b")
|
||||||
elseif el == "7" then
|
elseif el == "7" then
|
||||||
addWall(char+1,Line)
|
addWall(char+1,Line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fLevel.close()
|
fLevel.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawStars()
|
local function drawStars()
|
||||||
--CCR Background By : RamiLego--
|
--CCR Background By : RamiLego--
|
||||||
local cStar,cStarG,crStar,crStarB = colors.lightGray,colors.gray,".","*"
|
local cStar,cStarG,crStar,crStarB = colors.lightGray,colors.gray,".","*"
|
||||||
local DStar,BStar,nStar,gStar = 14,10,16,3
|
local DStar,BStar,nStar,gStar = 14,10,16,3
|
||||||
local TermW,TermH = term.getSize()
|
local TermW,TermH = term.getSize()
|
||||||
|
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
for x=1,TermW do
|
for x=1,TermW do
|
||||||
for y=1,TermH do
|
for y=1,TermH do
|
||||||
local StarT = math.random(1,30)
|
local StarT = math.random(1,30)
|
||||||
if StarT == DStar then
|
if StarT == DStar then
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
term.setTextColor(cStar)
|
term.setTextColor(cStar)
|
||||||
write(crStar)
|
write(crStar)
|
||||||
elseif StarT == BStar then
|
elseif StarT == BStar then
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
term.setTextColor(cStar)
|
term.setTextColor(cStar)
|
||||||
write(crStarB)
|
write(crStarB)
|
||||||
elseif StarT == nStar then
|
elseif StarT == nStar then
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
term.setTextColor(cStarG)
|
term.setTextColor(cStarG)
|
||||||
write(crStar)
|
write(crStar)
|
||||||
elseif StarT == gStar then
|
elseif StarT == gStar then
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
term.setTextColor(cStarG)
|
term.setTextColor(cStarG)
|
||||||
write(crStarB)
|
write(crStarB)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawMap()
|
local function drawMap()
|
||||||
for x=1,SizeW do
|
for x=1,SizeW do
|
||||||
for y=1,SizeH do
|
for y=1,SizeH do
|
||||||
|
|
||||||
local obj = tScreen[x][y]
|
local obj = tScreen[x][y]
|
||||||
if obj.ground == true then
|
if obj.ground == true then
|
||||||
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cG)
|
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cG)
|
||||||
end
|
end
|
||||||
if obj.wall == true then
|
if obj.wall == true then
|
||||||
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cW)
|
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cW)
|
||||||
end
|
end
|
||||||
|
|
||||||
local ex = tostring(tScreen[x][y].exit)
|
local ex = tostring(tScreen[x][y].exit)
|
||||||
if not(ex == "zz" or ex == "nil") then
|
if not(ex == "zz" or ex == "nil") then
|
||||||
if ex == "a" then
|
if ex == "a" then
|
||||||
ex = cR1
|
ex = cR1
|
||||||
elseif ex == "b" then
|
elseif ex == "b" then
|
||||||
ex = cR2
|
ex = cR2
|
||||||
elseif ex == "c" then
|
elseif ex == "c" then
|
||||||
ex = cR3
|
ex = cR3
|
||||||
elseif ex == "d" then
|
elseif ex == "d" then
|
||||||
ex = cR4
|
ex = cR4
|
||||||
else
|
else
|
||||||
return error("Exit Color Out")
|
return error("Exit Color Out")
|
||||||
end
|
end
|
||||||
term.setBackgroundColor(cG)
|
term.setBackgroundColor(cG)
|
||||||
term.setTextColor(ex)
|
term.setTextColor(ex)
|
||||||
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
||||||
print("X")
|
print("X")
|
||||||
end
|
end
|
||||||
|
|
||||||
local st = tostring(tScreen[x][y].start)
|
local st = tostring(tScreen[x][y].start)
|
||||||
if not(st == "zz" or st == "nil") then
|
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
|
if Cr == "a" then
|
||||||
Cr = cR1
|
Cr = cR1
|
||||||
elseif Cr == "b" then
|
elseif Cr == "b" then
|
||||||
Cr = cR2
|
Cr = cR2
|
||||||
elseif Cr == "c" then
|
elseif Cr == "c" then
|
||||||
Cr = cR3
|
Cr = cR3
|
||||||
elseif Cr == "d" then
|
elseif Cr == "d" then
|
||||||
Cr = cR4
|
Cr = cR4
|
||||||
else
|
else
|
||||||
return error("Start Color Out")
|
return error("Start Color Out")
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setTextColor(Cr)
|
term.setTextColor(Cr)
|
||||||
term.setBackgroundColor(cG)
|
term.setBackgroundColor(cG)
|
||||||
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
||||||
|
|
||||||
sSide = string.sub(st,1,1)
|
sSide = string.sub(st,1,1)
|
||||||
if sSide == "a" then
|
if sSide == "a" then
|
||||||
print("^")
|
print("^")
|
||||||
elseif sSide == "b" then
|
elseif sSide == "b" then
|
||||||
print(">")
|
print(">")
|
||||||
elseif sSide == "c" then
|
elseif sSide == "c" then
|
||||||
print("v")
|
print("v")
|
||||||
elseif sSide == "d" then
|
elseif sSide == "d" then
|
||||||
print("<")
|
print("<")
|
||||||
else
|
else
|
||||||
print("@")
|
print("@")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if obj.space == true then
|
if obj.space == true then
|
||||||
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cS)
|
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cS)
|
||||||
end
|
end
|
||||||
|
|
||||||
local rb = tostring(tScreen[x][y].robot)
|
local rb = tostring(tScreen[x][y].robot)
|
||||||
if not(rb == "zz" or rb == "nil") then
|
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
|
if Cr == "a" then
|
||||||
Cr = cR1
|
Cr = cR1
|
||||||
elseif Cr == "b" then
|
elseif Cr == "b" then
|
||||||
Cr = cR2
|
Cr = cR2
|
||||||
elseif Cr == "c" then
|
elseif Cr == "c" then
|
||||||
Cr = cR3
|
Cr = cR3
|
||||||
elseif Cr == "d" then
|
elseif Cr == "d" then
|
||||||
Cr = cR4
|
Cr = cR4
|
||||||
else
|
else
|
||||||
Cr = colors.white
|
Cr = colors.white
|
||||||
end
|
end
|
||||||
term.setBackgroundColor(Cr)
|
term.setBackgroundColor(Cr)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
term.setCursorPos(XOrgin+x,YOrgin+y+1)
|
||||||
sSide = string.sub(rb,1,1)
|
sSide = string.sub(rb,1,1)
|
||||||
if sSide == "a" then
|
if sSide == "a" then
|
||||||
print("^")
|
print("^")
|
||||||
elseif sSide == "b" then
|
elseif sSide == "b" then
|
||||||
print(">")
|
print(">")
|
||||||
elseif sSide == "c" then
|
elseif sSide == "c" then
|
||||||
print("v")
|
print("v")
|
||||||
elseif sSide == "d" then
|
elseif sSide == "d" then
|
||||||
print("<")
|
print("<")
|
||||||
else
|
else
|
||||||
print("@")
|
print("@")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function isBrick(x,y)
|
local function isBrick(x,y)
|
||||||
local brb = tostring(tScreen[x][y].robot)
|
local brb = tostring(tScreen[x][y].robot)
|
||||||
local bobj = oScreen[x][y]
|
local bobj = oScreen[x][y]
|
||||||
if (brb == "zz" or brb == "nil") and not bobj.wall == true then
|
if (brb == "zz" or brb == "nil") and not bobj.wall == true then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gRender(sContext)
|
local function gRender(sContext)
|
||||||
if sContext == "start" then
|
if sContext == "start" then
|
||||||
for x=1,SizeW do
|
for x=1,SizeW do
|
||||||
for y=1,SizeH do
|
for y=1,SizeH do
|
||||||
local st = tostring(tScreen[x][y].start)
|
local st = tostring(tScreen[x][y].start)
|
||||||
if not(st == "zz" or st == "nil") then
|
if not(st == "zz" or st == "nil") then
|
||||||
local Cr = string.sub(st,2,2)
|
local Cr = string.sub(st,2,2)
|
||||||
local sSide = string.sub(st,1,1)
|
local sSide = string.sub(st,1,1)
|
||||||
addRobot(x,y,sSide,Cr)
|
addRobot(x,y,sSide,Cr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif sContext == "tick" then
|
elseif sContext == "tick" then
|
||||||
buMap()
|
buMap()
|
||||||
for x=1,SizeW do
|
for x=1,SizeW do
|
||||||
for y=1,SizeH do
|
for y=1,SizeH do
|
||||||
local rb = tostring(oScreen[x][y].robot)
|
local rb = tostring(oScreen[x][y].robot)
|
||||||
@ -513,44 +513,44 @@ local function gRender(sContext)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function InterFace.drawBar()
|
function InterFace.drawBar()
|
||||||
term.setBackgroundColor( colors.black )
|
term.setBackgroundColor( colors.black )
|
||||||
term.setTextColor( InterFace.cTitle )
|
term.setTextColor( InterFace.cTitle )
|
||||||
printCentred( 1, " "..sLevelTitle.." " )
|
printCentred( 1, " "..sLevelTitle.." " )
|
||||||
|
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setBackgroundColor( cW )
|
term.setBackgroundColor( cW )
|
||||||
write( " " )
|
write( " " )
|
||||||
term.setBackgroundColor( colors.black )
|
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.setBackgroundColor( colors.black )
|
||||||
term.setTextColour(InterFace.cSpeedD)
|
term.setTextColour(InterFace.cSpeedD)
|
||||||
write(" <<" )
|
write(" <<" )
|
||||||
if bPaused then
|
if bPaused then
|
||||||
term.setTextColour(InterFace.cSpeedA)
|
term.setTextColour(InterFace.cSpeedA)
|
||||||
else
|
else
|
||||||
term.setTextColour(InterFace.cSpeedD)
|
term.setTextColour(InterFace.cSpeedD)
|
||||||
end
|
end
|
||||||
write(" ||")
|
write(" ||")
|
||||||
if fSpeedS then
|
if fSpeedS then
|
||||||
term.setTextColour(InterFace.cSpeedA)
|
term.setTextColour(InterFace.cSpeedA)
|
||||||
else
|
else
|
||||||
term.setTextColour(InterFace.cSpeedD)
|
term.setTextColour(InterFace.cSpeedD)
|
||||||
end
|
end
|
||||||
write(" >>")
|
write(" >>")
|
||||||
|
|
||||||
term.setCursorPos( TermW-1, 1 )
|
term.setCursorPos( TermW-1, 1 )
|
||||||
term.setBackgroundColor( colors.black )
|
term.setBackgroundColor( colors.black )
|
||||||
term.setTextColour( InterFace.cExit )
|
term.setTextColour( InterFace.cExit )
|
||||||
write(" X")
|
write(" X")
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
end
|
end
|
||||||
|
|
||||||
function InterFace.render()
|
function InterFace.render()
|
||||||
local id,p1,p2,p3 = os.pullEvent()
|
local id,p1,p2,p3 = os.pullEvent()
|
||||||
if id == "mouse_click" then
|
if id == "mouse_click" then
|
||||||
if p3 == 1 and p2 == TermW then
|
if p3 == 1 and p2 == TermW then
|
||||||
return "end"
|
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"
|
return "retry"
|
||||||
@ -570,7 +570,7 @@ function InterFace.render()
|
|||||||
Speed = (fSpeedS and fSpeed) or nSpeed
|
Speed = (fSpeedS and fSpeed) or nSpeed
|
||||||
Tick = os.startTimer(Speed)
|
Tick = os.startTimer(Speed)
|
||||||
InterFace.drawBar()
|
InterFace.drawBar()
|
||||||
elseif p3-1 < YOrgin+SizeH+1 and p3-1 > YOrgin and
|
elseif p3-1 < YOrgin+SizeH+1 and p3-1 > YOrgin and
|
||||||
p2 < XOrgin+SizeW+1 and p2 > XOrgin then
|
p2 < XOrgin+SizeW+1 and p2 > XOrgin then
|
||||||
local eobj = tScreen[p2-XOrgin][p3-YOrgin-1]
|
local eobj = tScreen[p2-XOrgin][p3-YOrgin-1]
|
||||||
local erobj = tostring(tScreen[p2-XOrgin][p3-YOrgin-1].robot)
|
local erobj = tostring(tScreen[p2-XOrgin][p3-YOrgin-1].robot)
|
||||||
@ -580,50 +580,50 @@ function InterFace.render()
|
|||||||
InterFace.drawBar()
|
InterFace.drawBar()
|
||||||
drawMap()
|
drawMap()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif id == "timer" and p1 == Tick then
|
elseif id == "timer" and p1 == Tick then
|
||||||
gRender("tick")
|
gRender("tick")
|
||||||
drawMap()
|
drawMap()
|
||||||
if Speed > 0 then
|
if Speed > 0 then
|
||||||
Tick = os.startTimer(Speed)
|
Tick = os.startTimer(Speed)
|
||||||
else
|
else
|
||||||
Tick = nil
|
Tick = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function startG(LevelN)
|
local function startG(LevelN)
|
||||||
drawStars()
|
drawStars()
|
||||||
loadLevel(LevelN)
|
loadLevel(LevelN)
|
||||||
centerOrgin()
|
centerOrgin()
|
||||||
local create = true
|
local create = true
|
||||||
drawMap()
|
drawMap()
|
||||||
InterFace.drawBar()
|
InterFace.drawBar()
|
||||||
gRender("start")
|
gRender("start")
|
||||||
drawMap()
|
drawMap()
|
||||||
|
|
||||||
local NExit = true
|
local NExit = true
|
||||||
if aExits == 0 then
|
if aExits == 0 then
|
||||||
NExit = false
|
NExit = false
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local isExit = InterFace.render()
|
local isExit = InterFace.render()
|
||||||
if isExit == "end" then
|
if isExit == "end" then
|
||||||
return nil
|
return nil
|
||||||
elseif isExit == "retry" then
|
elseif isExit == "retry" then
|
||||||
return LevelN
|
return LevelN
|
||||||
elseif fExit == "yes" then
|
elseif fExit == "yes" then
|
||||||
if fs.exists( fs.getDir( shell.getRunningProgram() ) .. "/levels/" .. tostring(LevelN + 1) ) then
|
if fs.exists( fs.getDir( shell.getRunningProgram() ) .. "/levels/" .. tostring(LevelN + 1) ) then
|
||||||
return LevelN + 1
|
return LevelN + 1
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if aExits == 0 and NExit == true then
|
if aExits == 0 and NExit == true then
|
||||||
fExit = "yes"
|
fExit = "yes"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = true, nil
|
local ok, err = true, nil
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +1,50 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
|
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usages:")
|
print( "Usages:")
|
||||||
print( "dj play" )
|
print( "dj play" )
|
||||||
print( "dj play <drive>" )
|
print( "dj play <drive>" )
|
||||||
print( "dj stop" )
|
print( "dj stop" )
|
||||||
end
|
end
|
||||||
|
|
||||||
if #tArgs > 2 then
|
if #tArgs > 2 then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sCommand = tArgs[1]
|
local sCommand = tArgs[1]
|
||||||
if sCommand == "stop" then
|
if sCommand == "stop" then
|
||||||
-- Stop audio
|
-- Stop audio
|
||||||
disk.stopAudio()
|
disk.stopAudio()
|
||||||
|
|
||||||
elseif sCommand == "play" or sCommand == nil then
|
elseif sCommand == "play" or sCommand == nil then
|
||||||
-- Play audio
|
-- Play audio
|
||||||
local sName = tArgs[2]
|
local sName = tArgs[2]
|
||||||
if sName == nil then
|
if sName == nil then
|
||||||
-- No disc specified, pick one at random
|
-- No disc specified, pick one at random
|
||||||
local tNames = {}
|
local tNames = {}
|
||||||
for n,sName in ipairs( peripheral.getNames() ) do
|
for n,sName in ipairs( peripheral.getNames() ) do
|
||||||
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
|
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
|
||||||
table.insert( tNames, sName )
|
table.insert( tNames, sName )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #tNames == 0 then
|
if #tNames == 0 then
|
||||||
print( "No Music Discs in attached disk drives" )
|
print( "No Music Discs in attached disk drives" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
sName = tNames[ math.random(1,#tNames) ]
|
sName = tNames[ math.random(1,#tNames) ]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Play the disc
|
-- Play the disc
|
||||||
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
|
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
|
||||||
print( "Playing "..disk.getAudioTitle( sName ) )
|
print( "Playing "..disk.getAudioTitle( sName ) )
|
||||||
disk.playAudio( sName )
|
disk.playAudio( sName )
|
||||||
else
|
else
|
||||||
print( "No Music Disc in disk drive: "..sName )
|
print( "No Music Disc in disk drive: "..sName )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
printUsage()
|
printUsage()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
term.setTextColour( 2^math.random(0,15) )
|
term.setTextColour( 2^math.random(0,15) )
|
||||||
end
|
end
|
||||||
textutils.slowPrint( "Hello World!" )
|
textutils.slowPrint( "Hello World!" )
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
|
@ -5,23 +5,23 @@ local w,h = term.getSize()
|
|||||||
local titleColour, headingColour, textColour, wormColour, fruitColour
|
local titleColour, headingColour, textColour, wormColour, fruitColour
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
titleColour = colours.red
|
titleColour = colours.red
|
||||||
headingColour = colours.yellow
|
headingColour = colours.yellow
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
wormColour = colours.green
|
wormColour = colours.green
|
||||||
fruitColour = colours.red
|
fruitColour = colours.red
|
||||||
else
|
else
|
||||||
titleColour = colours.white
|
titleColour = colours.white
|
||||||
headingColour = colours.white
|
headingColour = colours.white
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
wormColour = colours.white
|
wormColour = colours.white
|
||||||
fruitColour = colours.white
|
fruitColour = colours.white
|
||||||
end
|
end
|
||||||
|
|
||||||
local function printCentred( y, s )
|
local function printCentred( y, s )
|
||||||
local x = math.floor((w - string.len(s)) / 2)
|
local x = math.floor((w - string.len(s)) / 2)
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
--term.clearLine()
|
--term.clearLine()
|
||||||
term.write( s )
|
term.write( s )
|
||||||
end
|
end
|
||||||
|
|
||||||
local xVel,yVel = 1,0
|
local xVel,yVel = 1,0
|
||||||
@ -40,177 +40,177 @@ local nSpeed, nInterval
|
|||||||
-- Setup the screen
|
-- Setup the screen
|
||||||
local screen = {}
|
local screen = {}
|
||||||
for x=1,w do
|
for x=1,w do
|
||||||
screen[x] = {}
|
screen[x] = {}
|
||||||
for y=1,h do
|
for y=1,h do
|
||||||
screen[x][y] = {}
|
screen[x][y] = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
screen[xPos][yPos] = { snake = true }
|
screen[xPos][yPos] = { snake = true }
|
||||||
|
|
||||||
local nFruit = 1
|
local nFruit = 1
|
||||||
local tFruits = {
|
local tFruits = {
|
||||||
"A", "B", "C", "D", "E", "F", "G", "H",
|
"A", "B", "C", "D", "E", "F", "G", "H",
|
||||||
"I", "J", "K", "L", "M", "N", "O", "P",
|
"I", "J", "K", "L", "M", "N", "O", "P",
|
||||||
"Q", "R", "S", "T", "U", "V", "W", "X",
|
"Q", "R", "S", "T", "U", "V", "W", "X",
|
||||||
"Y", "Z",
|
"Y", "Z",
|
||||||
"a", "b", "c", "d", "e", "f", "g", "h",
|
"a", "b", "c", "d", "e", "f", "g", "h",
|
||||||
"i", "j", "k", "l", "m", "n", "o", "p",
|
"i", "j", "k", "l", "m", "n", "o", "p",
|
||||||
"q", "r", "s", "t", "u", "v", "w", "x",
|
"q", "r", "s", "t", "u", "v", "w", "x",
|
||||||
"y", "z",
|
"y", "z",
|
||||||
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
|
||||||
"@", "$", "%", "#", "&", "!", "?", "+", "*", "~"
|
"@", "$", "%", "#", "&", "!", "?", "+", "*", "~"
|
||||||
}
|
}
|
||||||
|
|
||||||
local function addFruit()
|
local function addFruit()
|
||||||
while true do
|
while true do
|
||||||
local x = math.random(1,w)
|
local x = math.random(1,w)
|
||||||
local y = math.random(2,h)
|
local y = math.random(2,h)
|
||||||
local fruit = screen[x][y]
|
local fruit = screen[x][y]
|
||||||
if fruit.snake == nil and fruit.wall == nil and fruit.fruit == nil then
|
if fruit.snake == nil and fruit.wall == nil and fruit.fruit == nil then
|
||||||
screen[x][y] = { fruit = true }
|
screen[x][y] = { fruit = true }
|
||||||
term.setCursorPos(x,y)
|
term.setCursorPos(x,y)
|
||||||
term.setBackgroundColour( fruitColour )
|
term.setBackgroundColour( fruitColour )
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
term.setBackgroundColour( colours.black )
|
term.setBackgroundColour( colours.black )
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
nFruit = nFruit + 1
|
nFruit = nFruit + 1
|
||||||
if nFruit > #tFruits then
|
if nFruit > #tFruits then
|
||||||
nFruit = 1
|
nFruit = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawMenu()
|
local function drawMenu()
|
||||||
term.setTextColour( headingColour )
|
term.setTextColour( headingColour )
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.write( "SCORE " )
|
term.write( "SCORE " )
|
||||||
|
|
||||||
term.setTextColour( textColour )
|
term.setTextColour( textColour )
|
||||||
term.setCursorPos(7,1)
|
term.setCursorPos(7,1)
|
||||||
term.write( tostring(nScore) )
|
term.write( tostring(nScore) )
|
||||||
|
|
||||||
term.setTextColour( headingColour )
|
term.setTextColour( headingColour )
|
||||||
term.setCursorPos(w-11,1)
|
term.setCursorPos(w-11,1)
|
||||||
term.write( "DIFFICULTY ")
|
term.write( "DIFFICULTY ")
|
||||||
|
|
||||||
term.setTextColour( textColour )
|
term.setTextColour( textColour )
|
||||||
term.setCursorPos(w,1)
|
term.setCursorPos(w,1)
|
||||||
term.write( tostring(nDifficulty or "?") )
|
term.write( tostring(nDifficulty or "?") )
|
||||||
|
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update( )
|
local function update( )
|
||||||
local x,y = xPos,yPos
|
local x,y = xPos,yPos
|
||||||
if pxVel and pyVel then
|
if pxVel and pyVel then
|
||||||
xVel, yVel = pxVel, pyVel
|
xVel, yVel = pxVel, pyVel
|
||||||
pxVel, pyVel = nil, nil
|
pxVel, pyVel = nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove the tail
|
-- Remove the tail
|
||||||
if nExtraLength == 0 then
|
if nExtraLength == 0 then
|
||||||
local tail = screen[tailX][tailY]
|
local tail = screen[tailX][tailY]
|
||||||
screen[tailX][tailY] = {}
|
screen[tailX][tailY] = {}
|
||||||
term.setCursorPos(tailX,tailY)
|
term.setCursorPos(tailX,tailY)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
tailX = tail.nextX
|
tailX = tail.nextX
|
||||||
tailY = tail.nextY
|
tailY = tail.nextY
|
||||||
else
|
else
|
||||||
nExtraLength = nExtraLength - 1
|
nExtraLength = nExtraLength - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the head
|
-- Update the head
|
||||||
local head = screen[xPos][yPos]
|
local head = screen[xPos][yPos]
|
||||||
local newXPos = xPos + xVel
|
local newXPos = xPos + xVel
|
||||||
local newYPos = yPos + yVel
|
local newYPos = yPos + yVel
|
||||||
if newXPos < 1 then
|
if newXPos < 1 then
|
||||||
newXPos = w
|
newXPos = w
|
||||||
elseif newXPos > w then
|
elseif newXPos > w then
|
||||||
newXPos = 1
|
newXPos = 1
|
||||||
end
|
end
|
||||||
if newYPos < 2 then
|
if newYPos < 2 then
|
||||||
newYPos = h
|
newYPos = h
|
||||||
elseif newYPos > h then
|
elseif newYPos > h then
|
||||||
newYPos = 2
|
newYPos = 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local newHead = screen[newXPos][newYPos]
|
local newHead = screen[newXPos][newYPos]
|
||||||
term.setCursorPos(1,1);
|
term.setCursorPos(1,1);
|
||||||
print( newHead.snake )
|
print( newHead.snake )
|
||||||
if newHead.snake == true or newHead.wall == true then
|
if newHead.snake == true or newHead.wall == true then
|
||||||
bRunning = false
|
bRunning = false
|
||||||
|
|
||||||
else
|
else
|
||||||
if newHead.fruit == true then
|
if newHead.fruit == true then
|
||||||
nScore = nScore + 10
|
nScore = nScore + 10
|
||||||
nExtraLength = nExtraLength + 1
|
nExtraLength = nExtraLength + 1
|
||||||
addFruit()
|
addFruit()
|
||||||
end
|
end
|
||||||
xPos = newXPos
|
xPos = newXPos
|
||||||
yPos = newYPos
|
yPos = newYPos
|
||||||
head.nextX = newXPos
|
head.nextX = newXPos
|
||||||
head.nextY = newYPos
|
head.nextY = newYPos
|
||||||
screen[newXPos][newYPos] = { snake = true }
|
screen[newXPos][newYPos] = { snake = true }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(xPos,yPos)
|
term.setCursorPos(xPos,yPos)
|
||||||
term.setBackgroundColour( wormColour )
|
term.setBackgroundColour( wormColour )
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
term.setBackgroundColour( colours.black )
|
term.setBackgroundColour( colours.black )
|
||||||
|
|
||||||
drawMenu()
|
drawMenu()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display the frontend
|
-- Display the frontend
|
||||||
term.clear()
|
term.clear()
|
||||||
local function drawFrontend()
|
local function drawFrontend()
|
||||||
--term.setTextColour( titleColour )
|
--term.setTextColour( titleColour )
|
||||||
--printCentred( math.floor(h/2) - 4, " W O R M " )
|
--printCentred( math.floor(h/2) - 4, " W O R M " )
|
||||||
|
|
||||||
term.setTextColour( headingColour )
|
term.setTextColour( headingColour )
|
||||||
printCentred( math.floor(h/2) - 3, "" )
|
printCentred( math.floor(h/2) - 3, "" )
|
||||||
printCentred( math.floor(h/2) - 2, " SELECT DIFFICULTY " )
|
printCentred( math.floor(h/2) - 2, " SELECT DIFFICULTY " )
|
||||||
printCentred( math.floor(h/2) - 1, "" )
|
printCentred( math.floor(h/2) - 1, "" )
|
||||||
|
|
||||||
printCentred( math.floor(h/2) + 0, " " )
|
printCentred( math.floor(h/2) + 0, " " )
|
||||||
printCentred( math.floor(h/2) + 1, " " )
|
printCentred( math.floor(h/2) + 1, " " )
|
||||||
printCentred( math.floor(h/2) + 2, " " )
|
printCentred( math.floor(h/2) + 2, " " )
|
||||||
printCentred( math.floor(h/2) - 1 + nDifficulty, " [ ] " )
|
printCentred( math.floor(h/2) - 1 + nDifficulty, " [ ] " )
|
||||||
|
|
||||||
term.setTextColour( textColour )
|
term.setTextColour( textColour )
|
||||||
printCentred( math.floor(h/2) + 0, "EASY" )
|
printCentred( math.floor(h/2) + 0, "EASY" )
|
||||||
printCentred( math.floor(h/2) + 1, "MEDIUM" )
|
printCentred( math.floor(h/2) + 1, "MEDIUM" )
|
||||||
printCentred( math.floor(h/2) + 2, "HARD" )
|
printCentred( math.floor(h/2) + 2, "HARD" )
|
||||||
printCentred( math.floor(h/2) + 3, "" )
|
printCentred( math.floor(h/2) + 3, "" )
|
||||||
|
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
end
|
end
|
||||||
|
|
||||||
drawMenu()
|
drawMenu()
|
||||||
drawFrontend()
|
drawFrontend()
|
||||||
while true do
|
while true do
|
||||||
local e,key = os.pullEvent( "key" )
|
local e,key = os.pullEvent( "key" )
|
||||||
if key == keys.up or key == keys.w then
|
if key == keys.up or key == keys.w then
|
||||||
-- Up
|
-- Up
|
||||||
if nDifficulty > 1 then
|
if nDifficulty > 1 then
|
||||||
nDifficulty = nDifficulty - 1
|
nDifficulty = nDifficulty - 1
|
||||||
drawMenu()
|
drawMenu()
|
||||||
drawFrontend()
|
drawFrontend()
|
||||||
end
|
end
|
||||||
elseif key == keys.down or key == keys.s then
|
elseif key == keys.down or key == keys.s then
|
||||||
-- Down
|
-- Down
|
||||||
if nDifficulty < 3 then
|
if nDifficulty < 3 then
|
||||||
nDifficulty = nDifficulty + 1
|
nDifficulty = nDifficulty + 1
|
||||||
drawMenu()
|
drawMenu()
|
||||||
drawFrontend()
|
drawFrontend()
|
||||||
end
|
end
|
||||||
elseif key == keys.enter then
|
elseif key == keys.enter then
|
||||||
-- Enter
|
-- Enter
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tSpeeds = { 5, 10, 25 }
|
local tSpeeds = { 5, 10, 25 }
|
||||||
@ -222,7 +222,7 @@ term.clear()
|
|||||||
drawMenu()
|
drawMenu()
|
||||||
screen[tailX][tailY].snake = true
|
screen[tailX][tailY].snake = true
|
||||||
while nExtraLength > 0 do
|
while nExtraLength > 0 do
|
||||||
update()
|
update()
|
||||||
end
|
end
|
||||||
addFruit()
|
addFruit()
|
||||||
addFruit()
|
addFruit()
|
||||||
@ -230,37 +230,37 @@ addFruit()
|
|||||||
-- Play the game
|
-- Play the game
|
||||||
local timer = os.startTimer(0)
|
local timer = os.startTimer(0)
|
||||||
while bRunning do
|
while bRunning do
|
||||||
local event, p1, p2 = os.pullEvent()
|
local event, p1, p2 = os.pullEvent()
|
||||||
if event == "timer" and p1 == timer then
|
if event == "timer" and p1 == timer then
|
||||||
timer = os.startTimer(nInterval)
|
timer = os.startTimer(nInterval)
|
||||||
update( false )
|
update( false )
|
||||||
|
|
||||||
elseif event == "key" then
|
elseif event == "key" then
|
||||||
local key = p1
|
local key = p1
|
||||||
if key == keys.up or key == keys.w then
|
if key == keys.up or key == keys.w then
|
||||||
-- Up
|
-- Up
|
||||||
if yVel == 0 then
|
if yVel == 0 then
|
||||||
pxVel,pyVel = 0,-1
|
pxVel,pyVel = 0,-1
|
||||||
end
|
end
|
||||||
elseif key == keys.down or key == keys.s then
|
elseif key == keys.down or key == keys.s then
|
||||||
-- Down
|
-- Down
|
||||||
if yVel == 0 then
|
if yVel == 0 then
|
||||||
pxVel,pyVel = 0,1
|
pxVel,pyVel = 0,1
|
||||||
end
|
end
|
||||||
elseif key == keys.left or key == keys.a then
|
elseif key == keys.left or key == keys.a then
|
||||||
-- Left
|
-- Left
|
||||||
if xVel == 0 then
|
if xVel == 0 then
|
||||||
pxVel,pyVel = -1,0
|
pxVel,pyVel = -1,0
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif key == keys.right or key == keys.d then
|
elseif key == keys.right or key == keys.d then
|
||||||
-- Right
|
-- Right
|
||||||
if xVel == 0 then
|
if xVel == 0 then
|
||||||
pxVel,pyVel = 1,0
|
pxVel,pyVel = 1,0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display the gameover screen
|
-- Display the gameover screen
|
||||||
@ -276,16 +276,16 @@ term.setTextColour( colours.white )
|
|||||||
|
|
||||||
local timer = os.startTimer(2.5)
|
local timer = os.startTimer(2.5)
|
||||||
repeat
|
repeat
|
||||||
local e,p = os.pullEvent()
|
local e,p = os.pullEvent()
|
||||||
if e == "timer" and p == timer then
|
if e == "timer" and p == timer then
|
||||||
term.setTextColour( textColour )
|
term.setTextColour( textColour )
|
||||||
printCentred( math.floor(h/2) + 2, " PRESS ANY KEY " )
|
printCentred( math.floor(h/2) + 2, " PRESS ANY KEY " )
|
||||||
printCentred( math.floor(h/2) + 3, " " )
|
printCentred( math.floor(h/2) + 3, " " )
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
end
|
end
|
||||||
until e == "char"
|
until e == "char"
|
||||||
|
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,104 +1,104 @@
|
|||||||
|
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usages:" )
|
print( "Usages:" )
|
||||||
print( "gps host" )
|
print( "gps host" )
|
||||||
print( "gps host <x> <y> <z>" )
|
print( "gps host <x> <y> <z>" )
|
||||||
print( "gps locate" )
|
print( "gps locate" )
|
||||||
end
|
end
|
||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sCommand = tArgs[1]
|
local sCommand = tArgs[1]
|
||||||
if sCommand == "locate" then
|
if sCommand == "locate" then
|
||||||
-- "gps locate"
|
-- "gps locate"
|
||||||
-- Just locate this computer (this will print the results)
|
-- Just locate this computer (this will print the results)
|
||||||
gps.locate( 2, true )
|
gps.locate( 2, true )
|
||||||
|
|
||||||
elseif sCommand == "host" then
|
elseif sCommand == "host" then
|
||||||
-- "gps host"
|
-- "gps host"
|
||||||
-- Act as a GPS host
|
-- Act as a GPS host
|
||||||
if pocket then
|
if pocket then
|
||||||
print( "GPS Hosts must be stationary" )
|
print( "GPS Hosts must be stationary" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Find a modem
|
-- Find a modem
|
||||||
local sModemSide = nil
|
local sModemSide = nil
|
||||||
for n,sSide in ipairs( rs.getSides() ) do
|
for n,sSide in ipairs( rs.getSides() ) do
|
||||||
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
|
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
|
||||||
sModemSide = sSide
|
sModemSide = sSide
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if sModemSide == nil then
|
if sModemSide == nil then
|
||||||
print( "No wireless modems found. 1 required." )
|
print( "No wireless modems found. 1 required." )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Determine position
|
-- Determine position
|
||||||
local x,y,z
|
local x,y,z
|
||||||
if #tArgs >= 4 then
|
if #tArgs >= 4 then
|
||||||
-- Position is manually specified
|
-- Position is manually specified
|
||||||
x = tonumber(tArgs[2])
|
x = tonumber(tArgs[2])
|
||||||
y = tonumber(tArgs[3])
|
y = tonumber(tArgs[3])
|
||||||
z = tonumber(tArgs[4])
|
z = tonumber(tArgs[4])
|
||||||
if x == nil or y == nil or z == nil then
|
if x == nil or y == nil or z == nil then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print( "Position is "..x..","..y..","..z )
|
print( "Position is "..x..","..y..","..z )
|
||||||
else
|
else
|
||||||
-- Position is to be determined using locate
|
-- 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
|
if x == nil then
|
||||||
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
|
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
|
||||||
if bCloseChannel then
|
if bCloseChannel then
|
||||||
print( "Closing GPS channel" )
|
print( "Closing GPS channel" )
|
||||||
modem.close( gps.CHANNEL_GPS )
|
modem.close( gps.CHANNEL_GPS )
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open a channel
|
-- Open a channel
|
||||||
local modem = peripheral.wrap( sModemSide )
|
local modem = peripheral.wrap( sModemSide )
|
||||||
print( "Opening channel on modem "..sModemSide )
|
print( "Opening channel on modem "..sModemSide )
|
||||||
modem.open( gps.CHANNEL_GPS )
|
modem.open( gps.CHANNEL_GPS )
|
||||||
|
|
||||||
-- Serve requests indefinately
|
-- Serve requests indefinately
|
||||||
local nServed = 0
|
local nServed = 0
|
||||||
while true do
|
while true do
|
||||||
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
|
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
|
||||||
if e == "modem_message" then
|
if e == "modem_message" then
|
||||||
-- We received a message from a modem
|
-- We received a message from a modem
|
||||||
local sSide, sChannel, sReplyChannel, sMessage, nDistance = p1, p2, p3, p4, p5
|
local sSide, sChannel, sReplyChannel, sMessage, nDistance = p1, p2, p3, p4, p5
|
||||||
if sSide == sModemSide and sChannel == gps.CHANNEL_GPS and sMessage == "PING" and nDistance then
|
if sSide == sModemSide and sChannel == gps.CHANNEL_GPS and sMessage == "PING" and nDistance then
|
||||||
-- We received a ping message on the GPS channel, send a response
|
-- We received a ping message on the GPS channel, send a response
|
||||||
modem.transmit( sReplyChannel, gps.CHANNEL_GPS, { x, y, z } )
|
modem.transmit( sReplyChannel, gps.CHANNEL_GPS, { x, y, z } )
|
||||||
|
|
||||||
-- Print the number of requests handled
|
-- Print the number of requests handled
|
||||||
nServed = nServed + 1
|
nServed = nServed + 1
|
||||||
if nServed > 1 then
|
if nServed > 1 then
|
||||||
local x,y = term.getCursorPos()
|
local x,y = term.getCursorPos()
|
||||||
term.setCursorPos(1,y-1)
|
term.setCursorPos(1,y-1)
|
||||||
end
|
end
|
||||||
print( nServed.." GPS requests served" )
|
print( nServed.." GPS requests served" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Close the channel
|
-- Close the channel
|
||||||
print( "Closing channel" )
|
print( "Closing channel" )
|
||||||
modem.close( gps.CHANNEL_GPS )
|
modem.close( gps.CHANNEL_GPS )
|
||||||
|
|
||||||
else
|
else
|
||||||
-- "gps somethingelse"
|
-- "gps somethingelse"
|
||||||
-- Error
|
-- Error
|
||||||
printUsage()
|
printUsage()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 0 then
|
if #tArgs > 0 then
|
||||||
sTopic = tArgs[1]
|
sTopic = tArgs[1]
|
||||||
else
|
else
|
||||||
sTopic = "intro"
|
sTopic = "intro"
|
||||||
end
|
end
|
||||||
|
|
||||||
if sTopic == "index" then
|
if sTopic == "index" then
|
||||||
print( "Help topics availiable:" )
|
print( "Help topics availiable:" )
|
||||||
local tTopics = help.topics()
|
local tTopics = help.topics()
|
||||||
textutils.pagedTabulate( tTopics )
|
textutils.pagedTabulate( tTopics )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local w,h = term.getSize()
|
local w,h = term.getSize()
|
||||||
local sFile = help.lookup( sTopic )
|
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
|
||||||
local nLinesPrinted = 0
|
local nLinesPrinted = 0
|
||||||
if file then
|
if file then
|
||||||
local sLine = file:read()
|
local sLine = file:read()
|
||||||
local nLines = 0
|
local nLines = 0
|
||||||
while sLine do
|
while sLine do
|
||||||
nLines = nLines + textutils.pagedPrint( sLine, (h-3) - nLines )
|
nLines = nLines + textutils.pagedPrint( sLine, (h-3) - nLines )
|
||||||
sLine = file:read()
|
sLine = file:read()
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
else
|
else
|
||||||
print( "No help available" )
|
print( "No help available" )
|
||||||
end
|
end
|
||||||
|
@ -121,4 +121,4 @@ elseif sCommand == "run" then
|
|||||||
else
|
else
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -2,29 +2,29 @@
|
|||||||
local sDrive = nil
|
local sDrive = nil
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 0 then
|
if #tArgs > 0 then
|
||||||
sDrive = tostring( tArgs[1] )
|
sDrive = tostring( tArgs[1] )
|
||||||
end
|
end
|
||||||
|
|
||||||
if sDrive == nil then
|
if sDrive == nil then
|
||||||
print( "This is computer #"..os.getComputerID() )
|
print( "This is computer #"..os.getComputerID() )
|
||||||
|
|
||||||
local label = os.getComputerLabel()
|
local label = os.getComputerLabel()
|
||||||
if label then
|
if label then
|
||||||
print( "This computer is labelled \""..label.."\"" )
|
print( "This computer is labelled \""..label.."\"" )
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
local bData = disk.hasData( sDrive )
|
local bData = disk.hasData( sDrive )
|
||||||
if not bData then
|
if not bData then
|
||||||
print( "No disk in drive "..sDrive )
|
print( "No disk in drive "..sDrive )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "The disk is #"..disk.getID( sDrive ) )
|
print( "The disk is #"..disk.getID( sDrive ) )
|
||||||
|
|
||||||
local label = disk.getLabel( sDrive )
|
local label = disk.getLabel( sDrive )
|
||||||
if label then
|
if label then
|
||||||
print( "The disk is labelled \""..label.."\"" )
|
print( "The disk is labelled \""..label.."\"" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usages:" )
|
print( "Usages:" )
|
||||||
print( "label get" )
|
print( "label get" )
|
||||||
print( "label get <drive>" )
|
print( "label get <drive>" )
|
||||||
print( "label set <text>" )
|
print( "label set <text>" )
|
||||||
print( "label set <drive> <text>" )
|
print( "label set <drive> <text>" )
|
||||||
print( "label clear" )
|
print( "label clear" )
|
||||||
print( "label clear <drive>" )
|
print( "label clear <drive>" )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function checkDrive( sDrive )
|
local function checkDrive( sDrive )
|
||||||
@ -18,15 +18,15 @@ local function checkDrive( sDrive )
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "No disk drive named "..sDrive )
|
print( "No disk drive named "..sDrive )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get( sDrive )
|
local function get( sDrive )
|
||||||
if sDrive ~= nil then
|
if sDrive ~= nil then
|
||||||
if checkDrive( sDrive ) then
|
if checkDrive( sDrive ) then
|
||||||
local sLabel = disk.getLabel( sDrive )
|
local sLabel = disk.getLabel( sDrive )
|
||||||
if sLabel then
|
if sLabel then
|
||||||
print( "Disk label is \""..sLabel.."\"" )
|
print( "Disk label is \""..sLabel.."\"" )
|
||||||
@ -34,19 +34,19 @@ local function get( sDrive )
|
|||||||
print( "No Disk label" )
|
print( "No Disk label" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local sLabel = os.getComputerLabel()
|
local sLabel = os.getComputerLabel()
|
||||||
if sLabel then
|
if sLabel then
|
||||||
print( "Computer label is \""..sLabel.."\"" )
|
print( "Computer label is \""..sLabel.."\"" )
|
||||||
else
|
else
|
||||||
print( "No Computer label" )
|
print( "No Computer label" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set( sDrive, sText )
|
local function set( sDrive, sText )
|
||||||
if sDrive ~= nil then
|
if sDrive ~= nil then
|
||||||
if checkDrive( sDrive ) then
|
if checkDrive( sDrive ) then
|
||||||
disk.setLabel( sDrive, sText )
|
disk.setLabel( sDrive, sText )
|
||||||
local sLabel = disk.getLabel( sDrive )
|
local sLabel = disk.getLabel( sDrive )
|
||||||
if sLabel then
|
if sLabel then
|
||||||
@ -55,15 +55,15 @@ local function set( sDrive, sText )
|
|||||||
print( "Disk label cleared" )
|
print( "Disk label cleared" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
os.setComputerLabel( sText )
|
os.setComputerLabel( sText )
|
||||||
local sLabel = os.getComputerLabel()
|
local sLabel = os.getComputerLabel()
|
||||||
if sLabel then
|
if sLabel then
|
||||||
print( "Computer label set to \""..sLabel.."\"" )
|
print( "Computer label set to \""..sLabel.."\"" )
|
||||||
else
|
else
|
||||||
print( "Computer label cleared" )
|
print( "Computer label cleared" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
|
@ -4,7 +4,7 @@ local tArgs = { ... }
|
|||||||
-- Get all the files in the directory
|
-- Get all the files in the directory
|
||||||
local sDir = shell.dir()
|
local sDir = shell.dir()
|
||||||
if tArgs[1] ~= nil then
|
if tArgs[1] ~= nil then
|
||||||
sDir = shell.resolve( tArgs[1] )
|
sDir = shell.resolve( tArgs[1] )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sort into dirs/files, and calculate column count
|
-- Sort into dirs/files, and calculate column count
|
||||||
@ -14,20 +14,20 @@ local tDirs = {}
|
|||||||
|
|
||||||
local bShowHidden = settings.get( "list.show_hidden" )
|
local bShowHidden = settings.get( "list.show_hidden" )
|
||||||
for n, sItem in pairs( tAll ) do
|
for n, sItem in pairs( tAll ) do
|
||||||
if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then
|
if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then
|
||||||
local sPath = fs.combine( sDir, sItem )
|
local sPath = fs.combine( sDir, sItem )
|
||||||
if fs.isDir( sPath ) then
|
if fs.isDir( sPath ) then
|
||||||
table.insert( tDirs, sItem )
|
table.insert( tDirs, sItem )
|
||||||
else
|
else
|
||||||
table.insert( tFiles, sItem )
|
table.insert( tFiles, sItem )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort( tDirs )
|
table.sort( tDirs )
|
||||||
table.sort( tFiles )
|
table.sort( tFiles )
|
||||||
|
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
textutils.pagedTabulate( colors.green, tDirs, colors.white, tFiles )
|
textutils.pagedTabulate( colors.green, tDirs, colors.white, tFiles )
|
||||||
else
|
else
|
||||||
textutils.pagedTabulate( tDirs, tFiles )
|
textutils.pagedTabulate( tDirs, tFiles )
|
||||||
end
|
end
|
||||||
|
@ -1,96 +1,96 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 0 then
|
if #tArgs > 0 then
|
||||||
print( "This is an interactive Lua prompt." )
|
print( "This is an interactive Lua prompt." )
|
||||||
print( "To run a lua program, just type its name." )
|
print( "To run a lua program, just type its name." )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local bRunning = true
|
local bRunning = true
|
||||||
local tCommandHistory = {}
|
local tCommandHistory = {}
|
||||||
local tEnv = {
|
local tEnv = {
|
||||||
["exit"] = function()
|
["exit"] = function()
|
||||||
bRunning = false
|
bRunning = false
|
||||||
end,
|
end,
|
||||||
["_echo"] = function( ... )
|
["_echo"] = function( ... )
|
||||||
return ...
|
return ...
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
setmetatable( tEnv, { __index = _ENV } )
|
setmetatable( tEnv, { __index = _ENV } )
|
||||||
|
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
term.setTextColour( colours.yellow )
|
term.setTextColour( colours.yellow )
|
||||||
end
|
end
|
||||||
print( "Interactive Lua prompt." )
|
print( "Interactive Lua prompt." )
|
||||||
print( "Call exit() to exit." )
|
print( "Call exit() to exit." )
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
|
|
||||||
while bRunning do
|
while bRunning do
|
||||||
--if term.isColour() then
|
--if term.isColour() then
|
||||||
-- term.setTextColour( colours.yellow )
|
-- term.setTextColour( colours.yellow )
|
||||||
--end
|
--end
|
||||||
write( "lua> " )
|
write( "lua> " )
|
||||||
--term.setTextColour( colours.white )
|
--term.setTextColour( colours.white )
|
||||||
|
|
||||||
local s = read( nil, tCommandHistory, function( sLine )
|
local s = read( nil, tCommandHistory, function( sLine )
|
||||||
if settings.get( "lua.autocomplete" ) then
|
if settings.get( "lua.autocomplete" ) then
|
||||||
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
|
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
|
||||||
if nStartPos then
|
if nStartPos then
|
||||||
sLine = string.sub( sLine, nStartPos )
|
sLine = string.sub( sLine, nStartPos )
|
||||||
end
|
end
|
||||||
if #sLine > 0 then
|
if #sLine > 0 then
|
||||||
return textutils.complete( sLine, tEnv )
|
return textutils.complete( sLine, tEnv )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end )
|
end )
|
||||||
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
|
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
|
||||||
table.insert( tCommandHistory, s )
|
table.insert( tCommandHistory, s )
|
||||||
end
|
end
|
||||||
|
|
||||||
local nForcePrint = 0
|
local nForcePrint = 0
|
||||||
local func, e = load( s, "lua", "t", tEnv )
|
local func, e = load( s, "lua", "t", tEnv )
|
||||||
local func2, e2 = load( "return _echo("..s..");", "lua", "t", tEnv )
|
local func2, e2 = load( "return _echo("..s..");", "lua", "t", tEnv )
|
||||||
if not func then
|
if not func then
|
||||||
if func2 then
|
if func2 then
|
||||||
func = func2
|
func = func2
|
||||||
e = nil
|
e = nil
|
||||||
nForcePrint = 1
|
nForcePrint = 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if func2 then
|
if func2 then
|
||||||
func = func2
|
func = func2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if func then
|
if func then
|
||||||
local tResults = { pcall( func ) }
|
local tResults = { pcall( func ) }
|
||||||
if tResults[1] then
|
if tResults[1] then
|
||||||
local n = 1
|
local n = 1
|
||||||
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
|
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
|
||||||
local value = tResults[ n + 1 ]
|
local value = tResults[ n + 1 ]
|
||||||
if type( value ) == "table" then
|
if type( value ) == "table" then
|
||||||
local metatable = getmetatable( value )
|
local metatable = getmetatable( value )
|
||||||
if type(metatable) == "table" and type(metatable.__tostring) == "function" then
|
if type(metatable) == "table" and type(metatable.__tostring) == "function" then
|
||||||
print( tostring( value ) )
|
print( tostring( value ) )
|
||||||
else
|
else
|
||||||
local ok, serialised = pcall( textutils.serialise, value )
|
local ok, serialised = pcall( textutils.serialise, value )
|
||||||
if ok then
|
if ok then
|
||||||
print( serialised )
|
print( serialised )
|
||||||
else
|
else
|
||||||
print( tostring( value ) )
|
print( tostring( value ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( tostring( value ) )
|
print( tostring( value ) )
|
||||||
end
|
end
|
||||||
n = n + 1
|
n = n + 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
printError( tResults[2] )
|
printError( tResults[2] )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
printError( e )
|
printError( e )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: mkdir <path>" )
|
print( "Usage: mkdir <path>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sNewDir = shell.resolve( tArgs[1] )
|
local sNewDir = shell.resolve( tArgs[1] )
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
|
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usage: monitor <name> <program> <arguments>" )
|
print( "Usage: monitor <name> <program> <arguments>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 2 then
|
if #tArgs < 2 then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sName = tArgs[1]
|
local sName = tArgs[1]
|
||||||
if peripheral.getType( sName ) ~= "monitor" then
|
if peripheral.getType( sName ) ~= "monitor" then
|
||||||
print( "No monitor named ".. sName )
|
print( "No monitor named ".. sName )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sProgram = tArgs[2]
|
local sProgram = tArgs[2]
|
||||||
local sPath = shell.resolveProgram( sProgram )
|
local sPath = shell.resolveProgram( sProgram )
|
||||||
if sPath == nil then
|
if sPath == nil then
|
||||||
print( "No such program: "..sProgram )
|
print( "No such program: "..sProgram )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Running "..sProgram.." on monitor "..sName )
|
print( "Running "..sProgram.." on monitor "..sName )
|
||||||
@ -35,33 +35,33 @@ end )
|
|||||||
local function resume( ... )
|
local function resume( ... )
|
||||||
local ok, param = coroutine.resume( co, ... )
|
local ok, param = coroutine.resume( co, ... )
|
||||||
if not ok then
|
if not ok then
|
||||||
printError( param )
|
printError( param )
|
||||||
end
|
end
|
||||||
return param
|
return param
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, param = pcall( function()
|
local ok, param = pcall( function()
|
||||||
local sFilter = resume()
|
local sFilter = resume()
|
||||||
while coroutine.status( co ) ~= "dead" do
|
while coroutine.status( co ) ~= "dead" do
|
||||||
local tEvent = table.pack( os.pullEventRaw() )
|
local tEvent = table.pack( os.pullEventRaw() )
|
||||||
if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
|
if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
|
||||||
sFilter = resume( table.unpack( tEvent, 1, tEvent.n ) )
|
sFilter = resume( table.unpack( tEvent, 1, tEvent.n ) )
|
||||||
end
|
end
|
||||||
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then
|
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then
|
||||||
if tEvent[1] == "monitor_touch" and tEvent[2] == sName then
|
if tEvent[1] == "monitor_touch" and tEvent[2] == sName then
|
||||||
sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3, tEvent.n ) )
|
sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3, tEvent.n ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then
|
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then
|
||||||
if tEvent[1] == "monitor_resize" and tEvent[2] == sName then
|
if tEvent[1] == "monitor_resize" and tEvent[2] == sName then
|
||||||
sFilter = resume( "term_resize" )
|
sFilter = resume( "term_resize" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end )
|
end )
|
||||||
|
|
||||||
term.redirect( previousTerm )
|
term.redirect( previousTerm )
|
||||||
if not ok then
|
if not ok then
|
||||||
printError( param )
|
printError( param )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 2 then
|
if #tArgs < 2 then
|
||||||
print( "Usage: mv <source> <destination>" )
|
print( "Usage: mv <source> <destination>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sSource = shell.resolve( tArgs[1] )
|
local sSource = shell.resolve( tArgs[1] )
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
local tPeripherals = peripheral.getNames()
|
local tPeripherals = peripheral.getNames()
|
||||||
print( "Attached Peripherals:" )
|
print( "Attached Peripherals:" )
|
||||||
if #tPeripherals > 0 then
|
if #tPeripherals > 0 then
|
||||||
for n=1,#tPeripherals do
|
for n=1,#tPeripherals do
|
||||||
local sPeripheral = tPeripherals[n]
|
local sPeripheral = tPeripherals[n]
|
||||||
print( sPeripheral .. " (" .. peripheral.getType( sPeripheral ) .. ")" )
|
print( sPeripheral .. " (" .. peripheral.getType( sPeripheral ) .. ")" )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "None" )
|
print( "None" )
|
||||||
end
|
end
|
||||||
|
@ -648,4 +648,4 @@ end
|
|||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
local bAll = false
|
local bAll = false
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 0 and tArgs[1] == "all" then
|
if #tArgs > 0 and tArgs[1] == "all" then
|
||||||
bAll = true
|
bAll = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local tPrograms = shell.programs( bAll )
|
local tPrograms = shell.programs( bAll )
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
term.setTextColour( colours.yellow )
|
term.setTextColour( colours.yellow )
|
||||||
end
|
end
|
||||||
print( "Goodbye" )
|
print( "Goodbye" )
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
|
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usages:" )
|
print( "Usages:" )
|
||||||
print( "chat host <hostname>" )
|
print( "chat host <hostname>" )
|
||||||
print( "chat join <hostname> <nickname>" )
|
print( "chat join <hostname> <nickname>" )
|
||||||
end
|
end
|
||||||
|
|
||||||
local sOpenedModem = nil
|
local sOpenedModem = nil
|
||||||
@ -32,11 +32,11 @@ end
|
|||||||
-- Colours
|
-- Colours
|
||||||
local highlightColour, textColour
|
local highlightColour, textColour
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
highlightColour = colours.yellow
|
highlightColour = colours.yellow
|
||||||
else
|
else
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
highlightColour = colours.white
|
highlightColour = colours.white
|
||||||
end
|
end
|
||||||
|
|
||||||
local sCommand = tArgs[1]
|
local sCommand = tArgs[1]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 2 then
|
if #tArgs < 2 then
|
||||||
print( "Usage: rename <source> <destination>" )
|
print( "Usage: rename <source> <destination>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sSource = shell.resolve( tArgs[1] )
|
local sSource = shell.resolve( tArgs[1] )
|
||||||
|
@ -1,42 +1,42 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs == 0 then
|
if #tArgs == 0 then
|
||||||
-- "set"
|
-- "set"
|
||||||
for n,sName in ipairs( settings.getNames() ) do
|
for n,sName in ipairs( settings.getNames() ) do
|
||||||
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
|
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif #tArgs == 1 then
|
elseif #tArgs == 1 then
|
||||||
-- "set foo"
|
-- "set foo"
|
||||||
local sName = tArgs[1]
|
local sName = tArgs[1]
|
||||||
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
|
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
|
||||||
|
|
||||||
else
|
else
|
||||||
-- "set foo bar"
|
-- "set foo bar"
|
||||||
local sName = tArgs[1]
|
local sName = tArgs[1]
|
||||||
local sValue = tArgs[2]
|
local sValue = tArgs[2]
|
||||||
local value
|
local value
|
||||||
if sValue == "true" then
|
if sValue == "true" then
|
||||||
value = true
|
value = true
|
||||||
elseif sValue == "false" then
|
elseif sValue == "false" then
|
||||||
value = false
|
value = false
|
||||||
elseif sValue == "nil" then
|
elseif sValue == "nil" then
|
||||||
value = nil
|
value = nil
|
||||||
elseif tonumber(sValue) then
|
elseif tonumber(sValue) then
|
||||||
value = tonumber(sValue)
|
value = tonumber(sValue)
|
||||||
else
|
else
|
||||||
value = sValue
|
value = sValue
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldValue = settings.get( sValue )
|
local oldValue = settings.get( sValue )
|
||||||
if value ~= nil then
|
if value ~= nil then
|
||||||
settings.set( sName, value )
|
settings.set( sName, value )
|
||||||
print( textutils.serialize(sName) .. " set to " .. textutils.serialize(value) )
|
print( textutils.serialize(sName) .. " set to " .. textutils.serialize(value) )
|
||||||
else
|
else
|
||||||
settings.unset( sName )
|
settings.unset( sName )
|
||||||
print( textutils.serialize(sName) .. " unset" )
|
print( textutils.serialize(sName) .. " unset" )
|
||||||
end
|
end
|
||||||
if value ~= oldValue then
|
if value ~= oldValue then
|
||||||
settings.save( ".settings" )
|
settings.save( ".settings" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,56 +16,56 @@ local tProgramStack = {}
|
|||||||
|
|
||||||
local shell = {}
|
local shell = {}
|
||||||
local tEnv = {
|
local tEnv = {
|
||||||
[ "shell" ] = shell,
|
[ "shell" ] = shell,
|
||||||
[ "multishell" ] = multishell,
|
[ "multishell" ] = multishell,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Colours
|
-- Colours
|
||||||
local promptColour, textColour, bgColour
|
local promptColour, textColour, bgColour
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
promptColour = colours.yellow
|
promptColour = colours.yellow
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
bgColour = colours.black
|
bgColour = colours.black
|
||||||
else
|
else
|
||||||
promptColour = colours.white
|
promptColour = colours.white
|
||||||
textColour = colours.white
|
textColour = colours.white
|
||||||
bgColour = colours.black
|
bgColour = colours.black
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run( _sCommand, ... )
|
local function run( _sCommand, ... )
|
||||||
local sPath = shell.resolveProgram( _sCommand )
|
local sPath = shell.resolveProgram( _sCommand )
|
||||||
if sPath ~= nil then
|
if sPath ~= nil then
|
||||||
tProgramStack[#tProgramStack + 1] = sPath
|
tProgramStack[#tProgramStack + 1] = sPath
|
||||||
if multishell then
|
if multishell then
|
||||||
local sTitle = fs.getName( sPath )
|
local sTitle = fs.getName( sPath )
|
||||||
if sTitle:sub(-4) == ".lua" then
|
if sTitle:sub(-4) == ".lua" then
|
||||||
sTitle = sTitle:sub(1,-5)
|
sTitle = sTitle:sub(1,-5)
|
||||||
end
|
end
|
||||||
multishell.setTitle( multishell.getCurrent(), sTitle )
|
multishell.setTitle( multishell.getCurrent(), sTitle )
|
||||||
end
|
end
|
||||||
local result = os.run( tEnv, sPath, ... )
|
local result = os.run( tEnv, sPath, ... )
|
||||||
tProgramStack[#tProgramStack] = nil
|
tProgramStack[#tProgramStack] = nil
|
||||||
if multishell then
|
if multishell then
|
||||||
if #tProgramStack > 0 then
|
if #tProgramStack > 0 then
|
||||||
local sTitle = fs.getName( tProgramStack[#tProgramStack] )
|
local sTitle = fs.getName( tProgramStack[#tProgramStack] )
|
||||||
if sTitle:sub(-4) == ".lua" then
|
if sTitle:sub(-4) == ".lua" then
|
||||||
sTitle = sTitle:sub(1,-5)
|
sTitle = sTitle:sub(1,-5)
|
||||||
end
|
end
|
||||||
multishell.setTitle( multishell.getCurrent(), sTitle )
|
multishell.setTitle( multishell.getCurrent(), sTitle )
|
||||||
else
|
else
|
||||||
multishell.setTitle( multishell.getCurrent(), "shell" )
|
multishell.setTitle( multishell.getCurrent(), "shell" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
else
|
else
|
||||||
printError( "No such program" )
|
printError( "No such program" )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tokenise( ... )
|
local function tokenise( ... )
|
||||||
local sLine = table.concat( { ... }, " " )
|
local sLine = table.concat( { ... }, " " )
|
||||||
local tWords = {}
|
local tWords = {}
|
||||||
local bQuoted = false
|
local bQuoted = false
|
||||||
for match in string.gmatch( sLine .. "\"", "(.-)\"" ) do
|
for match in string.gmatch( sLine .. "\"", "(.-)\"" ) do
|
||||||
if bQuoted then
|
if bQuoted then
|
||||||
@ -82,12 +82,12 @@ end
|
|||||||
|
|
||||||
-- Install shell API
|
-- Install shell API
|
||||||
function shell.run( ... )
|
function shell.run( ... )
|
||||||
local tWords = tokenise( ... )
|
local tWords = tokenise( ... )
|
||||||
local sCommand = tWords[1]
|
local sCommand = tWords[1]
|
||||||
if sCommand then
|
if sCommand then
|
||||||
return run( sCommand, table.unpack( tWords, 2 ) )
|
return run( sCommand, table.unpack( tWords, 2 ) )
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.exit()
|
function shell.exit()
|
||||||
@ -95,28 +95,28 @@ function shell.exit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.dir()
|
function shell.dir()
|
||||||
return sDir
|
return sDir
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.setDir( _sDir )
|
function shell.setDir( _sDir )
|
||||||
sDir = _sDir
|
sDir = _sDir
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.path()
|
function shell.path()
|
||||||
return sPath
|
return sPath
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.setPath( _sPath )
|
function shell.setPath( _sPath )
|
||||||
sPath = _sPath
|
sPath = _sPath
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.resolve( _sPath )
|
function shell.resolve( _sPath )
|
||||||
local sStartChar = string.sub( _sPath, 1, 1 )
|
local sStartChar = string.sub( _sPath, 1, 1 )
|
||||||
if sStartChar == "/" or sStartChar == "\\" then
|
if sStartChar == "/" or sStartChar == "\\" then
|
||||||
return fs.combine( "", _sPath )
|
return fs.combine( "", _sPath )
|
||||||
else
|
else
|
||||||
return fs.combine( sDir, _sPath )
|
return fs.combine( sDir, _sPath )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pathWithExtension( _sPath, _sExt )
|
local function pathWithExtension( _sPath, _sExt )
|
||||||
@ -130,77 +130,77 @@ local function pathWithExtension( _sPath, _sExt )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.resolveProgram( _sCommand )
|
function shell.resolveProgram( _sCommand )
|
||||||
-- Substitute aliases firsts
|
-- Substitute aliases firsts
|
||||||
if tAliases[ _sCommand ] ~= nil then
|
if tAliases[ _sCommand ] ~= nil then
|
||||||
_sCommand = tAliases[ _sCommand ]
|
_sCommand = tAliases[ _sCommand ]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If the path is a global path, use it directly
|
-- If the path is a global path, use it directly
|
||||||
local sStartChar = string.sub( _sCommand, 1, 1 )
|
local sStartChar = string.sub( _sCommand, 1, 1 )
|
||||||
if sStartChar == "/" or sStartChar == "\\" then
|
if sStartChar == "/" or sStartChar == "\\" then
|
||||||
local sPath = fs.combine( "", _sCommand )
|
local sPath = fs.combine( "", _sCommand )
|
||||||
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
||||||
return sPath
|
return sPath
|
||||||
else
|
else
|
||||||
local sPathLua = pathWithExtension( sPath, "lua" )
|
local sPathLua = pathWithExtension( sPath, "lua" )
|
||||||
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
|
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
|
||||||
return sPathLua
|
return sPathLua
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Otherwise, look on the path variable
|
-- Otherwise, look on the path variable
|
||||||
for sPath in string.gmatch(sPath, "[^:]+") do
|
for sPath in string.gmatch(sPath, "[^:]+") do
|
||||||
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
|
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
|
||||||
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
||||||
return sPath
|
return sPath
|
||||||
else
|
else
|
||||||
local sPathLua = pathWithExtension( sPath, "lua" )
|
local sPathLua = pathWithExtension( sPath, "lua" )
|
||||||
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
|
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
|
||||||
return sPathLua
|
return sPathLua
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Not found
|
-- Not found
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.programs( _bIncludeHidden )
|
function shell.programs( _bIncludeHidden )
|
||||||
local tItems = {}
|
local tItems = {}
|
||||||
|
|
||||||
-- Add programs from the path
|
-- Add programs from the path
|
||||||
for sPath in string.gmatch(sPath, "[^:]+") do
|
for sPath in string.gmatch(sPath, "[^:]+") do
|
||||||
sPath = shell.resolve( sPath )
|
sPath = shell.resolve( sPath )
|
||||||
if fs.isDir( sPath ) then
|
if fs.isDir( sPath ) then
|
||||||
local tList = fs.list( sPath )
|
local tList = fs.list( sPath )
|
||||||
for n=1,#tList do
|
for n=1,#tList do
|
||||||
local sFile = tList[n]
|
local sFile = tList[n]
|
||||||
if not fs.isDir( fs.combine( sPath, sFile ) ) and
|
if not fs.isDir( fs.combine( sPath, sFile ) ) and
|
||||||
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
|
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
|
||||||
if #sFile > 4 and sFile:sub(-4) == ".lua" then
|
if #sFile > 4 and sFile:sub(-4) == ".lua" then
|
||||||
sFile = sFile:sub(1,-5)
|
sFile = sFile:sub(1,-5)
|
||||||
end
|
end
|
||||||
tItems[ sFile ] = true
|
tItems[ sFile ] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sort and return
|
-- Sort and return
|
||||||
local tItemList = {}
|
local tItemList = {}
|
||||||
for sItem, b in pairs( tItems ) do
|
for sItem, b in pairs( tItems ) do
|
||||||
table.insert( tItemList, sItem )
|
table.insert( tItemList, sItem )
|
||||||
end
|
end
|
||||||
table.sort( tItemList )
|
table.sort( tItemList )
|
||||||
return tItemList
|
return tItemList
|
||||||
end
|
end
|
||||||
|
|
||||||
local function completeProgram( sLine )
|
local function completeProgram( sLine )
|
||||||
if #sLine > 0 and string.sub( sLine, 1, 1 ) == "/" then
|
if #sLine > 0 and string.sub( sLine, 1, 1 ) == "/" then
|
||||||
-- Add programs from the root
|
-- Add programs from the root
|
||||||
return fs.complete( sLine, "", true, false )
|
return fs.complete( sLine, "", true, false )
|
||||||
|
|
||||||
else
|
else
|
||||||
local tResults = {}
|
local tResults = {}
|
||||||
@ -277,7 +277,7 @@ function shell.complete( sLine )
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.completeProgram( sProgram )
|
function shell.completeProgram( sProgram )
|
||||||
@ -295,27 +295,27 @@ function shell.getCompletionInfo()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.getRunningProgram()
|
function shell.getRunningProgram()
|
||||||
if #tProgramStack > 0 then
|
if #tProgramStack > 0 then
|
||||||
return tProgramStack[#tProgramStack]
|
return tProgramStack[#tProgramStack]
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.setAlias( _sCommand, _sProgram )
|
function shell.setAlias( _sCommand, _sProgram )
|
||||||
tAliases[ _sCommand ] = _sProgram
|
tAliases[ _sCommand ] = _sProgram
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.clearAlias( _sCommand )
|
function shell.clearAlias( _sCommand )
|
||||||
tAliases[ _sCommand ] = nil
|
tAliases[ _sCommand ] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.aliases()
|
function shell.aliases()
|
||||||
-- Copy aliases
|
-- Copy aliases
|
||||||
local tCopy = {}
|
local tCopy = {}
|
||||||
for sAlias, sCommand in pairs( tAliases ) do
|
for sAlias, sCommand in pairs( tAliases ) do
|
||||||
tCopy[sAlias] = sCommand
|
tCopy[sAlias] = sCommand
|
||||||
end
|
end
|
||||||
return tCopy
|
return tCopy
|
||||||
end
|
end
|
||||||
|
|
||||||
if multishell then
|
if multishell then
|
||||||
@ -323,8 +323,8 @@ if multishell then
|
|||||||
local tWords = tokenise( ... )
|
local tWords = tokenise( ... )
|
||||||
local sCommand = tWords[1]
|
local sCommand = tWords[1]
|
||||||
if sCommand then
|
if sCommand then
|
||||||
local sPath = shell.resolveProgram( sCommand )
|
local sPath = shell.resolveProgram( sCommand )
|
||||||
if sPath == "rom/programs/shell.lua" then
|
if sPath == "rom/programs/shell.lua" then
|
||||||
return multishell.launch( tEnv, sPath, table.unpack( tWords, 2 ) )
|
return multishell.launch( tEnv, sPath, table.unpack( tWords, 2 ) )
|
||||||
elseif sPath ~= nil then
|
elseif sPath ~= nil then
|
||||||
return multishell.launch( tEnv, "rom/programs/shell.lua", sCommand, table.unpack( tWords, 2 ) )
|
return multishell.launch( tEnv, "rom/programs/shell.lua", sCommand, table.unpack( tWords, 2 ) )
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
term.setTextColour( colours.yellow )
|
term.setTextColour( colours.yellow )
|
||||||
end
|
end
|
||||||
print( "Goodbye" )
|
print( "Goodbye" )
|
||||||
term.setTextColour( colours.white )
|
term.setTextColour( colours.white )
|
||||||
|
@ -7,10 +7,10 @@ end
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
local nLimit = nil
|
local nLimit = nil
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: craft [number]" )
|
print( "Usage: craft [number]" )
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
nLimit = tonumber( tArgs[1] )
|
nLimit = tonumber( tArgs[1] )
|
||||||
end
|
end
|
||||||
|
|
||||||
local nCrafted = 0
|
local nCrafted = 0
|
||||||
|
@ -1,77 +1,77 @@
|
|||||||
|
|
||||||
local tMoves = {
|
local tMoves = {
|
||||||
function()
|
function()
|
||||||
turtle.up()
|
turtle.up()
|
||||||
turtle.down()
|
turtle.down()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.up()
|
turtle.up()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.down()
|
turtle.down()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.up()
|
turtle.up()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.down()
|
turtle.down()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.back()
|
turtle.back()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
textutils.slowWrite( "Preparing to get down." )
|
textutils.slowWrite( "Preparing to get down." )
|
||||||
@ -79,34 +79,34 @@ textutils.slowPrint( "..", 0.75 )
|
|||||||
|
|
||||||
local sAudio = nil
|
local sAudio = nil
|
||||||
for n,sName in pairs( peripheral.getNames() ) do
|
for n,sName in pairs( peripheral.getNames() ) do
|
||||||
if disk.hasAudio( sName ) then
|
if disk.hasAudio( sName ) then
|
||||||
disk.playAudio( sName )
|
disk.playAudio( sName )
|
||||||
print( "Jamming to "..disk.getAudioTitle( sName ) )
|
print( "Jamming to "..disk.getAudioTitle( sName ) )
|
||||||
sAudio = sName
|
sAudio = sName
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Press any key to stop the groove" )
|
print( "Press any key to stop the groove" )
|
||||||
|
|
||||||
local bEnd = false
|
local bEnd = false
|
||||||
parallel.waitForAll(
|
parallel.waitForAll(
|
||||||
function()
|
function()
|
||||||
while not bEnd do
|
while not bEnd do
|
||||||
local event, key = os.pullEvent("key")
|
local event, key = os.pullEvent("key")
|
||||||
if key ~= keys.escape then
|
if key ~= keys.escape then
|
||||||
bEnd = true
|
bEnd = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
while not bEnd do
|
while not bEnd do
|
||||||
local fnMove = tMoves[math.random(1,#tMoves)]
|
local fnMove = tMoves[math.random(1,#tMoves)]
|
||||||
fnMove()
|
fnMove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
if sAudio then
|
if sAudio then
|
||||||
disk.stopAudio( sAudio )
|
disk.stopAudio( sAudio )
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usage: equip <slot> <side>" )
|
print( "Usage: equip <slot> <side>" )
|
||||||
end
|
end
|
||||||
|
|
||||||
if #tArgs ~= 2 then
|
if #tArgs ~= 2 then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function equip( nSlot, fnEquipFunction )
|
local function equip( nSlot, fnEquipFunction )
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs ~= 1 then
|
if #tArgs ~= 1 then
|
||||||
print( "Usage: excavate <diameter>" )
|
print( "Usage: excavate <diameter>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Mine in a quarry pattern until we hit something we can't dig
|
-- Mine in a quarry pattern until we hit something we can't dig
|
||||||
local size = tonumber( tArgs[1] )
|
local size = tonumber( tArgs[1] )
|
||||||
if size < 1 then
|
if size < 1 then
|
||||||
print( "Excavate diameter must be positive" )
|
print( "Excavate diameter must be positive" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local depth = 0
|
local depth = 0
|
||||||
local unloaded = 0
|
local unloaded = 0
|
||||||
local collected = 0
|
local collected = 0
|
||||||
@ -23,257 +23,257 @@ local goTo -- Filled in further down
|
|||||||
local refuel -- Filled in further down
|
local refuel -- Filled in further down
|
||||||
|
|
||||||
local function unload( _bKeepOneFuelStack )
|
local function unload( _bKeepOneFuelStack )
|
||||||
print( "Unloading items..." )
|
print( "Unloading items..." )
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
local nCount = turtle.getItemCount(n)
|
local nCount = turtle.getItemCount(n)
|
||||||
if nCount > 0 then
|
if nCount > 0 then
|
||||||
turtle.select(n)
|
turtle.select(n)
|
||||||
local bDrop = true
|
local bDrop = true
|
||||||
if _bKeepOneFuelStack and turtle.refuel(0) then
|
if _bKeepOneFuelStack and turtle.refuel(0) then
|
||||||
bDrop = false
|
bDrop = false
|
||||||
_bKeepOneFuelStack = false
|
_bKeepOneFuelStack = false
|
||||||
end
|
end
|
||||||
if bDrop then
|
if bDrop then
|
||||||
turtle.drop()
|
turtle.drop()
|
||||||
unloaded = unloaded + nCount
|
unloaded = unloaded + nCount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
collected = 0
|
collected = 0
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function returnSupplies()
|
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..." )
|
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
|
if not refuel( fuelNeeded ) then
|
||||||
unload( true )
|
unload( true )
|
||||||
print( "Waiting for fuel" )
|
print( "Waiting for fuel" )
|
||||||
while not refuel( fuelNeeded ) do
|
while not refuel( fuelNeeded ) do
|
||||||
os.pullEvent( "turtle_inventory" )
|
os.pullEvent( "turtle_inventory" )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
unload( true )
|
unload( true )
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Resuming mining..." )
|
print( "Resuming mining..." )
|
||||||
goTo( x,y,z,xd,zd )
|
goTo( x,y,z,xd,zd )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function collect()
|
local function collect()
|
||||||
local bFull = true
|
local bFull = true
|
||||||
local nTotalItems = 0
|
local nTotalItems = 0
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
local nCount = turtle.getItemCount(n)
|
local nCount = turtle.getItemCount(n)
|
||||||
if nCount == 0 then
|
if nCount == 0 then
|
||||||
bFull = false
|
bFull = false
|
||||||
end
|
end
|
||||||
nTotalItems = nTotalItems + nCount
|
nTotalItems = nTotalItems + nCount
|
||||||
end
|
end
|
||||||
|
|
||||||
if nTotalItems > collected then
|
if nTotalItems > collected then
|
||||||
collected = nTotalItems
|
collected = nTotalItems
|
||||||
if math.fmod(collected + unloaded, 50) == 0 then
|
if math.fmod(collected + unloaded, 50) == 0 then
|
||||||
print( "Mined "..(collected + unloaded).." items." )
|
print( "Mined "..(collected + unloaded).." items." )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if bFull then
|
if bFull then
|
||||||
print( "No empty slots left." )
|
print( "No empty slots left." )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function refuel( ammount )
|
function refuel( ammount )
|
||||||
local fuelLevel = turtle.getFuelLevel()
|
local fuelLevel = turtle.getFuelLevel()
|
||||||
if fuelLevel == "unlimited" then
|
if fuelLevel == "unlimited" then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local needed = ammount or (xPos + zPos + depth + 2)
|
local needed = ammount or (xPos + zPos + depth + 2)
|
||||||
if turtle.getFuelLevel() < needed then
|
if turtle.getFuelLevel() < needed then
|
||||||
local fueled = false
|
local fueled = false
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
if turtle.getItemCount(n) > 0 then
|
if turtle.getItemCount(n) > 0 then
|
||||||
turtle.select(n)
|
turtle.select(n)
|
||||||
if turtle.refuel(1) then
|
if turtle.refuel(1) then
|
||||||
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
|
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
|
||||||
turtle.refuel(1)
|
turtle.refuel(1)
|
||||||
end
|
end
|
||||||
if turtle.getFuelLevel() >= needed then
|
if turtle.getFuelLevel() >= needed then
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryForwards()
|
local function tryForwards()
|
||||||
if not refuel() then
|
if not refuel() then
|
||||||
print( "Not enough Fuel" )
|
print( "Not enough Fuel" )
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
|
|
||||||
while not turtle.forward() do
|
while not turtle.forward() do
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
if turtle.dig() then
|
if turtle.dig() then
|
||||||
if not collect() then
|
if not collect() then
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif turtle.attack() then
|
elseif turtle.attack() then
|
||||||
if not collect() then
|
if not collect() then
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
xPos = xPos + xDir
|
xPos = xPos + xDir
|
||||||
zPos = zPos + zDir
|
zPos = zPos + zDir
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryDown()
|
local function tryDown()
|
||||||
if not refuel() then
|
if not refuel() then
|
||||||
print( "Not enough Fuel" )
|
print( "Not enough Fuel" )
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
|
|
||||||
while not turtle.down() do
|
while not turtle.down() do
|
||||||
if turtle.detectDown() then
|
if turtle.detectDown() then
|
||||||
if turtle.digDown() then
|
if turtle.digDown() then
|
||||||
if not collect() then
|
if not collect() then
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif turtle.attackDown() then
|
elseif turtle.attackDown() then
|
||||||
if not collect() then
|
if not collect() then
|
||||||
returnSupplies()
|
returnSupplies()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
depth = depth + 1
|
depth = depth + 1
|
||||||
if math.fmod( depth, 10 ) == 0 then
|
if math.fmod( depth, 10 ) == 0 then
|
||||||
print( "Descended "..depth.." metres." )
|
print( "Descended "..depth.." metres." )
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function turnLeft()
|
local function turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
xDir, zDir = -zDir, xDir
|
xDir, zDir = -zDir, xDir
|
||||||
end
|
end
|
||||||
|
|
||||||
local function turnRight()
|
local function turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
xDir, zDir = zDir, -xDir
|
xDir, zDir = zDir, -xDir
|
||||||
end
|
end
|
||||||
|
|
||||||
function goTo( x, y, z, xd, zd )
|
function goTo( x, y, z, xd, zd )
|
||||||
while depth > y do
|
while depth > y do
|
||||||
if turtle.up() then
|
if turtle.up() then
|
||||||
depth = depth - 1
|
depth = depth - 1
|
||||||
elseif turtle.digUp() or turtle.attackUp() then
|
elseif turtle.digUp() or turtle.attackUp() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if xPos > x then
|
if xPos > x then
|
||||||
while xDir ~= -1 do
|
while xDir ~= -1 do
|
||||||
turnLeft()
|
turnLeft()
|
||||||
end
|
end
|
||||||
while xPos > x do
|
while xPos > x do
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
xPos = xPos - 1
|
xPos = xPos - 1
|
||||||
elseif turtle.dig() or turtle.attack() then
|
elseif turtle.dig() or turtle.attack() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif xPos < x then
|
elseif xPos < x then
|
||||||
while xDir ~= 1 do
|
while xDir ~= 1 do
|
||||||
turnLeft()
|
turnLeft()
|
||||||
end
|
end
|
||||||
while xPos < x do
|
while xPos < x do
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
xPos = xPos + 1
|
xPos = xPos + 1
|
||||||
elseif turtle.dig() or turtle.attack() then
|
elseif turtle.dig() or turtle.attack() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if zPos > z then
|
if zPos > z then
|
||||||
while zDir ~= -1 do
|
while zDir ~= -1 do
|
||||||
turnLeft()
|
turnLeft()
|
||||||
end
|
end
|
||||||
while zPos > z do
|
while zPos > z do
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
zPos = zPos - 1
|
zPos = zPos - 1
|
||||||
elseif turtle.dig() or turtle.attack() then
|
elseif turtle.dig() or turtle.attack() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif zPos < z then
|
elseif zPos < z then
|
||||||
while zDir ~= 1 do
|
while zDir ~= 1 do
|
||||||
turnLeft()
|
turnLeft()
|
||||||
end
|
end
|
||||||
while zPos < z do
|
while zPos < z do
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
zPos = zPos + 1
|
zPos = zPos + 1
|
||||||
elseif turtle.dig() or turtle.attack() then
|
elseif turtle.dig() or turtle.attack() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
while depth < y do
|
while depth < y do
|
||||||
if turtle.down() then
|
if turtle.down() then
|
||||||
depth = depth + 1
|
depth = depth + 1
|
||||||
elseif turtle.digDown() or turtle.attackDown() then
|
elseif turtle.digDown() or turtle.attackDown() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
while zDir ~= zd or xDir ~= xd do
|
while zDir ~= zd or xDir ~= xd do
|
||||||
turnLeft()
|
turnLeft()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not refuel() then
|
if not refuel() then
|
||||||
print( "Out of Fuel" )
|
print( "Out of Fuel" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Excavating..." )
|
print( "Excavating..." )
|
||||||
@ -281,61 +281,61 @@ print( "Excavating..." )
|
|||||||
local reseal = false
|
local reseal = false
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
if turtle.digDown() then
|
if turtle.digDown() then
|
||||||
reseal = true
|
reseal = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local alternate = 0
|
local alternate = 0
|
||||||
local done = false
|
local done = false
|
||||||
while not done do
|
while not done do
|
||||||
for n=1,size do
|
for n=1,size do
|
||||||
for m=1,size-1 do
|
for m=1,size-1 do
|
||||||
if not tryForwards() then
|
if not tryForwards() then
|
||||||
done = true
|
done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if done then
|
if done then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if n<size then
|
if n<size then
|
||||||
if math.fmod(n + alternate,2) == 0 then
|
if math.fmod(n + alternate,2) == 0 then
|
||||||
turnLeft()
|
turnLeft()
|
||||||
if not tryForwards() then
|
if not tryForwards() then
|
||||||
done = true
|
done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
turnLeft()
|
turnLeft()
|
||||||
else
|
else
|
||||||
turnRight()
|
turnRight()
|
||||||
if not tryForwards() then
|
if not tryForwards() then
|
||||||
done = true
|
done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
turnRight()
|
turnRight()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if done then
|
if done then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if size > 1 then
|
if size > 1 then
|
||||||
if math.fmod(size,2) == 0 then
|
if math.fmod(size,2) == 0 then
|
||||||
turnRight()
|
turnRight()
|
||||||
else
|
else
|
||||||
if alternate == 0 then
|
if alternate == 0 then
|
||||||
turnLeft()
|
turnLeft()
|
||||||
else
|
else
|
||||||
turnRight()
|
turnRight()
|
||||||
end
|
end
|
||||||
alternate = 1 - alternate
|
alternate = 1 - alternate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not tryDown() then
|
if not tryDown() then
|
||||||
done = true
|
done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Returning to surface..." )
|
print( "Returning to surface..." )
|
||||||
@ -347,7 +347,7 @@ goTo( 0,0,0,0,1 )
|
|||||||
|
|
||||||
-- Seal the hole
|
-- Seal the hole
|
||||||
if reseal then
|
if reseal then
|
||||||
turtle.placeDown()
|
turtle.placeDown()
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Mined "..(collected + unloaded).." items total." )
|
print( "Mined "..(collected + unloaded).." items total." )
|
||||||
|
@ -1,53 +1,53 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: go <direction> <distance>" )
|
print( "Usage: go <direction> <distance>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tHandlers = {
|
local tHandlers = {
|
||||||
["fd"] = turtle.forward,
|
["fd"] = turtle.forward,
|
||||||
["forward"] = turtle.forward,
|
["forward"] = turtle.forward,
|
||||||
["forwards"] = turtle.forward,
|
["forwards"] = turtle.forward,
|
||||||
["bk"] = turtle.back,
|
["bk"] = turtle.back,
|
||||||
["back"] = turtle.back,
|
["back"] = turtle.back,
|
||||||
["up"] = turtle.up,
|
["up"] = turtle.up,
|
||||||
["dn"] = turtle.down,
|
["dn"] = turtle.down,
|
||||||
["down"] = turtle.down,
|
["down"] = turtle.down,
|
||||||
["lt"] = turtle.turnLeft,
|
["lt"] = turtle.turnLeft,
|
||||||
["left"] = turtle.turnLeft,
|
["left"] = turtle.turnLeft,
|
||||||
["rt"] = turtle.turnRight,
|
["rt"] = turtle.turnRight,
|
||||||
["right"] = turtle.turnRight,
|
["right"] = turtle.turnRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
local nArg = 1
|
local nArg = 1
|
||||||
while nArg <= #tArgs do
|
while nArg <= #tArgs do
|
||||||
local sDirection = tArgs[nArg]
|
local sDirection = tArgs[nArg]
|
||||||
local nDistance = 1
|
local nDistance = 1
|
||||||
if nArg < #tArgs then
|
if nArg < #tArgs then
|
||||||
local num = tonumber( tArgs[nArg + 1] )
|
local num = tonumber( tArgs[nArg + 1] )
|
||||||
if num then
|
if num then
|
||||||
nDistance = num
|
nDistance = num
|
||||||
nArg = nArg + 1
|
nArg = nArg + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
nArg = nArg + 1
|
nArg = nArg + 1
|
||||||
|
|
||||||
local fnHandler = tHandlers[string.lower(sDirection)]
|
local fnHandler = tHandlers[string.lower(sDirection)]
|
||||||
if fnHandler then
|
if fnHandler then
|
||||||
while nDistance > 0 do
|
while nDistance > 0 do
|
||||||
if fnHandler() then
|
if fnHandler() then
|
||||||
nDistance = nDistance - 1
|
nDistance = nDistance - 1
|
||||||
elseif turtle.getFuelLevel() == 0 then
|
elseif turtle.getFuelLevel() == 0 then
|
||||||
print( "Out of fuel" )
|
print( "Out of fuel" )
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "No such direction: "..sDirection )
|
print( "No such direction: "..sDirection )
|
||||||
print( "Try: forward, back, up, down" )
|
print( "Try: forward, back, up, down" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,28 +2,28 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
local nLimit = 1
|
local nLimit = 1
|
||||||
if #tArgs > 1 then
|
if #tArgs > 1 then
|
||||||
print( "Usage: refuel [number]" )
|
print( "Usage: refuel [number]" )
|
||||||
return
|
return
|
||||||
elseif #tArgs > 0 then
|
elseif #tArgs > 0 then
|
||||||
if tArgs[1] == "all" then
|
if tArgs[1] == "all" then
|
||||||
nLimit = 64 * 16
|
nLimit = 64 * 16
|
||||||
else
|
else
|
||||||
nLimit = tonumber( tArgs[1] )
|
nLimit = tonumber( tArgs[1] )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if turtle.getFuelLevel() ~= "unlimited" then
|
if turtle.getFuelLevel() ~= "unlimited" then
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
local nCount = turtle.getItemCount(n)
|
local nCount = turtle.getItemCount(n)
|
||||||
if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
|
if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
|
||||||
local nBurn = math.min( nLimit, nCount )
|
local nBurn = math.min( nLimit, nCount )
|
||||||
turtle.select( n )
|
turtle.select( n )
|
||||||
if turtle.refuel( nBurn ) then
|
if turtle.refuel( nBurn ) then
|
||||||
local nNewCount = turtle.getItemCount(n)
|
local nNewCount = turtle.getItemCount(n)
|
||||||
nLimit = nLimit - (nCount - nNewCount)
|
nLimit = nLimit - (nCount - nNewCount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print( "Fuel level is "..turtle.getFuelLevel() )
|
print( "Fuel level is "..turtle.getFuelLevel() )
|
||||||
if turtle.getFuelLevel() == turtle.getFuelLimit() then
|
if turtle.getFuelLevel() == turtle.getFuelLimit() then
|
||||||
print( "Fuel limit reached" )
|
print( "Fuel limit reached" )
|
||||||
|
@ -1,165 +1,165 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs ~= 1 then
|
if #tArgs ~= 1 then
|
||||||
print( "Usage: tunnel <length>" )
|
print( "Usage: tunnel <length>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Mine in a quarry pattern until we hit something we can't dig
|
-- Mine in a quarry pattern until we hit something we can't dig
|
||||||
local length = tonumber( tArgs[1] )
|
local length = tonumber( tArgs[1] )
|
||||||
if length < 1 then
|
if length < 1 then
|
||||||
print( "Tunnel length must be positive" )
|
print( "Tunnel length must be positive" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local depth = 0
|
local depth = 0
|
||||||
local collected = 0
|
local collected = 0
|
||||||
|
|
||||||
local function collect()
|
local function collect()
|
||||||
collected = collected + 1
|
collected = collected + 1
|
||||||
if math.fmod(collected, 25) == 0 then
|
if math.fmod(collected, 25) == 0 then
|
||||||
print( "Mined "..collected.." items." )
|
print( "Mined "..collected.." items." )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryDig()
|
local function tryDig()
|
||||||
while turtle.detect() do
|
while turtle.detect() do
|
||||||
if turtle.dig() then
|
if turtle.dig() then
|
||||||
collect()
|
collect()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryDigUp()
|
local function tryDigUp()
|
||||||
while turtle.detectUp() do
|
while turtle.detectUp() do
|
||||||
if turtle.digUp() then
|
if turtle.digUp() then
|
||||||
collect()
|
collect()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryDigDown()
|
local function tryDigDown()
|
||||||
while turtle.detectDown() do
|
while turtle.detectDown() do
|
||||||
if turtle.digDown() then
|
if turtle.digDown() then
|
||||||
collect()
|
collect()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function refuel()
|
local function refuel()
|
||||||
local fuelLevel = turtle.getFuelLevel()
|
local fuelLevel = turtle.getFuelLevel()
|
||||||
if fuelLevel == "unlimited" or fuelLevel > 0 then
|
if fuelLevel == "unlimited" or fuelLevel > 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryRefuel()
|
local function tryRefuel()
|
||||||
for n=1,16 do
|
for n=1,16 do
|
||||||
if turtle.getItemCount(n) > 0 then
|
if turtle.getItemCount(n) > 0 then
|
||||||
turtle.select(n)
|
turtle.select(n)
|
||||||
if turtle.refuel(1) then
|
if turtle.refuel(1) then
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not tryRefuel() then
|
if not tryRefuel() then
|
||||||
print( "Add more fuel to continue." )
|
print( "Add more fuel to continue." )
|
||||||
while not tryRefuel() do
|
while not tryRefuel() do
|
||||||
os.pullEvent( "turtle_inventory" )
|
os.pullEvent( "turtle_inventory" )
|
||||||
end
|
end
|
||||||
print( "Resuming Tunnel." )
|
print( "Resuming Tunnel." )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryUp()
|
local function tryUp()
|
||||||
refuel()
|
refuel()
|
||||||
while not turtle.up() do
|
while not turtle.up() do
|
||||||
if turtle.detectUp() then
|
if turtle.detectUp() then
|
||||||
if not tryDigUp() then
|
if not tryDigUp() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif turtle.attackUp() then
|
elseif turtle.attackUp() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryDown()
|
local function tryDown()
|
||||||
refuel()
|
refuel()
|
||||||
while not turtle.down() do
|
while not turtle.down() do
|
||||||
if turtle.detectDown() then
|
if turtle.detectDown() then
|
||||||
if not tryDigDown() then
|
if not tryDigDown() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif turtle.attackDown() then
|
elseif turtle.attackDown() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryForward()
|
local function tryForward()
|
||||||
refuel()
|
refuel()
|
||||||
while not turtle.forward() do
|
while not turtle.forward() do
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
if not tryDig() then
|
if not tryDig() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif turtle.attack() then
|
elseif turtle.attack() then
|
||||||
collect()
|
collect()
|
||||||
else
|
else
|
||||||
sleep( 0.5 )
|
sleep( 0.5 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "Tunnelling..." )
|
print( "Tunnelling..." )
|
||||||
|
|
||||||
for n=1,length do
|
for n=1,length do
|
||||||
turtle.placeDown()
|
turtle.placeDown()
|
||||||
tryDigUp()
|
tryDigUp()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
tryDig()
|
tryDig()
|
||||||
tryUp()
|
tryUp()
|
||||||
tryDig()
|
tryDig()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
tryDig()
|
tryDig()
|
||||||
tryDown()
|
tryDown()
|
||||||
tryDig()
|
tryDig()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
|
|
||||||
if n<length then
|
if n<length then
|
||||||
tryDig()
|
tryDig()
|
||||||
if not tryForward() then
|
if not tryForward() then
|
||||||
print( "Aborting Tunnel." )
|
print( "Aborting Tunnel." )
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "Tunnel complete." )
|
print( "Tunnel complete." )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -170,11 +170,11 @@ print( "Returning to start..." )
|
|||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
while depth > 0 do
|
while depth > 0 do
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
depth = depth - 1
|
depth = depth - 1
|
||||||
else
|
else
|
||||||
turtle.dig()
|
turtle.dig()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: turn <direction> <turns>" )
|
print( "Usage: turn <direction> <turns>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tHandlers = {
|
local tHandlers = {
|
||||||
["lt"] = turtle.turnLeft,
|
["lt"] = turtle.turnLeft,
|
||||||
["left"] = turtle.turnLeft,
|
["left"] = turtle.turnLeft,
|
||||||
["rt"] = turtle.turnRight,
|
["rt"] = turtle.turnRight,
|
||||||
["right"] = turtle.turnRight,
|
["right"] = turtle.turnRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
local nArg = 1
|
local nArg = 1
|
||||||
while nArg <= #tArgs do
|
while nArg <= #tArgs do
|
||||||
local sDirection = tArgs[nArg]
|
local sDirection = tArgs[nArg]
|
||||||
local nDistance = 1
|
local nDistance = 1
|
||||||
if nArg < #tArgs then
|
if nArg < #tArgs then
|
||||||
local num = tonumber( tArgs[nArg + 1] )
|
local num = tonumber( tArgs[nArg + 1] )
|
||||||
if num then
|
if num then
|
||||||
nDistance = num
|
nDistance = num
|
||||||
nArg = nArg + 1
|
nArg = nArg + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
nArg = nArg + 1
|
nArg = nArg + 1
|
||||||
|
|
||||||
local fnHandler = tHandlers[string.lower(sDirection)]
|
local fnHandler = tHandlers[string.lower(sDirection)]
|
||||||
if fnHandler then
|
if fnHandler then
|
||||||
for n=1,nDistance do
|
for n=1,nDistance do
|
||||||
fnHandler( nArg )
|
fnHandler( nArg )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "No such direction: "..sDirection )
|
print( "No such direction: "..sDirection )
|
||||||
print( "Try: left, right" )
|
print( "Try: left, right" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
local function printUsage()
|
local function printUsage()
|
||||||
print( "Usage: unequip <side>" )
|
print( "Usage: unequip <side>" )
|
||||||
end
|
end
|
||||||
|
|
||||||
if #tArgs ~= 1 then
|
if #tArgs ~= 1 then
|
||||||
printUsage()
|
printUsage()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function unequip( fnEquipFunction )
|
local function unequip( fnEquipFunction )
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs < 1 then
|
if #tArgs < 1 then
|
||||||
print( "Usage: type <path>" )
|
print( "Usage: type <path>" )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sPath = shell.resolve( tArgs[1] )
|
local sPath = shell.resolve( tArgs[1] )
|
||||||
if fs.exists( sPath ) then
|
if fs.exists( sPath ) then
|
||||||
if fs.isDir( sPath ) then
|
if fs.isDir( sPath ) then
|
||||||
print( "directory" )
|
print( "directory" )
|
||||||
else
|
else
|
||||||
print( "file" )
|
print( "file" )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print( "No such path" )
|
print( "No such path" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
-- Setup paths
|
-- Setup paths
|
||||||
local sPath = ".:/rom/programs"
|
local sPath = ".:/rom/programs"
|
||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
sPath = sPath..":/rom/programs/advanced"
|
sPath = sPath..":/rom/programs/advanced"
|
||||||
end
|
end
|
||||||
if turtle then
|
if turtle then
|
||||||
sPath = sPath..":/rom/programs/turtle"
|
sPath = sPath..":/rom/programs/turtle"
|
||||||
else
|
else
|
||||||
sPath = sPath..":/rom/programs/rednet:/rom/programs/fun"
|
sPath = sPath..":/rom/programs/rednet:/rom/programs/fun"
|
||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
sPath = sPath..":/rom/programs/fun/advanced"
|
sPath = sPath..":/rom/programs/fun/advanced"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pocket then
|
if pocket then
|
||||||
@ -19,7 +19,7 @@ if commands then
|
|||||||
sPath = sPath..":/rom/programs/command"
|
sPath = sPath..":/rom/programs/command"
|
||||||
end
|
end
|
||||||
if http then
|
if http then
|
||||||
sPath = sPath..":/rom/programs/http"
|
sPath = sPath..":/rom/programs/http"
|
||||||
end
|
end
|
||||||
shell.setPath( sPath )
|
shell.setPath( sPath )
|
||||||
help.setPath( "/rom/help" )
|
help.setPath( "/rom/help" )
|
||||||
@ -197,16 +197,16 @@ shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
|
|||||||
|
|
||||||
-- Run autorun files
|
-- Run autorun files
|
||||||
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
|
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
|
||||||
local tFiles = fs.list( "/rom/autorun" )
|
local tFiles = fs.list( "/rom/autorun" )
|
||||||
table.sort( tFiles )
|
table.sort( tFiles )
|
||||||
for n, sFile in ipairs( tFiles ) do
|
for n, sFile in ipairs( tFiles ) do
|
||||||
if string.sub( sFile, 1, 1 ) ~= "." then
|
if string.sub( sFile, 1, 1 ) ~= "." then
|
||||||
local sPath = "/rom/autorun/"..sFile
|
local sPath = "/rom/autorun/"..sFile
|
||||||
if not fs.isDir( sPath ) then
|
if not fs.isDir( sPath ) then
|
||||||
shell.run( sPath )
|
shell.run( sPath )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function findStartups( sBaseDir )
|
local function findStartups( sBaseDir )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user