View difference between Paste ID: fXLxQmpe and LFfjmtYb
SHOW: | | - or go back to the newest paste.
1-
-- Laser‑Guided Warp System (“ztc”) with H/I prompts on two bottom lines
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 6 lines will fit
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 >= 6 then
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     = "Laser Guided Warp System"
62
local subtitleText  = "Emit Scanning Laser to Warp"
63
local offsetText    = "Mining Laser Offset ( I ): "
64
local proximityText = "3D Proximity Offset ( O ): "
65
local promptH       = "Press H for Main Menu"
66
local promptI       = "Press I to Toggle Laser Miner Offset"
67-
-- Draw title, subtitle, and offset‑state line
67+
local promptO       = "Press O to Toggle 3D Proximity Offset"
68
69
-- Draw title, subtitle, offset‑state and proximity‑state lines
70
local function drawStatic()
71
  forAll(function(s)
72
    local w,_ = s.getSize()
73
    -- Title (line 1): white on black
74
    local xT = math.floor((w - #titleText)/2) + 1
75
    s.setTextColor(colors.white)
76
    s.setBackgroundColor(colors.black)
77
    s.setCursorPos(xT,1)
78
    s.write(titleText)
79
80
    -- Subtitle (line 3): black on lightGray
81
    local xS = math.floor((w - #subtitleText)/2) + 1
82
    s.setTextColor(colors.black)
83
    s.setBackgroundColor(colors.lightGray)
84
    s.setCursorPos(xS,3)
85-
    -- Offset‑state (line 4)
85+
86
87
    -- Mining Laser Offset (line 4)
88
    local fullOffset = offsetText.."OFF"
89
    local xO = math.floor((w - #fullOffset)/2) + 1
90
    s.setTextColor(colors.black)
91
    s.setBackgroundColor(colors.lightGray)
92
    s.setCursorPos(1,4)
93
    s.write(string.rep(" ", w))
94
    s.setCursorPos(xO,4)
95
    s.write(offsetText)
96
    s.setTextColor(colors.white)
97
    s.setBackgroundColor(colors.red)
98
    s.write("OFF")
99
100-
-- Draw prompts on the bottom two rows
100+
    -- 3D Proximity Offset (line 5)
101
    local fullProx = proximityText.."OFF"
102
    local xP = math.floor((w - #fullProx)/2) + 1
103
    s.setTextColor(colors.black)
104
    s.setBackgroundColor(colors.lightGray)
105
    s.setCursorPos(1,5)
106
    s.write(string.rep(" ", w))
107
    s.setCursorPos(xP,5)
108
    s.write(proximityText)
109
    s.setTextColor(colors.white)
110
    s.setBackgroundColor(colors.red)
111
    s.write("OFF")
112
  end)
113
end
114
115
-- Draw prompts on the bottom three rows
116
local function drawPrompt()
117
  forAll(function(s)
118
    local w,h = s.getSize()
119
    -- line h-2: O prompt
120
    s.setTextColor(colors.white)
121
    s.setBackgroundColor(colors.blue)
122
    s.setCursorPos(1,h-2)
123
    s.write(string.rep(" ", w))
124
    local xO = math.floor((w - #promptO)/2) + 1
125
    s.setCursorPos(xO,h-2)
126
    s.write(promptO)
127
    -- line h-1: H prompt
128
    s.setTextColor(colors.white)
129
    s.setBackgroundColor(colors.blue)
130
    s.setCursorPos(1,h-1)
131
    s.write(string.rep(" ", w))
132
    local xH = math.floor((w - #promptH)/2) + 1
133
    s.setCursorPos(xH,h-1)
134
    s.write(promptH)
135
    -- line h: I prompt
136
    s.setBackgroundColor(colors.blue)
137
    s.setCursorPos(1,h)
138
    s.write(string.rep(" ", w))
139
    local xI = math.floor((w - #promptI)/2) + 1
140
    s.setCursorPos(xI,h)
141
    s.write(promptI)
142
  end)
143
end
144
145
-- 5) Set up warpdriveLaserCamera peripherals
146
rednet.open("top")
147
local cams = peripheral.getNames()
148
for i=#cams,1,-1 do
149
  if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
150
    table.remove(cams,i)
151-
    s.setCursorPos(cx,5)
151+
152
    peripheral.wrap(cams[i]).beamFrequency(1420)
153
  end
154
end
155
156-
-- draw initial blanks
156+
157
clearAll()
158
drawStatic()
159
drawPrompt()
160
161-
  local ev,a,b,c,d = os.pullEventRaw()
161+
162
local function updateCoords(x,y,z)
163
  local sx = x and tostring(x) or "    "
164
  local sy = y and tostring(y) or "    "
165
  local sz = z and tostring(z) or "    "
166
  local coordLine = string.format("Target: X:%s   Y:%s   Z:%s", sx, sy, sz)
167-
	local data = { x = tx, y = ty, z = tz }
167+
168
    local w,_ = s.getSize()
169
    s.setTextColor(colors.black)
170
    s.setBackgroundColor(colors.lightGray)
171-
    if a == keys.h then
171+
    s.setCursorPos(1,6)
172
    s.write(string.rep(" ", w))
173-
    elseif a == keys.i then
173+
174
    s.setCursorPos(cx,6)
175-
      -- after running ztc, re‑draw UI
175+
176-
      clearAll()
176+
177-
      drawStatic()
177+
178-
      updateCoords(tx,ty,tz)
178+
179-
      drawPrompt()
179+
-- draw initial blanks (on line 6)
180
updateCoords(nil,nil,nil)
181
182
-- 8) Main loop: scan + key handling
183
while true do
184
  local ev,k,b,c,d = os.pullEventRaw()
185
  if ev == "laserScanning" then
186
    local tx = tonumber(b)
187
    local ty = tonumber(c)
188
    local tz = tonumber(d)
189
    updateCoords(tx,ty,tz)
190
local data = { x = tx, y = ty, z = tz }
191
    rednet.broadcast(data, "HorizontalJumpBroadcast")
192
193
  elseif ev == "key" then
194
    if k == keys.h then
195
      os.reboot()
196
    elseif k == keys.i then
197
      shell.run("ztc")
198
      clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
199
    elseif k == keys.o then
200
      shell.run("otc")
201
      clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
202
    end
203
  end
204
end
205