BrineUtil

Untitled

Jan 30th, 2021 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. local canvas = peripheral.call("back","canvas")
  2. rednet.open("top")
  3.  
  4. canvas.clear()
  5.  
  6. local suffixes = {[0]="RF", "KRF", "MRF", "GRF", "TRF", "PRF", "ERF", "ZRF", "YRF"}
  7. local activityIndicator = {[[|]],[[/]],[[-]],[[\]]}
  8. local pos = {1,1}
  9. local scale = 1
  10. local adjustmentRate = 0.0001
  11. local adjustmentCycles = 200
  12.  
  13. _G.data = {}
  14. local cycles = -1
  15.  
  16. function getData()
  17. rednet.send(124, "", "MECoreStat")
  18. local _, MECoreStatP = rednet.receive("MECoreStat",1)
  19. if MECoreStatP then data.MECoreStat = MECoreStatP end
  20. rednet.send(123, "", "DRCoreStat")
  21. local _, DRCoreStatP = rednet.receive("DRCoreStat",1)
  22. if DRCoreStatP then data.DRCoreStat = DRCoreStatP end
  23. rednet.send(122, "", "ReactorStat")
  24. local _, ReactorStatP = rednet.receive("ReactorStat",1)
  25. if ReactorStatP then data.reactor = ReactorStatP end
  26. end
  27.  
  28. function format(I,M,S)
  29. I = tonumber(I)
  30. if M == "RF" then
  31. local sign
  32. if I < 0 then
  33. sign = "-"
  34. I = 0-I
  35. elseif I > 0 then
  36. sign = S and "+" or ""
  37. else
  38. return "0RF"
  39. end
  40. local log = math.max(math.floor(math.log(I)/math.log(1000)),0)
  41. return sign..string.format("%0.3f",I/1000^log)..suffixes[log]
  42. elseif M == "time" then
  43. if I >= 315360000000 then
  44. return "A:Long:Time"
  45. elseif I < 1 then
  46. return "No:Time"
  47. end
  48. local S = string.format("%02d",I%60)
  49. local M = string.format("%02d",(I/60)%60)
  50. local H = string.format("%02d",(I/3600)%24)
  51. local D = string.format("%03d",(I/86400)%365)
  52. local Y = string.format("%04d",I/31536000)
  53. return Y..":"..D..":"..H..":"..M..":"..S
  54. end
  55. end
  56.  
  57. local rectangles
  58. rectangles = {
  59. {
  60. scalar = {1,1},
  61. pos = {0,0},
  62. size = {352, 41},
  63. color = 0x999999bb
  64. },
  65.  
  66. RF1 = {
  67. scalar = function()
  68. return {data.DRCoreStat.RF/data.DRCoreStat.MaxRF, 1}
  69. end,
  70. pos = {1,1},
  71. size = {350, 9},
  72. color = 0xff0000bb,
  73. },
  74.  
  75. RF2 = {
  76. scalar = function()
  77. return {data.MECoreStat.RF/data.MECoreStat.MaxRF, 1}
  78. end,
  79. pos = {1,11},
  80. size = {350, 9},
  81. color = 0xff0000bb,
  82. },
  83.  
  84. ReactorTemp = {
  85. scalar = function()
  86. return {data.reactor.temp/8000, 1}
  87. end,
  88. pos = {1,21},
  89. size = {350,9},
  90. color = 0xff8800bb
  91. },
  92.  
  93. ReactorShield = {
  94. scalar = function()
  95. return {data.reactor.shield/data.reactor.maxShield, 1}
  96. end,
  97. pos = {1,31},
  98. size = {350,9},
  99. color = 0x00ffffbb
  100. },
  101. --[[
  102. ReactorFuel2 = {
  103. scalar = {1,1},
  104. pos = {1,41},
  105. size = {350,9},
  106. color = 0xffaa00bb
  107. },
  108.  
  109. ReactorFuel1 = {
  110. scalar = function()
  111. return {data.reactor.fuel/data.reactor.maxFuel, 1}
  112. end,
  113. pos = {1,41},
  114. size = {350,9},
  115. color = 0x000000bb
  116. },]]
  117. }
  118.  
  119. local texts
  120. texts = {
  121. RF1 = {
  122. scale = 1,
  123. pos = {2,2},
  124. IO = 0,
  125. IOM = 0,
  126. text = function()
  127. texts.RF1.IO = texts.RF1.IO*(1-adjustmentRate) + data.DRCoreStat.IO*adjustmentRate
  128. if cycles%adjustmentCycles == 0 then
  129. texts.RF1.IO = (texts.RF1.IO-texts.RF1.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
  130. texts.RF1.IOM = texts.RF1.IO
  131. end
  132. local timeRemaining
  133. if texts.RF1.IO < 0 then
  134. timeRemaining = -(data.DRCoreStat.RF/texts.RF1.IOM)/20
  135. elseif texts.RF1.IO > 0 then
  136. timeRemaining = ((data.DRCoreStat.MaxRF-data.DRCoreStat.RF)/texts.RF1.IOM)/20
  137. else
  138. timeRemaining = ""
  139. end
  140. return format(data.DRCoreStat.RF,"RF").."/"..format(data.DRCoreStat.MaxRF,"RF")..
  141. " ("..string.format("%0.2f",100*data.DRCoreStat.RF/data.DRCoreStat.MaxRF).."%) "..
  142. format(texts.RF1.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
  143. " "..activityIndicator[cycles%#activityIndicator+1]
  144. end,
  145. color = 0xffff00ff
  146. },
  147.  
  148. RF2 = {
  149. scale = 1,
  150. pos = {2,12},
  151. IO = 0,
  152. IOM = 0,
  153. text = function()
  154. texts.RF2.IO = texts.RF2.IO*(1-adjustmentRate) + data.MECoreStat.IO*adjustmentRate
  155. if cycles%adjustmentCycles == 0 then
  156. texts.RF2.IO = (texts.RF2.IO-texts.RF2.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
  157. texts.RF2.IOM = texts.RF2.IO
  158. end
  159. local timeRemaining
  160. if texts.RF2.IO < 0 then
  161. timeRemaining = -(data.MECoreStat.RF/texts.RF2.IOM)/20
  162. elseif texts.RF2.IO > 0 then
  163. timeRemaining = ((data.MECoreStat.MaxRF-data.MECoreStat.RF)/texts.RF2.IOM)/20
  164. else
  165. timeRemaining = ""
  166. end
  167. return format(data.MECoreStat.RF,"RF").."/"..format(data.MECoreStat.MaxRF,"RF")..
  168. " ("..string.format("%0.2f",100*data.MECoreStat.RF/data.MECoreStat.MaxRF).."%) "..
  169. format(texts.RF2.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
  170. " "..activityIndicator[cycles%#activityIndicator+1]
  171. end,
  172. color = 0xffff00ff
  173. },
  174.  
  175. ReactorTemp = {
  176. scale = 1,
  177. pos = {2,22},
  178. text = function()
  179. return "Temp: "..data.reactor.temp.."C"
  180. end,
  181. color = 0xffffffff
  182. },
  183.  
  184. ReactorShield = {
  185. scale = 1,
  186. pos = {2,32},
  187. text = function()
  188. return "Field: "..string.format("%0.2f",100*data.reactor.shield/data.reactor.maxShield).."%"
  189. end,
  190. color = 0xffffffff
  191. },
  192. --[[
  193. ReactorFuel = {
  194. scale = 1,
  195. pos = {2,42},
  196. text = function()
  197. return "Chaos: "..string.format("%0.2f",100*data.reactor.fuel/data.reactor.maxFuel).."%"
  198. end,
  199. color = 0xffffffff
  200. }]]
  201. }
  202.  
  203. for i, v in pairs(rectangles) do
  204. v.object = canvas.addRectangle(0,0,0,0,0)
  205. end
  206.  
  207. for i, v in pairs(texts) do
  208. v.object = canvas.addText({0,0},"",0)
  209. end
  210.  
  211. while true do
  212. cycles = cycles+1
  213. getData()
  214. for i, v in pairs(rectangles) do
  215. local scalar, color
  216. if type(v.scalar) == "function" then
  217. scalar = v.scalar()
  218. else
  219. scalar = v.scalar
  220. end
  221.  
  222.  
  223. if type(v.color) == "function" then
  224. color = v.color()
  225. else
  226. color = v.color
  227. end
  228.  
  229. v.object.setSize(v.size[1]*scalar[1]*scale, v.size[2]*scalar[2]*scale)
  230. v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  231. v.object.setColor(color)
  232.  
  233. end
  234. for i, v in pairs(texts) do
  235. local text
  236. if type(v.text) == "function" then
  237. text = v.text()
  238. else
  239. text = v.text
  240. end
  241.  
  242. if type(v.color) == "function" then
  243. color = v.color()
  244. else
  245. color = v.color
  246. end
  247.  
  248. v.object.setScale(scale*v.scale)
  249. v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  250. v.object.setColor(color)
  251. v.object.setText(text)
  252. end
  253. end
Advertisement
Add Comment
Please, Sign In to add comment