bobmarley12345

nuclearstationfusioninfomonitor

Oct 22nd, 2020 (edited)
812
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MonitorSide = "monitor_56"
  2. Monitor = peripheral.wrap(MonitorSide)
  3.  
  4. function ClearMonitor()
  5.     Monitor.setTextColor(colours.black)
  6.     Monitor.setBackgroundColor(colours.black)
  7.     Monitor.clear()
  8.     Monitor.setCursorPos(1,1)
  9. end
  10.  
  11. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  12.     Monitor.setBackgroundColor(backgroundColour)
  13.     Monitor.setTextColor(textColour)
  14.     Monitor.setCursorPos(xPos,yPos)
  15.     Monitor.write(text)
  16. end
  17.  
  18. function DrawCenteredHorizontal(xPos, yPos, width, text, textColour, backgroundColour)
  19.     -- width could be the size of your monitor, or anything else. this means it
  20.     -- doesn't have to stretch your entire monitor's if you want. imagine
  21.     -- it as a rectangle and the text is in the center.
  22.     local textLength = string.len(text)
  23.     local centerX = (width / 2) - (textLength / 2)
  24.     DrawText(xPos + centerX, yPos, text, textColour, backgroundColour)
  25. end
  26.  
  27. function DrawLineH(xPos, yPos, lineLength, colour)
  28.     Monitor.setBackgroundColor(colour)
  29.     Monitor.setTextColor(colour)
  30.     Monitor.setCursorPos(xPos,yPos)
  31.     Monitor.write(string.rep(" ", lineLength))
  32. end
  33.  
  34. function DrawLineV(xPos, yPos, width, lineHeight, colour)
  35.     Monitor.setBackgroundColor(colour)
  36.     for i = 1, lineHeight, 1 do
  37.         Monitor.setCursorPos(xPos, yPos + (i - 1))
  38.         Monitor.write(string.rep(" ", width))
  39.     end
  40. end
  41.  
  42. function DrawSquare(xPos, yPos, nWidth, nHeight, backgroundColour)
  43.     Monitor.setBackgroundColor(backgroundColour)
  44.     for i = 1, math.ceil(nHeight), 1 do
  45.         Monitor.setCursorPos(xPos, yPos + (i - 1))
  46.         Monitor.write(string.rep(" ", nWidth))
  47.     end
  48. end
  49.  
  50. function ProgressBar(xPos, yPos, width, value, maxValue, backgroundColour, progressColour)
  51.     DrawLineH(xPos, yPos, width, backgroundColour) --backgoround bar
  52.     local barSize = math.floor((value/maxValue) * width)
  53.     DrawLineH(xPos, yPos, barSize, progressColour) --progress so far
  54. end
  55.  
  56. function GroupBoxHeader(xPos, yPos, width, header, textColour, backgroundColour)
  57.     local headerLength = string.len(header)
  58.     local repeatChars = width - 4 - headerLength - 1
  59.  
  60.     if (repeatChars < 0) then
  61.         repeatChars = 0
  62.     end
  63.  
  64.     local head = "--- " .. header .. " " .. string.rep("-", repeatChars)
  65.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  66. end
  67.  
  68. function GroupBoxFooter(xPos, yPos, width, textColour, backgroundColour)
  69.     if (width < 0) then
  70.         width = 0
  71.     end
  72.     local head = string.rep("-", width)
  73.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  74. end
  75.  
  76. function GroupBox(xPos, yPos, width, height, header, textColour, headerBackgroundColour)
  77.     GroupBoxHeader(xPos, yPos, width, header, textColour, headerBackgroundColour)
  78.     GroupBoxFooter(xPos, yPos + height + 1, width, textColour, headerBackgroundColour)
  79. end
  80.  
  81. FusionControlsInputSide = "bottom"
  82. Fusion1Colour = colours.white
  83. Fusion2Colour = colours.orange
  84. Fusion3Colour = colours.magenta
  85. Fusion4Colour = colours.lightBlue
  86. FuelGeneratorInputColour = colours.yellow
  87.  
  88. FusionControlsOutputSide = "right"
  89. ActiveFusionColours = 0
  90.  
  91. FuelGenerationOutputSide = "back"
  92. FuelGeneratorOutputColour = colours.white
  93.  
  94. function CheckFCINColourActive(colour)
  95.     return colours.test(redstone.getBundledInput(FusionControlsInputSide), colour)
  96. end
  97.  
  98. function IsFusion1On()
  99.     return CheckFCINColourActive(Fusion1Colour)
  100. end
  101.  
  102. function IsFusion2On()
  103.     return CheckFCINColourActive(Fusion2Colour)
  104. end
  105.  
  106. function IsFusion3On()
  107.     return CheckFCINColourActive(Fusion3Colour)
  108. end
  109.  
  110. function IsFusion4On()
  111.     return CheckFCINColourActive(Fusion4Colour)
  112. end
  113.  
  114. function StatusToColour(isActive)
  115.     if (isActive) then
  116.         return colours.green
  117.     else
  118.         return colours.red
  119.     end
  120. end
  121.  
  122. function UpdateFusion1()
  123.     if (IsFusion1On()) then
  124.         if (colours.test(ActiveFusionColours, Fusion1Colour) == false) then
  125.             ActiveFusionColours = ActiveFusionColours + Fusion1Colour
  126.         end
  127.     else
  128.         if (colours.test(ActiveFusionColours, Fusion1Colour)) then
  129.             ActiveFusionColours = ActiveFusionColours - Fusion1Colour
  130.         end
  131.     end
  132. end
  133.  
  134. function UpdateFusion2()
  135.     if (IsFusion2On()) then
  136.         if (colours.test(ActiveFusionColours, Fusion2Colour) == false) then
  137.             ActiveFusionColours = ActiveFusionColours + Fusion2Colour
  138.         end
  139.     else
  140.         if (colours.test(ActiveFusionColours, Fusion2Colour)) then
  141.             ActiveFusionColours = ActiveFusionColours - Fusion2Colour
  142.         end
  143.     end
  144. end
  145.  
  146. function UpdateFusion3()
  147.     if (IsFusion3On()) then
  148.         if (colours.test(ActiveFusionColours, Fusion3Colour) == false) then
  149.             ActiveFusionColours = ActiveFusionColours + Fusion3Colour
  150.         end
  151.     else
  152.         if (colours.test(ActiveFusionColours, Fusion3Colour)) then
  153.             ActiveFusionColours = ActiveFusionColours - Fusion3Colour
  154.         end
  155.     end
  156. end
  157.  
  158. function UpdateFusion4()
  159.     if (IsFusion4On()) then
  160.         if (colours.test(ActiveFusionColours, Fusion4Colour) == false) then
  161.             ActiveFusionColours = ActiveFusionColours + Fusion4Colour
  162.         end
  163.     else
  164.         if (colours.test(ActiveFusionColours, Fusion4Colour)) then
  165.             ActiveFusionColours = ActiveFusionColours - Fusion4Colour
  166.         end
  167.     end
  168. end
  169.  
  170. function ActivateReactors()
  171.     redstone.setBundledOutput(FusionControlsOutputSide, ActiveFusionColours)
  172. end
  173.  
  174. function DrawFusionReactor()
  175.     local yPos = 2
  176.     local xPos = 2
  177.     local frW = 20
  178.     local frH = 17
  179.     local frbW = 4
  180.     local frbH = 3
  181.     local blcW = 2
  182.     local blcH = 1
  183.  
  184.     DrawLineH(xPos + blcW      , yPos, frW, colours.orange)
  185.     DrawLineH(xPos + blcW      , frH , frW, colours.orange)
  186.     DrawLineV(xPos             , yPos + blcH, blcW, frH - blcH - yPos, colours.orange)
  187.     DrawLineV(xPos + frW + blcW, yPos + blcH, blcW, frH - blcH - yPos, colours.orange)
  188.     --  1  3
  189.     --  2  4
  190.     DrawSquare(xPos + blcW + frbW,       yPos + frbH      , frbW, frbH, StatusToColour(IsFusion1On()))
  191.     DrawSquare(xPos + blcW + frbW,       yPos + (frbH * 3), frbW, frbH, StatusToColour(IsFusion2On()))
  192.     DrawSquare(xPos + blcW + (frbW * 3), yPos + frbH      , frbW, frbH, StatusToColour(IsFusion3On()))
  193.     DrawSquare(xPos + blcW + (frbW * 3), yPos + (frbH * 3), frbW, frbH, StatusToColour(IsFusion4On()))
  194. end
  195.  
  196. function DrawFusion1(xPos, yPos)
  197.     if (IsFusion1On()) then
  198.         DrawText(xPos, yPos, "ONLINE", colours.white, colours.green)
  199.     else
  200.         DrawText(xPos, yPos, "OFFLINE", colours.white, colours.red)
  201.     end
  202. end
  203.  
  204. function DrawFusion2(xPos, yPos)
  205.     if (IsFusion2On()) then
  206.         DrawText(xPos, yPos, "ONLINE", colours.white, colours.green)
  207.     else
  208.         DrawText(xPos, yPos, "OFFLINE", colours.white, colours.red)
  209.     end
  210. end
  211.  
  212. function DrawFusion3(xPos, yPos)
  213.     if (IsFusion3On()) then
  214.         DrawText(xPos, yPos, "ONLINE", colours.white, colours.green)
  215.     else
  216.         DrawText(xPos, yPos, "OFFLINE", colours.white, colours.red)
  217.     end
  218. end
  219.  
  220. function DrawFusion4(xPos, yPos)
  221.     if (IsFusion4On()) then
  222.         DrawText(xPos, yPos, "ONLINE", colours.white, colours.green)
  223.     else
  224.         DrawText(xPos, yPos, "OFFLINE", colours.white, colours.red)
  225.     end
  226. end
  227.  
  228. function IsFuelGeneratorOn()
  229.     return colours.test(redstone.getBundledInput(FusionControlsInputSide, FuelGeneratorInputColour), FuelGeneratorInputColour)
  230. end
  231.  
  232. function Main()
  233.     local gbWidth = 18
  234.  
  235.     while true do
  236.         -- Draw reactor squares
  237.         local w, h = Monitor.getSize()
  238.  
  239.         UpdateFusion1()
  240.         UpdateFusion2()
  241.         UpdateFusion3()
  242.         UpdateFusion4()
  243.  
  244.         ActivateReactors()
  245.  
  246.         ClearMonitor()
  247.        
  248.         DrawFusionReactor()
  249.         DrawText(28, 2, "Fusion 1 - ", colours.white, colours.black)
  250.         DrawText(28, 4, "Fusion 2 - ", colours.white, colours.black)
  251.         DrawText(28, 6, "Fusion 3 - ", colours.white, colours.black)
  252.         DrawText(28, 8, "Fusion 4 - ", colours.white, colours.black)
  253.  
  254.         DrawFusion1(39, 2)
  255.         DrawFusion2(39, 4)
  256.         DrawFusion3(39, 6)
  257.         DrawFusion4(39, 8)
  258.  
  259.         GroupBox(28, 10, 24, 9, "Fuel Generator", colours.yellow, colours.black)
  260.         if (IsFuelGeneratorOn()) then
  261.             redstone.setBundledOutput(FuelGenerationOutputSide, FuelGeneratorOutputColour)
  262.             DrawSquare(28, 12, 24, 7, colours.green)
  263.             DrawCenteredHorizontal(28, 15, 24, "ONLINE", colours.white, colours.green)
  264.         else
  265.             redstone.setBundledOutput(FuelGenerationOutputSide, 0)
  266.             DrawSquare(28, 12, 24, 7, colours.red)
  267.             DrawCenteredHorizontal(28, 15, 24, "OFFLINE", colours.white, colours.red)
  268.         end
  269.  
  270.         sleep(0.5)
  271.     end
  272. end
  273.  
  274. Main()
RAW Paste Data