Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lastEnergy = 0
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- local maxX,maxY = mon.getSize()
- -- Text Format
- function TimeFormat(seconds)
- seconds = math.ceil(seconds)
- local hours = 0
- local minutes = 0
- local strlen = string.len(seconds)
- local bonus = 0
- if ( seconds >= 60 ) then
- minutes = math.floor(seconds/60)
- seconds = seconds - (minutes*60)
- end
- if ( minutes >= 60 ) then
- hours = math.floor(minutes/60)
- minutes = minutes - (hours*60)
- end
- if ( hours < 10 ) then
- hours = "0"..hours
- end
- if ( minutes < 10 ) then
- minutes = "0"..minutes
- end
- if ( seconds < 10 ) then
- seconds = "0"..seconds
- end
- return hours..":"..minutes..":"..seconds
- end
- function EnergyFormat(energy)
- local strlen = string.len(energy)
- local bonus = 0
- if ( energy < 0 ) then
- bonus = 1
- end
- if ( strlen >= 7+bonus ) then
- return string.sub(energy*0.000001,0,6+bonus) .. " mRF"
- end
- if ( strlen >= 4+bonus ) then
- return string.sub(energy*0.001,0,5+bonus) .. " kRF"
- end
- return energy .. " RF"
- end
- -- My Write API
- function writeSymbol(txtcolor, bgcolor, line, symbol)
- mon.setTextColor(txtcolor)
- mon.setBackgroundColor(bgcolor)
- for x=1, maxX do
- mon.setCursorPos(x, line)
- mon.write(symbol)
- end
- end
- function writeText(txtcolor, bgcolor, startx, line, txt)
- mon.setCursorPos(startx, line)
- mon.setTextColor(txtcolor)
- mon.setBackgroundColor(bgcolor)
- mon.write(txt)
- end
- function writeBackground(color, line, tox, startx)
- if ( tox == nil ) then
- tox = maxX
- end
- if ( startx == nil ) then
- startx = 1
- end
- mon.setCursorPos(1, line)
- for x = startx, tox do
- mon.setCursorPos(x,line)
- mon.setBackgroundColor(color)
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.black)
- end
- function MonitorScreen(e,m,rfs)
- mon.setTextScale(1)
- mon.clear()
- maxX,maxY = mon.getSize()
- writeSymbol(colors.white, colors.black, 1, "-")
- writeSymbol(colors.white, colors.black, 5, "-")
- writeText(colors.white, colors.black, 1, 2, "Energie: " .. EnergyFormat(e))
- writeText(colors.white, colors.black, 1, 3, "Max. Energie: " .. EnergyFormat(m))
- writeText(colors.white, colors.black, 1, 4, "Input:")
- color = colors.white
- if ( rfs > 0 ) then
- color = colors.green
- end
- if ( rfs < 0 ) then
- color = colors.red
- end
- writeText(color, colors.black, 15,4, EnergyFormat(rfs).."/s")
- text = ""
- if ( RFs < 0 ) then
- color = colors.red
- text = "Leer in " .. TimeFormat(e/rfs*-1)
- end
- if ( RFs > 0 ) then
- color = colors.green
- text = "Voll in " .. TimeFormat((m-e)/rfs)
- end
- writeText(color, colors.black, 1, 6, text)
- local fulled = e/m*100
- writeText(colors.white, colors.black, 2, 8, "Energie")
- writeText(colors.white, colors.black, maxX-4, 8, math.floor(fulled).."%")
- if ( fulled < 40 ) then
- color = colors.red
- elseif ( fulled < 80 ) then
- color = colors.yellow
- else
- color = colors.green
- end
- for x = 10, 11 do
- writeBackground(colors.gray, x, maxX-1, 2)
- writeBackground(color, x, (maxX-1)*(fulled/100), 2)
- end
- end
- while true do
- local storage = 0
- local maxStorage = 0
- local periList = peripheral.getNames()
- for i = 2, #periList do
- if ( peripheral.getType(periList[i]) == "tile_thermalexpansion_cell_reinforced_name" ) then
- cell = peripheral.wrap(periList[i])
- storage = storage + cell.getEnergyStored()
- maxStorage = maxStorage + cell.getMaxEnergyStored()
- end
- end
- RFs = storage-lastEnergy
- lastEnergy = storage
- MonitorScreen(storage, maxStorage, RFs)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment