1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-24 06:03:28 +00:00

Replaced tabs with spaces in all lua files

This commit is contained in:
Daniel Ratcliffe 2017-05-17 19:32:21 +01:00
parent b86708aaf8
commit f5edb32be9
46 changed files with 3613 additions and 3613 deletions

View File

@ -1,7 +1,7 @@
if not shell.openTab then
printError( "Requires multishell" )
return
printError( "Requires multishell" )
return
end
local tArgs = { ... }

View File

@ -1,7 +1,7 @@
if not shell.openTab then
printError( "Requires multishell" )
return
printError( "Requires multishell" )
return
end
local tArgs = { ... }

View File

@ -1,27 +1,27 @@
local tArgs = { ... }
if #tArgs > 2 then
print( "Usage: alias <alias> <program>" )
return
print( "Usage: alias <alias> <program>" )
return
end
local sAlias = tArgs[1]
local sProgram = tArgs[2]
if sAlias and sProgram then
-- Set alias
shell.setAlias( sAlias, sProgram )
-- Set alias
shell.setAlias( sAlias, sProgram )
elseif sAlias then
-- Clear alias
shell.clearAlias( sAlias )
-- Clear alias
shell.clearAlias( sAlias )
else
-- List aliases
local tAliases = shell.aliases()
local tList = {}
for sAlias, sCommand in pairs( tAliases ) do
table.insert( tList, sAlias )
end
table.sort( tList )
textutils.pagedTabulate( tList )
-- List aliases
local tAliases = shell.aliases()
local tList = {}
for sAlias, sCommand in pairs( tAliases ) do
table.insert( tList, sAlias )
end
table.sort( tList )
textutils.pagedTabulate( tList )
end

View File

@ -1,9 +1,9 @@
local tApis = {}
for k,v in pairs( _G ) do
if type(k) == "string" and type(v) == "table" and k ~= "_G" then
table.insert( tApis, k )
end
if type(k) == "string" and type(v) == "table" and k ~= "_G" then
table.insert( tApis, k )
end
end
table.insert( tApis, "shell" )
table.sort( tApis )

View File

@ -1,14 +1,14 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: cd <path>" )
return
print( "Usage: cd <path>" )
return
end
local sNewDir = shell.resolve( tArgs[1] )
if fs.isDir( sNewDir ) then
shell.setDir( sNewDir )
shell.setDir( sNewDir )
else
print( "Not a directory" )
return
print( "Not a directory" )
return
end

View File

@ -1,8 +1,8 @@
local tArgs = { ... }
if #tArgs < 2 then
print( "Usage: cp <source> <destination>" )
return
print( "Usage: cp <source> <destination>" )
return
end
local sSource = shell.resolve( tArgs[1] )
@ -21,4 +21,4 @@ if #tFiles > 0 then
end
else
printError( "No matching files" )
end
end

View File

@ -1,8 +1,8 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: rm <path>" )
return
print( "Usage: rm <path>" )
return
end
local sPath = shell.resolve( tArgs[1] )
@ -13,4 +13,4 @@ if #tFiles > 0 then
end
else
printError( "No matching files" )
end
end

View File

@ -3,19 +3,19 @@ local tArgs = { ... }
-- Get where a directory is mounted
local sPath = shell.dir()
if tArgs[1] ~= nil then
sPath = shell.resolve( tArgs[1] )
sPath = shell.resolve( tArgs[1] )
end
if fs.exists( sPath ) then
write( fs.getDrive( sPath ) .. " (" )
local nSpace = fs.getFreeSpace( sPath )
if nSpace >= 1000 * 1000 then
print( (math.floor( nSpace / (100 * 1000) ) / 10) .. "MB remaining)" )
elseif nSpace >= 1000 then
print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" )
else
print( nSpace .. "B remaining)" )
end
write( fs.getDrive( sPath ) .. " (" )
local nSpace = fs.getFreeSpace( sPath )
if nSpace >= 1000 * 1000 then
print( (math.floor( nSpace / (100 * 1000) ) / 10) .. "MB remaining)" )
elseif nSpace >= 1000 then
print( (math.floor( nSpace / 100 ) / 10) .. "KB remaining)" )
else
print( nSpace .. "B remaining)" )
end
else
print( "No such path" )
print( "No such path" )
end

View File

@ -2,8 +2,8 @@
-- Get arguments
local tArgs = { ... }
if #tArgs == 0 then
print( "Usage: eject <drive>" )
return
print( "Usage: eject <drive>" )
return
end
local sDrive = tArgs[1]
@ -11,8 +11,8 @@ local sDrive = tArgs[1]
-- Check the disk exists
local bPresent = disk.isPresent( sDrive )
if not bPresent then
print( "Nothing in "..sDrive.." drive" )
return
print( "Nothing in "..sDrive.." drive" )
return
end
disk.eject( sDrive )

View File

@ -27,21 +27,21 @@ local fMessage = "Press Ctrl to access menu"
-- Determine if we can even run this
if not term.isColour() then
print("Requires an Advanced Computer")
return
print("Requires an Advanced Computer")
return
end
-- Determines if the file exists, and can be edited on this computer
local tArgs = {...}
if #tArgs == 0 then
print("Usage: paint <path>")
return
print("Usage: paint <path>")
return
end
local sPath = shell.resolve(tArgs[1])
local bReadOnly = fs.isReadOnly(sPath)
if fs.exists(sPath) and fs.isDir(sPath) then
print("Cannot edit a directory.")
return
print("Cannot edit a directory.")
return
end
---------------
@ -56,327 +56,327 @@ local function getCanvasPixel( x, y )
end
--[[
Converts a colour value to a text character
params: colour = the number to convert to a hex value
returns: a string representing the chosen colour
Converts a colour value to a text character
params: colour = the number to convert to a hex value
returns: a string representing the chosen colour
]]
local function getCharOf( colour )
-- Incorrect values always convert to nil
if type(colour) == "number" then
local value = math.floor( math.log(colour) / math.log(2) ) + 1
if value >= 1 and value <= 16 then
return string.sub( "0123456789abcdef", value, value )
end
end
return " "
end
-- Incorrect values always convert to nil
if type(colour) == "number" then
local value = math.floor( math.log(colour) / math.log(2) ) + 1
if value >= 1 and value <= 16 then
return string.sub( "0123456789abcdef", value, value )
end
end
return " "
end
--[[
Converts a text character to colour value
params: char = the char (from string.byte) to convert to number
returns: the colour number of the hex value
Converts a text character to colour value
params: char = the char (from string.byte) to convert to number
returns: the colour number of the hex value
]]
local tColourLookup = {}
for n=1,16 do
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
end
local function getColourOf( char )
-- Values not in the hex table are transparent (canvas coloured)
return tColourLookup[char]
-- Values not in the hex table are transparent (canvas coloured)
return tColourLookup[char]
end
--[[
Loads the file into the canvas
params: path = the path of the file to open
returns: nil
Loads the file into the canvas
params: path = the path of the file to open
returns: nil
]]
local function load(path)
-- Load the file
if fs.exists(path) then
local file = fs.open(sPath, "r")
local sLine = file.readLine()
while sLine do
local line = {}
for x=1,w-2 do
line[x] = getColourOf( string.byte(sLine,x,x) )
end
table.insert( canvas, line )
sLine = file.readLine()
end
file.close()
end
-- Load the file
if fs.exists(path) then
local file = fs.open(sPath, "r")
local sLine = file.readLine()
while sLine do
local line = {}
for x=1,w-2 do
line[x] = getColourOf( string.byte(sLine,x,x) )
end
table.insert( canvas, line )
sLine = file.readLine()
end
file.close()
end
end
--[[
Saves the current canvas to file
params: path = the path of the file to save
returns: true if save was successful, false otherwise
Saves the current canvas to file
params: path = the path of the file to save
returns: true if save was successful, false otherwise
]]
local function save(path)
-- Open file
local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))
if not fs.exists(sDir) then
fs.makeDir(sDir)
end
local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))
if not fs.exists(sDir) then
fs.makeDir(sDir)
end
local file = fs.open( path, "w" )
if not file then
return false
end
local file = fs.open( path, "w" )
if not file then
return false
end
-- Encode (and trim)
local tLines = {}
local nLastLine = 0
for y=1,h-1 do
local sLine = ""
local nLastChar = 0
for x=1,w-2 do
local c = getCharOf( getCanvasPixel( x, y ) )
sLine = sLine .. c
if c ~= " " then
nLastChar = x
end
end
sLine = string.sub( sLine, 1, nLastChar )
tLines[y] = sLine
if string.len( sLine ) > 0 then
nLastLine = y
end
end
local tLines = {}
local nLastLine = 0
for y=1,h-1 do
local sLine = ""
local nLastChar = 0
for x=1,w-2 do
local c = getCharOf( getCanvasPixel( x, y ) )
sLine = sLine .. c
if c ~= " " then
nLastChar = x
end
end
sLine = string.sub( sLine, 1, nLastChar )
tLines[y] = sLine
if string.len( sLine ) > 0 then
nLastLine = y
end
end
-- Save out
for n=1,nLastLine do
file.writeLine( tLines[ n ] )
end
file.close()
return true
for n=1,nLastLine do
file.writeLine( tLines[ n ] )
end
file.close()
return true
end
--[[
Draws colour picker sidebar, the pallette and the footer
returns: nil
Draws colour picker sidebar, the pallette and the footer
returns: nil
]]
local function drawInterface()
-- Footer
term.setCursorPos(1, h)
term.setBackgroundColour(colours.black)
term.setTextColour(colours.yellow)
term.clearLine()
term.write(fMessage)
-- Colour Picker
for i=1,16 do
term.setCursorPos(w-1, i)
term.setBackgroundColour( 2^(i-1) )
term.write(" ")
end
-- Footer
term.setCursorPos(1, h)
term.setBackgroundColour(colours.black)
term.setTextColour(colours.yellow)
term.clearLine()
term.write(fMessage)
-- Colour Picker
for i=1,16 do
term.setCursorPos(w-1, i)
term.setBackgroundColour( 2^(i-1) )
term.write(" ")
end
term.setCursorPos(w-1, 17)
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127\127")
-- Left and Right Selected Colours
for i=18,18 do
term.setCursorPos(w-1, i)
if leftColour ~= nil then
term.setBackgroundColour( leftColour )
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127")
end
if rightColour ~= nil then
term.setBackgroundColour( rightColour )
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127")
end
end
term.setCursorPos(w-1, 17)
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127\127")
-- Left and Right Selected Colours
for i=18,18 do
term.setCursorPos(w-1, i)
if leftColour ~= nil then
term.setBackgroundColour( leftColour )
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127")
end
if rightColour ~= nil then
term.setBackgroundColour( rightColour )
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.write("\127")
end
end
-- Padding
term.setBackgroundColour( canvasColour )
for i=20,h-1 do
term.setCursorPos(w-1, i)
term.write(" ")
end
-- Padding
term.setBackgroundColour( canvasColour )
for i=20,h-1 do
term.setCursorPos(w-1, i)
term.write(" ")
end
end
--[[
Converts a single pixel of a single line of the canvas and draws it
returns: nil
Converts a single pixel of a single line of the canvas and draws it
returns: nil
]]
local function drawCanvasPixel( x, y )
local pixel = getCanvasPixel( x, y )
if pixel then
term.setBackgroundColour( pixel or canvasColour )
term.setCursorPos(x, y)
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.setCursorPos(x, y)
local pixel = getCanvasPixel( x, y )
if pixel then
term.setBackgroundColour( pixel or canvasColour )
term.setCursorPos(x, y)
term.write(" ")
else
term.setBackgroundColour( canvasColour )
term.setTextColour( colours.grey )
term.setCursorPos(x, y)
term.write("\127")
end
end
end
--[[
Converts each colour in a single line of the canvas and draws it
returns: nil
Converts each colour in a single line of the canvas and draws it
returns: nil
]]
local function drawCanvasLine( y )
for x = 1, w-2 do
drawCanvasPixel( x, y )
end
for x = 1, w-2 do
drawCanvasPixel( x, y )
end
end
--[[
Converts each colour in the canvas and draws it
returns: nil
Converts each colour in the canvas and draws it
returns: nil
]]
local function drawCanvas()
for y = 1, h-1 do
drawCanvasLine( y )
end
for y = 1, h-1 do
drawCanvasLine( y )
end
end
--[[
Draws menu options and handles input from within the menu.
returns: true if the program is to be exited; false otherwise
Draws menu options and handles input from within the menu.
returns: true if the program is to be exited; false otherwise
]]
local function accessMenu()
-- Selected menu option
local selection = 1
term.setBackgroundColour(colours.black)
while true do
-- Draw the menu
term.setCursorPos(1,h)
term.clearLine()
term.setTextColour(colours.white)
for k,v in pairs(mChoices) do
if selection==k then
term.setTextColour(colours.yellow)
local ox,_ = term.getCursorPos()
term.write("["..string.rep(" ",#v).."]")
term.setCursorPos(ox+1,h)
term.setTextColour(colours.white)
term.write(v)
term.setCursorPos(term.getCursorPos()+1,h)
else
term.write(" "..v.." ")
end
end
-- Handle input in the menu
local id,key = os.pullEvent("key")
if id == "key" then
-- S and E are shortcuts
if key == keys.s then
selection = 1
key = keys.enter
elseif key == keys.e then
selection = 2
key = keys.enter
end
if key == keys.right then
-- Move right
selection = selection + 1
if selection > #mChoices then
selection = 1
end
elseif key == keys.left and selection > 1 then
-- Move left
selection = selection - 1
if selection < 1 then
selection = #mChoices
end
elseif key == keys.enter then
-- Select an option
if mChoices[selection]=="Save" then
if bReadOnly then
fMessage = "Access Denied"
return false
end
local success = save(sPath)
if success then
fMessage = "Saved to "..sPath
else
fMessage = "Error saving to "..sPath
end
return false
elseif mChoices[selection]=="Exit" then
return true
end
elseif key == keys.leftCtrl or keys == keys.rightCtrl then
-- Cancel the menu
return false
end
end
end
-- Selected menu option
local selection = 1
term.setBackgroundColour(colours.black)
while true do
-- Draw the menu
term.setCursorPos(1,h)
term.clearLine()
term.setTextColour(colours.white)
for k,v in pairs(mChoices) do
if selection==k then
term.setTextColour(colours.yellow)
local ox,_ = term.getCursorPos()
term.write("["..string.rep(" ",#v).."]")
term.setCursorPos(ox+1,h)
term.setTextColour(colours.white)
term.write(v)
term.setCursorPos(term.getCursorPos()+1,h)
else
term.write(" "..v.." ")
end
end
-- Handle input in the menu
local id,key = os.pullEvent("key")
if id == "key" then
-- S and E are shortcuts
if key == keys.s then
selection = 1
key = keys.enter
elseif key == keys.e then
selection = 2
key = keys.enter
end
if key == keys.right then
-- Move right
selection = selection + 1
if selection > #mChoices then
selection = 1
end
elseif key == keys.left and selection > 1 then
-- Move left
selection = selection - 1
if selection < 1 then
selection = #mChoices
end
elseif key == keys.enter then
-- Select an option
if mChoices[selection]=="Save" then
if bReadOnly then
fMessage = "Access Denied"
return false
end
local success = save(sPath)
if success then
fMessage = "Saved to "..sPath
else
fMessage = "Error saving to "..sPath
end
return false
elseif mChoices[selection]=="Exit" then
return true
end
elseif key == keys.leftCtrl or keys == keys.rightCtrl then
-- Cancel the menu
return false
end
end
end
end
--[[
Runs the main thread of execution. Draws the canvas and interface, and handles
mouse and key events.
returns: nil
Runs the main thread of execution. Draws the canvas and interface, and handles
mouse and key events.
returns: nil
]]
local function handleEvents()
local programActive = true
while programActive do
local id,p1,p2,p3 = os.pullEvent()
if id=="mouse_click" or id=="mouse_drag" then
if p2 >= w-1 and p3 >= 1 and p3 <= 17 then
if id ~= "mouse_drag" then
-- Selecting an items in the colour picker
if p3 <= 16 then
if p1==1 then
leftColour = 2^(p3-1)
else
rightColour = 2^(p3-1)
end
else
if p1==1 then
leftColour = nil
else
rightColour = nil
end
end
--drawCanvas()
drawInterface()
end
elseif p2 < w-1 and p3 <= h-1 then
-- Clicking on the canvas
local paintColour = nil
if p1==1 then
paintColour = leftColour
elseif p1==2 then
paintColour = rightColour
end
if not canvas[p3] then
local programActive = true
while programActive do
local id,p1,p2,p3 = os.pullEvent()
if id=="mouse_click" or id=="mouse_drag" then
if p2 >= w-1 and p3 >= 1 and p3 <= 17 then
if id ~= "mouse_drag" then
-- Selecting an items in the colour picker
if p3 <= 16 then
if p1==1 then
leftColour = 2^(p3-1)
else
rightColour = 2^(p3-1)
end
else
if p1==1 then
leftColour = nil
else
rightColour = nil
end
end
--drawCanvas()
drawInterface()
end
elseif p2 < w-1 and p3 <= h-1 then
-- Clicking on the canvas
local paintColour = nil
if p1==1 then
paintColour = leftColour
elseif p1==2 then
paintColour = rightColour
end
if not canvas[p3] then
canvas[p3] = {}
end
end
canvas[p3][p2] = paintColour
drawCanvasPixel( p2, p3 )
end
elseif id=="key" then
if p1==keys.leftCtrl or p1==keys.rightCtrl then
programActive = not accessMenu()
drawInterface()
end
elseif id=="term_resize" then
w,h = term.getSize()
drawCanvasPixel( p2, p3 )
end
elseif id=="key" then
if p1==keys.leftCtrl or p1==keys.rightCtrl then
programActive = not accessMenu()
drawInterface()
end
elseif id=="term_resize" then
w,h = term.getSize()
drawCanvas()
drawInterface()
end
end
end
end
-- Init

View File

@ -60,25 +60,25 @@ local tArgs = { ... }
--Functions--
local function printCentred( yc, stg )
local xc = math.floor((TermW - string.len(stg)) / 2) + 1
term.setCursorPos(xc,yc)
term.write( stg )
local xc = math.floor((TermW - string.len(stg)) / 2) + 1
term.setCursorPos(xc,yc)
term.write( stg )
end
local function centerOrgin()
XOrgin = math.floor((TermW/2)-(SizeW/2))
YOrgin = math.floor((TermH/2)-(SizeH/2))
XOrgin = math.floor((TermW/2)-(SizeW/2))
YOrgin = math.floor((TermH/2)-(SizeH/2))
end
local function reMap()
tScreen = nil
tScreen = {}
for x=1,SizeW do
tScreen[x] = {}
for y=1,SizeH do
tScreen[x][y] = { space = true, wall = false, ground = false, robot = "zz", start = "zz", exit = "zz" }
end
end
tScreen = nil
tScreen = {}
for x=1,SizeW do
tScreen[x] = {}
for y=1,SizeH do
tScreen[x][y] = { space = true, wall = false, ground = false, robot = "zz", start = "zz", exit = "zz" }
end
end
end
local function tablecopy(t)
@ -90,305 +90,305 @@ local function tablecopy(t)
end
local function buMap()
oScreen = nil
oScreen = {}
for x=1,SizeW do
oScreen[x] = {}
for y=1,SizeH do
oScreen[x][y] = tablecopy(tScreen[x][y])
end
end
oScreen = nil
oScreen = {}
for x=1,SizeW do
oScreen[x] = {}
for y=1,SizeH do
oScreen[x][y] = tablecopy(tScreen[x][y])
end
end
end
local function addRobot(x,y,side,color)
local obj = tScreen[x][y]
local data = side..color
if obj.wall == nil and obj.robot == nil then
tScreen[x][y].robot = data
else
obj.wall = nil
obj.robot = "zz"
tScreen[x][y].robot = data
end
local obj = tScreen[x][y]
local data = side..color
if obj.wall == nil and obj.robot == nil then
tScreen[x][y].robot = data
else
obj.wall = nil
obj.robot = "zz"
tScreen[x][y].robot = data
end
end
local function addStart(x,y,side,color)
local obj = tScreen[x][y]
local data = side..color
if obj.wall == nil and obj.space == nil then
tScreen[x][y].start = data
else
obj.wall = nil
obj.space = nil
tScreen[x][y].start = data
end
aExits = aExits+1
local obj = tScreen[x][y]
local data = side..color
if obj.wall == nil and obj.space == nil then
tScreen[x][y].start = data
else
obj.wall = nil
obj.space = nil
tScreen[x][y].start = data
end
aExits = aExits+1
end
local function addGround(x,y)
local obj = tScreen[x][y]
if obj.space == nil and obj.exit == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].ground = true
else
obj.space = nil
obj.exit = "zz"
obj.wall = nil
obj.robot = "zz"
obj.start = "zz"
tScreen[x][y].ground = true
end
local obj = tScreen[x][y]
if obj.space == nil and obj.exit == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].ground = true
else
obj.space = nil
obj.exit = "zz"
obj.wall = nil
obj.robot = "zz"
obj.start = "zz"
tScreen[x][y].ground = true
end
end
local function addExit(x,y,cl)
local obj = tScreen[x][y]
if obj.space == nil and obj.ground == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].exit = cl
else
obj.space = nil
obj.ground = nil
obj.wall = nil
obj.robot = "zz"
obj.start = "zz"
tScreen[x][y].exit = cl
end
local obj = tScreen[x][y]
if obj.space == nil and obj.ground == nil and obj.wall == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].exit = cl
else
obj.space = nil
obj.ground = nil
obj.wall = nil
obj.robot = "zz"
obj.start = "zz"
tScreen[x][y].exit = cl
end
end
local function addWall(x,y)
local obj = tScreen[x][y]
if obj == nil then
return error("Here X"..x.." Y"..y)
end
if obj.space == nil and obj.exit == nil and obj.ground == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].wall = true
else
obj.space = nil
obj.exit = nil
obj.ground = nil
obj.robot = nil
obj.start = nil
tScreen[x][y].wall = true
end
local obj = tScreen[x][y]
if obj == nil then
return error("Here X"..x.." Y"..y)
end
if obj.space == nil and obj.exit == nil and obj.ground == nil and obj.robot == nil and obj.start == nil then
tScreen[x][y].wall = true
else
obj.space = nil
obj.exit = nil
obj.ground = nil
obj.robot = nil
obj.start = nil
tScreen[x][y].wall = true
end
end
local function loadLevel(nNum)
sLevelTitle = "Level "..nNum
if nNum == nil then return error("nNum == nil") end
local sDir = fs.getDir( shell.getRunningProgram() )
local sLevelD = sDir .. "/levels/" .. tostring(nNum)
if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end
fLevel = fs.open(sLevelD,"r")
local Line = 0
local wl = true
Blocks = tonumber(string.sub(fLevel.readLine(),1,1))
local xSize = string.len(fLevel.readLine())+2
local Lines = 3
while wl do
local wLine = fLevel.readLine()
if wLine == nil then
fLevel.close()
wl = false
else
xSize = math.max(string.len(wLine)+2,xSize)
Lines = Lines + 1
end
end
SizeW,SizeH = xSize,Lines
reMap()
fLevel = fs.open(sLevelD,"r")
fLevel.readLine()
for Line=2,Lines-1 do
sLine = fLevel.readLine()
local chars = string.len(sLine)
for char = 1, chars do
local el = string.sub(sLine,char,char)
if el == "8" then
addGround(char+1,Line)
elseif el == "0" then
addStart(char+1,Line,"a","a")
elseif el == "1" then
addStart(char+1,Line,"b","a")
elseif el == "2" then
addStart(char+1,Line,"c","a")
elseif el == "3" then
addStart(char+1,Line,"d","a")
elseif el == "4" then
addStart(char+1,Line,"a","b")
elseif el == "5" then
addStart(char+1,Line,"b","b")
elseif el == "6" then
addStart(char+1,Line,"c","b")
elseif el == "9" then
addStart(char+1,Line,"d","b")
elseif el == "b" then
addExit(char+1,Line,"a")
elseif el == "e" then
addExit(char+1,Line,"b")
elseif el == "7" then
addWall(char+1,Line)
end
end
end
fLevel.close()
if nNum == nil then return error("nNum == nil") end
local sDir = fs.getDir( shell.getRunningProgram() )
local sLevelD = sDir .. "/levels/" .. tostring(nNum)
if not ( fs.exists(sLevelD) or fs.isDir(sLevelD) ) then return error("Level Not Exists : "..sLevelD) end
fLevel = fs.open(sLevelD,"r")
local Line = 0
local wl = true
Blocks = tonumber(string.sub(fLevel.readLine(),1,1))
local xSize = string.len(fLevel.readLine())+2
local Lines = 3
while wl do
local wLine = fLevel.readLine()
if wLine == nil then
fLevel.close()
wl = false
else
xSize = math.max(string.len(wLine)+2,xSize)
Lines = Lines + 1
end
end
SizeW,SizeH = xSize,Lines
reMap()
fLevel = fs.open(sLevelD,"r")
fLevel.readLine()
for Line=2,Lines-1 do
sLine = fLevel.readLine()
local chars = string.len(sLine)
for char = 1, chars do
local el = string.sub(sLine,char,char)
if el == "8" then
addGround(char+1,Line)
elseif el == "0" then
addStart(char+1,Line,"a","a")
elseif el == "1" then
addStart(char+1,Line,"b","a")
elseif el == "2" then
addStart(char+1,Line,"c","a")
elseif el == "3" then
addStart(char+1,Line,"d","a")
elseif el == "4" then
addStart(char+1,Line,"a","b")
elseif el == "5" then
addStart(char+1,Line,"b","b")
elseif el == "6" then
addStart(char+1,Line,"c","b")
elseif el == "9" then
addStart(char+1,Line,"d","b")
elseif el == "b" then
addExit(char+1,Line,"a")
elseif el == "e" then
addExit(char+1,Line,"b")
elseif el == "7" then
addWall(char+1,Line)
end
end
end
fLevel.close()
end
local function drawStars()
--CCR Background By : RamiLego--
local cStar,cStarG,crStar,crStarB = colors.lightGray,colors.gray,".","*"
local DStar,BStar,nStar,gStar = 14,10,16,3
local TermW,TermH = term.getSize()
--CCR Background By : RamiLego--
local cStar,cStarG,crStar,crStarB = colors.lightGray,colors.gray,".","*"
local DStar,BStar,nStar,gStar = 14,10,16,3
local TermW,TermH = term.getSize()
term.clear()
term.setCursorPos(1,1)
for x=1,TermW do
for y=1,TermH do
local StarT = math.random(1,30)
if StarT == DStar then
term.setCursorPos(x,y)
term.setTextColor(cStar)
write(crStar)
elseif StarT == BStar then
term.setCursorPos(x,y)
term.setTextColor(cStar)
write(crStarB)
elseif StarT == nStar then
term.setCursorPos(x,y)
term.setTextColor(cStarG)
write(crStar)
elseif StarT == gStar then
term.setCursorPos(x,y)
term.setTextColor(cStarG)
write(crStarB)
end
end
end
for x=1,TermW do
for y=1,TermH do
local StarT = math.random(1,30)
if StarT == DStar then
term.setCursorPos(x,y)
term.setTextColor(cStar)
write(crStar)
elseif StarT == BStar then
term.setCursorPos(x,y)
term.setTextColor(cStar)
write(crStarB)
elseif StarT == nStar then
term.setCursorPos(x,y)
term.setTextColor(cStarG)
write(crStar)
elseif StarT == gStar then
term.setCursorPos(x,y)
term.setTextColor(cStarG)
write(crStarB)
end
end
end
end
local function drawMap()
for x=1,SizeW do
for y=1,SizeH do
local obj = tScreen[x][y]
if obj.ground == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cG)
end
if obj.wall == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cW)
end
local ex = tostring(tScreen[x][y].exit)
if not(ex == "zz" or ex == "nil") then
if ex == "a" then
ex = cR1
elseif ex == "b" then
ex = cR2
elseif ex == "c" then
ex = cR3
elseif ex == "d" then
ex = cR4
else
return error("Exit Color Out")
end
term.setBackgroundColor(cG)
term.setTextColor(ex)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
print("X")
end
local st = tostring(tScreen[x][y].start)
if not(st == "zz" or st == "nil") then
local Cr = string.sub(st,2,2)
if Cr == "a" then
Cr = cR1
elseif Cr == "b" then
Cr = cR2
elseif Cr == "c" then
Cr = cR3
elseif Cr == "d" then
Cr = cR4
else
return error("Start Color Out")
end
term.setTextColor(Cr)
term.setBackgroundColor(cG)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
sSide = string.sub(st,1,1)
if sSide == "a" then
print("^")
elseif sSide == "b" then
print(">")
elseif sSide == "c" then
print("v")
elseif sSide == "d" then
print("<")
else
print("@")
end
end
if obj.space == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cS)
end
local rb = tostring(tScreen[x][y].robot)
if not(rb == "zz" or rb == "nil") then
local Cr = string.sub(rb,2,2)
if Cr == "a" then
Cr = cR1
elseif Cr == "b" then
Cr = cR2
elseif Cr == "c" then
Cr = cR3
elseif Cr == "d" then
Cr = cR4
else
Cr = colors.white
end
term.setBackgroundColor(Cr)
term.setTextColor(colors.white)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
sSide = string.sub(rb,1,1)
if sSide == "a" then
print("^")
elseif sSide == "b" then
print(">")
elseif sSide == "c" then
print("v")
elseif sSide == "d" then
print("<")
else
print("@")
end
end
end
end
for x=1,SizeW do
for y=1,SizeH do
local obj = tScreen[x][y]
if obj.ground == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cG)
end
if obj.wall == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cW)
end
local ex = tostring(tScreen[x][y].exit)
if not(ex == "zz" or ex == "nil") then
if ex == "a" then
ex = cR1
elseif ex == "b" then
ex = cR2
elseif ex == "c" then
ex = cR3
elseif ex == "d" then
ex = cR4
else
return error("Exit Color Out")
end
term.setBackgroundColor(cG)
term.setTextColor(ex)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
print("X")
end
local st = tostring(tScreen[x][y].start)
if not(st == "zz" or st == "nil") then
local Cr = string.sub(st,2,2)
if Cr == "a" then
Cr = cR1
elseif Cr == "b" then
Cr = cR2
elseif Cr == "c" then
Cr = cR3
elseif Cr == "d" then
Cr = cR4
else
return error("Start Color Out")
end
term.setTextColor(Cr)
term.setBackgroundColor(cG)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
sSide = string.sub(st,1,1)
if sSide == "a" then
print("^")
elseif sSide == "b" then
print(">")
elseif sSide == "c" then
print("v")
elseif sSide == "d" then
print("<")
else
print("@")
end
end
if obj.space == true then
paintutils.drawPixel(XOrgin+x,YOrgin+y+1,cS)
end
local rb = tostring(tScreen[x][y].robot)
if not(rb == "zz" or rb == "nil") then
local Cr = string.sub(rb,2,2)
if Cr == "a" then
Cr = cR1
elseif Cr == "b" then
Cr = cR2
elseif Cr == "c" then
Cr = cR3
elseif Cr == "d" then
Cr = cR4
else
Cr = colors.white
end
term.setBackgroundColor(Cr)
term.setTextColor(colors.white)
term.setCursorPos(XOrgin+x,YOrgin+y+1)
sSide = string.sub(rb,1,1)
if sSide == "a" then
print("^")
elseif sSide == "b" then
print(">")
elseif sSide == "c" then
print("v")
elseif sSide == "d" then
print("<")
else
print("@")
end
end
end
end
end
local function isBrick(x,y)
local brb = tostring(tScreen[x][y].robot)
local bobj = oScreen[x][y]
if (brb == "zz" or brb == "nil") and not bobj.wall == true then
return false
else
return true
end
local brb = tostring(tScreen[x][y].robot)
local bobj = oScreen[x][y]
if (brb == "zz" or brb == "nil") and not bobj.wall == true then
return false
else
return true
end
end
local function gRender(sContext)
if sContext == "start" then
for x=1,SizeW do
for y=1,SizeH do
local st = tostring(tScreen[x][y].start)
if not(st == "zz" or st == "nil") then
local Cr = string.sub(st,2,2)
local sSide = string.sub(st,1,1)
addRobot(x,y,sSide,Cr)
end
end
end
elseif sContext == "tick" then
buMap()
if sContext == "start" then
for x=1,SizeW do
for y=1,SizeH do
local st = tostring(tScreen[x][y].start)
if not(st == "zz" or st == "nil") then
local Cr = string.sub(st,2,2)
local sSide = string.sub(st,1,1)
addRobot(x,y,sSide,Cr)
end
end
end
elseif sContext == "tick" then
buMap()
for x=1,SizeW do
for y=1,SizeH do
local rb = tostring(oScreen[x][y].robot)
@ -513,44 +513,44 @@ local function gRender(sContext)
end
function InterFace.drawBar()
term.setBackgroundColor( colors.black )
term.setTextColor( InterFace.cTitle )
printCentred( 1, " "..sLevelTitle.." " )
term.setCursorPos(1,1)
term.setBackgroundColor( cW )
write( " " )
term.setBackgroundColor( colors.black )
write( " x "..tostring(Blocks).." " )
term.setCursorPos( TermW-8,TermH )
term.setBackgroundColor( colors.black )
term.setBackgroundColor( colors.black )
term.setTextColor( InterFace.cTitle )
printCentred( 1, " "..sLevelTitle.." " )
term.setCursorPos(1,1)
term.setBackgroundColor( cW )
write( " " )
term.setBackgroundColor( colors.black )
write( " x "..tostring(Blocks).." " )
term.setCursorPos( TermW-8,TermH )
term.setBackgroundColor( colors.black )
term.setTextColour(InterFace.cSpeedD)
write(" <<" )
if bPaused then
term.setTextColour(InterFace.cSpeedA)
else
term.setTextColour(InterFace.cSpeedD)
end
write(" ||")
if fSpeedS then
term.setTextColour(InterFace.cSpeedA)
else
term.setTextColour(InterFace.cSpeedD)
end
write(" >>")
write(" <<" )
if bPaused then
term.setTextColour(InterFace.cSpeedA)
else
term.setTextColour(InterFace.cSpeedD)
end
write(" ||")
if fSpeedS then
term.setTextColour(InterFace.cSpeedA)
else
term.setTextColour(InterFace.cSpeedD)
end
write(" >>")
term.setCursorPos( TermW-1, 1 )
term.setBackgroundColor( colors.black )
term.setTextColour( InterFace.cExit )
write(" X")
term.setBackgroundColor(colors.black)
term.setCursorPos( TermW-1, 1 )
term.setBackgroundColor( colors.black )
term.setTextColour( InterFace.cExit )
write(" X")
term.setBackgroundColor(colors.black)
end
function InterFace.render()
local id,p1,p2,p3 = os.pullEvent()
if id == "mouse_click" then
if p3 == 1 and p2 == TermW then
local id,p1,p2,p3 = os.pullEvent()
if id == "mouse_click" then
if p3 == 1 and p2 == TermW then
return "end"
elseif p3 == TermH and p2 >= TermW-7 and p2 <= TermW-6 then
return "retry"
@ -570,7 +570,7 @@ function InterFace.render()
Speed = (fSpeedS and fSpeed) or nSpeed
Tick = os.startTimer(Speed)
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
local eobj = tScreen[p2-XOrgin][p3-YOrgin-1]
local erobj = tostring(tScreen[p2-XOrgin][p3-YOrgin-1].robot)
@ -580,50 +580,50 @@ function InterFace.render()
InterFace.drawBar()
drawMap()
end
end
elseif id == "timer" and p1 == Tick then
gRender("tick")
end
elseif id == "timer" and p1 == Tick then
gRender("tick")
drawMap()
if Speed > 0 then
Tick = os.startTimer(Speed)
else
Tick = nil
end
end
end
end
local function startG(LevelN)
drawStars()
loadLevel(LevelN)
centerOrgin()
local create = true
drawMap()
InterFace.drawBar()
gRender("start")
drawMap()
local NExit = true
if aExits == 0 then
NExit = false
end
while true do
local isExit = InterFace.render()
if isExit == "end" then
return nil
elseif isExit == "retry" then
return LevelN
elseif fExit == "yes" then
if fs.exists( fs.getDir( shell.getRunningProgram() ) .. "/levels/" .. tostring(LevelN + 1) ) then
return LevelN + 1
else
return nil
end
end
if aExits == 0 and NExit == true then
fExit = "yes"
end
end
drawStars()
loadLevel(LevelN)
centerOrgin()
local create = true
drawMap()
InterFace.drawBar()
gRender("start")
drawMap()
local NExit = true
if aExits == 0 then
NExit = false
end
while true do
local isExit = InterFace.render()
if isExit == "end" then
return nil
elseif isExit == "retry" then
return LevelN
elseif fExit == "yes" then
if fs.exists( fs.getDir( shell.getRunningProgram() ) .. "/levels/" .. tostring(LevelN + 1) ) then
return LevelN + 1
else
return nil
end
end
if aExits == 0 and NExit == true then
fExit = "yes"
end
end
end
local ok, err = true, nil

View File

@ -1,50 +1,50 @@
local tArgs = { ... }
local function printUsage()
print( "Usages:")
print( "dj play" )
print( "dj play <drive>" )
print( "dj stop" )
print( "Usages:")
print( "dj play" )
print( "dj play <drive>" )
print( "dj stop" )
end
if #tArgs > 2 then
printUsage()
return
printUsage()
return
end
local sCommand = tArgs[1]
if sCommand == "stop" then
-- Stop audio
disk.stopAudio()
-- Stop audio
disk.stopAudio()
elseif sCommand == "play" or sCommand == nil then
-- Play audio
local sName = tArgs[2]
if sName == nil then
-- No disc specified, pick one at random
local tNames = {}
for n,sName in ipairs( peripheral.getNames() ) do
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
table.insert( tNames, sName )
end
end
if #tNames == 0 then
print( "No Music Discs in attached disk drives" )
return
end
sName = tNames[ math.random(1,#tNames) ]
end
-- Play audio
local sName = tArgs[2]
if sName == nil then
-- No disc specified, pick one at random
local tNames = {}
for n,sName in ipairs( peripheral.getNames() ) do
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
table.insert( tNames, sName )
end
end
if #tNames == 0 then
print( "No Music Discs in attached disk drives" )
return
end
sName = tNames[ math.random(1,#tNames) ]
end
-- Play the disc
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
print( "Playing "..disk.getAudioTitle( sName ) )
disk.playAudio( sName )
else
print( "No Music Disc in disk drive: "..sName )
return
end
-- Play the disc
if disk.isPresent( sName ) and disk.hasAudio( sName ) then
print( "Playing "..disk.getAudioTitle( sName ) )
disk.playAudio( sName )
else
print( "No Music Disc in disk drive: "..sName )
return
end
else
printUsage()
printUsage()
end

View File

@ -1,5 +1,5 @@
if term.isColour() then
term.setTextColour( 2^math.random(0,15) )
term.setTextColour( 2^math.random(0,15) )
end
textutils.slowPrint( "Hello World!" )
term.setTextColour( colours.white )

View File

@ -5,23 +5,23 @@ local w,h = term.getSize()
local titleColour, headingColour, textColour, wormColour, fruitColour
if term.isColour() then
titleColour = colours.red
headingColour = colours.yellow
textColour = colours.white
wormColour = colours.green
fruitColour = colours.red
headingColour = colours.yellow
textColour = colours.white
wormColour = colours.green
fruitColour = colours.red
else
titleColour = colours.white
headingColour = colours.white
textColour = colours.white
wormColour = colours.white
fruitColour = colours.white
headingColour = colours.white
textColour = colours.white
wormColour = colours.white
fruitColour = colours.white
end
local function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
--term.clearLine()
term.write( s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
--term.clearLine()
term.write( s )
end
local xVel,yVel = 1,0
@ -40,177 +40,177 @@ local nSpeed, nInterval
-- Setup the screen
local screen = {}
for x=1,w do
screen[x] = {}
for y=1,h do
screen[x][y] = {}
end
screen[x] = {}
for y=1,h do
screen[x][y] = {}
end
end
screen[xPos][yPos] = { snake = true }
local nFruit = 1
local tFruits = {
"A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x",
"y", "z",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"@", "$", "%", "#", "&", "!", "?", "+", "*", "~"
"A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x",
"y", "z",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"@", "$", "%", "#", "&", "!", "?", "+", "*", "~"
}
local function addFruit()
while true do
local x = math.random(1,w)
local y = math.random(2,h)
local fruit = screen[x][y]
if fruit.snake == nil and fruit.wall == nil and fruit.fruit == nil then
screen[x][y] = { fruit = true }
term.setCursorPos(x,y)
term.setBackgroundColour( fruitColour )
term.write(" ")
term.setBackgroundColour( colours.black )
break
end
end
nFruit = nFruit + 1
if nFruit > #tFruits then
nFruit = 1
end
while true do
local x = math.random(1,w)
local y = math.random(2,h)
local fruit = screen[x][y]
if fruit.snake == nil and fruit.wall == nil and fruit.fruit == nil then
screen[x][y] = { fruit = true }
term.setCursorPos(x,y)
term.setBackgroundColour( fruitColour )
term.write(" ")
term.setBackgroundColour( colours.black )
break
end
end
nFruit = nFruit + 1
if nFruit > #tFruits then
nFruit = 1
end
end
local function drawMenu()
term.setTextColour( headingColour )
term.setCursorPos(1,1)
term.write( "SCORE " )
term.setTextColour( textColour )
term.setCursorPos(7,1)
term.write( tostring(nScore) )
term.setTextColour( headingColour )
term.setCursorPos(1,1)
term.write( "SCORE " )
term.setTextColour( textColour )
term.setCursorPos(7,1)
term.write( tostring(nScore) )
term.setTextColour( headingColour )
term.setCursorPos(w-11,1)
term.write( "DIFFICULTY ")
term.setTextColour( headingColour )
term.setCursorPos(w-11,1)
term.write( "DIFFICULTY ")
term.setTextColour( textColour )
term.setCursorPos(w,1)
term.write( tostring(nDifficulty or "?") )
term.setTextColour( textColour )
term.setCursorPos(w,1)
term.write( tostring(nDifficulty or "?") )
term.setTextColour( colours.white )
term.setTextColour( colours.white )
end
local function update( )
local x,y = xPos,yPos
if pxVel and pyVel then
xVel, yVel = pxVel, pyVel
pxVel, pyVel = nil, nil
end
local x,y = xPos,yPos
if pxVel and pyVel then
xVel, yVel = pxVel, pyVel
pxVel, pyVel = nil, nil
end
-- Remove the tail
if nExtraLength == 0 then
local tail = screen[tailX][tailY]
screen[tailX][tailY] = {}
term.setCursorPos(tailX,tailY)
term.write(" ")
tailX = tail.nextX
tailY = tail.nextY
else
nExtraLength = nExtraLength - 1
end
-- Update the head
local head = screen[xPos][yPos]
local newXPos = xPos + xVel
local newYPos = yPos + yVel
if newXPos < 1 then
newXPos = w
elseif newXPos > w then
newXPos = 1
end
if newYPos < 2 then
newYPos = h
elseif newYPos > h then
newYPos = 2
end
local newHead = screen[newXPos][newYPos]
term.setCursorPos(1,1);
print( newHead.snake )
if newHead.snake == true or newHead.wall == true then
bRunning = false
else
if newHead.fruit == true then
nScore = nScore + 10
nExtraLength = nExtraLength + 1
addFruit()
end
xPos = newXPos
yPos = newYPos
head.nextX = newXPos
head.nextY = newYPos
screen[newXPos][newYPos] = { snake = true }
end
term.setCursorPos(xPos,yPos)
term.setBackgroundColour( wormColour )
term.write(" ")
term.setBackgroundColour( colours.black )
-- Remove the tail
if nExtraLength == 0 then
local tail = screen[tailX][tailY]
screen[tailX][tailY] = {}
term.setCursorPos(tailX,tailY)
term.write(" ")
tailX = tail.nextX
tailY = tail.nextY
else
nExtraLength = nExtraLength - 1
end
-- Update the head
local head = screen[xPos][yPos]
local newXPos = xPos + xVel
local newYPos = yPos + yVel
if newXPos < 1 then
newXPos = w
elseif newXPos > w then
newXPos = 1
end
if newYPos < 2 then
newYPos = h
elseif newYPos > h then
newYPos = 2
end
local newHead = screen[newXPos][newYPos]
term.setCursorPos(1,1);
print( newHead.snake )
if newHead.snake == true or newHead.wall == true then
bRunning = false
else
if newHead.fruit == true then
nScore = nScore + 10
nExtraLength = nExtraLength + 1
addFruit()
end
xPos = newXPos
yPos = newYPos
head.nextX = newXPos
head.nextY = newYPos
screen[newXPos][newYPos] = { snake = true }
end
term.setCursorPos(xPos,yPos)
term.setBackgroundColour( wormColour )
term.write(" ")
term.setBackgroundColour( colours.black )
drawMenu()
drawMenu()
end
-- Display the frontend
term.clear()
local function drawFrontend()
--term.setTextColour( titleColour )
--term.setTextColour( titleColour )
--printCentred( math.floor(h/2) - 4, " W O R M " )
term.setTextColour( headingColour )
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, " SELECT DIFFICULTY " )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, " " )
printCentred( math.floor(h/2) + 1, " " )
printCentred( math.floor(h/2) + 2, " " )
printCentred( math.floor(h/2) - 1 + nDifficulty, " [ ] " )
term.setTextColour( headingColour )
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, " SELECT DIFFICULTY " )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, " " )
printCentred( math.floor(h/2) + 1, " " )
printCentred( math.floor(h/2) + 2, " " )
printCentred( math.floor(h/2) - 1 + nDifficulty, " [ ] " )
term.setTextColour( textColour )
printCentred( math.floor(h/2) + 0, "EASY" )
printCentred( math.floor(h/2) + 1, "MEDIUM" )
printCentred( math.floor(h/2) + 2, "HARD" )
printCentred( math.floor(h/2) + 3, "" )
term.setTextColour( textColour )
printCentred( math.floor(h/2) + 0, "EASY" )
printCentred( math.floor(h/2) + 1, "MEDIUM" )
printCentred( math.floor(h/2) + 2, "HARD" )
printCentred( math.floor(h/2) + 3, "" )
term.setTextColour( colours.white )
term.setTextColour( colours.white )
end
drawMenu()
drawFrontend()
while true do
local e,key = os.pullEvent( "key" )
if key == keys.up or key == keys.w then
-- Up
if nDifficulty > 1 then
nDifficulty = nDifficulty - 1
drawMenu()
drawFrontend()
end
elseif key == keys.down or key == keys.s then
-- Down
if nDifficulty < 3 then
nDifficulty = nDifficulty + 1
drawMenu()
drawFrontend()
end
elseif key == keys.enter then
-- Enter
break
end
local e,key = os.pullEvent( "key" )
if key == keys.up or key == keys.w then
-- Up
if nDifficulty > 1 then
nDifficulty = nDifficulty - 1
drawMenu()
drawFrontend()
end
elseif key == keys.down or key == keys.s then
-- Down
if nDifficulty < 3 then
nDifficulty = nDifficulty + 1
drawMenu()
drawFrontend()
end
elseif key == keys.enter then
-- Enter
break
end
end
local tSpeeds = { 5, 10, 25 }
@ -222,7 +222,7 @@ term.clear()
drawMenu()
screen[tailX][tailY].snake = true
while nExtraLength > 0 do
update()
update()
end
addFruit()
addFruit()
@ -230,37 +230,37 @@ addFruit()
-- Play the game
local timer = os.startTimer(0)
while bRunning do
local event, p1, p2 = os.pullEvent()
if event == "timer" and p1 == timer then
timer = os.startTimer(nInterval)
update( false )
elseif event == "key" then
local key = p1
if key == keys.up or key == keys.w then
-- Up
if yVel == 0 then
pxVel,pyVel = 0,-1
end
elseif key == keys.down or key == keys.s then
-- Down
if yVel == 0 then
pxVel,pyVel = 0,1
end
elseif key == keys.left or key == keys.a then
-- Left
if xVel == 0 then
pxVel,pyVel = -1,0
end
elseif key == keys.right or key == keys.d then
-- Right
if xVel == 0 then
pxVel,pyVel = 1,0
end
end
end
local event, p1, p2 = os.pullEvent()
if event == "timer" and p1 == timer then
timer = os.startTimer(nInterval)
update( false )
elseif event == "key" then
local key = p1
if key == keys.up or key == keys.w then
-- Up
if yVel == 0 then
pxVel,pyVel = 0,-1
end
elseif key == keys.down or key == keys.s then
-- Down
if yVel == 0 then
pxVel,pyVel = 0,1
end
elseif key == keys.left or key == keys.a then
-- Left
if xVel == 0 then
pxVel,pyVel = -1,0
end
elseif key == keys.right or key == keys.d then
-- Right
if xVel == 0 then
pxVel,pyVel = 1,0
end
end
end
end
-- Display the gameover screen
@ -276,16 +276,16 @@ term.setTextColour( colours.white )
local timer = os.startTimer(2.5)
repeat
local e,p = os.pullEvent()
if e == "timer" and p == timer then
term.setTextColour( textColour )
printCentred( math.floor(h/2) + 2, " PRESS ANY KEY " )
printCentred( math.floor(h/2) + 3, " " )
term.setTextColour( colours.white )
end
local e,p = os.pullEvent()
if e == "timer" and p == timer then
term.setTextColour( textColour )
printCentred( math.floor(h/2) + 2, " PRESS ANY KEY " )
printCentred( math.floor(h/2) + 3, " " )
term.setTextColour( colours.white )
end
until e == "char"
term.clear()
term.setCursorPos(1,1)

View File

@ -1,104 +1,104 @@
local function printUsage()
print( "Usages:" )
print( "gps host" )
print( "gps host <x> <y> <z>" )
print( "gps locate" )
print( "Usages:" )
print( "gps host" )
print( "gps host <x> <y> <z>" )
print( "gps locate" )
end
local tArgs = { ... }
if #tArgs < 1 then
printUsage()
return
printUsage()
return
end
local sCommand = tArgs[1]
if sCommand == "locate" then
-- "gps locate"
-- Just locate this computer (this will print the results)
gps.locate( 2, true )
-- "gps locate"
-- Just locate this computer (this will print the results)
gps.locate( 2, true )
elseif sCommand == "host" then
-- "gps host"
-- Act as a GPS host
if pocket then
print( "GPS Hosts must be stationary" )
return
end
-- "gps host"
-- Act as a GPS host
if pocket then
print( "GPS Hosts must be stationary" )
return
end
-- Find a modem
local sModemSide = nil
for n,sSide in ipairs( rs.getSides() ) do
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
sModemSide = sSide
break
end
end
-- Find a modem
local sModemSide = nil
for n,sSide in ipairs( rs.getSides() ) do
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
sModemSide = sSide
break
end
end
if sModemSide == nil then
print( "No wireless modems found. 1 required." )
return
end
if sModemSide == nil then
print( "No wireless modems found. 1 required." )
return
end
-- Determine position
local x,y,z
if #tArgs >= 4 then
-- Position is manually specified
x = tonumber(tArgs[2])
y = tonumber(tArgs[3])
z = tonumber(tArgs[4])
if x == nil or y == nil or z == nil then
printUsage()
return
end
print( "Position is "..x..","..y..","..z )
else
-- Position is to be determined using locate
x,y,z = gps.locate( 2, true )
if x == nil then
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
if bCloseChannel then
print( "Closing GPS channel" )
modem.close( gps.CHANNEL_GPS )
end
return
end
end
-- Open a channel
local modem = peripheral.wrap( sModemSide )
-- Determine position
local x,y,z
if #tArgs >= 4 then
-- Position is manually specified
x = tonumber(tArgs[2])
y = tonumber(tArgs[3])
z = tonumber(tArgs[4])
if x == nil or y == nil or z == nil then
printUsage()
return
end
print( "Position is "..x..","..y..","..z )
else
-- Position is to be determined using locate
x,y,z = gps.locate( 2, true )
if x == nil then
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
if bCloseChannel then
print( "Closing GPS channel" )
modem.close( gps.CHANNEL_GPS )
end
return
end
end
-- Open a channel
local modem = peripheral.wrap( sModemSide )
print( "Opening channel on modem "..sModemSide )
modem.open( gps.CHANNEL_GPS )
-- Serve requests indefinately
local nServed = 0
while true do
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
if e == "modem_message" then
-- We received a message from a modem
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
-- We received a ping message on the GPS channel, send a response
modem.transmit( sReplyChannel, gps.CHANNEL_GPS, { x, y, z } )
-- Print the number of requests handled
nServed = nServed + 1
if nServed > 1 then
local x,y = term.getCursorPos()
term.setCursorPos(1,y-1)
end
print( nServed.." GPS requests served" )
end
end
end
-- Serve requests indefinately
local nServed = 0
while true do
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
if e == "modem_message" then
-- We received a message from a modem
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
-- We received a ping message on the GPS channel, send a response
modem.transmit( sReplyChannel, gps.CHANNEL_GPS, { x, y, z } )
-- Print the number of requests handled
nServed = nServed + 1
if nServed > 1 then
local x,y = term.getCursorPos()
term.setCursorPos(1,y-1)
end
print( nServed.." GPS requests served" )
end
end
end
-- Close the channel
-- Close the channel
print( "Closing channel" )
modem.close( gps.CHANNEL_GPS )
else
-- "gps somethingelse"
-- Error
printUsage()
-- "gps somethingelse"
-- Error
printUsage()
end

View File

@ -1,29 +1,29 @@
local tArgs = { ... }
if #tArgs > 0 then
sTopic = tArgs[1]
sTopic = tArgs[1]
else
sTopic = "intro"
sTopic = "intro"
end
if sTopic == "index" then
print( "Help topics availiable:" )
local tTopics = help.topics()
textutils.pagedTabulate( tTopics )
return
print( "Help topics availiable:" )
local tTopics = help.topics()
textutils.pagedTabulate( tTopics )
return
end
local w,h = term.getSize()
local sFile = help.lookup( sTopic )
local file = ((sFile ~= nil) and io.open( sFile )) or nil
local nLinesPrinted = 0
if file then
local sLine = file:read()
local nLines = 0
while sLine do
nLines = nLines + textutils.pagedPrint( sLine, (h-3) - nLines )
sLine = file:read()
local sLine = file:read()
local nLines = 0
while sLine do
nLines = nLines + textutils.pagedPrint( sLine, (h-3) - nLines )
sLine = file:read()
end
file:close()
file:close()
else
print( "No help available" )
print( "No help available" )
end

View File

@ -121,4 +121,4 @@ elseif sCommand == "run" then
else
printUsage()
return
end
end

View File

@ -2,29 +2,29 @@
local sDrive = nil
local tArgs = { ... }
if #tArgs > 0 then
sDrive = tostring( tArgs[1] )
sDrive = tostring( tArgs[1] )
end
if sDrive == nil then
print( "This is computer #"..os.getComputerID() )
local label = os.getComputerLabel()
if label then
print( "This computer is labelled \""..label.."\"" )
end
print( "This is computer #"..os.getComputerID() )
local label = os.getComputerLabel()
if label then
print( "This computer is labelled \""..label.."\"" )
end
else
local bData = disk.hasData( sDrive )
if not bData then
print( "No disk in drive "..sDrive )
return
end
print( "The disk is #"..disk.getID( sDrive ) )
local bData = disk.hasData( sDrive )
if not bData then
print( "No disk in drive "..sDrive )
return
end
print( "The disk is #"..disk.getID( sDrive ) )
local label = disk.getLabel( sDrive )
if label then
print( "The disk is labelled \""..label.."\"" )
end
local label = disk.getLabel( sDrive )
if label then
print( "The disk is labelled \""..label.."\"" )
end
end

View File

@ -1,12 +1,12 @@
local function printUsage()
print( "Usages:" )
print( "label get" )
print( "label get <drive>" )
print( "label set <text>" )
print( "label set <drive> <text>" )
print( "label clear" )
print( "label clear <drive>" )
print( "Usages:" )
print( "label get" )
print( "label get <drive>" )
print( "label set <text>" )
print( "label set <drive> <text>" )
print( "label clear" )
print( "label clear <drive>" )
end
local function checkDrive( sDrive )
@ -18,15 +18,15 @@ local function checkDrive( sDrive )
return false
end
else
print( "No disk drive named "..sDrive )
print( "No disk drive named "..sDrive )
return false
end
return true
end
return true
end
local function get( sDrive )
if sDrive ~= nil then
if checkDrive( sDrive ) then
if sDrive ~= nil then
if checkDrive( sDrive ) then
local sLabel = disk.getLabel( sDrive )
if sLabel then
print( "Disk label is \""..sLabel.."\"" )
@ -34,19 +34,19 @@ local function get( sDrive )
print( "No Disk label" )
end
end
else
local sLabel = os.getComputerLabel()
if sLabel then
print( "Computer label is \""..sLabel.."\"" )
else
print( "No Computer label" )
end
end
else
local sLabel = os.getComputerLabel()
if sLabel then
print( "Computer label is \""..sLabel.."\"" )
else
print( "No Computer label" )
end
end
end
local function set( sDrive, sText )
if sDrive ~= nil then
if checkDrive( sDrive ) then
if sDrive ~= nil then
if checkDrive( sDrive ) then
disk.setLabel( sDrive, sText )
local sLabel = disk.getLabel( sDrive )
if sLabel then
@ -55,15 +55,15 @@ local function set( sDrive, sText )
print( "Disk label cleared" )
end
end
else
os.setComputerLabel( sText )
local sLabel = os.getComputerLabel()
if sLabel then
print( "Computer label set to \""..sLabel.."\"" )
else
print( "Computer label cleared" )
end
end
else
os.setComputerLabel( sText )
local sLabel = os.getComputerLabel()
if sLabel then
print( "Computer label set to \""..sLabel.."\"" )
else
print( "Computer label cleared" )
end
end
end
local tArgs = { ... }

View File

@ -4,7 +4,7 @@ local tArgs = { ... }
-- Get all the files in the directory
local sDir = shell.dir()
if tArgs[1] ~= nil then
sDir = shell.resolve( tArgs[1] )
sDir = shell.resolve( tArgs[1] )
end
-- Sort into dirs/files, and calculate column count
@ -14,20 +14,20 @@ local tDirs = {}
local bShowHidden = settings.get( "list.show_hidden" )
for n, sItem in pairs( tAll ) do
if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then
local sPath = fs.combine( sDir, sItem )
if fs.isDir( sPath ) then
table.insert( tDirs, sItem )
else
table.insert( tFiles, sItem )
end
end
if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then
local sPath = fs.combine( sDir, sItem )
if fs.isDir( sPath ) then
table.insert( tDirs, sItem )
else
table.insert( tFiles, sItem )
end
end
end
table.sort( tDirs )
table.sort( tFiles )
if term.isColour() then
textutils.pagedTabulate( colors.green, tDirs, colors.white, tFiles )
textutils.pagedTabulate( colors.green, tDirs, colors.white, tFiles )
else
textutils.pagedTabulate( tDirs, tFiles )
textutils.pagedTabulate( tDirs, tFiles )
end

View File

@ -1,96 +1,96 @@
local tArgs = { ... }
if #tArgs > 0 then
print( "This is an interactive Lua prompt." )
print( "To run a lua program, just type its name." )
return
print( "This is an interactive Lua prompt." )
print( "To run a lua program, just type its name." )
return
end
local bRunning = true
local tCommandHistory = {}
local tEnv = {
["exit"] = function()
bRunning = false
end,
["_echo"] = function( ... )
return ...
end,
["exit"] = function()
bRunning = false
end,
["_echo"] = function( ... )
return ...
end,
}
setmetatable( tEnv, { __index = _ENV } )
if term.isColour() then
term.setTextColour( colours.yellow )
term.setTextColour( colours.yellow )
end
print( "Interactive Lua prompt." )
print( "Call exit() to exit." )
term.setTextColour( colours.white )
while bRunning do
--if term.isColour() then
-- term.setTextColour( colours.yellow )
--end
write( "lua> " )
--term.setTextColour( colours.white )
--if term.isColour() then
-- term.setTextColour( colours.yellow )
--end
write( "lua> " )
--term.setTextColour( colours.white )
local s = read( nil, tCommandHistory, function( sLine )
if settings.get( "lua.autocomplete" ) then
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
if nStartPos then
sLine = string.sub( sLine, nStartPos )
end
if #sLine > 0 then
return textutils.complete( sLine, tEnv )
end
end
local s = read( nil, tCommandHistory, function( sLine )
if settings.get( "lua.autocomplete" ) then
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
if nStartPos then
sLine = string.sub( sLine, nStartPos )
end
if #sLine > 0 then
return textutils.complete( sLine, tEnv )
end
end
return nil
end )
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
table.insert( tCommandHistory, s )
end
local nForcePrint = 0
local func, e = load( s, "lua", "t", tEnv )
local func2, e2 = load( "return _echo("..s..");", "lua", "t", tEnv )
if not func then
if func2 then
func = func2
e = nil
nForcePrint = 1
end
else
if func2 then
func = func2
end
end
if func then
end )
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
table.insert( tCommandHistory, s )
end
local nForcePrint = 0
local func, e = load( s, "lua", "t", tEnv )
local func2, e2 = load( "return _echo("..s..");", "lua", "t", tEnv )
if not func then
if func2 then
func = func2
e = nil
nForcePrint = 1
end
else
if func2 then
func = func2
end
end
if func then
local tResults = { pcall( func ) }
if tResults[1] then
local n = 1
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
local value = tResults[ n + 1 ]
if type( value ) == "table" then
local metatable = getmetatable( value )
if type(metatable) == "table" and type(metatable.__tostring) == "function" then
print( tostring( value ) )
else
local n = 1
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
local value = tResults[ n + 1 ]
if type( value ) == "table" then
local metatable = getmetatable( value )
if type(metatable) == "table" and type(metatable.__tostring) == "function" then
print( tostring( value ) )
else
local ok, serialised = pcall( textutils.serialise, value )
if ok then
print( serialised )
else
print( tostring( value ) )
end
end
else
print( tostring( value ) )
end
n = n + 1
end
end
else
print( tostring( value ) )
end
n = n + 1
end
else
printError( tResults[2] )
printError( tResults[2] )
end
else
printError( e )
printError( e )
end
end

View File

@ -1,7 +1,7 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: mkdir <path>" )
return
print( "Usage: mkdir <path>" )
return
end
local sNewDir = shell.resolve( tArgs[1] )

View File

@ -1,26 +1,26 @@
local function printUsage()
print( "Usage: monitor <name> <program> <arguments>" )
return
print( "Usage: monitor <name> <program> <arguments>" )
return
end
local tArgs = { ... }
if #tArgs < 2 then
printUsage()
return
printUsage()
return
end
local sName = tArgs[1]
if peripheral.getType( sName ) ~= "monitor" then
print( "No monitor named ".. sName )
return
print( "No monitor named ".. sName )
return
end
local sProgram = tArgs[2]
local sPath = shell.resolveProgram( sProgram )
if sPath == nil then
print( "No such program: "..sProgram )
return
print( "No such program: "..sProgram )
return
end
print( "Running "..sProgram.." on monitor "..sName )
@ -35,33 +35,33 @@ end )
local function resume( ... )
local ok, param = coroutine.resume( co, ... )
if not ok then
printError( param )
printError( param )
end
return param
end
local ok, param = pcall( function()
local sFilter = resume()
while coroutine.status( co ) ~= "dead" do
local tEvent = table.pack( os.pullEventRaw() )
if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
sFilter = resume( table.unpack( tEvent, 1, tEvent.n ) )
end
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then
if tEvent[1] == "monitor_touch" and tEvent[2] == sName then
sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3, tEvent.n ) )
end
end
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then
if tEvent[1] == "monitor_resize" and tEvent[2] == sName then
sFilter = resume( "term_resize" )
end
end
end
local sFilter = resume()
while coroutine.status( co ) ~= "dead" do
local tEvent = table.pack( os.pullEventRaw() )
if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
sFilter = resume( table.unpack( tEvent, 1, tEvent.n ) )
end
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then
if tEvent[1] == "monitor_touch" and tEvent[2] == sName then
sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3, tEvent.n ) )
end
end
if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then
if tEvent[1] == "monitor_resize" and tEvent[2] == sName then
sFilter = resume( "term_resize" )
end
end
end
end )
term.redirect( previousTerm )
if not ok then
printError( param )
printError( param )
end

View File

@ -1,8 +1,8 @@
local tArgs = { ... }
if #tArgs < 2 then
print( "Usage: mv <source> <destination>" )
return
print( "Usage: mv <source> <destination>" )
return
end
local sSource = shell.resolve( tArgs[1] )

View File

@ -1,10 +1,10 @@
local tPeripherals = peripheral.getNames()
print( "Attached Peripherals:" )
if #tPeripherals > 0 then
for n=1,#tPeripherals do
local sPeripheral = tPeripherals[n]
print( sPeripheral .. " (" .. peripheral.getType( sPeripheral ) .. ")" )
end
for n=1,#tPeripherals do
local sPeripheral = tPeripherals[n]
print( sPeripheral .. " (" .. peripheral.getType( sPeripheral ) .. ")" )
end
else
print( "None" )
end
print( "None" )
end

View File

@ -648,4 +648,4 @@ end
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
term.setCursorPos(1,1)

View File

@ -2,7 +2,7 @@
local bAll = false
local tArgs = { ... }
if #tArgs > 0 and tArgs[1] == "all" then
bAll = true
bAll = true
end
local tPrograms = shell.programs( bAll )

View File

@ -1,5 +1,5 @@
if term.isColour() then
term.setTextColour( colours.yellow )
term.setTextColour( colours.yellow )
end
print( "Goodbye" )
term.setTextColour( colours.white )

View File

@ -2,9 +2,9 @@
local tArgs = { ... }
local function printUsage()
print( "Usages:" )
print( "chat host <hostname>" )
print( "chat join <hostname> <nickname>" )
print( "Usages:" )
print( "chat host <hostname>" )
print( "chat join <hostname> <nickname>" )
end
local sOpenedModem = nil
@ -32,11 +32,11 @@ end
-- Colours
local highlightColour, textColour
if term.isColour() then
textColour = colours.white
highlightColour = colours.yellow
textColour = colours.white
highlightColour = colours.yellow
else
textColour = colours.white
highlightColour = colours.white
textColour = colours.white
highlightColour = colours.white
end
local sCommand = tArgs[1]

View File

@ -1,7 +1,7 @@
local tArgs = { ... }
if #tArgs < 2 then
print( "Usage: rename <source> <destination>" )
return
print( "Usage: rename <source> <destination>" )
return
end
local sSource = shell.resolve( tArgs[1] )

View File

@ -1,42 +1,42 @@
local tArgs = { ... }
if #tArgs == 0 then
-- "set"
for n,sName in ipairs( settings.getNames() ) do
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
end
-- "set"
for n,sName in ipairs( settings.getNames() ) do
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
end
elseif #tArgs == 1 then
-- "set foo"
local sName = tArgs[1]
-- "set foo"
local sName = tArgs[1]
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
else
-- "set foo bar"
local sName = tArgs[1]
local sValue = tArgs[2]
local value
if sValue == "true" then
value = true
elseif sValue == "false" then
value = false
elseif sValue == "nil" then
value = nil
elseif tonumber(sValue) then
value = tonumber(sValue)
else
value = sValue
end
-- "set foo bar"
local sName = tArgs[1]
local sValue = tArgs[2]
local value
if sValue == "true" then
value = true
elseif sValue == "false" then
value = false
elseif sValue == "nil" then
value = nil
elseif tonumber(sValue) then
value = tonumber(sValue)
else
value = sValue
end
local oldValue = settings.get( sValue )
if value ~= nil then
settings.set( sName, value )
print( textutils.serialize(sName) .. " set to " .. textutils.serialize(value) )
else
settings.unset( sName )
print( textutils.serialize(sName) .. " unset" )
end
if value ~= oldValue then
settings.save( ".settings" )
end
local oldValue = settings.get( sValue )
if value ~= nil then
settings.set( sName, value )
print( textutils.serialize(sName) .. " set to " .. textutils.serialize(value) )
else
settings.unset( sName )
print( textutils.serialize(sName) .. " unset" )
end
if value ~= oldValue then
settings.save( ".settings" )
end
end

View File

@ -16,56 +16,56 @@ local tProgramStack = {}
local shell = {}
local tEnv = {
[ "shell" ] = shell,
[ "multishell" ] = multishell,
[ "shell" ] = shell,
[ "multishell" ] = multishell,
}
-- Colours
local promptColour, textColour, bgColour
if term.isColour() then
promptColour = colours.yellow
textColour = colours.white
bgColour = colours.black
promptColour = colours.yellow
textColour = colours.white
bgColour = colours.black
else
promptColour = colours.white
textColour = colours.white
bgColour = colours.black
promptColour = colours.white
textColour = colours.white
bgColour = colours.black
end
local function run( _sCommand, ... )
local sPath = shell.resolveProgram( _sCommand )
if sPath ~= nil then
tProgramStack[#tProgramStack + 1] = sPath
if multishell then
local sPath = shell.resolveProgram( _sCommand )
if sPath ~= nil then
tProgramStack[#tProgramStack + 1] = sPath
if multishell then
local sTitle = fs.getName( sPath )
if sTitle:sub(-4) == ".lua" then
sTitle = sTitle:sub(1,-5)
end
multishell.setTitle( multishell.getCurrent(), sTitle )
end
local result = os.run( tEnv, sPath, ... )
tProgramStack[#tProgramStack] = nil
if multishell then
if #tProgramStack > 0 then
local sTitle = fs.getName( tProgramStack[#tProgramStack] )
if sTitle:sub(-4) == ".lua" then
sTitle = sTitle:sub(1,-5)
multishell.setTitle( multishell.getCurrent(), sTitle )
end
local result = os.run( tEnv, sPath, ... )
tProgramStack[#tProgramStack] = nil
if multishell then
if #tProgramStack > 0 then
local sTitle = fs.getName( tProgramStack[#tProgramStack] )
if sTitle:sub(-4) == ".lua" then
sTitle = sTitle:sub(1,-5)
end
multishell.setTitle( multishell.getCurrent(), sTitle )
else
multishell.setTitle( multishell.getCurrent(), "shell" )
end
end
return result
else
printError( "No such program" )
return false
else
multishell.setTitle( multishell.getCurrent(), "shell" )
end
end
return result
else
printError( "No such program" )
return false
end
end
local function tokenise( ... )
local sLine = table.concat( { ... }, " " )
local tWords = {}
local tWords = {}
local bQuoted = false
for match in string.gmatch( sLine .. "\"", "(.-)\"" ) do
if bQuoted then
@ -82,12 +82,12 @@ end
-- Install shell API
function shell.run( ... )
local tWords = tokenise( ... )
local sCommand = tWords[1]
if sCommand then
return run( sCommand, table.unpack( tWords, 2 ) )
end
return false
local tWords = tokenise( ... )
local sCommand = tWords[1]
if sCommand then
return run( sCommand, table.unpack( tWords, 2 ) )
end
return false
end
function shell.exit()
@ -95,28 +95,28 @@ function shell.exit()
end
function shell.dir()
return sDir
return sDir
end
function shell.setDir( _sDir )
sDir = _sDir
sDir = _sDir
end
function shell.path()
return sPath
return sPath
end
function shell.setPath( _sPath )
sPath = _sPath
sPath = _sPath
end
function shell.resolve( _sPath )
local sStartChar = string.sub( _sPath, 1, 1 )
if sStartChar == "/" or sStartChar == "\\" then
return fs.combine( "", _sPath )
else
return fs.combine( sDir, _sPath )
end
local sStartChar = string.sub( _sPath, 1, 1 )
if sStartChar == "/" or sStartChar == "\\" then
return fs.combine( "", _sPath )
else
return fs.combine( sDir, _sPath )
end
end
local function pathWithExtension( _sPath, _sExt )
@ -130,77 +130,77 @@ local function pathWithExtension( _sPath, _sExt )
end
function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
_sCommand = tAliases[ _sCommand ]
end
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
_sCommand = tAliases[ _sCommand ]
end
-- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 )
if sStartChar == "/" or sStartChar == "\\" then
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
else
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
else
local sPathLua = pathWithExtension( sPath, "lua" )
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
return sPathLua
end
end
return nil
return nil
end
-- Otherwise, look on the path variable
-- Otherwise, look on the path variable
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
else
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
else
local sPathLua = pathWithExtension( sPath, "lua" )
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
return sPathLua
end
end
end
-- Not found
return nil
-- Not found
return nil
end
function shell.programs( _bIncludeHidden )
local tItems = {}
-- Add programs from the path
local tItems = {}
-- Add programs from the path
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = shell.resolve( sPath )
if fs.isDir( sPath ) then
local tList = fs.list( sPath )
sPath = shell.resolve( sPath )
if fs.isDir( sPath ) then
local tList = fs.list( sPath )
for n=1,#tList do
local sFile = tList[n]
if not fs.isDir( fs.combine( sPath, sFile ) ) and
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
if #sFile > 4 and sFile:sub(-4) == ".lua" then
sFile = sFile:sub(1,-5)
end
tItems[ sFile ] = true
end
end
end
end
if not fs.isDir( fs.combine( sPath, sFile ) ) and
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
if #sFile > 4 and sFile:sub(-4) == ".lua" then
sFile = sFile:sub(1,-5)
end
tItems[ sFile ] = true
end
end
end
end
-- Sort and return
local tItemList = {}
for sItem, b in pairs( tItems ) do
-- Sort and return
local tItemList = {}
for sItem, b in pairs( tItems ) do
table.insert( tItemList, sItem )
end
table.sort( tItemList )
return tItemList
end
table.sort( tItemList )
return tItemList
end
local function completeProgram( sLine )
if #sLine > 0 and string.sub( sLine, 1, 1 ) == "/" then
-- Add programs from the root
return fs.complete( sLine, "", true, false )
if #sLine > 0 and string.sub( sLine, 1, 1 ) == "/" then
-- Add programs from the root
return fs.complete( sLine, "", true, false )
else
local tResults = {}
@ -277,7 +277,7 @@ function shell.complete( sLine )
end
end
return nil
return nil
end
function shell.completeProgram( sProgram )
@ -295,27 +295,27 @@ function shell.getCompletionInfo()
end
function shell.getRunningProgram()
if #tProgramStack > 0 then
return tProgramStack[#tProgramStack]
end
return nil
if #tProgramStack > 0 then
return tProgramStack[#tProgramStack]
end
return nil
end
function shell.setAlias( _sCommand, _sProgram )
tAliases[ _sCommand ] = _sProgram
tAliases[ _sCommand ] = _sProgram
end
function shell.clearAlias( _sCommand )
tAliases[ _sCommand ] = nil
tAliases[ _sCommand ] = nil
end
function shell.aliases()
-- Copy aliases
local tCopy = {}
for sAlias, sCommand in pairs( tAliases ) do
tCopy[sAlias] = sCommand
end
return tCopy
-- Copy aliases
local tCopy = {}
for sAlias, sCommand in pairs( tAliases ) do
tCopy[sAlias] = sCommand
end
return tCopy
end
if multishell then
@ -323,8 +323,8 @@ if multishell then
local tWords = tokenise( ... )
local sCommand = tWords[1]
if sCommand then
local sPath = shell.resolveProgram( sCommand )
if sPath == "rom/programs/shell.lua" then
local sPath = shell.resolveProgram( sCommand )
if sPath == "rom/programs/shell.lua" then
return multishell.launch( tEnv, sPath, table.unpack( tWords, 2 ) )
elseif sPath ~= nil then
return multishell.launch( tEnv, "rom/programs/shell.lua", sCommand, table.unpack( tWords, 2 ) )

View File

@ -1,5 +1,5 @@
if term.isColour() then
term.setTextColour( colours.yellow )
term.setTextColour( colours.yellow )
end
print( "Goodbye" )
term.setTextColour( colours.white )

View File

@ -7,10 +7,10 @@ end
local tArgs = { ... }
local nLimit = nil
if #tArgs < 1 then
print( "Usage: craft [number]" )
return
print( "Usage: craft [number]" )
return
else
nLimit = tonumber( tArgs[1] )
nLimit = tonumber( tArgs[1] )
end
local nCrafted = 0

View File

@ -1,77 +1,77 @@
local tMoves = {
function()
turtle.up()
turtle.down()
end,
function()
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.down()
end,
function()
turtle.up()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.down()
end,
function()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
end,
function()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
end,
function()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.turnRight()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.turnLeft()
end,
function()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.turnRight()
end,
function()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
end,
function()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
end,
function()
turtle.up()
turtle.down()
end,
function()
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.down()
end,
function()
turtle.up()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.down()
end,
function()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnLeft()
end,
function()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
end,
function()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.turnRight()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.turnLeft()
end,
function()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.turnRight()
end,
function()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
end,
function()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
turtle.back()
turtle.turnRight()
end,
}
textutils.slowWrite( "Preparing to get down." )
@ -79,34 +79,34 @@ textutils.slowPrint( "..", 0.75 )
local sAudio = nil
for n,sName in pairs( peripheral.getNames() ) do
if disk.hasAudio( sName ) then
disk.playAudio( sName )
print( "Jamming to "..disk.getAudioTitle( sName ) )
sAudio = sName
break
end
if disk.hasAudio( sName ) then
disk.playAudio( sName )
print( "Jamming to "..disk.getAudioTitle( sName ) )
sAudio = sName
break
end
end
print( "Press any key to stop the groove" )
local bEnd = false
parallel.waitForAll(
function()
while not bEnd do
local event, key = os.pullEvent("key")
if key ~= keys.escape then
bEnd = true
end
end
end,
function()
while not bEnd do
local fnMove = tMoves[math.random(1,#tMoves)]
fnMove()
end
end
function()
while not bEnd do
local event, key = os.pullEvent("key")
if key ~= keys.escape then
bEnd = true
end
end
end,
function()
while not bEnd do
local fnMove = tMoves[math.random(1,#tMoves)]
fnMove()
end
end
)
if sAudio then
disk.stopAudio( sAudio )
disk.stopAudio( sAudio )
end

View File

@ -1,12 +1,12 @@
local tArgs = { ... }
local function printUsage()
print( "Usage: equip <slot> <side>" )
print( "Usage: equip <slot> <side>" )
end
if #tArgs ~= 2 then
printUsage()
return
return
end
local function equip( nSlot, fnEquipFunction )

View File

@ -1,17 +1,17 @@
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: excavate <diameter>" )
return
print( "Usage: excavate <diameter>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local size = tonumber( tArgs[1] )
if size < 1 then
print( "Excavate diameter must be positive" )
return
print( "Excavate diameter must be positive" )
return
end
local depth = 0
local unloaded = 0
local collected = 0
@ -23,257 +23,257 @@ local goTo -- Filled in further down
local refuel -- Filled in further down
local function unload( _bKeepOneFuelStack )
print( "Unloading items..." )
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount > 0 then
turtle.select(n)
local bDrop = true
if _bKeepOneFuelStack and turtle.refuel(0) then
bDrop = false
_bKeepOneFuelStack = false
end
if bDrop then
turtle.drop()
unloaded = unloaded + nCount
end
end
end
collected = 0
turtle.select(1)
print( "Unloading items..." )
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount > 0 then
turtle.select(n)
local bDrop = true
if _bKeepOneFuelStack and turtle.refuel(0) then
bDrop = false
_bKeepOneFuelStack = false
end
if bDrop then
turtle.drop()
unloaded = unloaded + nCount
end
end
end
collected = 0
turtle.select(1)
end
local function returnSupplies()
local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
print( "Returning to surface..." )
goTo( 0,0,0,0,-1 )
local fuelNeeded = 2*(x+y+z) + 1
if not refuel( fuelNeeded ) then
unload( true )
print( "Waiting for fuel" )
while not refuel( fuelNeeded ) do
os.pullEvent( "turtle_inventory" )
end
else
unload( true )
end
print( "Resuming mining..." )
goTo( x,y,z,xd,zd )
local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
print( "Returning to surface..." )
goTo( 0,0,0,0,-1 )
local fuelNeeded = 2*(x+y+z) + 1
if not refuel( fuelNeeded ) then
unload( true )
print( "Waiting for fuel" )
while not refuel( fuelNeeded ) do
os.pullEvent( "turtle_inventory" )
end
else
unload( true )
end
print( "Resuming mining..." )
goTo( x,y,z,xd,zd )
end
local function collect()
local bFull = true
local nTotalItems = 0
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount == 0 then
bFull = false
end
nTotalItems = nTotalItems + nCount
end
if nTotalItems > collected then
collected = nTotalItems
if math.fmod(collected + unloaded, 50) == 0 then
print( "Mined "..(collected + unloaded).." items." )
end
end
if bFull then
print( "No empty slots left." )
return false
end
return true
local function collect()
local bFull = true
local nTotalItems = 0
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount == 0 then
bFull = false
end
nTotalItems = nTotalItems + nCount
end
if nTotalItems > collected then
collected = nTotalItems
if math.fmod(collected + unloaded, 50) == 0 then
print( "Mined "..(collected + unloaded).." items." )
end
end
if bFull then
print( "No empty slots left." )
return false
end
return true
end
function refuel( ammount )
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" then
return true
end
local needed = ammount or (xPos + zPos + depth + 2)
if turtle.getFuelLevel() < needed then
local fueled = false
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
turtle.refuel(1)
end
if turtle.getFuelLevel() >= needed then
turtle.select(1)
return true
end
end
end
end
turtle.select(1)
return false
end
return true
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" then
return true
end
local needed = ammount or (xPos + zPos + depth + 2)
if turtle.getFuelLevel() < needed then
local fueled = false
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
turtle.refuel(1)
end
if turtle.getFuelLevel() >= needed then
turtle.select(1)
return true
end
end
end
end
turtle.select(1)
return false
end
return true
end
local function tryForwards()
if not refuel() then
print( "Not enough Fuel" )
returnSupplies()
end
while not turtle.forward() do
if turtle.detect() then
if turtle.dig() then
if not collect() then
returnSupplies()
end
else
return false
end
elseif turtle.attack() then
if not collect() then
returnSupplies()
end
else
sleep( 0.5 )
end
end
xPos = xPos + xDir
zPos = zPos + zDir
return true
if not refuel() then
print( "Not enough Fuel" )
returnSupplies()
end
while not turtle.forward() do
if turtle.detect() then
if turtle.dig() then
if not collect() then
returnSupplies()
end
else
return false
end
elseif turtle.attack() then
if not collect() then
returnSupplies()
end
else
sleep( 0.5 )
end
end
xPos = xPos + xDir
zPos = zPos + zDir
return true
end
local function tryDown()
if not refuel() then
print( "Not enough Fuel" )
returnSupplies()
end
while not turtle.down() do
if turtle.detectDown() then
if turtle.digDown() then
if not collect() then
returnSupplies()
end
else
return false
end
elseif turtle.attackDown() then
if not collect() then
returnSupplies()
end
else
sleep( 0.5 )
end
end
if not refuel() then
print( "Not enough Fuel" )
returnSupplies()
end
while not turtle.down() do
if turtle.detectDown() then
if turtle.digDown() then
if not collect() then
returnSupplies()
end
else
return false
end
elseif turtle.attackDown() then
if not collect() then
returnSupplies()
end
else
sleep( 0.5 )
end
end
depth = depth + 1
if math.fmod( depth, 10 ) == 0 then
print( "Descended "..depth.." metres." )
end
depth = depth + 1
if math.fmod( depth, 10 ) == 0 then
print( "Descended "..depth.." metres." )
end
return true
return true
end
local function turnLeft()
turtle.turnLeft()
xDir, zDir = -zDir, xDir
turtle.turnLeft()
xDir, zDir = -zDir, xDir
end
local function turnRight()
turtle.turnRight()
xDir, zDir = zDir, -xDir
turtle.turnRight()
xDir, zDir = zDir, -xDir
end
function goTo( x, y, z, xd, zd )
while depth > y do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() or turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
while depth > y do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() or turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
if xPos > x then
while xDir ~= -1 do
turnLeft()
end
while xPos > x do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif xPos < x then
while xDir ~= 1 do
turnLeft()
end
while xPos < x do
if turtle.forward() then
xPos = xPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
if zPos > z then
while zDir ~= -1 do
turnLeft()
end
while zPos > z do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif zPos < z then
while zDir ~= 1 do
turnLeft()
end
while zPos < z do
if turtle.forward() then
zPos = zPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
while depth < y do
if turtle.down() then
depth = depth + 1
elseif turtle.digDown() or turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
while zDir ~= zd or xDir ~= xd do
turnLeft()
end
if xPos > x then
while xDir ~= -1 do
turnLeft()
end
while xPos > x do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif xPos < x then
while xDir ~= 1 do
turnLeft()
end
while xPos < x do
if turtle.forward() then
xPos = xPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
if zPos > z then
while zDir ~= -1 do
turnLeft()
end
while zPos > z do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif zPos < z then
while zDir ~= 1 do
turnLeft()
end
while zPos < z do
if turtle.forward() then
zPos = zPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
while depth < y do
if turtle.down() then
depth = depth + 1
elseif turtle.digDown() or turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
while zDir ~= zd or xDir ~= xd do
turnLeft()
end
end
if not refuel() then
print( "Out of Fuel" )
return
print( "Out of Fuel" )
return
end
print( "Excavating..." )
@ -281,61 +281,61 @@ print( "Excavating..." )
local reseal = false
turtle.select(1)
if turtle.digDown() then
reseal = true
reseal = true
end
local alternate = 0
local done = false
while not done do
for n=1,size do
for m=1,size-1 do
if not tryForwards() then
done = true
break
end
end
if done then
break
end
if n<size then
if math.fmod(n + alternate,2) == 0 then
turnLeft()
if not tryForwards() then
done = true
break
end
turnLeft()
else
turnRight()
if not tryForwards() then
done = true
break
end
turnRight()
end
end
end
if done then
break
end
if size > 1 then
if math.fmod(size,2) == 0 then
turnRight()
else
if alternate == 0 then
turnLeft()
else
turnRight()
end
alternate = 1 - alternate
end
end
if not tryDown() then
done = true
break
end
for n=1,size do
for m=1,size-1 do
if not tryForwards() then
done = true
break
end
end
if done then
break
end
if n<size then
if math.fmod(n + alternate,2) == 0 then
turnLeft()
if not tryForwards() then
done = true
break
end
turnLeft()
else
turnRight()
if not tryForwards() then
done = true
break
end
turnRight()
end
end
end
if done then
break
end
if size > 1 then
if math.fmod(size,2) == 0 then
turnRight()
else
if alternate == 0 then
turnLeft()
else
turnRight()
end
alternate = 1 - alternate
end
end
if not tryDown() then
done = true
break
end
end
print( "Returning to surface..." )
@ -347,7 +347,7 @@ goTo( 0,0,0,0,1 )
-- Seal the hole
if reseal then
turtle.placeDown()
turtle.placeDown()
end
print( "Mined "..(collected + unloaded).." items total." )

View File

@ -1,53 +1,53 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: go <direction> <distance>" )
return
print( "Usage: go <direction> <distance>" )
return
end
local tHandlers = {
["fd"] = turtle.forward,
["forward"] = turtle.forward,
["forwards"] = turtle.forward,
["bk"] = turtle.back,
["back"] = turtle.back,
["up"] = turtle.up,
["dn"] = turtle.down,
["down"] = turtle.down,
["lt"] = turtle.turnLeft,
["left"] = turtle.turnLeft,
["rt"] = turtle.turnRight,
["right"] = turtle.turnRight,
["fd"] = turtle.forward,
["forward"] = turtle.forward,
["forwards"] = turtle.forward,
["bk"] = turtle.back,
["back"] = turtle.back,
["up"] = turtle.up,
["dn"] = turtle.down,
["down"] = turtle.down,
["lt"] = turtle.turnLeft,
["left"] = turtle.turnLeft,
["rt"] = turtle.turnRight,
["right"] = turtle.turnRight,
}
local nArg = 1
while nArg <= #tArgs do
local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber( tArgs[nArg + 1] )
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1
local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber( tArgs[nArg + 1] )
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1
local fnHandler = tHandlers[string.lower(sDirection)]
if fnHandler then
while nDistance > 0 do
if fnHandler() then
nDistance = nDistance - 1
elseif turtle.getFuelLevel() == 0 then
print( "Out of fuel" )
return
else
sleep(0.5)
end
end
else
print( "No such direction: "..sDirection )
print( "Try: forward, back, up, down" )
return
end
local fnHandler = tHandlers[string.lower(sDirection)]
if fnHandler then
while nDistance > 0 do
if fnHandler() then
nDistance = nDistance - 1
elseif turtle.getFuelLevel() == 0 then
print( "Out of fuel" )
return
else
sleep(0.5)
end
end
else
print( "No such direction: "..sDirection )
print( "Try: forward, back, up, down" )
return
end
end
end

View File

@ -2,28 +2,28 @@
local tArgs = { ... }
local nLimit = 1
if #tArgs > 1 then
print( "Usage: refuel [number]" )
return
print( "Usage: refuel [number]" )
return
elseif #tArgs > 0 then
if tArgs[1] == "all" then
nLimit = 64 * 16
else
nLimit = tonumber( tArgs[1] )
end
if tArgs[1] == "all" then
nLimit = 64 * 16
else
nLimit = tonumber( tArgs[1] )
end
end
if turtle.getFuelLevel() ~= "unlimited" then
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
local nBurn = math.min( nLimit, nCount )
turtle.select( n )
if turtle.refuel( nBurn ) then
local nNewCount = turtle.getItemCount(n)
nLimit = nLimit - (nCount - nNewCount)
end
end
end
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
local nBurn = math.min( nLimit, nCount )
turtle.select( n )
if turtle.refuel( nBurn ) then
local nNewCount = turtle.getItemCount(n)
nLimit = nLimit - (nCount - nNewCount)
end
end
end
print( "Fuel level is "..turtle.getFuelLevel() )
if turtle.getFuelLevel() == turtle.getFuelLimit() then
print( "Fuel limit reached" )

View File

@ -1,165 +1,165 @@
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigDown()
while turtle.detectDown() do
if turtle.digDown() then
collect()
sleep(0.5)
else
return false
end
end
return true
while turtle.detectDown() do
if turtle.digDown() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
os.pullEvent( "turtle_inventory" )
end
print( "Resuming Tunnel." )
end
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
os.pullEvent( "turtle_inventory" )
end
print( "Resuming Tunnel." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
print( "Tunnelling..." )
for n=1,length do
turtle.placeDown()
tryDigUp()
turtle.turnLeft()
tryDig()
tryUp()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
tryDown()
tryDig()
turtle.turnLeft()
if n<length then
tryDig()
if not tryForward() then
print( "Aborting Tunnel." )
break
end
else
print( "Tunnel complete." )
end
turtle.placeDown()
tryDigUp()
turtle.turnLeft()
tryDig()
tryUp()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
tryDown()
tryDig()
turtle.turnLeft()
if n<length then
tryDig()
if not tryForward() then
print( "Aborting Tunnel." )
break
end
else
print( "Tunnel complete." )
end
end
@ -170,11 +170,11 @@ print( "Returning to start..." )
turtle.turnLeft()
turtle.turnLeft()
while depth > 0 do
if turtle.forward() then
depth = depth - 1
else
turtle.dig()
end
if turtle.forward() then
depth = depth - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()

View File

@ -1,38 +1,38 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: turn <direction> <turns>" )
return
print( "Usage: turn <direction> <turns>" )
return
end
local tHandlers = {
["lt"] = turtle.turnLeft,
["left"] = turtle.turnLeft,
["rt"] = turtle.turnRight,
["right"] = turtle.turnRight,
["lt"] = turtle.turnLeft,
["left"] = turtle.turnLeft,
["rt"] = turtle.turnRight,
["right"] = turtle.turnRight,
}
local nArg = 1
while nArg <= #tArgs do
local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber( tArgs[nArg + 1] )
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1
local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber( tArgs[nArg + 1] )
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1
local fnHandler = tHandlers[string.lower(sDirection)]
if fnHandler then
for n=1,nDistance do
fnHandler( nArg )
end
else
print( "No such direction: "..sDirection )
print( "Try: left, right" )
return
end
end
local fnHandler = tHandlers[string.lower(sDirection)]
if fnHandler then
for n=1,nDistance do
fnHandler( nArg )
end
else
print( "No such direction: "..sDirection )
print( "Try: left, right" )
return
end
end

View File

@ -1,12 +1,12 @@
local tArgs = { ... }
local function printUsage()
print( "Usage: unequip <side>" )
print( "Usage: unequip <side>" )
end
if #tArgs ~= 1 then
printUsage()
return
return
end
local function unequip( fnEquipFunction )

View File

@ -1,18 +1,18 @@
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: type <path>" )
return
print( "Usage: type <path>" )
return
end
local sPath = shell.resolve( tArgs[1] )
if fs.exists( sPath ) then
if fs.isDir( sPath ) then
print( "directory" )
else
print( "file" )
end
if fs.isDir( sPath ) then
print( "directory" )
else
print( "file" )
end
else
print( "No such path" )
print( "No such path" )
end

View File

@ -2,14 +2,14 @@
-- Setup paths
local sPath = ".:/rom/programs"
if term.isColor() then
sPath = sPath..":/rom/programs/advanced"
sPath = sPath..":/rom/programs/advanced"
end
if turtle then
sPath = sPath..":/rom/programs/turtle"
sPath = sPath..":/rom/programs/turtle"
else
sPath = sPath..":/rom/programs/rednet:/rom/programs/fun"
if term.isColor() then
sPath = sPath..":/rom/programs/fun/advanced"
sPath = sPath..":/rom/programs/fun/advanced"
end
end
if pocket then
@ -19,7 +19,7 @@ if commands then
sPath = sPath..":/rom/programs/command"
end
if http then
sPath = sPath..":/rom/programs/http"
sPath = sPath..":/rom/programs/http"
end
shell.setPath( sPath )
help.setPath( "/rom/help" )
@ -197,16 +197,16 @@ shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
-- Run autorun files
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
local tFiles = fs.list( "/rom/autorun" )
table.sort( tFiles )
for n, sFile in ipairs( tFiles ) do
if string.sub( sFile, 1, 1 ) ~= "." then
local sPath = "/rom/autorun/"..sFile
if not fs.isDir( sPath ) then
shell.run( sPath )
end
end
end
local tFiles = fs.list( "/rom/autorun" )
table.sort( tFiles )
for n, sFile in ipairs( tFiles ) do
if string.sub( sFile, 1, 1 ) ~= "." then
local sPath = "/rom/autorun/"..sFile
if not fs.isDir( sPath ) then
shell.run( sPath )
end
end
end
end
local function findStartups( sBaseDir )