miezto

maincore

Nov 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 KB | None | 0 0
  1. local monitor = peripheral.wrap("monitor_138")
  2. local core = peripheral.wrap("draconic_rf_storage_13")
  3. local gateBlock1 = peripheral.wrap("flux_gate_65")
  4. local gateBlock2 = peripheral.wrap("flux_gate_63")
  5. local gateBlock3 = peripheral.wrap("flux_gate_61")
  6. local gateBlock4 = peripheral.wrap("flux_gate_64")
  7. local gateBlock5 = peripheral.wrap("flux_gate_62")
  8. local gateBlock6 = peripheral.wrap("flux_gate_60")
  9. local gateExtra = peripheral.wrap("flux_gate_67")
  10.  
  11. local mon, monX, monY
  12. monX, monY = monitor.getSize()
  13. mon = {}
  14. mon.monitor,mon.X, mon.Y = monitor, monX, monY
  15.  
  16. function clear(mon)
  17.     term.clear()
  18.     term.setCursorPos(1,1)
  19.     mon.monitor.setBackgroundColor(colors.black)
  20.     mon.monitor.clear()
  21.     mon.monitor.setCursorPos(1,1)
  22. end
  23.  
  24. function draw_text(mon, x, y, text, text_color, bg_color)
  25.     mon.monitor.setBackgroundColor(bg_color)
  26.     mon.monitor.setTextColor(text_color)
  27.     mon.monitor.setCursorPos(x,y)
  28.     mon.monitor.write(text)
  29. end
  30.  
  31. function draw_text_right(mon, offset, y, text, text_color, bg_color)
  32.     mon.monitor.setBackgroundColor(bg_color)
  33.     mon.monitor.setTextColor(text_color)
  34.     mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
  35.     mon.monitor.write(text)
  36. end
  37.  
  38. function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color)
  39.     draw_text(mon, x, y, text1, text1_color, bg_color)
  40.     draw_text_right(mon, offset, y, text2, text2_color, bg_color)
  41. end
  42.  
  43. function draw_line(mon, x, y, length, color)
  44.     if length < 0 then
  45.         length = 0
  46.     end
  47.     mon.monitor.setBackgroundColor(color)
  48.     mon.monitor.setCursorPos(x,y)
  49.     mon.monitor.write(string.rep(" ", length))
  50. end
  51.  
  52. function progress_bar(mon, x, y, length, minVal, maxVal, bar_color, bg_color)
  53.     draw_line(mon, x, y, length, bg_color)
  54.     local barSize = math.floor((minVal/maxVal) * length)
  55.     draw_line(mon, x, y, barSize, bar_color)
  56. end
  57.  
  58. function format_int(number)
  59.     if number == nil then number = 0 end
  60.     local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
  61.     int = int:reverse():gsub("(%d%d%d)", "%1,")
  62.     return minus .. int:reverse():gsub("^,", "") .. fraction
  63. end
  64.  
  65. local eMax
  66. local eNow
  67. local ePercent
  68. local eLast = 0
  69. local eFlow
  70.  
  71. function update()
  72.     while true do
  73.         clear(mon)
  74.        
  75.         eMax = core.getMaxEnergyStored()
  76.         eNow = core.getEnergyStored()
  77.         ePercent = (math.floor(eNow/eMax*10000))/100
  78.         eFlow = math.floor((eNow-eLast)/2)
  79.         eLast = eNow
  80.  
  81.     -- terminal display
  82.         print(" Capacity:  " .. eMax .. " rf")
  83.         print("   Energy:  " .. eNow .. " rf ... " .. ePercent .. " %")
  84.         print()
  85.         if (eFlow > 0) then
  86.             print("Avg. flow: +" .. eFlow .. " rf/t")
  87.         else
  88.             print("Avg. flow: " .. eFlow .. " rf/t")
  89.         end
  90.         print()
  91.  
  92.     -- monitor display
  93.         draw_text_lr(mon, 2, 2, 0, "Main Energy Core", "Tier 7", colors.orange, colors.orange, colors.black)
  94.  
  95.         local energyColor
  96.         if ePercent >= 75 then energyColor = colors.orange end
  97.         if ePercent < 75 and ePercent >= 50 then energyColor = colors.red end
  98.         if ePercent < 50 and ePercent >= 25 then energyColor = colors.purple end
  99.         if ePercent < 25 then energyColor = colors.cyan end
  100.  
  101.         if eNow >= 1000000000000 then
  102.             draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000000000))/1000) .. " T rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
  103.         elseif eNow < 1000000000000 and eNow >= 1000000000 then
  104.             draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000000))/1000) .. " B rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
  105.         elseif eNow < 1000000000 and eNow >= 1000000 then
  106.             draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000))/1000) .. " M rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
  107.         else
  108.             draw_text_lr(mon, 2, 4, 0, format_int(eNow) .. " rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
  109.         end    
  110.  
  111.         progress_bar(mon, 2, 5, mon.X-2, ePercent, 100, energyColor, colors.gray)
  112.  
  113.         local energyUpDown
  114.         if eFlow > 0 then energyUpDown = colors.lime end
  115.         if eFlow == 0 then energyUpDown = colors.gray end
  116.         if eFlow < 0 then energyUpDown = colors.red end
  117.  
  118.         if eFlow >= math.abs(1000000000) then
  119.             if eFlow > 0 then
  120.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black)
  121.             else
  122.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black)
  123.             end
  124.         elseif eFlow < math.abs(1000000000) and eFlow >= math.abs(1000000) then
  125.             if eFlow > 0 then
  126.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black)
  127.             else
  128.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black)
  129.             end
  130.         else
  131.             if eFlow > 0 then
  132.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black)
  133.             else
  134.                 draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black)
  135.             end
  136.         end
  137.  
  138.         sleep(0.1)
  139.     end
  140. end
  141.  
  142. parallel.waitForAny(update)
Add Comment
Please, Sign In to add comment