:3
This commit is contained in:
parent
491112768c
commit
68ec37f994
66 changed files with 6591 additions and 10096 deletions
11
computer/26/bg.lua
Normal file
11
computer/26/bg.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
if not shell.openTab then
|
||||
printError("Requires multishell")
|
||||
return
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs > 0 then
|
||||
shell.openTab(table.unpack(tArgs))
|
||||
else
|
||||
shell.openTab("shell")
|
||||
end
|
106
computer/26/expand.lua
Normal file
106
computer/26/expand.lua
Normal file
|
@ -0,0 +1,106 @@
|
|||
require("path")
|
||||
pp = require("cc.pretty").pretty_print
|
||||
|
||||
require("progress")
|
||||
|
||||
-- mirror = wall is to the right
|
||||
local mirror = true
|
||||
mirror = mirror or false
|
||||
|
||||
local TILES = 13
|
||||
|
||||
function save(layer)
|
||||
fs.delete("progress.lua")
|
||||
repeat
|
||||
file = fs.open("progress.lua", "w")
|
||||
until file
|
||||
file.write("progress = " .. progress .. "\n")
|
||||
file.write("layer_start = " .. layer .. "\n")
|
||||
-- todo save pos separately, more frequently
|
||||
file.close()
|
||||
end
|
||||
|
||||
function mine_step()
|
||||
repeat
|
||||
turtle.dig()
|
||||
until goForward()
|
||||
end
|
||||
|
||||
function mine3_step()
|
||||
turtle.digUp()
|
||||
turtle.digDown()
|
||||
repeat
|
||||
turtle.dig()
|
||||
until goForward()
|
||||
end
|
||||
|
||||
local turnLeft = true
|
||||
function turn()
|
||||
if turnLeft then
|
||||
goLeft()
|
||||
else
|
||||
goRight()
|
||||
end
|
||||
end
|
||||
|
||||
-- assumes position is on lamp, right in front of the slice to be mined
|
||||
-- nearest the wall
|
||||
function clear_tile_slice()
|
||||
for layer = layer_start, 5 do
|
||||
save(layer)
|
||||
local y = 12 - layer * 3
|
||||
local x = 9
|
||||
local length = 8 * TILES + 9
|
||||
if layer == 5 then
|
||||
x = x - 3
|
||||
length = length - 3
|
||||
end
|
||||
turnLeft = (layer % 2 == 0) ~= mirror
|
||||
local z = progress*8 + 1 + (layer % 2) * 7
|
||||
if y < 0 then
|
||||
-- avoid breaking the existing floor
|
||||
for _ = 0, progress*8 do
|
||||
goForward()
|
||||
end
|
||||
end
|
||||
if mirror then
|
||||
goTo(vector.new(-x,y,z), "east", true)
|
||||
else
|
||||
goTo(vector.new(x,y,z), "west", true)
|
||||
end
|
||||
|
||||
for strip = 1, 8 do
|
||||
for _ = 1, length do
|
||||
mine3_step()
|
||||
end
|
||||
if strip ~= 8 then
|
||||
turn()
|
||||
mine3_step()
|
||||
turn()
|
||||
turnLeft = not turnLeft;
|
||||
end
|
||||
end
|
||||
goLeft()
|
||||
goLeft()
|
||||
end
|
||||
end
|
||||
|
||||
goHome()
|
||||
clear_tile_slice()
|
||||
progress = progress + 1
|
||||
save(0)
|
||||
for i = 1, 16 do
|
||||
turtle.select(i)
|
||||
turtle.drop()
|
||||
end
|
||||
turtle.select(1)
|
||||
goHome()
|
||||
goLeft()
|
||||
goLeft()
|
||||
while turtle.getFuelLevel() < 20000 do
|
||||
turtle.suck()
|
||||
turtle.refuel()
|
||||
end
|
||||
turtle.drop()
|
||||
goLeft()
|
||||
goLeft()
|
85
computer/26/garbidge/dig.lua
Normal file
85
computer/26/garbidge/dig.lua
Normal file
|
@ -0,0 +1,85 @@
|
|||
width = 5
|
||||
length = 31
|
||||
MinFuelLevel = 19500
|
||||
|
||||
y = 0
|
||||
|
||||
|
||||
function layer()
|
||||
turnLeft = 1
|
||||
|
||||
function turn()
|
||||
if turnLeft == 1 then
|
||||
turtle.turnLeft()
|
||||
else
|
||||
turtle.turnRight()
|
||||
end
|
||||
end
|
||||
function digStep()
|
||||
turtle.dig()
|
||||
turtle.digUp()
|
||||
turtle.digDown()
|
||||
turtle.forward()
|
||||
end
|
||||
|
||||
for row = 1, width do
|
||||
for i = 1,length do
|
||||
digStep()
|
||||
end
|
||||
turn()
|
||||
digStep()
|
||||
turn()
|
||||
turnLeft = -turnLeft
|
||||
end
|
||||
if turnLeft == 1 then
|
||||
turtle.turnRight()
|
||||
for i = 1, width do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
else
|
||||
turtle.turnLeft()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
for i = 1, length do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
for i = 1, width do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
end
|
||||
end
|
||||
|
||||
function unload()
|
||||
for i = 1, 16 do
|
||||
turtle.select(i)
|
||||
turtle.dropUp()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
while turtle.getFuelLevel() < MinFuelLevel do
|
||||
turtle.suck()
|
||||
turtle.refuel()
|
||||
end
|
||||
turtle.drop()
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
|
||||
end
|
||||
|
||||
while true do
|
||||
turtle.forward()
|
||||
for i = 1, y do
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
end
|
||||
layer()
|
||||
for i = 1, y do
|
||||
turtle.up()
|
||||
end
|
||||
turtle.back()
|
||||
unload()
|
||||
y = y + 3
|
||||
end
|
34
computer/26/garbidge/roof.lua
Normal file
34
computer/26/garbidge/roof.lua
Normal file
|
@ -0,0 +1,34 @@
|
|||
width = 5
|
||||
length = 23
|
||||
|
||||
turtle.select(1)
|
||||
|
||||
tLeft = true
|
||||
|
||||
function turn()
|
||||
if tLeft then
|
||||
turtle.turnLeft()
|
||||
else
|
||||
turtle.turnRight()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function step()
|
||||
turtle.placeUp()
|
||||
turtle.forward()
|
||||
if turtle.getItemCount() == 0 then
|
||||
turtle.select(turtle.getSelectedSlot()+1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for row = 1, width do
|
||||
for i = 1, length do
|
||||
step()
|
||||
end
|
||||
turn()
|
||||
step()
|
||||
turn()
|
||||
tLeft = not tLeft
|
||||
end
|
32
computer/26/garbidge/tile.lua
Normal file
32
computer/26/garbidge/tile.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
tile = function()
|
||||
pf = require("pathfinding")
|
||||
function selectItem(name)
|
||||
for i = 1, 16 do
|
||||
d= turtle.getItemDetail(i)
|
||||
if d.name == name then
|
||||
turtle.select(i)
|
||||
return
|
||||
end
|
||||
end
|
||||
print("pls give me", name)
|
||||
turtle.select(16)
|
||||
print("then press enter")
|
||||
read()
|
||||
end
|
||||
|
||||
--turtle.forward()
|
||||
--turtle.turnLeft()
|
||||
--turtle.forward()
|
||||
--turtle.turnRight()
|
||||
|
||||
for x = 1, 7 do
|
||||
for z = 1, 7 do
|
||||
turtle.select(((x == 4) and (z==4) and 3) or math.mod(x+z,2)+1)
|
||||
goTo(vector.new(x,0,z))
|
||||
turtle.placeDown()
|
||||
end
|
||||
end
|
||||
goTo(vector.new(8,0,0))
|
||||
_G.pos=pos-pos
|
||||
end
|
||||
return tile
|
4
computer/26/garbidge/tilemany.lua
Normal file
4
computer/26/garbidge/tilemany.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
t = require("tile")
|
||||
for i = 1,2 do
|
||||
t()
|
||||
end
|
429
computer/26/multishell.lua
Normal file
429
computer/26/multishell.lua
Normal file
|
@ -0,0 +1,429 @@
|
|||
--- Multishell allows multiple programs to be run at the same time.
|
||||
--
|
||||
-- When multiple programs are running, it displays a tab bar at the top of the
|
||||
-- screen, which allows you to switch between programs. New programs can be
|
||||
-- launched using the `fg` or `bg` programs, or using the @{shell.openTab} and
|
||||
-- @{multishell.launch} functions.
|
||||
--
|
||||
-- Each process is identified by its ID, which corresponds to its position in
|
||||
-- the tab list. As tabs may be opened and closed, this ID is _not_ constant
|
||||
-- over a program's run. As such, be careful not to use stale IDs.
|
||||
--
|
||||
-- As with @{shell}, @{multishell} is not a "true" API. Instead, it is a
|
||||
-- standard program, which launches a shell and injects its API into the shell's
|
||||
-- environment. This API is not available in the global environment, and so is
|
||||
-- not available to @{os.loadAPI|APIs}.
|
||||
--
|
||||
-- @module[module] multishell
|
||||
-- @since 1.6
|
||||
|
||||
local expect = dofile("rom/modules/main/cc/expect.lua").expect
|
||||
|
||||
-- Setup process switching
|
||||
local parentTerm = term.current()
|
||||
local w, h = parentTerm.getSize()
|
||||
|
||||
local tProcesses = {}
|
||||
local nCurrentProcess = nil
|
||||
local nRunningProcess = nil
|
||||
local bShowMenu = false
|
||||
local bWindowsResized = false
|
||||
local nScrollPos = 1
|
||||
local bScrollRight = false
|
||||
|
||||
local function selectProcess(n)
|
||||
if nCurrentProcess ~= n then
|
||||
if nCurrentProcess then
|
||||
local tOldProcess = tProcesses[nCurrentProcess]
|
||||
tOldProcess.window.setVisible(false)
|
||||
end
|
||||
nCurrentProcess = n
|
||||
if nCurrentProcess then
|
||||
local tNewProcess = tProcesses[nCurrentProcess]
|
||||
tNewProcess.window.setVisible(true)
|
||||
tNewProcess.bInteracted = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function setProcessTitle(n, sTitle)
|
||||
tProcesses[n].sTitle = sTitle
|
||||
end
|
||||
|
||||
local function resumeProcess(nProcess, sEvent, ...)
|
||||
local tProcess = tProcesses[nProcess]
|
||||
local sFilter = tProcess.sFilter
|
||||
if sFilter == nil or sFilter == sEvent or sEvent == "terminate" then
|
||||
local nPreviousProcess = nRunningProcess
|
||||
nRunningProcess = nProcess
|
||||
term.redirect(tProcess.terminal)
|
||||
local ok, result = coroutine.resume(tProcess.co, sEvent, ...)
|
||||
tProcess.terminal = term.current()
|
||||
if ok then
|
||||
tProcess.sFilter = result
|
||||
else
|
||||
printError(result)
|
||||
end
|
||||
nRunningProcess = nPreviousProcess
|
||||
end
|
||||
end
|
||||
|
||||
local function launchProcess(bFocus, tProgramEnv, sProgramPath, ...)
|
||||
local tProgramArgs = table.pack(...)
|
||||
local nProcess = #tProcesses + 1
|
||||
local tProcess = {}
|
||||
tProcess.sTitle = fs.getName(sProgramPath)
|
||||
if bShowMenu then
|
||||
tProcess.window = window.create(parentTerm, 1, 2, w, h - 1, false)
|
||||
else
|
||||
tProcess.window = window.create(parentTerm, 1, 1, w, h, false)
|
||||
end
|
||||
tProcess.co = coroutine.create(function()
|
||||
os.run(tProgramEnv, sProgramPath, table.unpack(tProgramArgs, 1, tProgramArgs.n))
|
||||
if not tProcess.bInteracted then
|
||||
term.setCursorBlink(false)
|
||||
print("Press any key to continue")
|
||||
os.pullEvent("char")
|
||||
end
|
||||
end)
|
||||
tProcess.sFilter = nil
|
||||
tProcess.terminal = tProcess.window
|
||||
tProcess.bInteracted = false
|
||||
tProcesses[nProcess] = tProcess
|
||||
if bFocus then
|
||||
selectProcess(nProcess)
|
||||
end
|
||||
resumeProcess(nProcess)
|
||||
return nProcess
|
||||
end
|
||||
|
||||
local function cullProcess(nProcess)
|
||||
local tProcess = tProcesses[nProcess]
|
||||
if coroutine.status(tProcess.co) == "dead" then
|
||||
if nCurrentProcess == nProcess then
|
||||
selectProcess(nil)
|
||||
end
|
||||
table.remove(tProcesses, nProcess)
|
||||
if nCurrentProcess == nil then
|
||||
if nProcess > 1 then
|
||||
selectProcess(nProcess - 1)
|
||||
elseif #tProcesses > 0 then
|
||||
selectProcess(1)
|
||||
end
|
||||
end
|
||||
if nScrollPos ~= 1 then
|
||||
nScrollPos = nScrollPos - 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function cullProcesses()
|
||||
local culled = false
|
||||
for n = #tProcesses, 1, -1 do
|
||||
culled = culled or cullProcess(n)
|
||||
end
|
||||
return culled
|
||||
end
|
||||
|
||||
-- Setup the main menu
|
||||
local menuMainTextColor, menuMainBgColor, menuOtherTextColor, menuOtherBgColor
|
||||
if parentTerm.isColor() then
|
||||
menuMainTextColor, menuMainBgColor = colors.yellow, colors.black
|
||||
menuOtherTextColor, menuOtherBgColor = colors.black, colors.gray
|
||||
else
|
||||
menuMainTextColor, menuMainBgColor = colors.white, colors.black
|
||||
menuOtherTextColor, menuOtherBgColor = colors.black, colors.gray
|
||||
end
|
||||
|
||||
local function redrawMenu()
|
||||
if bShowMenu then
|
||||
-- Draw menu
|
||||
parentTerm.setCursorPos(1, 1)
|
||||
parentTerm.setBackgroundColor(menuOtherBgColor)
|
||||
parentTerm.clearLine()
|
||||
local nCharCount = 0
|
||||
local nSize = parentTerm.getSize()
|
||||
if nScrollPos ~= 1 then
|
||||
parentTerm.setTextColor(menuOtherTextColor)
|
||||
parentTerm.setBackgroundColor(menuOtherBgColor)
|
||||
parentTerm.write("<")
|
||||
nCharCount = 1
|
||||
end
|
||||
for n = nScrollPos, #tProcesses do
|
||||
if n == nCurrentProcess then
|
||||
parentTerm.setTextColor(menuMainTextColor)
|
||||
parentTerm.setBackgroundColor(menuMainBgColor)
|
||||
else
|
||||
parentTerm.setTextColor(menuOtherTextColor)
|
||||
parentTerm.setBackgroundColor(menuOtherBgColor)
|
||||
end
|
||||
parentTerm.write(" " .. tProcesses[n].sTitle .. " ")
|
||||
nCharCount = nCharCount + #tProcesses[n].sTitle + 2
|
||||
end
|
||||
if nCharCount > nSize then
|
||||
parentTerm.setTextColor(menuOtherTextColor)
|
||||
parentTerm.setBackgroundColor(menuOtherBgColor)
|
||||
parentTerm.setCursorPos(nSize, 1)
|
||||
parentTerm.write(">")
|
||||
bScrollRight = true
|
||||
else
|
||||
bScrollRight = false
|
||||
end
|
||||
|
||||
-- Put the cursor back where it should be
|
||||
local tProcess = tProcesses[nCurrentProcess]
|
||||
if tProcess then
|
||||
tProcess.window.restoreCursor()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function resizeWindows()
|
||||
local windowY, windowHeight
|
||||
if bShowMenu then
|
||||
windowY = 2
|
||||
windowHeight = h - 1
|
||||
else
|
||||
windowY = 1
|
||||
windowHeight = h
|
||||
end
|
||||
for n = 1, #tProcesses do
|
||||
local tProcess = tProcesses[n]
|
||||
local x, y = tProcess.window.getCursorPos()
|
||||
if y > windowHeight then
|
||||
tProcess.window.scroll(y - windowHeight)
|
||||
tProcess.window.setCursorPos(x, windowHeight)
|
||||
end
|
||||
tProcess.window.reposition(1, windowY, w, windowHeight)
|
||||
end
|
||||
bWindowsResized = true
|
||||
end
|
||||
|
||||
local function setMenuVisible(bVis)
|
||||
if bShowMenu ~= bVis then
|
||||
bShowMenu = bVis
|
||||
resizeWindows()
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
|
||||
local multishell = {} --- @export
|
||||
|
||||
--- Get the currently visible process. This will be the one selected on
|
||||
-- the tab bar.
|
||||
--
|
||||
-- Note, this is different to @{getCurrent}, which returns the process which is
|
||||
-- currently executing.
|
||||
--
|
||||
-- @treturn number The currently visible process's index.
|
||||
-- @see setFocus
|
||||
function multishell.getFocus()
|
||||
return nCurrentProcess
|
||||
end
|
||||
|
||||
--- Change the currently visible process.
|
||||
--
|
||||
-- @tparam number n The process index to switch to.
|
||||
-- @treturn boolean If the process was changed successfully. This will
|
||||
-- return @{false} if there is no process with this id.
|
||||
-- @see getFocus
|
||||
function multishell.setFocus(n)
|
||||
expect(1, n, "number")
|
||||
if n >= 1 and n <= #tProcesses then
|
||||
selectProcess(n)
|
||||
redrawMenu()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Get the title of the given tab.
|
||||
--
|
||||
-- This starts as the name of the program, but may be changed using
|
||||
-- @{multishell.setTitle}.
|
||||
-- @tparam number n The process index.
|
||||
-- @treturn string|nil The current process title, or @{nil} if the
|
||||
-- process doesn't exist.
|
||||
function multishell.getTitle(n)
|
||||
expect(1, n, "number")
|
||||
if n >= 1 and n <= #tProcesses then
|
||||
return tProcesses[n].sTitle
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Set the title of the given process.
|
||||
--
|
||||
-- @tparam number n The process index.
|
||||
-- @tparam string title The new process title.
|
||||
-- @see getTitle
|
||||
-- @usage Change the title of the current process
|
||||
--
|
||||
-- multishell.setTitle(multishell.getCurrent(), "Hello")
|
||||
function multishell.setTitle(n, title)
|
||||
expect(1, n, "number")
|
||||
expect(2, title, "string")
|
||||
if n >= 1 and n <= #tProcesses then
|
||||
setProcessTitle(n, title)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the index of the currently running process.
|
||||
--
|
||||
-- @treturn number The currently running process.
|
||||
function multishell.getCurrent()
|
||||
return nRunningProcess
|
||||
end
|
||||
|
||||
--- Start a new process, with the given environment, program and arguments.
|
||||
--
|
||||
-- The returned process index is not constant over the program's run. It can be
|
||||
-- safely used immediately after launching (for instance, to update the title or
|
||||
-- switch to that tab). However, after your program has yielded, it may no
|
||||
-- longer be correct.
|
||||
--
|
||||
-- @tparam table tProgramEnv The environment to load the path under.
|
||||
-- @tparam string sProgramPath The path to the program to run.
|
||||
-- @param ... Additional arguments to pass to the program.
|
||||
-- @treturn number The index of the created process.
|
||||
-- @see os.run
|
||||
-- @usage Run the "hello" program, and set its title to "Hello!"
|
||||
--
|
||||
-- local id = multishell.launch({}, "/rom/programs/fun/hello.lua")
|
||||
-- multishell.setTitle(id, "Hello!")
|
||||
function multishell.launch(tProgramEnv, sProgramPath, ...)
|
||||
expect(1, tProgramEnv, "table")
|
||||
expect(2, sProgramPath, "string")
|
||||
local previousTerm = term.current()
|
||||
setMenuVisible(#tProcesses + 1 >= 2)
|
||||
local nResult = launchProcess(false, tProgramEnv, sProgramPath, ...)
|
||||
redrawMenu()
|
||||
term.redirect(previousTerm)
|
||||
return nResult
|
||||
end
|
||||
|
||||
--- Get the number of processes within this multishell.
|
||||
--
|
||||
-- @treturn number The number of processes.
|
||||
function multishell.getCount()
|
||||
return #tProcesses
|
||||
end
|
||||
|
||||
-- Begin
|
||||
parentTerm.clear()
|
||||
setMenuVisible(false)
|
||||
launchProcess(true, {
|
||||
["shell"] = shell,
|
||||
["multishell"] = multishell,
|
||||
}, "/rom/programs/shell.lua")
|
||||
|
||||
-- Run processes
|
||||
while #tProcesses > 0 do
|
||||
-- Get the event
|
||||
local tEventData = table.pack(os.pullEventRaw())
|
||||
local sEvent = tEventData[1]
|
||||
if sEvent == "term_resize" then
|
||||
-- Resize event
|
||||
w, h = parentTerm.getSize()
|
||||
resizeWindows()
|
||||
redrawMenu()
|
||||
|
||||
elseif sEvent == "char" or sEvent == "key" or sEvent == "key_up" or sEvent == "paste" or sEvent == "terminate" then
|
||||
-- Keyboard event
|
||||
-- Passthrough to current process
|
||||
if tEventData[2] == 290 and sEvent == "key" then
|
||||
multishell.setFocus((nCurrentProcess or 0) % #tProcesses + 1)
|
||||
else
|
||||
resumeProcess(nCurrentProcess, table.unpack(tEventData, 1, tEventData.n))
|
||||
if cullProcess(nCurrentProcess) then
|
||||
setMenuVisible(#tProcesses >= 2)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
elseif sEvent == "mouse_click" then
|
||||
-- Click event
|
||||
local button, x, y = tEventData[2], tEventData[3], tEventData[4]
|
||||
if bShowMenu and y == 1 then
|
||||
-- Switch process
|
||||
if x == 1 and nScrollPos ~= 1 then
|
||||
nScrollPos = nScrollPos - 1
|
||||
redrawMenu()
|
||||
elseif bScrollRight and x == term.getSize() then
|
||||
nScrollPos = nScrollPos + 1
|
||||
redrawMenu()
|
||||
else
|
||||
local tabStart = 1
|
||||
if nScrollPos ~= 1 then
|
||||
tabStart = 2
|
||||
end
|
||||
for n = nScrollPos, #tProcesses do
|
||||
local tabEnd = tabStart + #tProcesses[n].sTitle + 1
|
||||
if x >= tabStart and x <= tabEnd then
|
||||
selectProcess(n)
|
||||
redrawMenu()
|
||||
break
|
||||
end
|
||||
tabStart = tabEnd + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Passthrough to current process
|
||||
resumeProcess(nCurrentProcess, sEvent, button, x, bShowMenu and y - 1 or y)
|
||||
if cullProcess(nCurrentProcess) then
|
||||
setMenuVisible(#tProcesses >= 2)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
|
||||
elseif sEvent == "mouse_drag" or sEvent == "mouse_up" or sEvent == "mouse_scroll" then
|
||||
-- Other mouse event
|
||||
local p1, x, y = tEventData[2], tEventData[3], tEventData[4]
|
||||
if bShowMenu and sEvent == "mouse_scroll" and y == 1 then
|
||||
if p1 == -1 and nScrollPos ~= 1 then
|
||||
nScrollPos = nScrollPos - 1
|
||||
redrawMenu()
|
||||
elseif bScrollRight and p1 == 1 then
|
||||
nScrollPos = nScrollPos + 1
|
||||
redrawMenu()
|
||||
end
|
||||
elseif not (bShowMenu and y == 1) then
|
||||
-- Passthrough to current process
|
||||
resumeProcess(nCurrentProcess, sEvent, p1, x, bShowMenu and y - 1 or y)
|
||||
if cullProcess(nCurrentProcess) then
|
||||
setMenuVisible(#tProcesses >= 2)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
-- Other event
|
||||
-- Passthrough to all processes
|
||||
local nLimit = #tProcesses -- Storing this ensures any new things spawned don't get the event
|
||||
for n = 1, nLimit do
|
||||
resumeProcess(n, table.unpack(tEventData, 1, tEventData.n))
|
||||
end
|
||||
if cullProcesses() then
|
||||
setMenuVisible(#tProcesses >= 2)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
|
||||
if bWindowsResized then
|
||||
-- Pass term_resize to all processes
|
||||
local nLimit = #tProcesses -- Storing this ensures any new things spawned don't get the event
|
||||
for n = 1, nLimit do
|
||||
resumeProcess(n, "term_resize")
|
||||
end
|
||||
bWindowsResized = false
|
||||
if cullProcesses() then
|
||||
setMenuVisible(#tProcesses >= 2)
|
||||
redrawMenu()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Shutdown
|
||||
term.redirect(parentTerm)
|
124
computer/26/path.lua
Normal file
124
computer/26/path.lua
Normal file
|
@ -0,0 +1,124 @@
|
|||
pp = require("cc.pretty").pretty_print
|
||||
|
||||
_G.facing = _G.facing or "south"
|
||||
_G.pos = _G.pos or vector.new(0,0,0)
|
||||
|
||||
local up = vector.new(0,1,0)
|
||||
|
||||
local rightOf = {
|
||||
south = "west",
|
||||
west = "north",
|
||||
north = "east",
|
||||
east = "south"
|
||||
}
|
||||
|
||||
local leftOf = {
|
||||
west = "south",
|
||||
north = "west",
|
||||
east = "north",
|
||||
south = "east"
|
||||
}
|
||||
|
||||
local vecOf = {
|
||||
north = vector.new(0,0,-1),
|
||||
south = vector.new(0,0,1),
|
||||
east = vector.new(1,0,0),
|
||||
west = vector.new(-1,0,0),
|
||||
}
|
||||
|
||||
function goUp()
|
||||
if turtle.up() then
|
||||
_G.pos.y = _G.pos.y + 1
|
||||
return true
|
||||
end
|
||||
printError("failed to go up")
|
||||
printError(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
function goDown()
|
||||
if turtle.down() then
|
||||
_G.pos.y = _G.pos.y - 1
|
||||
return true
|
||||
end
|
||||
printError("failed to go down")
|
||||
printError(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
function goLeft()
|
||||
turtle.turnLeft()
|
||||
_G.facing = leftOf[_G.facing]
|
||||
end
|
||||
|
||||
function goRight()
|
||||
turtle.turnRight()
|
||||
_G.facing = rightOf[_G.facing]
|
||||
end
|
||||
|
||||
function goForward()
|
||||
if turtle.forward() then
|
||||
_G.pos = _G.pos + vecOf[_G.facing]
|
||||
return true
|
||||
end
|
||||
-- printError("failed to go forward")
|
||||
-- printError(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
function goBack()
|
||||
if turtle.back() then
|
||||
_G.pos = _G.pos - vecOf[_G.facing]
|
||||
return true
|
||||
end
|
||||
printError("failed to go backward")
|
||||
printError(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
function stepTo(target, dig)
|
||||
local delta = target - _G.pos
|
||||
-- print(delta)
|
||||
if delta.y > 0 then
|
||||
if dig then
|
||||
repeat turtle.digUp() until goUp()
|
||||
else
|
||||
goUp()
|
||||
end
|
||||
elseif delta.y < 0 then
|
||||
if dig then
|
||||
turtle.digDown()
|
||||
end
|
||||
goDown()
|
||||
elseif delta:dot(vecOf[_G.facing]) > 0 then
|
||||
if dig then
|
||||
repeat turtle.dig() until goForward()
|
||||
else
|
||||
goForward()
|
||||
end
|
||||
elseif delta:dot(vecOf[_G.facing]:cross(up)) > 0 then
|
||||
goRight()
|
||||
else
|
||||
goLeft()
|
||||
end
|
||||
end
|
||||
|
||||
function goTo(target, face, dig)
|
||||
while target ~= _G.pos do
|
||||
stepTo(target, dig)
|
||||
end
|
||||
if face and face ~= _G.facing then
|
||||
if rightOf[_G.facing] == face then
|
||||
goRight()
|
||||
elseif leftOf[_G.facing] == face then
|
||||
goLeft()
|
||||
else
|
||||
goRight()
|
||||
goRight()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function goHome()
|
||||
goTo(vector.new(0,0,0), "south")
|
||||
end
|
2
computer/26/progress.lua
Normal file
2
computer/26/progress.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
progress = 1
|
||||
layer_start = 1
|
1
computer/26/startup.lua
Normal file
1
computer/26/startup.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require("multishell")
|
Loading…
Add table
Add a link
Reference in a new issue