NeoGriever

Untitled

Jul 18th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. -- Original by Merung (October, 2018)
  2.  
  3. local component = require("component")
  4. local term = require("term")
  5. local gpu = component.gpu
  6.  
  7. -- Setup components
  8.  
  9. if not component.isAvailable("draconic_rf_storage") then
  10. print("Draconic Energy Core not connected. Please connect computer to Energy Core with an Adapter")
  11. os.exit()
  12. end
  13.  
  14. storage = component.draconic_rf_storage
  15.  
  16. if not component.isAvailable("screen") then
  17. print("How do you expect to view this?")
  18. os.exit()
  19. end
  20.  
  21. -- Set Resolution
  22. res_x = 120
  23. res_y = 25
  24. gpu.setResolution(res_x, res_y)
  25.  
  26. -- Set Max Value and increment for bottom bars
  27. io_max_rate = 600000
  28. io_increment = io_max_rate / 100
  29.  
  30. -- Functions
  31.  
  32. function exit_msg(msg)
  33. term.clear()
  34. print(msg)
  35. os.exit()
  36. end
  37.  
  38. function get_tier_level(maxrf)
  39. local tier_level = 0
  40. if maxrf == 45500000 then
  41. tier_level = 1
  42. elseif maxrf == 273000000 then
  43. tier_level = 2
  44. elseif maxrf == 1640000000 then
  45. tier_level = 3
  46. elseif maxrf == 9880000000 then
  47. tier_level = 4
  48. elseif maxrf == 59300000000 then
  49. tier_level = 5
  50. elseif maxrf == 356000000000 then
  51. tier_level = 6
  52. elseif maxrf == 2140000000000 then
  53. tier_level = 7
  54. else
  55. tier_level = 8
  56. end
  57. return tier_level
  58. end
  59.  
  60. function convert_value(rf)
  61. if rf == 0 then return "0 RF" end
  62. local i, units = 1, { "RF", "K RF", "M RF", "G RF", "T RF", "P RF", "E RF", "Y RF" }
  63. while rf >= 1000 do
  64. rf = rf / 1000
  65. i = i + 1
  66. end
  67. local unit = units[ i ] or "?"
  68. local fstr
  69. if unit == "RF" then
  70. fstr = "%.0f %s"
  71. else
  72. fstr = "%.2f %s"
  73. end
  74. return string.format( fstr, rf, unit )
  75. end
  76.  
  77. function get_percent_color(energy)
  78. local energycolor
  79. if energy <= 5 then
  80. energycolor = RED
  81. elseif energy <= 25 then
  82. energycolor = ORANGE
  83. elseif energy <= 50 then
  84. energycolor = YELLOW
  85. elseif energy <= 75 then
  86. energycolor = GREEN
  87. elseif energy <= 99 then
  88. energycolor = BLUE
  89. else
  90. energycolor = BLACK
  91. end
  92. return energycolor
  93. end
  94.  
  95. function draw_legend(io)
  96. gpu.setForeground(fg_default)
  97.  
  98. for loc = 0, 100, 10
  99. do
  100. term.setCursor(offset + loc, visual_y_start + 11)
  101. term.write(loc)
  102. term.setCursor(offset + loc, visual_y_start + 12)
  103. term.write("|")
  104. end
  105.  
  106. draw_direction(io)
  107.  
  108. end
  109.  
  110. function draw_direction(io)
  111.  
  112. local is_neg
  113. local pos_num
  114.  
  115. if io == 0
  116. then
  117. return
  118. elseif io > 0
  119. then
  120. is_neg = 0
  121. pos_num = io
  122. elseif io < 0
  123. then
  124. is_neg = 1
  125. pos_num = io * -1
  126. end
  127.  
  128. -- Determine how many "="
  129. local num_col = pos_num / io_increment
  130. if num_col > 100 then num_col = 100 end
  131. if num_col < 1 then num_col = 1 end
  132.  
  133. -- Create the bars
  134.  
  135. local base_bar = ""
  136. local base_bar1 = ""
  137. local base_bar2 = ""
  138. local base_bar3 = ""
  139. local num_spaces = 100 - num_col
  140. local space_offset = num_spaces / 2
  141.  
  142.  
  143. for int_space = 0, space_offset, 1
  144. do
  145. base_bar = base_bar .. " "
  146. end
  147.  
  148. if is_neg == 1
  149. then
  150. base_bar1 = base_bar .. "/"
  151. base_bar2 = base_bar .. "<="
  152. base_bar3 = base_bar .. "\\"
  153. else
  154. base_bar1 = base_bar
  155. base_bar2 = base_bar
  156. base_bar3 = base_bar
  157. end
  158.  
  159. for int_eq = 0, num_col, 1
  160. do
  161. base_bar1 = base_bar1 .. "="
  162. base_bar2 = base_bar2 .. "="
  163. base_bar3 = base_bar3 .. "="
  164. end
  165.  
  166. if is_neg == 0
  167. then
  168. base_bar1 = base_bar1 .. "\\"
  169. base_bar2 = base_bar2 .. "=>"
  170. base_bar3 = base_bar3 .. "/"
  171. end
  172.  
  173. -- Draw the actual bars
  174. if is_neg == 1
  175. then
  176. gpu.setForeground(RED)
  177. term.setCursor(offset, visual_y_start + 15)
  178. term.write(base_bar1)
  179. term.setCursor(offset - 1, visual_y_start + 16)
  180. term.write(base_bar2)
  181. term.setCursor(offset, visual_y_start + 17)
  182. term.write(base_bar3)
  183. gpu.setForeground(fg_default)
  184. else
  185. gpu.setForeground(GREEN)
  186. term.setCursor(offset, visual_y_start + 15)
  187. term.write(base_bar1)
  188. term.setCursor(offset, visual_y_start + 16)
  189. term.write(base_bar2)
  190. term.setCursor(offset, visual_y_start + 17)
  191. term.write(base_bar3)
  192. gpu.setForeground(fg_default)
  193. end
  194.  
  195. end
  196.  
  197. function draw_visuals(percent)
  198.  
  199. term.setCursor(offset, visual_y_start + 13)
  200. for check = 0, 100, 1
  201. do
  202. if check <= percent
  203. then
  204. gpu.setForeground(get_percent_color(check))
  205. term.write("|")
  206. gpu.setForeground(fg_default)
  207. else
  208. gpu.setForeground(fg_default)
  209. term.write(".")
  210. end
  211. end
  212. end
  213.  
  214. -- Define Colors
  215.  
  216. RED = 0xFF0000
  217. BLUE = 0x0000FF
  218. GREEN = 0x00FF00
  219. BLACK = 0x000000
  220. WHITE = 0xFFFFFF
  221. PURPLE = 0x800080
  222. YELLOW = 0xFFFF00
  223. ORANGE = 0xFFA500
  224. DARKRED = 0x880000
  225.  
  226. -- Main Code
  227.  
  228. loopdelay = 1
  229.  
  230. event_loop = true
  231. while event_loop do
  232.  
  233. if not component.isAvailable( "draconic_rf_storage" ) then
  234. exit_msg("Energy Core disconnected. Exiting.")
  235. end
  236.  
  237. local storedenergyinit = storage.getEnergyStored()
  238. local maxenergyinit = storage.getMaxEnergyStored()
  239. local iorate = storage.getTransferPerTick()
  240. local tier = get_tier_level(maxenergyinit)
  241.  
  242. local percentenergy = storedenergyinit / maxenergyinit * 100
  243.  
  244. local convstored = convert_value( storedenergyinit )
  245. local convmax = convert_value( maxenergyinit )
  246.  
  247. offset = 10
  248. visual_y_start = 5
  249. fg_default = WHITE
  250. fg_color_max = PURPLE
  251. local fg_color_stored = get_percent_color(percentenergy)
  252. local fg_color_percent = fg_color_stored
  253.  
  254. local fg_color_io
  255.  
  256. if iorate <= 0 then
  257. fg_color_io = RED
  258. else
  259. fg_color_io = GREEN
  260. end
  261.  
  262. if percentenergy <= 99 then
  263. gpu.setBackground(BLACK)
  264. else
  265. gpu.setBackground(DARKRED)
  266. end
  267.  
  268. term.clear()
  269. gpu.setForeground(fg_color_max)
  270. term.setCursor(48, visual_y_start)
  271. term.write("Energy Storage Tier: " .. tier)
  272. gpu.setForeground(fg_default)
  273. term.setCursor(30, visual_y_start + 1)
  274. term.write("Current Stored Energy / Max Energy: ")
  275. gpu.setForeground(fg_color_stored)
  276. term.write(convstored)
  277. gpu.setForeground(fg_default)
  278. term.write (" / ")
  279. gpu.setForeground(fg_color_max)
  280. term.write(convmax)
  281. gpu.setForeground(fg_default)
  282. term.setCursor(44,visual_y_start + 2)
  283. term.write("Percent Full: ")
  284. gpu.setForeground(fg_color_percent)
  285. term.write(string.format("%.12f %s", percentenergy, " %"))
  286. gpu.setForeground(fg_default)
  287. term.setCursor(48,visual_y_start + 3)
  288. term.write("RF/Tick Change: ")
  289. gpu.setForeground(fg_color_io)
  290. term.write(iorate)
  291.  
  292. draw_visuals(percentenergy)
  293. draw_legend(iorate)
  294.  
  295. os.sleep(loopdelay)
  296.  
  297. end
Add Comment
Please, Sign In to add comment