Advertisement
infiniteblock

Untitled

Nov 12th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.41 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. end
  228. function ClearWarning()
  229. if clearWarningTick > 0 then
  230. clearWarningTick = clearWarningTick - 1
  231. elseif clearWarningTick == 0 then
  232. SetColorDefault()
  233. local sizeX, sizeY = term.getSize()
  234. SetCursorPos(1, sizeY)
  235. clearLine()
  236. clearWarningTick = -1
  237. end
  238. end
  239.  
  240. ----------- Formatting & popups
  241.  
  242. function FormatFloat(value, nbchar)
  243. local str = "?"
  244. if value ~= nil then
  245. str = string.format("%g", value)
  246. end
  247. if nbchar ~= nil then
  248. str = string.sub(" " .. str, -nbchar)
  249. end
  250. return str
  251. end
  252. function FormatInteger(value, nbchar)
  253. local str = "?"
  254. if value ~= nil then
  255. str = string.format("%d", value)
  256. end
  257. if nbchar ~= nil then
  258. str = string.sub(" " .. str, -nbchar)
  259. end
  260. return str
  261. end
  262.  
  263. function boolToYesNo(bool)
  264. if bool then
  265. return "YES"
  266. else
  267. return "no"
  268. end
  269. end
  270.  
  271. function readInputNumber(currentValue)
  272. local inputAbort = false
  273. local input = string.format(currentValue)
  274. if input == "0" then
  275. input = ""
  276. end
  277. local x, y = term.getCursorPos()
  278. repeat
  279. ClearWarning()
  280. SetColorDefault()
  281. SetCursorPos(x, y)
  282. Write(input .. " ")
  283. input = string.sub(input, -9)
  284.  
  285. local params = { os.pullEventRaw() }
  286. local eventName = params[1]
  287. local address = params[2]
  288. if address == nil then address = "none" end
  289. if eventName == "key" then
  290. local keycode = params[2]
  291. if keycode >= 2 and keycode <= 10 then -- 1 to 9
  292. input = input .. string.format(keycode - 1)
  293. elseif keycode == 11 or keycode == 82 then -- 0 & keypad 0
  294. input = input .. "0"
  295. elseif keycode >= 79 and keycode <= 81 then -- keypad 1 to 3
  296. input = input .. string.format(keycode - 78)
  297. elseif keycode >= 75 and keycode <= 77 then -- keypad 4 to 6
  298. input = input .. string.format(keycode - 71)
  299. elseif keycode >= 71 and keycode <= 73 then -- keypad 7 to 9
  300. input = input .. string.format(keycode - 64)
  301. elseif keycode == 14 then -- Backspace
  302. input = string.sub(input, 1, string.len(input) - 1)
  303. elseif keycode == 211 then -- Delete
  304. input = ""
  305. elseif keycode == 28 then -- Enter
  306. inputAbort = true
  307. elseif keycode == 74 or keycode == 12 or keycode == 49 then -- - on numeric keypad or - on US top or n letter
  308. if string.sub(input, 1, 1) == "-" then
  309. input = string.sub(input, 2)
  310. else
  311. input = "-" .. input
  312. end
  313. elseif char == 43 or keycode == 78 then -- +
  314. if string.sub(input, 1, 1) == "-" then
  315. input = string.sub(input, 2)
  316. end
  317. else
  318. ShowWarning("Key " .. keycode .. " is invalid")
  319. end
  320. elseif eventName == "terminate" then
  321. inputAbort = true
  322. elseif not common_event(eventName, params[2]) then
  323. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  324. end
  325. until inputAbort
  326. SetCursorPos(1, y + 1)
  327. if input == "" or input == "-" then
  328. return currentValue
  329. else
  330. return tonumber(input)
  331. end
  332. end
  333. function readInput(currentValue)
  334. local inputAbort = false
  335. local input = string.format(currentValue)
  336. local x, y = term.getCursorPos()
  337. Write(input)
  338. os.pullEventRaw() -- skip first char event
  339. repeat
  340. ClearWarning()
  341. SetColorDefault()
  342. SetCursorPos(x, y)
  343. Write(input .. " ")
  344. input = string.sub(input, -123)
  345.  
  346. local params = { os.pullEventRaw() }
  347. local eventName = params[1]
  348. local address = params[2]
  349. if address == nil then address = "none" end
  350. if eventName == "key" then
  351. local keycode = params[2]
  352. if keycode == 14 then -- Backspace
  353. input = string.sub(input, 1, string.len(input) - 1)
  354. elseif keycode == 211 then -- Delete
  355. input = ""
  356. elseif keycode == 28 then -- Enter
  357. inputAbort = true
  358. end
  359. elseif eventName == "char" then
  360. local char = params[2]
  361. if char >= ' ' and char <= '~' then -- 1 to 9
  362. input = input .. char
  363. end
  364. elseif eventName == "terminate" then
  365. inputAbort = true
  366. elseif eventName == "paste" then
  367. input = params[2]
  368. elseif not common_event(eventName, params[2]) then
  369. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  370. end
  371. until inputAbort
  372. SetCursorPos(1, y + 1)
  373. if input == "" then
  374. return currentValue
  375. else
  376. return input
  377. end
  378. end
  379. function readInputText(currentValue)
  380. local inputAbort = false
  381. local input = string.format(currentValue)
  382. local x, y = term.getCursorPos()
  383. Write(input)
  384. os.pullEventRaw() -- skip first char event
  385. repeat
  386. ClearWarning()
  387. SetColorDefault()
  388. SetCursorPos(x, y)
  389. Write(input .. " ")
  390. input = string.sub(input, -30)
  391.  
  392. local params = { os.pullEventRaw() }
  393. local eventName = params[1]
  394. local address = params[2]
  395. if address == nil then address = "none" end
  396. if eventName == "key" then
  397. local keycode = params[2]
  398. if keycode == 14 then -- Backspace
  399. input = string.sub(input, 1, string.len(input) - 1)
  400. elseif keycode == 211 then -- Delete
  401. input = ""
  402. elseif keycode == 28 then -- Enter
  403. inputAbort = true
  404. else
  405. ShowWarning("Key " .. keycode .. " is invalid")
  406. end
  407. elseif eventName == "char" then
  408. local char = params[2]
  409. if char >= ' ' and char <= '~' then -- 1 to 9
  410. input = input .. char
  411. else
  412. ShowWarning("Char #" .. string.byte(char) .. " is invalid")
  413. end
  414. elseif eventName == "terminate" then
  415. inputAbort = true
  416. elseif not common_event(eventName, params[2]) then
  417. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  418. end
  419. until inputAbort
  420. SetCursorPos(1, y + 1)
  421. if input == "" then
  422. return currentValue
  423. else
  424. return input
  425. end
  426. end
  427.  
  428. function readConfirmation(msg)
  429. if msg == nil then
  430. ShowWarning("Are you sure? (y/n)")
  431. else
  432. ShowWarning(msg)
  433. end
  434. repeat
  435. local params = { os.pullEventRaw() }
  436. local eventName = params[1]
  437. local address = params[2]
  438. if address == nil then address = "none" end
  439. if eventName == "key" then
  440. local keycode = params[2]
  441. if keycode == 21 then -- Y
  442. return true
  443. else
  444. return false
  445. end
  446. elseif eventName == "terminate" then
  447. return false
  448. elseif not common_event(eventName, params[2]) then
  449. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  450. end
  451. until false
  452. end
  453.  
  454. ----------- commons: menu, event handlers, etc.
  455.  
  456. function common_event(eventName, param)
  457. if eventName == "redstone" then
  458. redstone_event(param)
  459. elseif eventName == "timer" then
  460. if param == radar_timerId then
  461. radar_timerEvent()
  462. end
  463. elseif eventName == "char" then
  464. elseif eventName == "key_up" then
  465. elseif eventName == "mouse_click" then
  466. elseif eventName == "mouse_up" then
  467. elseif eventName == "mouse_drag" then
  468. elseif eventName == "monitor_touch" then
  469. elseif eventName == "monitor_resize" then
  470. elseif eventName == "peripheral" then
  471. elseif eventName == "peripheral_detach" then
  472. else
  473. return false
  474. end
  475. return true
  476. end
  477.  
  478. function menu_common()
  479. SetCursorPos(1, 18)
  480. SetColorFooter()
  481. ShowMenu(" 0 Home 1 Shields 2 Webhook ")
  482. SetColorDefault()
  483. end
  484.  
  485. ----------- Redstone support
  486.  
  487. local tblRedstoneState = {-- Remember redstone state on each side
  488. ["top"] = rs.getInput("top"),
  489. ["front"] = rs.getInput("front"),
  490. ["left"] = rs.getInput("left"),
  491. ["right"] = rs.getInput("right"),
  492. ["back"] = rs.getInput("back"),
  493. ["bottom"] = rs.getInput("bottom"),
  494. }
  495. local tblSides = {-- list all sides and offset coordinates
  496. ["top" ] = { 3, 1},
  497. ["front" ] = { 1, 3},
  498. ["left" ] = { 3, 3},
  499. ["right" ] = { 5, 3},
  500. ["back" ] = { 5, 5},
  501. ["bottom"] = { 3, 5},
  502. }
  503.  
  504. function redstone_event()
  505. -- Event only returns nil so we need to check sides manually
  506. local message = ""
  507. for side, state in pairs(tblRedstoneState) do
  508. if rs.getInput(side) ~= state then
  509. -- print(side .. " is now " .. tostring(rs.getInput(side)))
  510. message = message .. side .. " "
  511. tblRedstoneState[side] = rs.getInput(side)
  512. end
  513. end
  514. if message ~= "" then
  515. message = "Redstone changed on " .. message
  516. showWarning(message)
  517. end
  518. end
  519.  
  520.  
  521. ----------- Shield support
  522.  
  523. forcefieldprojector_currentKey = 1
  524. function shield_key(char, keycode)
  525. if char == 83 or char == 115 or keycode == 31 then -- S
  526. projector_start()
  527. return true
  528. elseif char == 80 or char == 112 or keycode == 25 then -- P
  529. projector_stop()
  530. return true
  531. end
  532. return false
  533. end
  534.  
  535. function shield_page()
  536. SetCursorPos(0, 1)
  537. SetColorTitle()
  538. ShowTitle(label .. " - Shield Status")
  539. local forcefieldprojector = nil
  540. if forcefieldprojectors ~= nil then
  541. if forcefieldprojector_currentKey > #forcefieldprojectors then
  542. forcefieldprojector_currentKey = 1
  543. end
  544. forcefieldprojector = forcefieldprojectors[forcefieldprojector_currentKey]
  545. end
  546.  
  547. SetCursorPos(1, 2)
  548. if #forcefieldprojectors == 0 then
  549. SetColorDisabled()
  550. Write("No Force Field Projectors detected...")
  551. elseif forcefieldprojector == nil or forcefieldprojector.isInterfaced() == nil then
  552. SetColorWarning()
  553. Write("Force Field Projector " .. forcefieldprojector_currentKey .. " of " .. #forcefieldprojectors .. " is invalid")
  554. else
  555. SetColorDefault()
  556. Write("Force Field Projector " .. forcefieldprojector_currentKey .. " of " .. #forcefieldprojectors)
  557. local isAssemblyValid = forcefieldprojector.getAssemblyStatus()
  558. local energyStored, energyMax, energyUnits = forcefieldprojector.getEnergyStatus()
  559. local isEnabled = forcefieldprojector.enable()
  560. local tier = forcefieldprojector.getTier()
  561. -- local upgrades = forcefieldprojector.getUpgrades()
  562. if tier == 1 then
  563. tier1 = "Basic"
  564. tierpower = 103427
  565. elseif tier == 2 then
  566. tier1 = "Advanced"
  567. tierpower = 35284
  568. else
  569. tier1 = "Superior"
  570. tierpower = 610141
  571. end
  572. if not isAssemblyValid then
  573. SetColorWarning()
  574. SetCursorPos(1, 3)
  575. Write("Invalid assembly!")
  576. SetColorDefault()
  577. SetCursorPos(1, 4)
  578. print("Projector is missing a upgrade or shape.")
  579. else
  580. SetCursorPos(1, 4)
  581. Write("Assembly is valid")
  582.  
  583. if energyStored < tierpower then
  584. SetColorWarning()
  585. else
  586. SetColorDefault()
  587. end
  588. SetCursorPos(1, 6)
  589. Write("Energy level is " .. energyStored .. " " .. energyUnits)
  590. SetCursorPos(1, 7)
  591. Write("Tier is " .. tier1)
  592. SetCursorPos(1, 8)
  593. -- Write("Upgrades ")
  594. SetCursorPos(1, 9)
  595. -- Write(" "..(upgrades and 'true' or 'false'),0,1,2,3)
  596. SetCursorPos(1, 11)
  597. if isEnabled then
  598. if energyStored <= 500 then
  599. SetColorWarning()
  600. else
  601. SetColorSuccess()
  602. end
  603. Write("Projector is enabled")
  604. else
  605. SetColorWarning()
  606. Write("Projector is disabled")
  607. end
  608. end
  609. end
  610. os.sleep(0.1)
  611. forcefieldprojector_currentKey = forcefieldprojector_currentKey + 1
  612. SetColorDefault()
  613. SetCursorPos(1, 12)
  614. SetCursorPos(1, 13)
  615. SetColorFooter()
  616. SetCursorPos(1, 16)
  617. ShowMenu(" s(T)art Projector - st(O)p Projector ")
  618. ShowMenu(" (S)tart All Projectors - sto(P) All Projectors ")
  619. SetColorDefault()
  620. end
  621.  
  622. function projector_start()
  623. for key,forcefieldprojector in pairs(forcefieldprojectors) do
  624. forcefieldprojector.enable(false)
  625. forcefieldprojector.enable(true)
  626. end
  627. end
  628.  
  629. function projector_stop()
  630. for key,forcefieldprojector in pairs(forcefieldprojectors) do
  631. forcefieldprojector.enable(false)
  632. end
  633. end
  634.  
  635. ----------- Configuration
  636.  
  637. function data_save()
  638. local file = fs.open(".shield", "w")
  639. if file ~= nil then
  640. file.writeLine(textutils.serialize(data))
  641. file.close()
  642. else
  643. ShowWarning("No file system")
  644. os.sleep(3)
  645. end
  646. end
  647.  
  648. function data_read()
  649. data = { }
  650. if fs.exists(".shield") then
  651. local file = fs.open(".shield", "r")
  652. data = textutils.unserialize(file.readAll())
  653. file.close()
  654. if data == nil then data = {}; end
  655. end
  656. if data.shield_hook == nil then data.auto_hook = 0; end
  657. end
  658.  
  659. function data_setName()
  660. if ship ~= nil then
  661. ShowTitle("<==== Set Shield name ====>")
  662. else
  663. ShowTitle("<==== Set name ====>")
  664. end
  665.  
  666. SetCursorPos(1, 2)
  667. Write("Enter ship name: ")
  668. label = readInputText(label)
  669. os.setComputerLabel(label)
  670. if ship ~= nil then
  671. ship.coreFrequency(label)
  672. end
  673. os.reboot()
  674. end
  675.  
  676. function string_split(source, sep)
  677. local sep = sep or ":"
  678. local fields = {}
  679. local pattern = string.format("([^%s]+)", sep)
  680. source:gsub(pattern, function(c) fields[#fields + 1] = c end)
  681. return fields
  682. end
  683.  
  684. function hooks_page_config()
  685. ShowTitle(label .. " - Webhook configuration")
  686.  
  687. SetCursorPos(1, 2)
  688. SetColorDefault()
  689. SetCursorPos(1, 3)
  690. Write("Ship Shield Webhook: ")
  691. hook_shieldset(readInput(data.shield_hook))
  692. data_save()
  693. end
  694. function hook_shieldset(newShield)
  695. data.shield_hook = newShield
  696. end
  697.  
  698. ----------- Boot sequence
  699. math.randomseed(os.time())
  700. label = os.getComputerLabel()
  701. if not label then
  702. label = "" .. os.getComputerID()
  703. end
  704.  
  705. -- read configuration
  706. data_read()
  707. clear()
  708. print("data_read...")
  709.  
  710. -- initial scanning
  711. monitors = {}
  712. ShowTitle(label .. " - Connecting...")
  713. WriteLn("")
  714.  
  715. sides = peripheral.getNames()
  716. forcefieldprojectors = {}
  717. warpdrivetransportercores = {}
  718. for key,side in pairs(sides) do
  719. os.sleep(0)
  720. Write("Checking " .. side .. " ")
  721. local componentType = peripheral.getType(side)
  722. Write(componentType .. " ")
  723. if componentType == "warpdriveForceFieldProjector" then
  724. Write("wrapping!")
  725. table.insert(forcefieldprojectors, peripheral.wrap(side))
  726. elseif componentType == "monitor" then
  727. Write("wrapping!")
  728. lmonitor = peripheral.wrap(side)
  729. table.insert(monitors, lmonitor)
  730. lmonitor.setTextScale(monitor_textScale)
  731. end
  732. WriteLn("")
  733. end
  734.  
  735. if not os.getComputerLabel() and (ship ~= nil or reactor ~= nil) then
  736. data_setName()
  737. end
  738.  
  739. -- peripherals status
  740. function connections_page()
  741. SetCursorPos(0, 1)
  742. SetColorTitle()
  743. ShowTitle(label .. " - Connections")
  744.  
  745. WriteLn("")
  746. if #monitors == 0 then
  747. SetColorWarning()
  748. WriteLn("No Monitor detected")
  749. elseif #monitors == 1 then
  750. SetColorSuccess()
  751. WriteLn("1 monitor detected")
  752. else
  753. SetColorSuccess()
  754. WriteLn(#monitors .. " Monitors detected")
  755. end
  756. if #forcefieldprojectors == 0 then
  757. SetColorWarning()
  758. WriteLn("No Force Field Pojectors detected")
  759. elseif #forcefieldprojectors == 1 then
  760. SetColorSuccess()
  761. WriteLn(#"1 Force Field Projector detected")
  762. else
  763. SetColorSuccess()
  764. WriteLn(#forcefieldprojectors .. " Force Field Projectors detected")
  765. end
  766.  
  767. WriteLn("")
  768. SetColorDefault()
  769. WriteLn("Please refer to below menu for keyboard controls")
  770. WriteLn("For example, press 1 to access Ship page")
  771. end
  772.  
  773. -- peripheral boot up
  774. clear()
  775. connections_page()
  776. SetColorDefault()
  777. WriteLn("")
  778. os.sleep(2)
  779.  
  780. -- main loop
  781. abort = false
  782. refresh = true
  783. page = shield_page
  784. keyHandler = shield_key
  785. repeat
  786. ClearWarning()
  787. if refresh then
  788. clear()
  789. page()
  790. menu_common()
  791. refresh = false
  792. end
  793. params = { os.pullEventRaw() }
  794. eventName = params[1]
  795. address = params[2]
  796. if address == nil then address = "none" end
  797. -- WriteLn("...")
  798. -- WriteLn("Event '" .. eventName .. "', " .. address .. ", " .. params[3] .. ", " .. params[4] .. " received")
  799. -- os.sleep(0.2)
  800. if eventName == "key" then
  801. keycode = params[2]
  802. if char == 88 or char == 120 or keycode == 45 then -- x for eXit
  803. os.pullEventRaw()
  804. abort = true
  805. elseif char == 48 or keycode == 11 or keycode == 82 then -- 0
  806. page = connections_page
  807. keyHandler = nil
  808. refresh = true
  809. elseif char == 49 or keycode == 2 or keycode == 79 then -- 1
  810. page = shield_page
  811. keyHandler = shield_key
  812. refresh = true
  813. elseif char == 50 or keycode == 3 or keycode == 80 then -- 2
  814. page = hooks_page_config
  815. keyHandler = hooks_page_key
  816. refresh = true
  817. elseif keyHandler ~= nil and keyHandler(char, keycode) then
  818. refresh = true
  819. os.sleep(0)
  820. elseif char == 0 then -- control chars
  821. refresh = false
  822. os.sleep(0)
  823. else
  824. ShowWarning("Key " .. keycode .. " is invalid")
  825. os.sleep(0.2)
  826. end
  827. elseif eventName == "reactorPulse" then
  828. reactor_pulse(params[2])
  829. refresh = (page == reactor_page)
  830. elseif eventName == "terminate" then
  831. abort = true
  832. elseif not common_event(eventName, params[2]) then
  833. ShowWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  834. refresh = true
  835. os.sleep(0.2)
  836. end
  837. until abort
  838.  
  839. -- exiting
  840. if data.core_summon then
  841. data.core_summon = false
  842. data_save()
  843. end
  844.  
  845. if ship ~= nil then
  846. ship.enable()
  847. end
  848.  
  849. -- clear screens on exit
  850. SetMonitorColorFrontBack(colors.white, colors.black)
  851. term.clear()
  852. if monitors ~= nil then
  853. for key,monitor in pairs(monitors) do
  854. monitor.clear()
  855. end
  856. end
  857. SetCursorPos(1, 1)
  858. WriteLn("Program terminated")
  859. WriteLn("Type startup to restart it")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement