mirror of
https://github.com/kepler155c/opus
synced 2025-10-25 12:47:41 +00:00
major directory reorganize
This commit is contained in:
@@ -287,10 +287,10 @@ function Browser:eventHandler(event)
|
||||
Event.exitPullEvents()
|
||||
|
||||
elseif event.type == 'edit' and file then
|
||||
self:run('/apps/shell', 'edit', file.name)
|
||||
self:run('sys/apps/shell', 'edit', file.name)
|
||||
|
||||
elseif event.type == 'shell' then
|
||||
self:run('/apps/shell')
|
||||
self:run('sys/apps/shell')
|
||||
|
||||
elseif event.type == 'refresh' then
|
||||
self:updateDirectory(self.dir)
|
||||
@@ -339,7 +339,7 @@ function Browser:eventHandler(event)
|
||||
if file.isDir then
|
||||
self:setDir(file.fullName)
|
||||
else
|
||||
self:run('/apps/shell', file.name)
|
||||
self:run('sys/apps/shell', file.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -65,14 +65,14 @@ function page:eventHandler(event)
|
||||
if t then
|
||||
if event.type == 'telnet' or event.type == 'grid_select' then
|
||||
multishell.openTab({
|
||||
path = '/apps/telnet.lua',
|
||||
path = 'sys/apps/telnet.lua',
|
||||
focused = true,
|
||||
args = { t.id },
|
||||
title = t.label,
|
||||
})
|
||||
elseif event.type == 'vnc' then
|
||||
multishell.openTab({
|
||||
path = '/apps/vnc.lua',
|
||||
path = 'sys/apps/vnc.lua',
|
||||
focused = true,
|
||||
args = { t.id },
|
||||
title = t.label,
|
||||
|
||||
@@ -17,7 +17,8 @@ local options = {
|
||||
desc = 'Displays the options' },
|
||||
}
|
||||
|
||||
local SCRIPTS_PATH = '/apps/scripts'
|
||||
local USR_SCRIPTS_PATH = 'usr/scripts'
|
||||
local SYS_SCRIPTS_PATH = 'sys/etc/scripts'
|
||||
|
||||
local nullTerm = Terminal.getNullTerm(term.current())
|
||||
local turtles = { }
|
||||
@@ -153,10 +154,12 @@ function page:runFunction(script, nowrap)
|
||||
end
|
||||
|
||||
function page:runScript(scriptName)
|
||||
local cmd = string.format('Script %d %s', self.turtle.id, scriptName)
|
||||
local ot = term.redirect(nullTerm)
|
||||
pcall(function() shell.run(cmd) end)
|
||||
term.redirect(ot)
|
||||
if self.turtle then
|
||||
local cmd = string.format('Script %d %s', self.turtle.id, scriptName)
|
||||
local ot = term.redirect(nullTerm)
|
||||
pcall(function() shell.run(cmd) end)
|
||||
term.redirect(ot)
|
||||
end
|
||||
end
|
||||
|
||||
function page.coords:draw()
|
||||
@@ -214,10 +217,24 @@ function page.tabs.inventory:eventHandler(event)
|
||||
end
|
||||
|
||||
function page.tabs.scripts:draw()
|
||||
|
||||
local function combineDirs(...)
|
||||
local list = { }
|
||||
for _,path in pairs({...}) do
|
||||
if fs.exists(path) then
|
||||
local files = fs.list(path)
|
||||
for _,f in pairs(files) do
|
||||
list[f] = fs.combine(path, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,f in pairs(files) do
|
||||
table.insert(self.values, { label = f, path = fs.combine(SCRIPTS_PATH, f) })
|
||||
local files = combineDirs(SYS_SCRIPTS_PATH, USR_SCRIPTS_PATH)
|
||||
for f,path in pairs(files) do
|
||||
table.insert(self.values, { label = f, path = path })
|
||||
end
|
||||
self:update()
|
||||
UI.Grid.draw(self)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
turtle.abortAction()
|
||||
@@ -1,121 +0,0 @@
|
||||
local function follow(id)
|
||||
|
||||
require = requireInjector(getfenv(1))
|
||||
local GPS = require('gps')
|
||||
local Socket = require('socket')
|
||||
local Point = require('point')
|
||||
local process = require('process')
|
||||
|
||||
turtle.status = 'follow ' .. id
|
||||
|
||||
local pt = GPS.getPointAndHeading()
|
||||
if not pt or not pt.heading then
|
||||
error('turtle: No GPS found')
|
||||
end
|
||||
|
||||
turtle.setPoint(pt)
|
||||
|
||||
local socket = Socket.connect(id, 161)
|
||||
if not socket then
|
||||
error('turtle: Unable to connect to ' .. id)
|
||||
return
|
||||
end
|
||||
|
||||
local lastPoint
|
||||
local following = false
|
||||
|
||||
local followThread = process:newThread('follower', function()
|
||||
while true do
|
||||
|
||||
local function getRemotePoint()
|
||||
if not turtle.abort then
|
||||
if socket:write({ type = 'gps' }) then
|
||||
return socket:read(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- sometimes gps will fail if moving
|
||||
local pt, d
|
||||
|
||||
for i = 1, 3 do
|
||||
pt, d = getRemotePoint()
|
||||
if pt then
|
||||
break
|
||||
end
|
||||
os.sleep(.5)
|
||||
end
|
||||
|
||||
if not pt or turtle.abort then
|
||||
error('Did not receive GPS location')
|
||||
end
|
||||
|
||||
if not lastPoint or (lastPoint.x ~= pt.x or lastPoint.y ~= pt.y or lastPoint.z ~= pt.z) then
|
||||
|
||||
if following then
|
||||
turtle.abort = true
|
||||
while following do
|
||||
os.sleep(.1)
|
||||
end
|
||||
turtle.abort = false
|
||||
end
|
||||
|
||||
-- check if gps is inaccurate (player moving too fast)
|
||||
if d < Point.pythagoreanDistance(turtle.point, pt) + 10 then
|
||||
lastPoint = Point.copy(pt)
|
||||
following = true
|
||||
process:newThread('turtle_follow', function()
|
||||
|
||||
local pts = {
|
||||
{ x = pt.x + 2, z = pt.z, y = pt.y },
|
||||
{ x = pt.x - 2, z = pt.z, y = pt.y },
|
||||
{ x = pt.x, z = pt.z + 2, y = pt.y },
|
||||
{ x = pt.x, z = pt.z - 2, y = pt.y },
|
||||
}
|
||||
|
||||
local cpt = Point.closest(turtle.point, pts)
|
||||
|
||||
local blocks = { }
|
||||
|
||||
local function addBlocks(tpt)
|
||||
table.insert(blocks, tpt)
|
||||
local apts = Point.adjacentPoints(tpt)
|
||||
for _,apt in pairs(apts) do
|
||||
table.insert(blocks, apt)
|
||||
end
|
||||
end
|
||||
|
||||
-- don't run into player
|
||||
addBlocks(pt)
|
||||
addBlocks({ x = pt.x, z = pt.z, y = pt.y + 1 })
|
||||
|
||||
if turtle.pathfind(cpt, blocks) then
|
||||
turtle.headTowards(pt)
|
||||
end
|
||||
following = false
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
os.sleep(.5)
|
||||
end
|
||||
end)
|
||||
|
||||
while true do
|
||||
local e = process:pullEvent()
|
||||
if e == 'terminate' or followThread:isDead() or e =='turtle_abort' then
|
||||
process:threadEvent('terminate')
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
socket:close()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local s, m = turtle.run(function() follow({COMPUTER_ID}) end)
|
||||
if not s and m then
|
||||
error(m)
|
||||
end
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
turtle.run(turtle.gotoGPSHome)
|
||||
@@ -1,30 +0,0 @@
|
||||
turtle.run(function()
|
||||
require = requireInjector(getfenv(1))
|
||||
local GPS = require('gps')
|
||||
local Socket = require('socket')
|
||||
|
||||
local id = {COMPUTER_ID}
|
||||
|
||||
local pt = GPS.getPointAndHeading()
|
||||
if not pt or not pt.heading then
|
||||
error('turtle: No GPS found')
|
||||
end
|
||||
|
||||
turtle.setPoint(pt)
|
||||
|
||||
local socket = Socket.connect(id, 161)
|
||||
if not socket then
|
||||
error('turtle: Unable to connect to ' .. id)
|
||||
end
|
||||
|
||||
socket:write({ type = 'gps' })
|
||||
|
||||
local pt = socket:read(3)
|
||||
if not pt then
|
||||
error('turtle: No GPS response')
|
||||
end
|
||||
|
||||
if not turtle.pathfind(pt, nil, 64) then
|
||||
error('Unable to go to location')
|
||||
end
|
||||
end)
|
||||
@@ -1,100 +0,0 @@
|
||||
require = requireInjector(getfenv(1))
|
||||
local Point = require('point')
|
||||
|
||||
local checkedNodes, nodes
|
||||
|
||||
local function addNode(node)
|
||||
|
||||
for i = 0, 3 do
|
||||
local hi = turtle.getHeadingInfo(i)
|
||||
local testNode = { x = node.x + hi.xd, z = node.z + hi.zd }
|
||||
|
||||
local key = table.concat({ testNode.x, testNode.z }, ':')
|
||||
if not checkedNodes[key] then
|
||||
nodes[key] = testNode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function findObsidian()
|
||||
repeat
|
||||
local node = { x = turtle.point.x, z = turtle.point.z }
|
||||
local key = table.concat({ node.x, node.z }, ':')
|
||||
|
||||
checkedNodes[key] = true
|
||||
nodes[key] = nil
|
||||
|
||||
local _,b = turtle.inspectDown()
|
||||
if b and (b.name == 'minecraft:lava' or b.name == 'minecraft:flowing_lava') then
|
||||
if turtle.selectSlot('minecraft:water_bucket') then
|
||||
while true do
|
||||
if turtle.up() then
|
||||
break
|
||||
end
|
||||
print('stuck')
|
||||
end
|
||||
turtle.placeDown()
|
||||
os.sleep(2)
|
||||
turtle.placeDown()
|
||||
turtle.down()
|
||||
turtle.select(1)
|
||||
_, b = turtle.inspectDown()
|
||||
end
|
||||
end
|
||||
|
||||
if turtle.getCount(16) > 0 then
|
||||
print('Inventory full')
|
||||
print('Enter to continue...')
|
||||
read()
|
||||
end
|
||||
|
||||
if b and b.name == 'minecraft:obsidian' then
|
||||
turtle.digDown()
|
||||
addNode(node)
|
||||
else
|
||||
turtle.digDown()
|
||||
end
|
||||
|
||||
print(string.format('%d nodes remaining', Util.size(nodes)))
|
||||
|
||||
if Util.size(nodes) == 0 then
|
||||
break
|
||||
end
|
||||
|
||||
local node = Point.closest(turtle.point, nodes)
|
||||
if not turtle.gotoPoint(node) then
|
||||
break
|
||||
end
|
||||
until turtle.abort
|
||||
end
|
||||
|
||||
turtle.reset()
|
||||
turtle.setPolicy(turtle.policies.digOnly)
|
||||
local s, m = turtle.run(function()
|
||||
repeat
|
||||
|
||||
checkedNodes = { }
|
||||
nodes = { }
|
||||
|
||||
local _,b = turtle.inspectDown()
|
||||
if not b or b.name ~= 'minecraft:obsidian' then
|
||||
break
|
||||
end
|
||||
|
||||
findObsidian()
|
||||
if not turtle.selectSlot('minecraft:water_bucket') then
|
||||
break
|
||||
end
|
||||
turtle.goto(0, 0)
|
||||
turtle.placeDown()
|
||||
os.sleep(2)
|
||||
turtle.placeDown()
|
||||
turtle.down()
|
||||
turtle.select(1)
|
||||
until turtle.abort
|
||||
end)
|
||||
turtle.goto(0, 0, 0, 0)
|
||||
turtle.reset()
|
||||
if not s and m then
|
||||
error(m)
|
||||
end
|
||||
@@ -1 +0,0 @@
|
||||
os.reboot()
|
||||
@@ -1 +0,0 @@
|
||||
turtle.run(turtle.setGPSHome)
|
||||
@@ -1 +0,0 @@
|
||||
os.shutdown()
|
||||
@@ -1,73 +0,0 @@
|
||||
local function summon(id)
|
||||
|
||||
require = requireInjector(getfenv(1))
|
||||
local GPS = require('gps')
|
||||
local Socket = require('socket')
|
||||
local Point = require('point')
|
||||
|
||||
turtle.status = 'GPSing'
|
||||
turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0 })
|
||||
|
||||
local pts = {
|
||||
[ 1 ] = { x = 0, z = 0, y = 0 },
|
||||
[ 2 ] = { x = 4, z = 0, y = 0 },
|
||||
[ 3 ] = { x = 2, z = -2, y = 2 },
|
||||
[ 4 ] = { x = 2, z = 2, y = 2 },
|
||||
}
|
||||
local tFixes = { }
|
||||
|
||||
local socket = Socket.connect(id, 161)
|
||||
|
||||
if not socket then
|
||||
error('turtle: Unable to connect to ' .. id)
|
||||
end
|
||||
|
||||
local function getDistance()
|
||||
socket:write({ type = 'ping' })
|
||||
local _, d = socket:read(5)
|
||||
return d
|
||||
end
|
||||
|
||||
local function doGPS()
|
||||
tFixes = { }
|
||||
for i = 1, 4 do
|
||||
if not turtle.gotoPoint(pts[i]) then
|
||||
error('turtle: Unable to perform GPS maneuver')
|
||||
end
|
||||
local distance = getDistance()
|
||||
if not distance then
|
||||
error('turtle: No response from ' .. id)
|
||||
end
|
||||
table.insert(tFixes, {
|
||||
position = vector.new(turtle.point.x, turtle.point.y, turtle.point.z),
|
||||
distance = distance
|
||||
})
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if not doGPS() then
|
||||
turtle.turnAround()
|
||||
turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0})
|
||||
if not doGPS() then
|
||||
socket:close()
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
socket:close()
|
||||
|
||||
local pos = GPS.trilaterate(tFixes)
|
||||
|
||||
if pos then
|
||||
local pt = { x = pos.x, y = pos.y, z = pos.z }
|
||||
local _, h = Point.calculateMoves(turtle.getPoint(), pt)
|
||||
local hi = turtle.getHeadingInfo(h)
|
||||
turtle.status = 'recalling'
|
||||
turtle.pathfind({ x = pt.x - hi.xd, z = pt.z - hi.zd, y = pt.y - hi.yd, heading = h })
|
||||
else
|
||||
error("turtle: Could not determine position")
|
||||
end
|
||||
end
|
||||
|
||||
turtle.run(function() summon({COMPUTER_ID}) end)
|
||||
@@ -1 +0,0 @@
|
||||
shell.run('/apps/update.lua')
|
||||
@@ -300,7 +300,6 @@ local function autocompleteFile(results, words)
|
||||
|
||||
if fs.isDir(startDir) then
|
||||
local files = fs.list(startDir)
|
||||
debug({ rawPath, startDir })
|
||||
for _,f in pairs(files) do
|
||||
local path = fs.combine(rawPath, f)
|
||||
if fs.isDir(fs.combine(startDir, f)) then
|
||||
|
||||
Reference in New Issue
Block a user