BrineUtil

Untitled

Feb 5th, 2021 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. local moduleName = ...
  2. local moduleSettings
  3. if hudSettings[moduleName] then
  4. moduleSettings = hudSettings[moduleName]
  5. else
  6. local settingsFile = fs.open("/Hud/hudSettings","a")
  7. settingsFile.write(moduleName..[[
  8. = {
  9. coreComputerID = 0,
  10. coreComputerProtocol = "energyCore",
  11. rfSuffixes = {"K","M","G","T","P","E","Z","Y"},
  12. ioAdjustmentCycles = 200,
  13. ioAdjustmentRate = 0.0001,
  14. alpha = 1,
  15. barColor = 0xff0000,
  16. textColor = 0xffff00,
  17. y = 1,
  18. x = 1,
  19. height = 9,
  20. width = 350,
  21. }
  22.  
  23. ]])
  24. settingsFile.close()
  25. os.loadAPI("/Hud/hudSettings")
  26. moduleSettings = hudSettings[moduleName]
  27. end
  28.  
  29. function formatRF(rf,forceSign)
  30. local sign
  31. if rf < 0 then
  32. sign = "-"
  33. rf = 0-rf
  34. elseif rf > 0 then
  35. sign = forceSign and "+" or ""
  36. else
  37. return "0RF"
  38. end
  39.  
  40. local log = math.floor(math.log(rf)/math.log(1000))
  41. return sign..string.format("%0.3f",rf/1000^log)..(log > 0 and moduleSettings.rfSuffixes[log] or "").."RF"
  42. end
  43.  
  44. function formatTime(time)
  45. if time >= 315360000000 then
  46. return "A:Long:Time"
  47. elseif time < 1 then
  48. return "No:Time"
  49. end
  50. local seconds = string.format("%02d",time%60)
  51. local minutes = string.format("%02d",(time/60)%60)
  52. local hours = string.format("%02d",(time/3600)%24)
  53. local days = string.format("%03d",(time/86400)%365)
  54. local years = string.format("%04d",time/31536000)
  55. return years..":"..days..":"..hours..":"..minutes..":"..seconds
  56. end
  57.  
  58. canvas.addRectangle(
  59. (moduleSettings.x + hudSettings.x-1) * hudSettings.scale,
  60. (moduleSettings.y + hudSettings.y-1) * hudSettings.scale,
  61. (moduleSettings.width + 2) * hudSettings.scale,
  62. (moduleSettings.height + 2) * hudSettings.scale,
  63. hudSettings.backgroundColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
  64. )
  65.  
  66. local bar = {
  67. size = {
  68. moduleSettings.width * hudSettings.scale,
  69. moduleSettings.height * hudSettings.scale
  70. },
  71. object = canvas.addRectangle(
  72. (moduleSettings.x + hudSettings.x) * hudSettings.scale,
  73. (moduleSettings.y + hudSettings.y) * hudSettings.scale,
  74. 0, 0,
  75. moduleSettings.barColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
  76. ),
  77. }
  78.  
  79. local text = {
  80. object = canvas.addText(
  81. {
  82. (1+moduleSettings.x+hudSettings.x) * hudSettings.scale,
  83. (1+moduleSettings.y+hudSettings.y) * hudSettings.scale
  84. },
  85. "",
  86. moduleSettings.textColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
  87. )
  88. }
  89. text.object.setScale(moduleSettings.height * hudSettings.scale / 9)
  90.  
  91. local trueIO, instantIO, cycles = 0, 0, 0
  92.  
  93. while true do
  94. local data
  95. repeat
  96. rednet.send(
  97. moduleSettings.coreComputerID, "",
  98. moduleSettings.coreComputerProtocol
  99. )
  100.  
  101. _, data = rednet.receive(moduleSettings.coreComputerProtocol, 1)
  102. until data
  103.  
  104. instantIO = instantIO*(1-moduleSettings.ioAdjustmentRate) + data.IO*(moduleSettings.ioAdjustmentRate)
  105. if cycles%moduleSettings.ioAdjustmentCycles == 0 then
  106. instantIO = (instantIO - trueIO*(1-moduleSettings.ioAdjustmentRate)^moduleSettings.ioAdjustmentCycles)/
  107. (1-(1-moduleSettings.ioAdjustmentRate)^moduleSettings.ioAdjustmentCycles)
  108. trueIO = instantIO
  109. end
  110.  
  111. local timeRemaining
  112. if trueIO < 0 then
  113. timeRemaining = -(data.RF/trueIO)/20
  114. elseif trueIO > 0 then
  115. timeRemaining = ((data.MaxRF-data.RF)/trueIO)/20
  116. else
  117. timeRemaining = 10^9
  118. end
  119.  
  120. bar.object.setSize(bar.size[1]*data.RF/data.MaxRF, bar.size[2])
  121. text.object.setText(
  122. formatRF(data.RF).."/"..formatRF(data.MaxRF)..
  123. " ("..string.format("%0.2f",data.RF/data.MaxRF*100,true).."%) "..
  124. formatRF(trueIO,true).."/t "..formatTime(timeRemaining))
  125.  
  126. cycles = cycles+1
  127. end
  128.  
Add Comment
Please, Sign In to add comment