jaklsfjlsak

激光扫描发射器 水平跳船 投屏

Apr 20th, 2025 (edited)
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
  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. -- Monitors
  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)
  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 >= 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
  51.  
  52. -- 4) Header & Subtitle
  53. local titleText    = "Laser Guided Warp System"
  54. local subtitleText = "Emit Scanning Laser to Warp"
  55.  
  56. local function drawHeader()
  57.   forAll(function(s)
  58.     local w,_ = s.getSize()
  59.     s.clear()
  60.     -- Title (line 1): white on black
  61.     local xT = math.floor((w - #titleText)/2) + 1
  62.     s.setTextColor(colors.white)
  63.     s.setBackgroundColor(colors.black)
  64.     s.setCursorPos(xT,1)
  65.     s.write(titleText)
  66.     -- Subtitle (line 3): black on lightGray
  67.     local xS = math.floor((w - #subtitleText)/2) + 1
  68.     s.setTextColor(colors.black)
  69.     s.setBackgroundColor(colors.lightGray)
  70.     s.setCursorPos(xS,3)
  71.     s.write(subtitleText)
  72.   end)
  73. end
  74.  
  75. -- 5) Setup peripherals
  76. rednet.open("top")
  77. local lasers = peripheral.getNames()
  78. for i=#lasers,1,-1 do
  79.   if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
  80.     table.remove(lasers,i)
  81.   else
  82.     peripheral.wrap(lasers[i]).beamFrequency(1420)
  83.   end
  84. end
  85.  
  86. -- 6) Initial draw
  87. clearAll()
  88. drawHeader()
  89.  
  90. -- 7) Dynamic coordinate line on row 5 (full X, Y, Z)
  91. local function updateCoords(x,y,z)
  92.   local line = string.format("Target: X:%d   Y:%d   Z:%d", x, y, z)
  93.   forAll(function(s)
  94.     local w,_ = s.getSize()
  95.     -- clear entire line 5
  96.     s.setTextColor(colors.black)
  97.     s.setBackgroundColor(colors.lightGray)
  98.     s.setCursorPos(1,5)
  99.     s.write(string.rep(" ", w))
  100.     -- write centered
  101.     local xs = math.floor((w - #line)/2) + 1
  102.     s.setCursorPos(xs,5)
  103.     s.write(line)
  104.   end)
  105. end
  106.  
  107. -- 8) Main loop: listen for laserScanning
  108. while true do
  109.   local event, side, lx, ly, lz = os.pullEvent("laserScanning")
  110.   local tx = tonumber(lx)
  111.   local ty = tonumber(ly)
  112.   local tz = tonumber(lz)
  113.   updateCoords(tx, ty, tz)
  114.   rednet.broadcast({ x = tx, y = ty, z = tz }, "HorizontalJumpBroadcast")
  115. end
  116.  
Advertisement
Add Comment
Please, Sign In to add comment