derpierre65

1231432

Jan 2nd, 2016 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. local lastEnergy = 0
  2. local mon = peripheral.wrap("top")
  3. mon.setTextScale(1)
  4. local maxX,maxY = mon.getSize()
  5.  
  6. -- Text Format
  7. function TimeFormat(seconds)
  8.     seconds = math.ceil(seconds)
  9.     local hours = 0
  10.     local minutes = 0
  11.     local strlen = string.len(seconds)
  12.     local bonus = 0
  13.     if ( seconds >= 60 ) then
  14.         minutes = math.floor(seconds/60)
  15.         seconds = seconds - (minutes*60)
  16.     end
  17.     if ( minutes >= 60 ) then
  18.         hours = math.floor(minutes/60)
  19.         minutes = minutes - (hours*60)
  20.     end
  21.    
  22.     if ( hours < 10 ) then
  23.         hours = "0"..hours
  24.     end
  25.     if ( minutes < 10 ) then
  26.         minutes = "0"..minutes
  27.     end
  28.     if ( seconds < 10 ) then
  29.         seconds = "0"..seconds
  30.     end
  31.     return hours..":"..minutes..":"..seconds
  32. end
  33. function EnergyFormat(energy)
  34.     local strlen = string.len(energy)
  35.     local bonus = 0
  36.     if ( energy < 0 ) then
  37.         bonus = 1
  38.     end
  39.     if ( strlen >= 7+bonus ) then
  40.         return string.sub(energy*0.000001,0,6+bonus) .. " mRF"
  41.     end
  42.     if ( strlen >= 4+bonus ) then
  43.         return string.sub(energy*0.001,0,5+bonus) .. " kRF"
  44.     end
  45.     return energy .. " RF"
  46. end
  47.  
  48. -- My Write API
  49. function writeSymbol(txtcolor, bgcolor, line, symbol)
  50.     mon.setTextColor(txtcolor)
  51.     mon.setBackgroundColor(bgcolor)
  52.     for x=1, maxX do
  53.         mon.setCursorPos(x, line)
  54.         mon.write(symbol)
  55.     end
  56. end
  57. function writeText(txtcolor, bgcolor, startx, line, txt)
  58.     mon.setCursorPos(startx, line)
  59.     mon.setTextColor(txtcolor)
  60.     mon.setBackgroundColor(bgcolor)
  61.     mon.write(txt)
  62. end
  63. function writeBackground(color, line, tox, startx)
  64.     if ( tox == nil ) then
  65.         tox = maxX
  66.     end
  67.     if ( startx == nil ) then
  68.         startx = 1
  69.     end
  70.     mon.setCursorPos(1, line)
  71.     for x = startx, tox do
  72.         mon.setCursorPos(x,line)
  73.         mon.setBackgroundColor(color)
  74.         mon.write(" ")
  75.     end
  76.     mon.setBackgroundColor(colors.black)
  77. end
  78.  
  79. function MonitorScreen(e,m,rfs)
  80.     mon.setTextScale(1)
  81.     mon.clear()
  82.     maxX,maxY = mon.getSize()
  83.    
  84.     writeSymbol(colors.white, colors.black, 1, "-")
  85.     writeSymbol(colors.white, colors.black, 5, "-")
  86.     writeText(colors.white, colors.black, 1, 2, "Energie:      " .. EnergyFormat(e))
  87.     writeText(colors.white, colors.black, 1, 3, "Max. Energie: " .. EnergyFormat(m))
  88.     writeText(colors.white, colors.black, 1, 4, "Input:")
  89.     color = colors.white
  90.     if ( rfs > 0 ) then
  91.         color = colors.green
  92.     end
  93.     if ( rfs < 0 ) then
  94.         color = colors.red
  95.     end
  96.     writeText(color, colors.black, 15,4, EnergyFormat(rfs).."/s")
  97.    
  98.     text = ""
  99.     if ( RFs < 0 ) then
  100.         color = colors.red
  101.         text = "Leer in " .. TimeFormat(e/rfs*-1)
  102.     end
  103.     if ( RFs > 0 ) then
  104.         color = colors.green
  105.         text = "Voll in " .. TimeFormat((m-e)/rfs)
  106.     end
  107.     writeText(color, colors.black, 1, 6, text)
  108.    
  109.     local fulled = e/m*100
  110.     writeText(colors.white, colors.black, 2, 8, "Energie")
  111.     writeText(colors.white, colors.black, maxX-4, 8, math.floor(fulled).."%")
  112.    
  113.     if ( fulled < 40 ) then
  114.         color = colors.red
  115.     elseif ( fulled < 80 ) then
  116.         color = colors.yellow
  117.     else
  118.         color = colors.green
  119.     end
  120.    
  121.     for x = 10, 11 do
  122.         writeBackground(colors.gray, x, maxX-1, 2)
  123.         writeBackground(color, x, (maxX-1)*(fulled/100), 2)
  124.     end
  125.    
  126. end
  127.  
  128. while true do
  129.     local storage = 0
  130.     local maxStorage = 0
  131.     local periList = peripheral.getNames()
  132.     for i = 2, #periList do
  133.         if ( peripheral.getType(periList[i]) == "tile_thermalexpansion_cell_reinforced_name" ) then
  134.             cell = peripheral.wrap(periList[i])
  135.             storage = storage + cell.getEnergyStored()
  136.             maxStorage = maxStorage + cell.getMaxEnergyStored()
  137.         end
  138.     end
  139.     RFs = storage-lastEnergy
  140.     lastEnergy = storage
  141.     MonitorScreen(storage, maxStorage, RFs)
  142.     sleep(1)
  143. end
Advertisement
Add Comment
Please, Sign In to add comment