View difference between Paste ID: Lv1SHsGc and PUy0adWE
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
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
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 ): "
63+
local offsetText    = "Guided Mining System ( I ): "
64
local promptH       = "Press H for Main Menu"
65-
local promptI       = "Press C to Configure Miner"
65+
local promptI       = "Press J to Switch to Laser Guided Jump"
66-
local promptO       = "Press L to Toggle Miner"
66+
local promptO       = "Press T to Toggle Miner"
67
68-
-- Draw title, subtitle, and offset‑state line (now on line 5)
68+
-- track offset state
69
local isOffsetOn = false
70
71
-- Draw title, subtitle, and offset-state line (now on line 5)
72-
    -- Title (line 1): white on black
72+
73
  forAll(function(s)
74
    local w,_ = s.getSize()
75
    -- Title (line 1): white on black
76
    local xT = math.floor((w - #titleText)/2) + 1
77
    s.setTextColor(colors.white)
78
    s.setBackgroundColor(colors.black)
79-
    -- Subtitle (line 3): black on lightGray
79+
80
    s.write(titleText)
81
82
    -- Subtitle (line 3): black on lightGray
83
    local xS = math.floor((w - #subtitleText)/2) + 1
84
    s.setTextColor(colors.black)
85
    s.setBackgroundColor(colors.lightGray)
86-
    -- (line 4 is intentionally left blank)
86+
87
    s.write(subtitleText)
88-
    -- Mining Laser Offset (line 5)
88+
89-
    local fullOffset = offsetText .. "OFF"
89+
    -- (line 4 is intentionally left blank)
90
91
    -- Mining Laser Offset (line 5)
92
    local statusText = isOffsetOn and "ON" or "OFF"
93
    local fullOffset = offsetText .. statusText
94
    local xO = math.floor((w - #fullOffset)/2) + 1
95
96
    -- background bar
97
    s.setTextColor(colors.black)
98-
    s.setBackgroundColor(colors.red)
98+
99-
    s.write("OFF")
99+
100
    s.write(string.rep(" ", w))
101
102
    -- label
103
    s.setCursorPos(xO,5)
104
    s.write(offsetText)
105
106
    -- ON vs OFF coloring
107-
    -- line h-2: O prompt
107+
108
    s.setBackgroundColor(isOffsetOn and colors.lime or colors.red)
109
    s.write(statusText)
110
  end)
111
end
112
113
-- Draw prompts on the bottom three rows
114
local function drawPrompt()
115-
    -- line h-1: H prompt
115+
116
    local w,h = s.getSize()
117
    -- line h-2: O prompt
118
    s.setTextColor(colors.white)
119
    s.setBackgroundColor(colors.blue)
120
    s.setCursorPos(1,h-2)
121
    s.write(string.rep(" ", w))
122
    local xO = math.floor((w - #promptO)/2) + 1
123-
    -- line h: I prompt
123+
124
    s.write(promptO)
125
    -- line h-1: H prompt
126
    s.setTextColor(colors.white)
127
    s.setBackgroundColor(colors.blue)
128
    s.setCursorPos(1,h-1)
129
    s.write(string.rep(" ", w))
130
    local xH = math.floor((w - #promptH)/2) + 1
131
    s.setCursorPos(xH,h-1)
132
    s.write(promptH)
133-
-- 5) Set up warpdriveLaserCamera peripherals
133+
    -- line h: I prompt
134-
rednet.open("top")
134+
135
    s.setCursorPos(1,h)
136
    s.write(string.rep(" ", w))
137
    local xI = math.floor((w - #promptI)/2) + 1
138
    s.setCursorPos(xI,h)
139
    s.write(promptI)
140
  end)
141
end
142
143
-- 5) Set up all modems for rednet, then broadcast a startup check
144
for _, side in ipairs(peripheral.getNames()) do
145
  if peripheral.getType(side) == "modem" then
146
    rednet.open(side)
147
  end
148
end
149-
-- 7) Coords line, accepts nil → blanks before first scan (on line 6)
149+
rednet.broadcast("check", "SMiner")
150
151
-- now set up warpdriveLaserCamera peripherals
152
local cams = peripheral.getNames()
153
for i=#cams,1,-1 do
154
  if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
155
    table.remove(cams,i)
156
  else
157
    peripheral.wrap(cams[i]).beamFrequency(1420)
158
  end
159
end
160
161
-- 6) Initial draw (blank coords)
162
clearAll()
163
drawStatic()
164
drawPrompt()
165
166
-- 7) Coords line, accepts nil → blanks before first scan (on line 6)
167-
-- draw initial blanks (on line 6)
167+
168
  local sx = x and tostring(x) or "    "
169
  local sy = y and tostring(y) or "    "
170-
-- 8) Main loop: scan + key handling
170+
171
  local coordLine = string.format("Target: X:%s   Y:%s   Z:%s", sx, sy, sz)
172
  forAll(function(s)
173
    local w,_ = s.getSize()
174-
    local tx = tonumber(b)
174+
175-
    local ty = tonumber(c)
175+
176-
    local tz = tonumber(d)
176+
177-
    updateCoords(tx,ty,tz)
177+
178-
    local data = { x = tx, y = ty, z = tz }
178+
179-
    rednet.broadcast(data, "SMineBroadcast")
179+
180
    s.write(coordLine)
181
  end)
182
end
183
184-
    elseif k == keys.c then
184+
-- draw initial blanks (on line 6)
185-
      shell.run("conf")
185+
186-
      clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
186+
187-
    elseif k == keys.l then
187+
-- keep last coords around for redraws
188-
      rednet.broadcast("Toggle", "Miner")
188+
local lastX, lastY, lastZ = nil, nil, nil
189
190
-- 8) Main loop: scan + key handling + status listener
191
while true do
192
  -- 8a) non-blocking check for SMiner status messages
193
  local sender, msg, proto = rednet.receive("SMiner", 0)
194
  if msg == "StatON" then
195
    isOffsetOn = true
196
    clearAll(); drawStatic(); updateCoords(lastX,lastY,lastZ); drawPrompt()
197
  elseif msg == "StatOFF" then
198
    isOffsetOn = false
199
    clearAll(); drawStatic(); updateCoords(lastX,lastY,lastZ); drawPrompt()
200
  end
201
202
  -- 8b) main events
203
  local ev,k,b,c,d = os.pullEventRaw()
204
  if ev == "laserScanning" then
205
    lastX = tonumber(b)
206
    lastY = tonumber(c)
207
    lastZ = tonumber(d)
208
    updateCoords(lastX,lastY,lastZ)
209
    rednet.broadcast({ x = lastX, y = lastY, z = lastZ }, "SMineBroadcast")
210
211
  elseif ev == "key" then
212
    if k == keys.h then
213
      os.reboot()
214
	elseif k == keys.j then
215
    shell.run("otc")
216
clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
217
    elseif k == keys.t then
218
      rednet.broadcast("Toggle","SMiner")
219
    end
220
  end
221
end
222