Advertisement
infiniteblock

Untitled

Nov 12th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.47 KB | None | 0 0
  1. if not term.isColor() then
  2. print("Advanced computer required")
  3. error()
  4. end
  5. print("loading...")
  6.  
  7. monitor_textScale = 0.5
  8.  
  9. Style = {
  10. CDefault = colors.black,
  11. BGDefault = colors.lightGray,
  12.  
  13. CTitle = colors.orange,
  14. BGTitle = colors.black,
  15.  
  16. CFooter = colors.white,
  17. BGFooter = colors.blue,
  18.  
  19. CWarning = colors.white,
  20. BGWarning = colors.red,
  21.  
  22. CSuccess = colors.white,
  23. BGSuccess = colors.lime,
  24.  
  25. CDisabled = colors.gray,
  26. BGDisabled = colors.blue,
  27.  
  28. CRadarmap = colors.gray,
  29. BGRadarmap = colors.green,
  30.  
  31. CRadarborder = colors.white,
  32. BGRadarborder = colors.black,
  33.  
  34. CRadarself = colors.white,
  35. BGRadarself = colors.lime,
  36. TextRadarself = "R",
  37.  
  38. CRadarother = colors.black,
  39. BGRadarother = colors.red,
  40. TextRadarother = "#"
  41. }
  42.  
  43. ----------- Monitor support
  44.  
  45. function SetMonitorColorFrontBack(frontColor, backgroundColor)
  46. term.setBackgroundColor(backgroundColor)
  47. term.setTextColor(frontColor)
  48. if monitors ~= nil then
  49. for key,monitor in pairs(monitors) do
  50. monitor.setTextColor(frontColor)
  51. monitor.setBackgroundColor(backgroundColor)
  52. end
  53. end
  54. end
  55.  
  56. function Write(text)
  57. term.write(text)
  58. if monitors ~= nil then
  59. for key,monitor in pairs(monitors) do
  60. if key ~= data.radar_monitorIndex then
  61. monitor.write(text)
  62. end
  63. end
  64. end
  65. end
  66. local function getCursorPos()
  67. local x, y = term.getCursorPos()
  68. return x, y
  69. end
  70.  
  71. function SetCursorPos(x, y)
  72. term.setCursorPos(x, y)
  73. if monitors ~= nil then
  74. for key,monitor in pairs(monitors) do
  75. if key ~= data.radar_monitorIndex then
  76. monitor.setCursorPos(x, y)
  77. end
  78. end
  79. end
  80. end
  81.  
  82. local function getResolution()
  83. local sizeX, sizeY = term.getSize()
  84. return sizeX, sizeY
  85. end
  86.  
  87. function SetColorDefault()
  88. SetMonitorColorFrontBack(Style.CDefault, Style.BGDefault)
  89. end
  90.  
  91. function SetColorTitle()
  92. SetMonitorColorFrontBack(Style.CTitle, Style.BGTitle)
  93. end
  94.  
  95. function SetColorFooter()
  96. SetMonitorColorFrontBack(Style.CFooter, Style.BGFooter)
  97. end
  98.  
  99. function SetColorWarning()
  100. SetMonitorColorFrontBack(Style.CWarning, Style.BGWarning)
  101. end
  102.  
  103. function SetColorSuccess()
  104. SetMonitorColorFrontBack(Style.CSuccess, Style.BGSuccess)
  105. end
  106.  
  107. function SetColorDisabled()
  108. SetMonitorColorFrontBack(Style.CDisabled, Style.BGDisabled)
  109. end
  110.  
  111. function SetColorNormal()
  112. SetMonitorColorFrontBack(Style.CDefault, Style.BGDefault)
  113. end
  114.  
  115. function SetColorRadarmap()
  116. SetMonitorColorFrontBack(Style.CRadarmap, Style.BGRadarmap)
  117. end
  118.  
  119. function SetColorRadarborder()
  120. SetMonitorColorFrontBack(Style.CRadarborder, Style.BGRadarborder)
  121. end
  122.  
  123. local function clear(colorFront, colorBack)
  124. clearWarningTick = -1
  125. if CDefault == nil or BGDefault == nil then
  126. SetMonitorColorFrontBack(Style.CDefault, Style.BGDefault)
  127. else
  128. SetMonitorColorFrontBack(Style.CDefault, Style.BGDefault)
  129. end
  130. term.clear()
  131. if monitors ~= nil then
  132. for key, monitor in pairs(monitors) do
  133. if key ~= data.radar_monitorIndex then
  134. monitor.clear()
  135. end
  136. end
  137. end
  138. SetCursorPos(1, 1)
  139. end
  140.  
  141. local function clearLine()
  142. term.clearLine()
  143. if monitors ~= nil then
  144. for key, monitor in pairs(monitors) do
  145. if key ~= data.radar_monitorIndex then
  146. monitor.clearLine()
  147. end
  148. end
  149. end
  150. local x, y = getCursorPos()
  151. SetCursorPos(1, y)
  152. end
  153.  
  154. function WriteLn(text)
  155. Write(text)
  156. local x, y = term.getCursorPos()
  157. local width, height = term.getSize()
  158. if y > height - 1 then
  159. y = 1
  160. end
  161. SetCursorPos(1, y + 1)
  162. end
  163.  
  164. function WriteCentered(y, text)
  165. local unused
  166. if text == nil then
  167. text = y
  168. unused, y = getCursorPos()
  169. end
  170.  
  171. SetCursorPos((51 - text:len()) / 2, y)
  172. term.write(text)
  173. if monitors ~= nil then
  174. for key,monitor in pairs(monitors) do
  175. if key ~= data.radar_monitorIndex then
  176. local sizeX, sizeY = monitor.getSize()
  177. if sizeX ~= nil then
  178. monitor.setCursorPos((sizeX - text:len()) / 2, y)
  179. monitor.write(text)
  180. end
  181. end
  182. end
  183. end
  184. local xt, yt = term.getCursorPos()
  185. SetCursorPos(1, y + 1)
  186. end
  187. local function page_begin(text)
  188. clear()
  189. SetColorTitle()
  190. SetCursorPos(1, 1)
  191. SetColorTitle()
  192. clearLine()
  193. WriteCentered(1, text)
  194. SetCursorPos(1, 2)
  195. SetColorNormal()
  196. end
  197. function ShowTitle(text)
  198. clear()
  199. SetCursorPos(0, 1)
  200. SetColorTitle()
  201. clearLine()
  202. WriteCentered(1, text)
  203. SetCursorPos(1, 2)
  204. SetColorDefault()
  205. end
  206.  
  207. function ShowMenu(text)
  208. Write(text)
  209. local sizeX, sizeY = term.getSize()
  210. local xt, yt = term.getCursorPos()
  211. for i = xt, sizeX do
  212. Write(" ")
  213. end
  214. SetCursorPos(1, yt + 1)
  215. end
  216.  
  217. local clearWarningTick = -1
  218. function ShowWarning(text)
  219. local sizeX, sizeY = term.getSize()
  220. SetCursorPos(1, sizeY)
  221. clearLine()
  222. SetColorWarning()
  223. SetCursorPos((sizeX - text:len() - 2) / 2, sizeY)
  224. Write(" " .. text .. " ")
  225. SetColorDefault()
  226. clearWarningTick = 5
  227. -- clearLine()
  228. end
  229. function ClearWarning()
  230. if clearWarningTick > 0 then
  231. clearWarningTick = clearWarningTick - 1
  232. elseif clearWarningTick == 0 then
  233. SetColorDefault()
  234. local sizeX, sizeY = term.getSize()
  235. SetCursorPos(1, sizeY)
  236. clearLine()
  237. clearWarningTick = -1
  238. end
  239. end
  240.  
  241. ----------- Formatting & popups
  242.  
  243. function FormatFloat(value, nbchar)
  244. local str = "?"
  245. if value ~= nil then
  246. str = string.format("%g", value)
  247. end
  248. if nbchar ~= nil then
  249. str = string.sub(" " .. str, -nbchar)
  250. end
  251. return str
  252. end
  253. function FormatInteger(value, nbchar)
  254. local str = "?"
  255. if value ~= nil then
  256. str = string.format("%d", value)
  257. end
  258. if nbchar ~= nil then
  259. str = string.sub(" " .. str, -nbchar)
  260. end
  261. return str
  262. end
  263.  
  264. function boolToYesNo(bool)
  265. if bool then
  266. return "YES"
  267. else
  268. return "no"
  269. end
  270. end
  271.  
  272. function readInputNumber(currentValue)
  273. local inputAbort = false
  274. local input = string.format(currentValue)
  275. if input == "0" then
  276. input = ""
  277. end
  278. local x, y = term.getCursorPos()
  279. repeat
  280. ClearWarning()
  281. SetColorDefault()
  282. SetCursorPos(x, y)
  283. Write(input .. " ")
  284. input = string.sub(input, -9)
  285.  
  286. local params = { os.pullEventRaw() }
  287. local eventName = params[1]
  288. local address = params[2]
  289. if address == nil then address = "none" end
  290. if eventName == "key" then
  291. local keycode = params[2]
  292. if keycode >= 2 and keycode <= 10 then -- 1 to 9
  293. input = input .. string.format(keycode - 1)
  294. elseif keycode == 11 or keycode == 82 then -- 0 & keypad 0
  295. input = input .. "0"
  296. elseif keycode >= 79 and keycode <= 81 then -- keypad 1 to 3
  297. input = input .. string.format(keycode - 78)
  298. elseif keycode >= 75 and keycode <= 77 then -- keypad 4 to 6
  299. input = input .. string.format(keycode - 71)
  300. elseif keycode >= 71 and keycode <= 73 then -- keypad 7 to 9
  301. input = input .. string.format(keycode - 64)
  302. elseif keycode == 14 then -- Backspace
  303. input = string.sub(input, 1, string.len(input) - 1)
  304. elseif keycode == 211 then -- Delete
  305. input = ""
  306. elseif keycode == 28 then -- Enter
  307. inputAbort = true
  308. elseif keycode == 74 or keycode == 12 or keycode == 49 then -- - on numeric keypad or - on US top or n letter
  309. if string.sub(input, 1, 1) == "-" then
  310. input = string.sub(input, 2)
  311. else
  312. input = "-" .. input
  313. end
  314. elseif char == 43 or keycode == 78 then -- +
  315. if string.sub(input, 1, 1) == "-" then
  316. input = string.sub(input, 2)
  317. end
  318. else
  319. ShowWarning("Key " .. keycode .. " is invalid")
  320. end
  321. elseif eventName == "terminate" then
  322. inputAbort = true
  323. elseif not common_event(eventName, params[2]) then
  324. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  325. end
  326. until inputAbort
  327. SetCursorPos(1, y + 1)
  328. if input == "" or input == "-" then
  329. return currentValue
  330. else
  331. return tonumber(input)
  332. end
  333. end
  334. function readInput(currentValue)
  335. local inputAbort = false
  336. local input = string.format(currentValue)
  337. local x, y = term.getCursorPos()
  338. Write(input)
  339. os.pullEventRaw() -- skip first char event
  340. repeat
  341. ClearWarning()
  342. SetColorDefault()
  343. SetCursorPos(x, y)
  344. Write(input .. " ")
  345. input = string.sub(input, -123)
  346.  
  347. local params = { os.pullEventRaw() }
  348. local eventName = params[1]
  349. local address = params[2]
  350. if address == nil then address = "none" end
  351. if eventName == "key" then
  352. local keycode = params[2]
  353. if keycode == 14 then -- Backspace
  354. input = string.sub(input, 1, string.len(input) - 1)
  355. elseif keycode == 211 then -- Delete
  356. input = ""
  357. elseif keycode == 28 then -- Enter
  358. inputAbort = true
  359. end
  360. elseif eventName == "char" then
  361. local char = params[2]
  362. if char >= ' ' and char <= '~' then -- 1 to 9
  363. input = input .. char
  364. end
  365. elseif eventName == "terminate" then
  366. inputAbort = true
  367. elseif eventName == "paste" then
  368. input = params[2]
  369. elseif not common_event(eventName, params[2]) then
  370. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  371. end
  372. until inputAbort
  373. SetCursorPos(1, y + 1)
  374. if input == "" then
  375. return currentValue
  376. else
  377. return input
  378. end
  379. end
  380. function readInputText(currentValue)
  381. local inputAbort = false
  382. local input = string.format(currentValue)
  383. local x, y = term.getCursorPos()
  384. Write(input)
  385. os.pullEventRaw() -- skip first char event
  386. repeat
  387. ClearWarning()
  388. SetColorDefault()
  389. SetCursorPos(x, y)
  390. Write(input .. " ")
  391. input = string.sub(input, -30)
  392.  
  393. local params = { os.pullEventRaw() }
  394. local eventName = params[1]
  395. local address = params[2]
  396. if address == nil then address = "none" end
  397. if eventName == "key" then
  398. local keycode = params[2]
  399. if keycode == 14 then -- Backspace
  400. input = string.sub(input, 1, string.len(input) - 1)
  401. elseif keycode == 211 then -- Delete
  402. input = ""
  403. elseif keycode == 28 then -- Enter
  404. inputAbort = true
  405. else
  406. ShowWarning("Key " .. keycode .. " is invalid")
  407. end
  408. elseif eventName == "char" then
  409. local char = params[2]
  410. if char >= ' ' and char <= '~' then -- 1 to 9
  411. input = input .. char
  412. else
  413. ShowWarning("Char #" .. string.byte(char) .. " is invalid")
  414. end
  415. elseif eventName == "terminate" then
  416. inputAbort = true
  417. elseif not common_event(eventName, params[2]) then
  418. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  419. end
  420. until inputAbort
  421. SetCursorPos(1, y + 1)
  422. if input == "" then
  423. return currentValue
  424. else
  425. return input
  426. end
  427. end
  428.  
  429. function readConfirmation(msg)
  430. if msg == nil then
  431. ShowWarning("Are you sure? (y/n)")
  432. else
  433. ShowWarning(msg)
  434. end
  435. repeat
  436. local params = { os.pullEventRaw() }
  437. local eventName = params[1]
  438. local address = params[2]
  439. if address == nil then address = "none" end
  440. if eventName == "key" then
  441. local keycode = params[2]
  442. if keycode == 21 then -- Y
  443. return true
  444. else
  445. return false
  446. end
  447. elseif eventName == "terminate" then
  448. return false
  449. elseif not common_event(eventName, params[2]) then
  450. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  451. end
  452. until false
  453. end
  454.  
  455. ----------- commons: menu, event handlers, etc.
  456.  
  457. function common_event(eventName, param)
  458. if eventName == "redstone" then
  459. redstone_event(param)
  460. elseif eventName == "timer" then
  461. if param == radar_timerId then
  462. radar_timerEvent()
  463. end
  464. elseif eventName == "shipCoreCooldownDone" then
  465. ShowWarning("Ship core cooldown done")
  466. elseif eventName == "reactorPulse" then
  467. reactor_pulse(param)
  468. -- elseif eventName == "reactorDeactivation" then
  469. -- ShowWarning("Reactor deactivated")
  470. -- elseif eventName == "reactorActivation" then
  471. -- ShowWarning("Reactor activated")
  472. elseif eventName == "char" then
  473. elseif eventName == "key_up" then
  474. elseif eventName == "mouse_click" then
  475. elseif eventName == "mouse_up" then
  476. elseif eventName == "mouse_drag" then
  477. elseif eventName == "monitor_touch" then
  478. elseif eventName == "monitor_resize" then
  479. elseif eventName == "peripheral" then
  480. elseif eventName == "peripheral_detach" then
  481. else
  482. return false
  483. end
  484. return true
  485. end
  486.  
  487. function menu_common()
  488. SetCursorPos(1, 17)
  489. SetColorFooter()
  490. ShowMenu("0 Home 1 Ship 2 Cloak 3 Shield 4 Radar 5 Mining ")
  491. ShowMenu("6 Transport 7 Reactor 8 Hooks X eXit ")
  492. SetColorDefault()
  493. end
  494.  
  495. ----------- Redstone support
  496.  
  497. local tblRedstoneState = {-- Remember redstone state on each side
  498. ["top"] = rs.getInput("top"),
  499. ["front"] = rs.getInput("front"),
  500. ["left"] = rs.getInput("left"),
  501. ["right"] = rs.getInput("right"),
  502. ["back"] = rs.getInput("back"),
  503. ["bottom"] = rs.getInput("bottom"),
  504. }
  505. local tblSides = {-- list all sides and offset coordinates
  506. ["top" ] = { 3, 1},
  507. ["front" ] = { 1, 3},
  508. ["left" ] = { 3, 3},
  509. ["right" ] = { 5, 3},
  510. ["back" ] = { 5, 5},
  511. ["bottom"] = { 3, 5},
  512. }
  513.  
  514. function redstone_event()
  515. -- Event only returns nil so we need to check sides manually
  516. local message = ""
  517. for side, state in pairs(tblRedstoneState) do
  518. if rs.getInput(side) ~= state then
  519. -- print(side .. " is now " .. tostring(rs.getInput(side)))
  520. message = message .. side .. " "
  521. tblRedstoneState[side] = rs.getInput(side)
  522. end
  523. end
  524. if message ~= "" then
  525. message = "Redstone changed on " .. message
  526. showWarning(message)
  527. end
  528. end
  529.  
  530.  
  531. ----------- Shield support
  532.  
  533. forcefieldprojector_currentKey = 1
  534. function shield_key(char, keycode)
  535. if char == 83 or char == 115 or keycode == 31 then -- S
  536. projector_start()
  537. return true
  538. elseif char == 80 or char == 112 or keycode == 25 then -- P
  539. projector_stop()
  540. return true
  541. end
  542. return false
  543. end
  544.  
  545. function shield_page()
  546. SetCursorPos(0, 1)
  547. SetColorTitle()
  548. ShowTitle(label .. " - Shield Status")
  549. local forcefieldprojector = nil
  550. if forcefieldprojectors ~= nil then
  551. if forcefieldprojector_currentKey > #forcefieldprojectors then
  552. forcefieldprojector_currentKey = 1
  553. end
  554. forcefieldprojector = forcefieldprojectors[forcefieldprojector_currentKey]
  555. end
  556.  
  557. SetCursorPos(1, 2)
  558. if #forcefieldprojectors == 0 then
  559. SetColorDisabled()
  560. Write("No Force Field Projectors detected...")
  561. elseif forcefieldprojector == nil or forcefieldprojector.isInterfaced() == nil then
  562. SetColorWarning()
  563. Write("Force Field Projector " .. forcefieldprojector_currentKey .. " of " .. #forcefieldprojectors .. " is invalid")
  564. else
  565. SetColorDefault()
  566. Write("Force Field Projector " .. forcefieldprojector_currentKey .. " of " .. #forcefieldprojectors)
  567. local isAssemblyValid = forcefieldprojector.getAssemblyStatus()
  568. local energyStored, energyMax, energyUnits = forcefieldprojector.getEnergyStatus()
  569. local isEnabled = forcefieldprojector.enable()
  570. local tier = forcefieldprojector.getTier()
  571. -- local upgrades = forcefieldprojector.getUpgrades()
  572. if tier == 1 then
  573. tier1 = "Basic"
  574. tierpower = 103427
  575. elseif tier == 2 then
  576. tier1 = "Advanced"
  577. tierpower = 35284
  578. else
  579. tier1 = "Superior"
  580. tierpower = 610141
  581. end
  582. if not isAssemblyValid then
  583. SetColorWarning()
  584. SetCursorPos(1, 3)
  585. Write("Invalid assembly!")
  586. SetColorDefault()
  587. SetCursorPos(1, 4)
  588. print("Projector is missing a upgrade or shape.")
  589. else
  590. SetCursorPos(1, 4)
  591. Write("Assembly is valid")
  592.  
  593. if energyStored < tierpower then
  594. SetColorWarning()
  595. else
  596. SetColorDefault()
  597. end
  598. SetCursorPos(1, 6)
  599. Write("Energy level is " .. energyStored .. " " .. energyUnits)
  600. SetCursorPos(1, 7)
  601. Write("Tier is " .. tier1)
  602. SetCursorPos(1, 8)
  603. -- Write("Upgrades ")
  604. SetCursorPos(1, 9)
  605. -- Write(" "..(upgrades and 'true' or 'false'),0,1,2,3)
  606. SetCursorPos(1, 11)
  607. if isEnabled then
  608. if energyStored <= 500 then
  609. SetColorWarning()
  610. else
  611. SetColorSuccess()
  612. end
  613. Write("Projector is enabled")
  614. else
  615. SetColorWarning()
  616. Write("Projector is disabled")
  617. end
  618. end
  619. end
  620. os.sleep(0.1)
  621. forcefieldprojector_currentKey = forcefieldprojector_currentKey + 1
  622. SetColorDefault()
  623. SetCursorPos(1, 12)
  624. SetCursorPos(1, 13)
  625. SetColorFooter()
  626. SetCursorPos(1, 16)
  627. ShowMenu(" (S)tart Projector - sto(P) Projector")
  628. SetColorDefault()
  629. end
  630.  
  631. function projector_start()
  632. for key,forcefieldprojector in pairs(forcefieldprojectors) do
  633. forcefieldprojector.enable(false)
  634. forcefieldprojector.enable(true)
  635. end
  636. end
  637.  
  638. function projector_stop()
  639. for key,forcefieldprojector in pairs(forcefieldprojectors) do
  640. forcefieldprojector.enable(false)
  641. end
  642. end
  643.  
  644. ----------- Configuration
  645.  
  646. function data_save()
  647. local file = fs.open("shipdata.txt", "w")
  648. if file ~= nil then
  649. file.writeLine(textutils.serialize(data))
  650. file.close()
  651. else
  652. ShowWarning("No file system")
  653. os.sleep(3)
  654. end
  655. end
  656.  
  657. function data_read()
  658. data = { }
  659. if fs.exists(".shield") then
  660. local file = fs.open(".shield", "r")
  661. data = textutils.unserialize(file.readAll())
  662. file.close()
  663. if data == nil then data = {}; end
  664. end
  665. if data.shield_hook == nil then data.auto_hook = 0; end
  666. end
  667.  
  668. function data_setName()
  669. if ship ~= nil then
  670. ShowTitle("<==== Set Shield name ====>")
  671. else
  672. ShowTitle("<==== Set name ====>")
  673. end
  674.  
  675. SetCursorPos(1, 2)
  676. Write("Enter ship name: ")
  677. label = readInputText(label)
  678. os.setComputerLabel(label)
  679. if ship ~= nil then
  680. ship.coreFrequency(label)
  681. end
  682. os.reboot()
  683. end
  684.  
  685. function string_split(source, sep)
  686. local sep = sep or ":"
  687. local fields = {}
  688. local pattern = string.format("([^%s]+)", sep)
  689. source:gsub(pattern, function(c) fields[#fields + 1] = c end)
  690. return fields
  691. end
  692.  
  693. function hooks_page_config()
  694. ShowTitle(label .. " - Webhook configuration")
  695.  
  696. SetCursorPos(1, 2)
  697. SetColorDefault()
  698. SetCursorPos(1, 3)
  699. Write("Ship Shield Webhook: ")
  700. hook_shieldset(readInput(data.shield_hook))
  701. data_save()
  702. end
  703. function hook_shieldset(newShield)
  704. data.shield_hook = newShield
  705. end
  706.  
  707. ----------- Boot sequence
  708. math.randomseed(os.time())
  709. label = os.getComputerLabel()
  710. if not label then
  711. label = "" .. os.getComputerID()
  712. end
  713.  
  714. -- read configuration
  715. data_read()
  716. clear()
  717. print("data_read...")
  718.  
  719. -- initial scanning
  720. monitors = {}
  721. ShowTitle(label .. " - Connecting...")
  722. WriteLn("")
  723.  
  724. sides = peripheral.getNames()
  725. forcefieldprojectors = {}
  726. warpdrivetransportercores = {}
  727. for key,side in pairs(sides) do
  728. os.sleep(0)
  729. Write("Checking " .. side .. " ")
  730. local componentType = peripheral.getType(side)
  731. Write(componentType .. " ")
  732. if componentType == "warpdriveForceFieldProjector" then
  733. Write("wrapping!")
  734. table.insert(forcefieldprojectors, peripheral.wrap(side))
  735. elseif componentType == "monitor" then
  736. Write("wrapping!")
  737. lmonitor = peripheral.wrap(side)
  738. table.insert(monitors, lmonitor)
  739. lmonitor.setTextScale(monitor_textScale)
  740. end
  741. WriteLn("")
  742. end
  743.  
  744. if not os.getComputerLabel() and (ship ~= nil or reactor ~= nil) then
  745. data_setName()
  746. end
  747.  
  748. -- peripherals status
  749. function connections_page()
  750. SetCursorPos(0, 1)
  751. SetColorTitle()
  752. ShowTitle(label .. " - Connections")
  753.  
  754. WriteLn("")
  755. if #monitors == 0 then
  756. SetColorWarning()
  757. WriteLn("No Monitor detected")
  758. elseif #monitors == 1 then
  759. SetColorSuccess()
  760. WriteLn("1 monitor detected")
  761. else
  762. SetColorSuccess()
  763. WriteLn(#monitors .. " Monitors detected")
  764. end
  765. if #forcefieldprojectors == 0 then
  766. SetColorWarning()
  767. WriteLn("No Force Field Pojectors detected")
  768. elseif #forcefieldprojectors == 1 then
  769. SetColorSuccess()
  770. WriteLn(#"1 Force Field Projector detected")
  771. else
  772. SetColorSuccess()
  773. WriteLn(#forcefieldprojectors .. " Force Field Projectors detected")
  774. end
  775.  
  776. WriteLn("")
  777. SetColorDefault()
  778. WriteLn("Please refer to below menu for keyboard controls")
  779. WriteLn("For example, press 1 to access Ship page")
  780. end
  781.  
  782. -- peripheral boot up
  783. clear()
  784. connections_page()
  785. SetColorDefault()
  786. WriteLn("")
  787. os.sleep(0)
  788.  
  789. -- main loop
  790. abort = false
  791. refresh = true
  792. page = connections_page
  793. keyHandler = nil
  794. repeat
  795. ClearWarning()
  796. if refresh then
  797. clear()
  798. page()
  799. menu_common()
  800. refresh = false
  801. end
  802. params = { os.pullEventRaw() }
  803. eventName = params[1]
  804. address = params[2]
  805. if address == nil then address = "none" end
  806. -- WriteLn("...")
  807. -- WriteLn("Event '" .. eventName .. "', " .. address .. ", " .. params[3] .. ", " .. params[4] .. " received")
  808. -- os.sleep(0.2)
  809. if eventName == "key" then
  810. keycode = params[2]
  811. if char == 88 or char == 120 or keycode == 45 then -- x for eXit
  812. os.pullEventRaw()
  813. abort = true
  814. elseif char == 48 or keycode == 11 or keycode == 82 then -- 0
  815. page = connections_page
  816. keyHandler = nil
  817. refresh = true
  818. elseif char == 49 or keycode == 2 or keycode == 79 then -- 1
  819. page = core_page
  820. keyHandler = core_key
  821. refresh = true
  822. elseif char == 50 or keycode == 3 or keycode == 80 then -- 2
  823. page = cloaking_page
  824. keyHandler = cloaking_key
  825. refresh = true
  826. elseif char == 51 or keycode == 4 or keycode == 81 then -- 3
  827. page = shield_page
  828. keyHandler = shield_key
  829. refresh = true
  830. elseif char == 52 or keycode == 5 or keycode == 75 then -- 4
  831. page = radar_page
  832. keyHandler = radar_key
  833. refresh = true
  834. elseif char == 53 or keycode == 6 or keycode == 76 then -- 5
  835. page = mining_page
  836. keyHandler = mining_key
  837. refresh = true
  838. elseif char == 54 or keycode == 7 or keycode == 77 then -- 6
  839. page = mining_page
  840. keyHandler = mining_key
  841. refresh = true
  842. elseif char == 55 or keycode == 8 then -- 7
  843. page = reactor_page
  844. keyHandler = reactor_key
  845. refresh = true
  846. elseif char == 56 or keycode == 9 or keycode == 79 then -- 8
  847. page = hooks_page_config
  848. keyHandler = hooks_page_key
  849. refresh = true
  850. elseif keyHandler ~= nil and keyHandler(char, keycode) then
  851. refresh = true
  852. os.sleep(0)
  853. elseif char == 0 then -- control chars
  854. refresh = false
  855. os.sleep(0)
  856. else
  857. ShowWarning("Key " .. keycode .. " is invalid")
  858. os.sleep(0.2)
  859. end
  860. elseif eventName == "reactorPulse" then
  861. reactor_pulse(params[2])
  862. refresh = (page == reactor_page)
  863. elseif eventName == "terminate" then
  864. abort = true
  865. elseif not common_event(eventName, params[2]) then
  866. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  867. refresh = true
  868. os.sleep(0.2)
  869. end
  870. until abort
  871.  
  872. -- exiting
  873. if data.core_summon then
  874. data.core_summon = false
  875. data_save()
  876. end
  877.  
  878. if ship ~= nil then
  879. ship.enable()
  880. end
  881.  
  882. -- clear screens on exit
  883. SetMonitorColorFrontBack(colors.white, colors.black)
  884. term.clear()
  885. if monitors ~= nil then
  886. for key,monitor in pairs(monitors) do
  887. monitor.clear()
  888. end
  889. end
  890. SetCursorPos(1, 1)
  891. WriteLn("Program terminated")
  892. WriteLn("Type startup to restart it")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement