SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Laser‑Guided Warp System (“ztc”) with H/I/O prompts and O‑key to run otc | |
| 2 | ||
| 3 | -- 1) Wrap terminal + any attached monitors | |
| 4 | local screens = {}
| |
| 5 | ||
| 6 | -- Terminal wrapper | |
| 7 | table.insert(screens, {
| |
| 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 | -- 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 at least 7 lines 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
| |
| 37 | s.monitor.setTextScale(scale) | |
| 38 | local w,h = s.getSize() | |
| 39 | if w >= 40 and h >= 7 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 | ||
| 51 | -- Clear every screen to lightGray | |
| 52 | local function clearAll() | |
| 53 | forAll(function(s) | |
| 54 | s.setTextColor(colors.black) | |
| 55 | s.setBackgroundColor(colors.lightGray) | |
| 56 | s.clear() | |
| 57 | end) | |
| 58 | end | |
| 59 | ||
| 60 | -- 4) Static texts | |
| 61 | local titleText = "Horizontal Mining System" | |
| 62 | local subtitleText = "Emit Scanning Laser to Mine Target" | |
| 63 | local offsetText = "Horizontal Miner ( L ): " | |
| 64 | local promptH = "Press H for Main Menu" | |
| 65 | local promptI = "Press C to Configure Miner" | |
| 66 | local promptO = "Press L to Toggle Miner" | |
| 67 | ||
| 68 | - | -- Draw title, subtitle, offset‑state and proximity‑state lines |
| 68 | + | -- Draw title, subtitle, and offset‑state line (now on line 5) |
| 69 | local function drawStatic() | |
| 70 | forAll(function(s) | |
| 71 | local w,_ = s.getSize() | |
| 72 | -- Title (line 1): white on black | |
| 73 | local xT = math.floor((w - #titleText)/2) + 1 | |
| 74 | s.setTextColor(colors.white) | |
| 75 | s.setBackgroundColor(colors.black) | |
| 76 | s.setCursorPos(xT,1) | |
| 77 | s.write(titleText) | |
| 78 | ||
| 79 | -- Subtitle (line 3): black on lightGray | |
| 80 | local xS = math.floor((w - #subtitleText)/2) + 1 | |
| 81 | s.setTextColor(colors.black) | |
| 82 | s.setBackgroundColor(colors.lightGray) | |
| 83 | s.setCursorPos(xS,3) | |
| 84 | s.write(subtitleText) | |
| 85 | ||
| 86 | - | -- Mining Laser Offset (line 4) |
| 86 | + | -- (line 4 is intentionally left blank) |
| 87 | - | local fullOffset = offsetText.."OFF" |
| 87 | + | |
| 88 | -- Mining Laser Offset (line 5) | |
| 89 | local fullOffset = offsetText .. "OFF" | |
| 90 | local xO = math.floor((w - #fullOffset)/2) + 1 | |
| 91 | - | s.setCursorPos(1,4) |
| 91 | + | |
| 92 | s.setBackgroundColor(colors.lightGray) | |
| 93 | - | s.setCursorPos(xO,4) |
| 93 | + | s.setCursorPos(1,5) |
| 94 | s.write(string.rep(" ", w))
| |
| 95 | s.setCursorPos(xO,5) | |
| 96 | s.write(offsetText) | |
| 97 | s.setTextColor(colors.white) | |
| 98 | s.setBackgroundColor(colors.red) | |
| 99 | s.write("OFF")
| |
| 100 | end) | |
| 101 | end | |
| 102 | ||
| 103 | -- Draw prompts on the bottom three rows | |
| 104 | local function drawPrompt() | |
| 105 | forAll(function(s) | |
| 106 | local w,h = s.getSize() | |
| 107 | -- line h-2: O prompt | |
| 108 | s.setTextColor(colors.white) | |
| 109 | s.setBackgroundColor(colors.blue) | |
| 110 | s.setCursorPos(1,h-2) | |
| 111 | s.write(string.rep(" ", w))
| |
| 112 | local xO = math.floor((w - #promptO)/2) + 1 | |
| 113 | s.setCursorPos(xO,h-2) | |
| 114 | s.write(promptO) | |
| 115 | -- line h-1: H prompt | |
| 116 | s.setTextColor(colors.white) | |
| 117 | s.setBackgroundColor(colors.blue) | |
| 118 | s.setCursorPos(1,h-1) | |
| 119 | s.write(string.rep(" ", w))
| |
| 120 | local xH = math.floor((w - #promptH)/2) + 1 | |
| 121 | s.setCursorPos(xH,h-1) | |
| 122 | s.write(promptH) | |
| 123 | -- line h: I prompt | |
| 124 | s.setBackgroundColor(colors.blue) | |
| 125 | s.setCursorPos(1,h) | |
| 126 | s.write(string.rep(" ", w))
| |
| 127 | local xI = math.floor((w - #promptI)/2) + 1 | |
| 128 | s.setCursorPos(xI,h) | |
| 129 | s.write(promptI) | |
| 130 | end) | |
| 131 | end | |
| 132 | ||
| 133 | -- 5) Set up warpdriveLaserCamera peripherals | |
| 134 | rednet.open("top")
| |
| 135 | local cams = peripheral.getNames() | |
| 136 | for i=#cams,1,-1 do | |
| 137 | if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then | |
| 138 | table.remove(cams,i) | |
| 139 | else | |
| 140 | peripheral.wrap(cams[i]).beamFrequency(1420) | |
| 141 | end | |
| 142 | end | |
| 143 | ||
| 144 | -- 6) Initial draw (blank coords) | |
| 145 | clearAll() | |
| 146 | drawStatic() | |
| 147 | drawPrompt() | |
| 148 | - | -- 7) Coords line, accepts nil → blanks before first scan |
| 148 | + | |
| 149 | -- 7) Coords line, accepts nil → blanks before first scan (on line 6) | |
| 150 | local function updateCoords(x,y,z) | |
| 151 | local sx = x and tostring(x) or " " | |
| 152 | local sy = y and tostring(y) or " " | |
| 153 | local sz = z and tostring(z) or " " | |
| 154 | local coordLine = string.format("Target: X:%s Y:%s Z:%s", sx, sy, sz)
| |
| 155 | forAll(function(s) | |
| 156 | local w,_ = s.getSize() | |
| 157 | s.setTextColor(colors.black) | |
| 158 | s.setBackgroundColor(colors.lightGray) | |
| 159 | s.setCursorPos(1,6) | |
| 160 | s.write(string.rep(" ", w))
| |
| 161 | local cx = math.floor((w - #coordLine)/2) + 1 | |
| 162 | s.setCursorPos(cx,6) | |
| 163 | s.write(coordLine) | |
| 164 | end) | |
| 165 | end | |
| 166 | ||
| 167 | -- draw initial blanks (on line 6) | |
| 168 | updateCoords(nil,nil,nil) | |
| 169 | ||
| 170 | -- 8) Main loop: scan + key handling | |
| 171 | while true do | |
| 172 | local ev,k,b,c,d = os.pullEventRaw() | |
| 173 | if ev == "laserScanning" then | |
| 174 | local tx = tonumber(b) | |
| 175 | local ty = tonumber(c) | |
| 176 | local tz = tonumber(d) | |
| 177 | - | local data = { x = tx, y = ty, z = tz }
|
| 177 | + | |
| 178 | local data = { x = tx, y = ty, z = tz }
| |
| 179 | rednet.broadcast(data, "SMineBroadcast") | |
| 180 | ||
| 181 | elseif ev == "key" then | |
| 182 | if k == keys.h then | |
| 183 | os.reboot() | |
| 184 | elseif k == keys.c then | |
| 185 | shell.run("conf")
| |
| 186 | clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt() | |
| 187 | elseif k == keys.l then | |
| 188 | rednet.broadcast("Toggle", "Miner")
| |
| 189 | end | |
| 190 | end | |
| 191 | end | |
| 192 |