BrineUtil

Untitled

Jan 30th, 2021 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 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. "XOOOO", "OXOOO",
  9. "XOOOO", "OOXOO",
  10. "XOOOO", "OOOXO",
  11. "XOOOO", "OXOOO",
  12. "XOOOO", "OOXOO",
  13. "XOOOO", "OOOXO",
  14. "XOOOO", "OOOOX",
  15. "XOOOO", "OOOXO",
  16. "XOOOO", "OOOOX",
  17. "XOOOO", "OOXOO",
  18. "XOOOO", "OOOXO",
  19. "XOOOO", "OXOOO",
  20. "XOOOO", "OOOOX",
  21. "XOOOO", "OOXOO",
  22. "XOOOO", "OOOXO",
  23. "XOOOO", "OOXOO",
  24. "XOOOO", "OXOOO",
  25. "XOOOO", "OOXOO",
  26. }
  27. local pos = {1,1}
  28. local scale = 0.5
  29. local adjustmentRate = 0.0001
  30. local adjustmentCycles = 200
  31.  
  32. local data = {}
  33. local cycles = -1
  34.  
  35. function getData()
  36. rednet.send(112, "", "CoreStat")
  37. local _, CoreStatP = rednet.receive("CoreStat",1)
  38. if CoreStatP then data.CoreStat = CoreStatP end
  39. end
  40.  
  41. function format(I,M,S)
  42. I = I and tonumber(I) or 0
  43. if M == "RF" then
  44. if I == 0 then
  45. return "0RF"
  46. end
  47. local sign = (I < 0 and "-") or (S and "+" or "")
  48. I = sign == "-" and 0-I or I
  49. local log = math.max(math.floor(math.log(I)/math.log(1000)),0)
  50. return sign..string.format("%0.3f",I/1000^log)..suffixes[log]
  51. elseif M == "time" then
  52. if I >= 315360000000 then
  53. return "A:Long:Time"
  54. elseif I < 1 then
  55. return "No:Time"
  56. end
  57. local S = string.format("%02d",I%60)
  58. local M = string.format("%02d",(I/60)%60)
  59. local H = string.format("%02d",(I/3600)%24)
  60. local D = string.format("%03d",(I/86400)%365)
  61. local Y = string.format("%04d",I/31536000)
  62. return Y..":"..D..":"..H..":"..M..":"..S
  63. end
  64. end
  65.  
  66. local rectangles
  67. rectangles = {
  68. BG = {
  69. scalar = {1,1},
  70. pos = {0,0},
  71. size = {352, 11},
  72. color = 0x999999bb
  73. },
  74.  
  75. RF = {
  76. scalar = function()
  77. return {data.CoreStat.RF/data.CoreStat.MaxRF, 1}
  78. end,
  79. pos = {1,1},
  80. size = {350, 9},
  81. color = 0xff0000bb,
  82. }
  83. }
  84.  
  85. local texts
  86. texts = {
  87. RF = {
  88. scale = 1,
  89. pos = {2,2},
  90. IO = 0,
  91. IOM = 0,
  92. text = function()
  93. texts.RF.IO = texts.RF.IO*(1-adjustmentRate) + data.CoreStat.IO*adjustmentRate
  94. if cycles%adjustmentCycles == 0 then
  95. texts.RF.IO = (texts.RF.IO-texts.RF.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
  96. texts.RF.IOM = texts.RF.IO
  97. end
  98. local timeRemaining
  99. if texts.RF.IO < 0 then
  100. timeRemaining = -(data.CoreStat.RF/texts.RF.IOM)/20
  101. elseif texts.RF.IO > 0 then
  102. timeRemaining = ((data.CoreStat.MaxRF-data.CoreStat.RF)/texts.RF.IOM)/20
  103. else
  104. timeRemaining = ""
  105. end
  106. return format(data.CoreStat.RF,"RF").."/"..format(data.CoreStat.MaxRF,"RF")..
  107. " ("..string.format("%0.2f",100*data.CoreStat.RF/data.CoreStat.MaxRF).."%) "..
  108. format(texts.RF.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
  109. " "..activityIndicator[math.floor(cycles/2)%#activityIndicator+1]
  110. end,
  111. color = 0xffff00ff
  112. }
  113. }
  114.  
  115. for i, v in pairs(rectangles) do
  116. v.object = canvas.addRectangle(0,0,0,0,0)
  117. end
  118.  
  119. for i, v in pairs(texts) do
  120. v.object = canvas.addText({0,0},"",0)
  121. end
  122.  
  123. while true do
  124. cycles = cycles+1
  125. getData()
  126. for i, v in pairs(rectangles) do
  127. local color = type(v.color) == "function" and v.color() or v.color
  128. local scalar = type(v.scalar) == "function" and v.scalar() or v.scalar
  129.  
  130. v.object.setSize(v.size[1]*scalar[1]*scale, v.size[2]*scalar[2]*scale)
  131. v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  132. v.object.setColor(color)
  133.  
  134. end
  135. for i, v in pairs(texts) do
  136. local color = type(v.color) == "function" and v.color() or v.color
  137. local text = type(v.text) == "function" and v.text() or v.text
  138.  
  139. v.object.setScale(scale*v.scale)
  140. v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  141. v.object.setColor(color)
  142. v.object.setText(text)
  143. end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment