Advertisement
Guest User

startup

a guest
Feb 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.66 KB | None | 0 0
  1. monitor_textScale = 0.5
  2.  
  3. Style = {
  4.     CDefault = colors.white,
  5.     BGDefault = colors.blue,
  6.  
  7.     CTitle = colors.black,
  8.     BGTitle = colors.cyan,
  9.  
  10.     CWarning = colors.white,
  11.     BGWarning = colors.red,
  12.  
  13.     CSuccess = colors.white,
  14.     BGSuccess = colors.lime,
  15.  
  16.     CDisabled = colors.gray,
  17.     BGDisabled = colors.blue,
  18.  
  19.     CRadarmap = colors.gray,
  20.     BGRadarmap = colors.green,
  21.  
  22.     CRadarborder = colors.white,
  23.     BGRadarborder = colors.black,
  24.  
  25.     CRadarself = colors.white,
  26.     BGRadarself = colors.lime,
  27.     TextRadarself = "R",
  28.    
  29.     CRadarother = colors.black,
  30.     BGRadarother = colors.red,
  31.     TextRadarother = "#"
  32. }
  33.  
  34. if not term.isColor() then
  35.     print("Advanced computer required")
  36.     exit()
  37. end
  38.  
  39. ----------- Monitor support
  40.  
  41. function SetMonitorColorFrontBack(frontColor, backgroundColor)
  42.     term.setBackgroundColor(backgroundColor)
  43.     term.setTextColor(frontColor)  
  44. end
  45.  
  46. function Write(text)
  47.     term.write(text)   
  48. end
  49.  
  50. function SetCursorPos(x, y)
  51.     term.setCursorPos(x, y)
  52. end
  53.  
  54. function SetColorDefault()
  55.     SetMonitorColorFrontBack(Style.CDefault, Style.BGDefault)
  56. end
  57.  
  58. function SetColorTitle()
  59.     SetMonitorColorFrontBack(Style.CTitle, Style.BGTitle)
  60. end
  61.  
  62. function SetColorWarning()
  63.     SetMonitorColorFrontBack(Style.CWarning, Style.BGWarning)
  64. end
  65.  
  66. function SetColorSuccess()
  67.     SetMonitorColorFrontBack(Style.CSuccess, Style.BGSuccess)
  68. end
  69.  
  70. function SetColorDisabled()
  71.     SetMonitorColorFrontBack(Style.CDisabled, Style.BGDisabled)
  72. end
  73.  
  74. function SetColorRadarmap()
  75.     SetMonitorColorFrontBack(Style.CRadarmap, Style.BGRadarmap)
  76. end
  77.  
  78. function SetColorRadarborder()
  79.     SetMonitorColorFrontBack(Style.CRadarborder, Style.BGRadarborder)
  80. end
  81.  
  82. function Clear()
  83.     clearWarningTick = -1
  84.     SetColorDefault()
  85.     term.clear()   
  86.     SetCursorPos(1, 1)
  87. end
  88.  
  89. function ClearLine()
  90.     SetColorDefault()
  91.     term.clearLine()   
  92.     SetCursorPos(1, 1)
  93. end
  94.  
  95. function WriteLn(Text)
  96.     Write(Text)
  97.     local x, y = term.getCursorPos()
  98.     local width, height = term.getSize()
  99.     if y > height - 1 then
  100.         y = 1
  101.     end
  102.     SetCursorPos(1, y + 1)
  103. end
  104.  
  105. function WriteCentered(y, text)
  106.     SetCursorPos((51 - text:len()) / 2, y)
  107.     term.write(text)   
  108.     local xt, yt = term.getCursorPos()
  109.     SetCursorPos(1, yt + 1)
  110. end
  111.  
  112. function ShowTitle(text)
  113.     Clear()
  114.     SetColorTitle()
  115.     WriteCentered(1, text)
  116.     SetColorDefault()
  117. end
  118.  
  119. function ShowMenu(text)
  120.     Write(text)
  121.     local xt, yt = term.getCursorPos()
  122.     for i = xt, 51 do
  123.         Write(" ")
  124.     end
  125.     SetCursorPos(1, yt + 1)
  126. end
  127.  
  128. local clearWarningTick = -1
  129. function ShowWarning(text)
  130.     SetColorWarning()
  131.     SetCursorPos((51 - text:len() - 2) / 2, 19)
  132.     Write(" " .. text .. " ")
  133.     SetColorDefault()
  134.     clearWarningTick = 5
  135. end
  136. function ClearWarning(text)
  137.     if clearWarningTick > 0 then
  138.         clearWarningTick = clearWarningTick - 1
  139.     elseif clearWarningTick == 0 then
  140.         SetColorDefault()
  141.         SetCursorPos(1, 19)
  142.         ClearLine()
  143.     end
  144. end
  145.  
  146. ----------- Formatting & popups
  147.  
  148. function FormatFloat(value, nbchar)
  149.     local str = "?"
  150.     if value ~= nil then
  151.         str = string.format("%f", value)
  152.     end
  153.     if nbchar ~= nil then
  154.         str = string.sub("               " .. str, -nbchar)
  155.     end
  156.     return str
  157. end
  158. function FormatInteger(value, nbchar)
  159.     local str = "?"
  160.     if value ~= nil then
  161.         str = string.format("%d", value)
  162.     end
  163.     if nbchar ~= nil then
  164.         str = string.sub("               " .. str, -nbchar)
  165.     end
  166.     return str
  167. end
  168.  
  169. function boolToYesNo(bool)
  170.     if bool then
  171.         return "YES"
  172.     else
  173.         return "no"
  174.     end
  175. end
  176.  
  177. function readInputNumber(currentValue)
  178.     local inputAbort = false
  179.     local input = string.format(currentValue)
  180.     if input == "0" then
  181.         input = ""
  182.     end
  183.     local x, y = term.getCursorPos()
  184.     repeat
  185.         ClearWarning()
  186.         SetColorDefault()
  187.         SetCursorPos(x, y)
  188.         Write(input .. "            ")
  189.         input = string.sub(input, -9)
  190.        
  191.         local params = { os.pullEventRaw() }
  192.         local eventName = params[1]
  193.         local side = params[2]
  194.         if side == nil then side = "none" end
  195.         if eventName == "key" then
  196.             local keycode = params[2]
  197.             if keycode >= 2 and keycode <= 10 then -- 1 to 9
  198.                 input = input .. string.format(keycode - 1)
  199.             elseif keycode == 11 or keycode == 82 then -- 0 & keypad 0
  200.                 input = input .. "0"
  201.             elseif keycode >= 79 and keycode <= 81 then -- keypad 1 to 3
  202.                 input = input .. string.format(keycode - 78)
  203.             elseif keycode >= 75 and keycode <= 87 then -- keypad 4 to 6
  204.                 input = input .. string.format(keycode - 71)
  205.             elseif keycode >= 71 and keycode <= 73 then -- keypad 7 to 9
  206.                 input = input .. string.format(keycode - 64)
  207.             elseif keycode == 14 then -- Backspace
  208.                 input = string.sub(input, 1, string.len(input) - 1)
  209.             elseif keycode == 211 then -- Delete
  210.                 input = ""
  211.             elseif keycode == 28 then -- Enter
  212.                 inputAbort = true
  213.             else
  214.                 ShowWarning("Key " .. keycode .. " is invalid")
  215.             end
  216.         elseif eventName == "char" then
  217.             -- drop it
  218.         elseif eventName == "key_up" then
  219.             -- drop it
  220.         elseif eventName == "terminate" then
  221.             inputAbort = true
  222.         elseif not common_event(eventName, params[2]) then
  223.             ShowWarning("Event '" .. eventName .. "', " .. side .. " is unsupported")
  224.         end
  225.     until inputAbort
  226.     SetCursorPos(1, y + 1)
  227.     if input == "" then
  228.         return currentValue
  229.     else
  230.         return tonumber(input)
  231.     end
  232. end
  233.  
  234. function readInputText(currentValue)
  235.     local inputAbort = false
  236.     local input = string.format(currentValue)
  237.     local x, y = term.getCursorPos()
  238.     repeat
  239.         ClearWarning()
  240.         SetColorDefault()
  241.         SetCursorPos(x, y)
  242.         Write(input .. "                              ")
  243.         input = string.sub(input, -30)
  244.        
  245.         local params = { os.pullEventRaw() }
  246.         local eventName = params[1]
  247.         local side = params[2]
  248.         if side == nil then side = "none" end
  249.         if eventName == "key" then
  250.             local keycode = params[2]
  251.             if keycode == 14 then -- Backspace
  252.                 input = string.sub(input, 1, string.len(input) - 1)
  253.             elseif keycode == 211 then -- Delete
  254.                 input = ""
  255.             elseif keycode == 28 then -- Enter
  256.                 inputAbort = true
  257.             else
  258.                 -- ShowWarning("Key " .. keycode .. " is invalid")
  259.             end
  260.         elseif eventName == "char" then
  261.             local char = params[2]
  262.             if char >= ' ' and char <= '~' then -- 1 to 9
  263.                 input = input .. char
  264.             else
  265.                 ShowWarning("Char #" .. string.byte(char) .. " is invalid")
  266.             end
  267.         elseif eventName == "key_up" then
  268.             -- drop it
  269.         elseif eventName == "terminate" then
  270.             inputAbort = true
  271.         elseif not common_event(eventName, params[2]) then
  272.             ShowWarning("Event '" .. eventName .. "', " .. side .. " is unsupported")
  273.         end
  274.     until inputAbort
  275.     SetCursorPos(1, y + 1)
  276.     if input == "" then
  277.         return currentValue
  278.     else
  279.         return input
  280.     end
  281. end
  282.  
  283. function readConfirmation()
  284.     ShowWarning("Are you sure? (y/n)")
  285.     repeat
  286.         local params = { os.pullEventRaw() }
  287.         local eventName = params[1]
  288.         local side = params[2]
  289.         if side == nil then side = "none" end
  290.         if eventName == "key" then
  291.             local keycode = params[2]
  292.             if keycode == 21 then -- Y
  293.                 return true
  294.             else
  295.                 return false
  296.             end
  297.         elseif eventName == "char" then
  298.             -- drop it
  299.         elseif eventName == "key_up" then
  300.             -- drop it
  301.         elseif eventName == "terminate" then
  302.             return false
  303.         elseif not common_event(eventName, params[2]) then
  304.             ShowWarning("Event '" .. eventName .. "', " .. side .. " is unsupported")
  305.         end
  306.     until false
  307. end
  308.  
  309. ----------- commons: menu, event handlers, etc.
  310.  
  311. function common_event(eventName, param)
  312.     if eventName == "redstone" then
  313.         redstone_event(param)
  314.     elseif eventName == "timer" then
  315.     elseif eventName == "reactorPulse" then
  316.         reactor_pulse(param)
  317. --  elseif eventName == "reactorDeactivation" then
  318. --      ShowWarning("Reactor deactivated")
  319. --  elseif eventName == "reactorActivation" then
  320. --      ShowWarning("Reactor activated")
  321.     else
  322.         return false
  323.     end
  324.     return true
  325. end
  326.  
  327. function menu_common()
  328.     SetCursorPos(1, 18)
  329.     SetColorTitle()
  330.     ShowMenu("0 Connections, 1 Reactor, X Exit")
  331. end
  332.  
  333. ----------- Redstone support
  334.  
  335. local tblRedstoneState = {-- Remember redstone state on each side
  336.     ["top"] = rs.getInput("top"),
  337.     ["front"] = rs.getInput("front"),
  338.     ["left"] = rs.getInput("left"),
  339.     ["right"] = rs.getInput("right"),
  340.     ["back"] = rs.getInput("back"),
  341.     ["bottom"] = rs.getInput("bottom"),
  342. }
  343. local tblSides = {-- list all sides and offset coordinates
  344.     ["top"   ] = { 3, 1},
  345.     ["front" ] = { 1, 3},
  346.     ["left"  ] = { 3, 3},
  347.     ["right" ] = { 5, 3},
  348.     ["back"  ] = { 5, 5},
  349.     ["bottom"] = { 3, 5},
  350. }
  351.  
  352. function redstone_event()
  353.     -- Event only returns nil so we need to check sides manually
  354.     local message = ""
  355.     for side, state in pairs(tblRedstoneState) do
  356.         if rs.getInput(side) ~= state then
  357.             -- print(side .. " is now " .. tostring(rs.getInput(side)))
  358.             message = message .. side .. " "
  359.             tblRedstoneState[side] = rs.getInput(side)
  360.         end
  361.     end
  362.     if message ~= "" then
  363.         message = "Redstone changed on " .. message
  364.         showWarning(message)
  365.     end
  366. end
  367.  
  368. ----------- Configuration
  369.  
  370. function data_save()
  371.     local file = fs.open("shipdata.txt", "w")
  372.     file.writeLine(textutils.serialize(data))
  373.     file.close()
  374. end
  375.  
  376. function data_read()
  377.     if fs.exists("shipdata.txt") then
  378.         local file = fs.open("shipdata.txt", "r")
  379.         data = textutils.unserialize(file.readAll())
  380.         file.close()
  381.     else
  382.         data = { }
  383.     end
  384.     if data.reactor_mode == nil then data.reactor_mode = 0; end
  385.     if data.reactor_rate == nil then data.reactor_rate = 100; end
  386.     if data.reactor_targetStability == nil then data.reactor_targetStability = 50; end
  387.     if data.reactor_laserAmount == nil then data.reactor_laserAmount = 10000; end
  388. end
  389.  
  390. function data_setName()
  391.     ShowTitle("<==== Set name ====>")
  392.    
  393.     SetCursorPos(1, 2)
  394.     Write("Enter ship name: ")
  395.     label = readInputText(label)
  396.     os.setComputerLabel(label)
  397.     os.reboot()
  398. end
  399.  
  400. ----------- Reactor support
  401.  
  402. reactor_output = 0
  403.  
  404. function reactor_boot()
  405.     if reactor ~= nil then
  406.         WriteLn("Booting Reactor...")
  407.         local isActive, strMode, releaseRate = reactor.active()
  408.         if strMode == "OFF" then
  409.             data.reactor_mode = 0
  410.         elseif strMode == "MANUAL" then
  411.             data.reactor_mode = 1
  412.         elseif strMode == "ABOVE" then
  413.             data.reactor_mode = 2
  414.         elseif strMode == "RATE" then
  415.             data.reactor_mode = 3
  416.         else
  417.             data.reactor_mode = 0
  418.         end
  419.     end
  420. end
  421.  
  422. function reactor_key(keycode)
  423.     if keycode == 31 then -- S
  424.         reactor_start()
  425.         return true
  426.     elseif keycode == 25 then -- P
  427.         reactor_stop()
  428.         return true
  429.     elseif keycode == 38 then -- L
  430.         reactor_laser()
  431.         return true
  432.     elseif keycode == 24 then -- O
  433.         data.reactor_mode = (data.reactor_mode + 1) % 4
  434.         reactor_setMode()
  435.         data_save()
  436.         return true
  437.     elseif keycode == 34 then -- G
  438.         data.reactor_rate = data.reactor_rate / 10
  439.         reactor_setMode()
  440.         data_save()
  441.         return true
  442.     elseif keycode == 20 then -- T
  443.         data.reactor_rate = data.reactor_rate * 10
  444.         reactor_setMode()
  445.         data_save()
  446.         return true
  447.     elseif keycode == 36 then -- J
  448.         data.reactor_laserAmount = data.reactor_laserAmount / 10
  449.         reactor_setLaser()
  450.         data_save()
  451.         return true
  452.     elseif keycode == 22 then -- U
  453.         data.reactor_laserAmount = data.reactor_laserAmount * 10
  454.         reactor_setLaser()
  455.         data_save()
  456.         return true
  457.     elseif keycode == 74 then -- -
  458.         data.reactor_targetStability = data.reactor_targetStability - 1
  459.         reactor_setTargetStability()
  460.         data_save()
  461.         return true
  462.     elseif keycode == 78 then -- +
  463.         data.reactor_targetStability = data.reactor_targetStability + 1
  464.         reactor_setTargetStability()
  465.         data_save()
  466.         return true
  467.     elseif keycode == 46 then -- C
  468.         reactor_config()
  469.         data_save()
  470.         return true
  471.     end
  472.     return false
  473. end
  474.  
  475. function reactor_page()
  476.     ShowTitle(label .. " - Reactor status")
  477.  
  478.     SetCursorPos(1, 2)
  479.     if reactor == nil then
  480.         SetColorDisabled()
  481.         Write("Reactor not detected")
  482.     else
  483.         SetColorDefault()
  484.         Write("Reactor stability")
  485.         instabilities = { reactor.instability() }
  486.         average = 0
  487.         for key,instability in pairs(instabilities) do
  488.             SetCursorPos(12, 2 + key)
  489.             stability = math.floor((100.0 - instability) * 10) / 10
  490.             if stability >= data.reactor_targetStability then
  491.                 SetColorSuccess()
  492.             else
  493.                 SetColorWarning()
  494.             end
  495.             Write(FormatFloat(stability, 5) .. " %")
  496.             average = average + instability
  497.         end
  498.         average = average / #instabilities
  499.  
  500.         SetColorDefault()
  501.         local energy = { reactor.energy() }
  502.         SetCursorPos(1, 7)
  503.         Write("Energy   : ")
  504.         if energy[1] ~= nil then
  505.             Write(FormatInteger(energy[1], 10) .. " / " .. energy[2] .. " RF +" .. FormatInteger(reactor_output, 5) .. " RF/t")
  506.         else
  507.             Write("???")
  508.         end
  509.         SetCursorPos(1, 8)
  510.         Write("Outputing: ")
  511.         if energy[1] ~= nil then
  512.             Write(energy[3] .. " RF/t")
  513.         end
  514.  
  515.         SetColorDefault()
  516.         SetCursorPos(1, 9)
  517.         Write("Activated: ")
  518.         isActive = reactor.active()
  519.         if isActive then SetColorSuccess() else SetColorDefault() end
  520.         Write(boolToYesNo(isActive))
  521.     end
  522.  
  523.     if #reactorlasers == 0 then
  524.         SetColorDisabled()
  525.         SetCursorPos(30, 2)
  526.         Write("Lasers not detected")
  527.     else
  528.         SetColorDefault()
  529.         SetCursorPos(30, 2)
  530.         Write("Lasers")
  531.  
  532.         for key,reactorlaser in pairs(reactorlasers) do
  533.             local side = reactorlaser.side()
  534.             if side ~= nil then
  535.                 side = side % 4
  536.                 SetColorDefault()
  537.                 SetCursorPos(4, 3 + side)
  538.                 Write("Side " .. side .. ":")
  539.                 SetCursorPos(30, 3 + side)
  540.                 local energy = reactorlaser.energy()
  541.                 if not reactorlaser.hasReactor() then
  542.                     SetColorDisabled()
  543.                 elseif energy > 3 * data.reactor_laserAmount then
  544.                     SetColorSuccess()
  545.                 else
  546.                     SetColorWarning()
  547.                 end
  548.                 Write(FormatInteger(reactorlaser.energy(), 6))
  549.             end
  550.         end
  551.     end
  552.  
  553.     SetColorDefault()
  554.     SetCursorPos(1, 10)
  555.     Write("  -----------------------------------------------")
  556.     SetCursorPos(1, 11)
  557.     Write("Output mode     : ")
  558.     if data.reactor_mode == 0 then
  559.         SetColorDisabled()
  560.         Write("hold")
  561.     elseif data.reactor_mode == 1 then
  562.         Write("manual/unlimited")
  563.     elseif data.reactor_mode == 2 then
  564.         Write("surplus above " .. data.reactor_rate .. " RF")
  565.     else
  566.         Write("rated at " .. data.reactor_rate .. " RF")
  567.     end
  568.     SetColorDefault()
  569.     SetCursorPos( 1, 12)
  570.     Write("Target stability: " .. data.reactor_targetStability .. "%")
  571.     SetCursorPos(30, 12)
  572.     Write("Laser amount: " .. data.reactor_laserAmount)
  573.    
  574.     SetColorTitle()
  575.     SetCursorPos(1, 14)
  576.     ShowMenu("S - Start reactor, P - Stop reactor, L - Use lasers")
  577.     SetCursorPos(1, 15)
  578.     ShowMenu("O - Output mode, C - Configuration")
  579.     SetCursorPos(1, 16)
  580.     ShowMenu("+/- - Target stability, U/J - Laser amount")
  581.     SetCursorPos(1, 17)
  582.     ShowMenu("G/T - Output rate/threshold")
  583. end
  584.  
  585. function reactor_setMode()
  586.     if data.reactor_rate < 1 then
  587.         data.reactor_rate = 1
  588.     elseif data.reactor_rate > 100000 then
  589.         data.reactor_rate = 100000
  590.     end
  591.     if reactor ~= nil then
  592.         if data.reactor_mode == 0 then
  593.             reactor.release(false)
  594.         elseif data.reactor_mode == 1 then
  595.             reactor.release(true)
  596.         elseif data.reactor_mode == 2 then
  597.             reactor.releaseAbove(data.reactor_rate)
  598.         else
  599.             reactor.releaseRate(data.reactor_rate)
  600.         end
  601.     end
  602. end
  603.  
  604. function reactor_setLaser()
  605.     if data.reactor_laserAmount < 1 then
  606.         data.reactor_laserAmount = 1
  607.     elseif data.reactor_laserAmount > 100000 then
  608.         data.reactor_laserAmount = 100000
  609.     end
  610. end
  611.  
  612. function reactor_setTargetStability()
  613.     if data.reactor_targetStability < 1 then
  614.         data.reactor_targetStability = 1
  615.     elseif data.reactor_targetStability > 100 then
  616.         data.reactor_targetStability = 100
  617.     end
  618. end
  619.  
  620. function reactor_start()
  621.     if reactor ~= nil then
  622.         reactor_setMode()
  623.         reactor.active(true)
  624.     end
  625. end
  626.  
  627. function reactor_stop()
  628.     if reactor ~= nil then
  629.         reactor.active(false)
  630.     end
  631. end
  632.  
  633. function reactor_laser(side)
  634.     for key,reactorlaser in pairs(reactorlasers) do
  635.         if (side == nil) or (reactorlaser.side() == side) then
  636.             reactorlaser.stabilize(data.reactor_laserAmount)
  637.         end
  638.     end
  639. end
  640.  
  641. function reactor_pulse(output)
  642.     reactor_output = output
  643.     if reactor == nil then
  644.         os.reboot()
  645.     end
  646.     local instabilities = { reactor.instability() }
  647.     for key,instability in pairs(instabilities) do
  648.         local stability = math.floor((100.0 - instability) * 10) / 10
  649.         if stability < data.reactor_targetStability then
  650.             reactor_laser(key - 1)
  651.         end
  652.     end
  653. end
  654.  
  655. function reactor_config()
  656.     ShowTitle(label .. " - Reactor configuration")
  657.    
  658.     SetCursorPos(1, 2)
  659.     if reactor == nil then
  660.         SetColorDisabled()
  661.         Write("Reactor not detected")
  662.     else
  663.         SetColorDefault()
  664.         SetCursorPos(1, 4)
  665.         Write("Reactor output rate (" .. data.reactor_rate .. " RF): ")
  666.         data.reactor_rate = readInputNumber(data.reactor_rate)
  667.         reactor_setMode()
  668.         SetCursorPos(1, 5)
  669.         Write("Reactor output rate set")
  670.        
  671.         SetCursorPos(1, 7)
  672.         Write("Laser energy level (" .. data.reactor_laserAmount .. "): ")
  673.         data.reactor_laserAmount = readInputNumber(data.reactor_laserAmount)
  674.         reactor_setLaser()
  675.         SetCursorPos(1, 8)
  676.         Write("Laser energy level set")
  677.        
  678.         SetCursorPos(1, 10)
  679.         Write("Reactor target stability (" .. data.reactor_targetStability .. "%): ")
  680.         data.reactor_targetStability = readInputNumber(data.reactor_targetStability)
  681.         reactor_setTargetStability()
  682.         SetCursorPos(1, 11)
  683.         Write("Reactor target stability set")
  684.     end
  685. end
  686.  
  687. ----------- Boot sequence
  688. label = os.getComputerLabel()
  689. if not label then
  690.     label = "" .. os.getComputerID()
  691. end
  692.  
  693. -- read configuration
  694. data_read()
  695.  
  696. -- initial scanning
  697. monitors = {}
  698. ShowTitle(label .. " - Connecting...")
  699. WriteLn("")
  700.  
  701. sides = peripheral.getNames()
  702. reactor = nil
  703. reactorlasers = {}
  704. for key,side in pairs(sides) do
  705.     sleep(0)
  706.     if peripheral.getType(side) == "warpdriveEnanReactorCore" then
  707.         WriteLn("Wrapping " .. side)
  708.         reactor =  peripheral.wrap(side)
  709.     elseif peripheral.getType(side) == "warpdriveEnanReactorLaser" then
  710.         WriteLn("Wrapping " .. side)
  711.         table.insert(reactorlasers, peripheral.wrap(side))
  712.     end
  713. end
  714. -- sleep(1)
  715.  
  716. if not os.getComputerLabel() and reactor ~= nil then
  717.     data_setName()
  718. end
  719.  
  720. -- peripherals status
  721. function connections_page()
  722.     ShowTitle(label .. " - Connections")
  723.  
  724.     WriteLn("")
  725.     if #monitors == 0 then
  726.         SetColorDisabled()
  727.         WriteLn("No Monitor detected") 
  728.     end
  729.  
  730.     if reactor == nil then
  731.         SetColorDisabled()
  732.         WriteLn("No Enantiomorphic reactor detected")
  733.     else
  734.         SetColorSuccess()
  735.         WriteLn("Enantiomorphic reactor detected")
  736.     end
  737.  
  738.     if #reactorlasers == 0 then
  739.         SetColorDisabled()
  740.         WriteLn("No reactor stabilisation laser detected")
  741.     elseif #reactorlasers == 1 then
  742.         SetColorSuccess()
  743.         WriteLn("1 reactor stabilisation laser detected")
  744.     else
  745.         SetColorSuccess()
  746.         WriteLn(#reactorlasers .. " reactor stabilisation lasers detected")
  747.     end
  748. end
  749.  
  750. -- peripheral boot up
  751. Clear()
  752. connections_page()
  753. SetColorDefault()
  754. WriteLn("")
  755. sleep(0.5)
  756. reactor_boot()
  757.  
  758. -- main loop
  759. abort = false
  760. refresh = false
  761. page = reactor_page
  762. keyHandler = reactor_key
  763. tickRefresh = 10
  764. repeat
  765.     ClearWarning()
  766.     if refresh and tickRefresh == 0 then
  767.         Clear()
  768.         page()
  769.         menu_common()
  770.         refresh = false
  771.         tickRefresh = 10
  772.     else
  773.         tickRefresh = tickRefresh - 1
  774.     end
  775.     eventName, var = os.pullEventRaw()
  776.    
  777.     if side == nil then side = "none" end
  778.     if eventName == "key" then
  779.         keycode = var
  780.         if keycode == 45 then -- x for eXit
  781.             os.pullEventRaw()
  782.             abort = true
  783.         elseif keycode == 11 or keycode == 82 then -- 0
  784.             page = connections_page
  785.             keyHandler = nil
  786.             refresh = true
  787.         elseif keycode == 2 or keycode == 79 then -- 1
  788.             page = reactor_page
  789.             keyHandler = reactor_key
  790.             refresh = true
  791.         elseif keyHandler ~= nil and keyHandler(keycode) then
  792.             refresh = true
  793.             os.sleep(0.2)
  794.         else
  795.             ShowWarning("Key " .. keycode .. " is invalid")
  796.             os.sleep(0.2)
  797.         end
  798.     elseif eventName == "reactorPulse" then
  799.         reactor_pulse(var)     
  800.         refresh = (page == reactor_page)
  801.     elseif eventName == "terminate" then
  802.         abort = true
  803.     elseif not common_event(eventName, var) then
  804.         ShowWarning("Event '" .. eventName .. "', " .. side .. " is unsupported")
  805.         refresh = true
  806.         os.sleep(0.2)
  807.     end
  808. until abort
  809.  
  810. -- clear screens on exit
  811. SetMonitorColorFrontBack(colors.white, colors.black)
  812. term.clear()
  813. SetCursorPos(1, 1)
  814. Write("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement