Advertisement
vacanickel

Untitled

Jan 15th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. --BR control by Graypup
  2. --Legalese below
  3. --[[
  4. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  5. Version 2, December 2004
  6.  
  7. Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
  8.  
  9. Everyone is permitted to copy and distribute verbatim or modified
  10. copies of this license document, and changing it is allowed as long
  11. as the name is changed.
  12.  
  13. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  14. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  15.  
  16. 0. You just DO WHAT THE FUCK YOU WANT TO.
  17.  
  18. ]]
  19. local term = require("term")
  20. local component = require("component")
  21. local unicode = require("unicode")
  22. local event = require("event")
  23.  
  24. local br = component.br_reactor
  25. local gpu = component.gpu
  26.  
  27. --Constants:
  28. local cpromsg = "Currently producing: "
  29. local fueltempmsg = "Current fuel temperature: "
  30. local casetempmsg = "Current casing temperature: "
  31. local estoragemsg = "Energy Stored: "
  32.  
  33. local ff = true
  34. local lastOot
  35. local lastActive
  36. local resX, resY = gpu.getResolution()
  37.  
  38. local function round(num, idp)
  39. local mult = 10^(idp or 0)
  40. return math.floor(num * mult + 0.5) / mult
  41. end
  42. local function dotZero(num)
  43. if num % 1 == 0 then
  44. return num .. ".0"
  45. else
  46. return num
  47. end
  48. end
  49. local function printCentered(thing)
  50. local _,y = term.getCursor()
  51. local w = gpu.getResolution()
  52. term.setCursor((w-thing:len())/2, y)
  53. end
  54. local function printEnergyStorageBar()
  55. local outOfTen = round(br.getEnergyStored() / 10000000 * 10)
  56. local x,y = estoragemsg:len()+1, 5
  57. if outOfTen ~= lastOot then
  58. local b, bp = gpu.getBackground()
  59. gpu.setBackground(0x00FF00)
  60. gpu.fill(x, y, outOfTen, 1, " ")
  61. if 10-outOfTen > 0 then
  62. gpu.setBackground(0xFF0000)
  63. gpu.fill(x+outOfTen, y, 10-outOfTen, 1, " ")
  64. end
  65. gpu.setBackground(b,bp)
  66. end
  67. end
  68. local function printActive()
  69. isActive = br.getActive()
  70. if isActive ~= lastActive then
  71. local f, fb = gpu.getForeground()
  72. if isActive then
  73. gpu.fill(1, 1, resX, 1, " ")
  74. gpu.setForeground(0x00FF00)
  75. gpu.set(1, 1, "Online")
  76. else
  77. gpu.fill(1, 1, resX, 1, " ")
  78. gpu.setForeground(0xFF0000)
  79. gpu.set(1, 1, "Offline")
  80. end
  81. gpu.setForeground(f,fb)
  82. end
  83. lastActive = isActive
  84. end
  85. local function redraw()
  86. printActive()
  87. gpu.set(cpromsg:len()+1, 2, dotZero(tonumber(string.format("%.1f", br.getEnergyProducedLastTick()/1000))) .. " KiRF/t ")
  88. gpu.set(fueltempmsg:len()+1, 3, dotZero(tonumber(string.format("%.1f", br.getFuelTemperature()))) .. unicode.char(0x00b0) .. "C ")
  89. gpu.set(casetempmsg:len()+1, 4, dotZero(tonumber(string.format("%.1f", br.getCasingTemperature()))) .. unicode.char(0x00b0) .. "C ")
  90. printEnergyStorageBar()
  91. end
  92. local function reactorControl()
  93. br.setAllControlRodLevels(br.getEnergyStored() / 10000000 * 100)
  94. end
  95. term.clear()
  96. gpu.set(1, 2, cpromsg)
  97. gpu.set(1, 3, fueltempmsg)
  98. gpu.set(1, 4, casetempmsg)
  99. gpu.set(1, 5, estoragemsg)
  100. --Get the painting and control running
  101. event.timer(0.4, reactorControl, math.huge)
  102. event.timer(0.8, redraw, math.huge)
  103. while true do
  104. local _, _, char = event.pull("key_down")
  105. if unicode.char(char) == " " then
  106. stateToSet = not br.getActive()
  107. br.setActive(stateToSet)
  108. printActive()
  109. end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement