Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Laser‑Guided Warp System (“ztc”) with H/I/O prompts and O‑key to run otc
- -- 1) Wrap terminal + any attached monitors
- local screens = {}
- -- Terminal wrapper
- table.insert(screens, {
- clear = function() term.clear(); term.setCursorPos(1,1) end,
- getSize = function() return term.getSize() end,
- setTextColor = term.setTextColor,
- setBackgroundColor = term.setBackgroundColor,
- setCursorPos = term.setCursorPos,
- write = term.write,
- })
- -- Monitor wrappers
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "monitor" then
- local m = peripheral.wrap(side)
- table.insert(screens, {
- clear = function() m.clear(); m.setCursorPos(1,1) end,
- getSize = function() return m.getSize() end,
- setTextColor = function(c) m.setTextColor(c) end,
- setBackgroundColor = function(c) m.setBackgroundColor(c) end,
- setCursorPos = function(x,y) m.setCursorPos(x,y) end,
- write = function(txt) m.write(txt) end,
- monitor = m,
- })
- end
- end
- -- 2) Auto‑scale monitors so at least 7 lines will fit
- for _, s in ipairs(screens) do
- if s.monitor then
- local best = 0.5
- for _, scale in ipairs({1, 0.5}) do
- s.monitor.setTextScale(scale)
- local w,h = s.getSize()
- if w >= 40 and h >= 7 then
- best = scale
- break
- end
- end
- s.monitor.setTextScale(best)
- end
- end
- -- 3) Helpers
- local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
- -- Clear every screen to lightGray
- local function clearAll()
- forAll(function(s)
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.clear()
- end)
- end
- -- 4) Static texts
- local titleText = "Laser Guided Warp System"
- local subtitleText = "Emit Scanning Laser to Warp"
- local offsetText = "Mining Laser Offset ( I ): "
- local proximityText = "3D Proximity Offset ( O ): "
- local promptH = "Press H for Main Menu"
- local promptI = "Press I to Toggle Laser Miner Offset"
- local promptO = "Press O to Toggle 3D Proximity Offset"
- -- Draw title, subtitle, offset‑state and proximity‑state lines
- local function drawStatic()
- forAll(function(s)
- local w,_ = s.getSize()
- -- Title (line 1): white on black
- local xT = math.floor((w - #titleText)/2) + 1
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.black)
- s.setCursorPos(xT,1)
- s.write(titleText)
- -- Subtitle (line 3): black on lightGray
- local xS = math.floor((w - #subtitleText)/2) + 1
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(xS,3)
- s.write(subtitleText)
- -- Mining Laser Offset (line 4)
- local fullOffset = offsetText.."ON"
- local xO = math.floor((w - #fullOffset)/2) + 1
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,4)
- s.write(string.rep(" ", w))
- s.setCursorPos(xO,4)
- s.write(offsetText)
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.lime)
- s.write("ON")
- -- 3D Proximity Offset (line 5)
- local fullProx = proximityText.."OFF"
- local xP = math.floor((w - #fullProx)/2) + 1
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,5)
- s.write(string.rep(" ", w))
- s.setCursorPos(xP,5)
- s.write(proximityText)
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.red)
- s.write("OFF")
- end)
- end
- -- Draw prompts on the bottom three rows
- local function drawPrompt()
- forAll(function(s)
- local w,h = s.getSize()
- -- line h-2: O prompt
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h-2)
- s.write(string.rep(" ", w))
- local xO = math.floor((w - #promptO)/2) + 1
- s.setCursorPos(xO,h-2)
- s.write(promptO)
- -- line h-1: H prompt
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h-1)
- s.write(string.rep(" ", w))
- local xH = math.floor((w - #promptH)/2) + 1
- s.setCursorPos(xH,h-1)
- s.write(promptH)
- -- line h: I prompt
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h)
- s.write(string.rep(" ", w))
- local xI = math.floor((w - #promptI)/2) + 1
- s.setCursorPos(xI,h)
- s.write(promptI)
- end)
- end
- -- 5) Set up warpdriveLaserCamera peripherals
- rednet.open("top")
- local cams = peripheral.getNames()
- for i=#cams,1,-1 do
- if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
- table.remove(cams,i)
- else
- peripheral.wrap(cams[i]).beamFrequency(1420)
- end
- end
- -- 6) Initial draw (blank coords)
- clearAll()
- drawStatic()
- drawPrompt()
- -- 7) Coords line, accepts nil → blanks before first scan
- local function updateCoords(x,y,z)
- local sx = x and tostring(x) or " "
- local sy = y and tostring(y) or " "
- local sz = z and tostring(z) or " "
- local coordLine = string.format("Target: X:%s Y:%s Z:%s", sx, sy, sz)
- forAll(function(s)
- local w,_ = s.getSize()
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,6)
- s.write(string.rep(" ", w))
- local cx = math.floor((w - #coordLine)/2) + 1
- s.setCursorPos(cx,6)
- s.write(coordLine)
- end)
- end
- -- draw initial blanks (on line 6)
- updateCoords(nil,nil,nil)
- -- 8) Main loop: scan + key handling
- while true do
- local ev,k,b,c,d = os.pullEventRaw()
- if ev == "laserScanning" then
- local tx = tonumber(b)
- local ty = tonumber(c)
- local tz = tonumber(d)
- updateCoords(tx,ty,tz)
- local data = { x = tx, y = ty, z = tz }
- rednet.broadcast(data, "HorizontalJumpMinerBroadcast")
- elseif ev == "key" then
- if k == keys.h then
- os.reboot()
- elseif k == keys.i then
- shell.run("itc")
- clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
- elseif k == keys.o then
- shell.run("otc")
- clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement