Advertisement
Guest User

Untitled

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