SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Laser‑Guided Warp System (“ztc”) with clean, scaled UI and full X,Y,Z reporting | |
| 2 | ||
| 3 | -- 1) Wrap terminal + any attached monitors | |
| 4 | local screens = {}
| |
| 5 | ||
| 6 | - | -- Terminal |
| 6 | + | -- Terminal wrapper |
| 7 | table.insert(screens, {
| |
| 8 | - | clear = function() term.clear() term.setCursorPos(1,1) end, |
| 8 | + | clear = function() term.clear(); term.setCursorPos(1,1) end, |
| 9 | getSize = function() return term.getSize() end, | |
| 10 | setTextColor = term.setTextColor, | |
| 11 | setBackgroundColor = term.setBackgroundColor, | |
| 12 | setCursorPos = term.setCursorPos, | |
| 13 | write = term.write, | |
| 14 | }) | |
| 15 | ||
| 16 | - | -- Monitors |
| 16 | + | -- Monitor wrappers |
| 17 | for _, side in ipairs(peripheral.getNames()) do | |
| 18 | if peripheral.getType(side) == "monitor" then | |
| 19 | local m = peripheral.wrap(side) | |
| 20 | table.insert(screens, {
| |
| 21 | clear = function() m.clear(); m.setCursorPos(1,1) end, | |
| 22 | getSize = function() return m.getSize() end, | |
| 23 | setTextColor = function(c) m.setTextColor(c) end, | |
| 24 | setBackgroundColor = function(c) m.setBackgroundColor(c) end, | |
| 25 | setCursorPos = function(x,y) m.setCursorPos(x,y) end, | |
| 26 | write = function(txt) m.write(txt) end, | |
| 27 | monitor = m, | |
| 28 | }) | |
| 29 | end | |
| 30 | end | |
| 31 | ||
| 32 | - | -- 2) Auto‑scale monitors so 5 lines fit (lines 1,3,5) |
| 32 | + | -- 2) Auto‑scale monitors so 5 lines (1,3,5) will fit |
| 33 | for _, s in ipairs(screens) do | |
| 34 | if s.monitor then | |
| 35 | local best = 0.5 | |
| 36 | - | for _, scale in ipairs({1,0.5}) do
|
| 36 | + | for _, scale in ipairs({1, 0.5}) do
|
| 37 | s.monitor.setTextScale(scale) | |
| 38 | local w,h = s.getSize() | |
| 39 | if w >= 40 and h >= 5 then | |
| 40 | best = scale | |
| 41 | break | |
| 42 | end | |
| 43 | end | |
| 44 | s.monitor.setTextScale(best) | |
| 45 | end | |
| 46 | end | |
| 47 | ||
| 48 | -- 3) Helpers | |
| 49 | local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end | |
| 50 | - | local function clearAll() forAll(function(s) s.clear() end) end |
| 50 | + | local function clearAll() |
| 51 | forAll(function(s) | |
| 52 | -- fill with lightGray background first | |
| 53 | s.setTextColor(colors.black) | |
| 54 | s.setBackgroundColor(colors.lightGray) | |
| 55 | s.clear() | |
| 56 | end) | |
| 57 | end | |
| 58 | ||
| 59 | -- 4) Header & Subtitle | |
| 60 | - | -- Title (line 1): white on black |
| 60 | + | |
| 61 | local subtitleText = "Emit Scanning Laser to Warp" | |
| 62 | ||
| 63 | local function drawHeader() | |
| 64 | - | s.setCursorPos(xT,1) |
| 64 | + | |
| 65 | local w,_ = s.getSize() | |
| 66 | - | -- Subtitle (line 3): black on lightGray |
| 66 | + | -- Title on line 1 (white on black) |
| 67 | local xT = math.floor((w - #titleText)/2) + 1 | |
| 68 | s.setTextColor(colors.white) | |
| 69 | s.setBackgroundColor(colors.black) | |
| 70 | - | s.setCursorPos(xS,3) |
| 70 | + | s.setCursorPos(xT, 1) |
| 71 | s.write(titleText) | |
| 72 | ||
| 73 | -- Subtitle on line 3 (black on lightGray) | |
| 74 | local xS = math.floor((w - #subtitleText)/2) + 1 | |
| 75 | - | -- 5) Setup peripherals |
| 75 | + | |
| 76 | s.setBackgroundColor(colors.lightGray) | |
| 77 | s.setCursorPos(xS, 3) | |
| 78 | s.write(subtitleText) | |
| 79 | end) | |
| 80 | - | table.remove(lasers,i) |
| 80 | + | |
| 81 | ||
| 82 | -- 5) Setup warpdriveLaserCamera peripherals | |
| 83 | rednet.open("top")
| |
| 84 | local lasers = peripheral.getNames() | |
| 85 | for i=#lasers,1,-1 do | |
| 86 | if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then | |
| 87 | table.remove(lasers, i) | |
| 88 | else | |
| 89 | peripheral.wrap(lasers[i]).beamFrequency(1420) | |
| 90 | end | |
| 91 | end | |
| 92 | ||
| 93 | -- 6) Initial draw | |
| 94 | clearAll() | |
| 95 | - | -- clear entire line 5 |
| 95 | + | |
| 96 | ||
| 97 | -- 7) Dynamic coordinate line on row 5 (full X, Y, Z) | |
| 98 | local function updateCoords(x,y,z) | |
| 99 | local line = string.format("Target: X:%d Y:%d Z:%d", x, y, z)
| |
| 100 | forAll(function(s) | |
| 101 | local w,_ = s.getSize() | |
| 102 | -- clear line 5 | |
| 103 | s.setTextColor(colors.black) | |
| 104 | s.setBackgroundColor(colors.lightGray) | |
| 105 | s.setCursorPos(1,5) | |
| 106 | s.write(string.rep(" ", w))
| |
| 107 | - | -- 8) Main loop: listen for laserScanning |
| 107 | + | |
| 108 | local xs = math.floor((w - #line)/2) + 1 | |
| 109 | - | local event, side, lx, ly, lz = os.pullEvent("laserScanning")
|
| 109 | + | |
| 110 | s.write(line) | |
| 111 | end) | |
| 112 | end | |
| 113 | ||
| 114 | - | rednet.broadcast({ x = tx, y = ty, z = tz }, "HorizontalJumpBroadcast")
|
| 114 | + | -- 8) Main loop: listen for laserScanning, refresh coords, broadcast |
| 115 | while true do | |
| 116 | local _, side, lx, ly, lz = os.pullEvent("laserScanning")
| |
| 117 | local tx = tonumber(lx) | |
| 118 | local ty = tonumber(ly) | |
| 119 | local tz = tonumber(lz) | |
| 120 | updateCoords(tx, ty, tz) | |
| 121 | rednet.broadcast({ x=tx, y=ty, z=tz }, "HorizontalJumpBroadcast")
| |
| 122 | end | |
| 123 |