Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local sides = require("sides")
- local monitor = component.screen
- local powercell = component.rftools_powercell
- local gpu = component.gpu
- local W, H = nil
- local prevEnergy = nil
- local minPerTick = 0
- local maxPerTick = 0
- local curColor = 0xF0F0F0
- local maxPower = 0
- local startTime = os.time()
- local startPower = powercell.getEnergy()
- local sections = {}
- local stats = {}
- local buttons = {}
- local colors = {
- white = 0xF0F0F0,
- orange = 0xFF6A00,
- magenta = 0xE57FD8,
- lightBlue = 0x99B2F2,
- yellow = 0xFFEE00,
- lime = 0x7FCC19,
- pink = 0xF2B2CC,
- gray = 0x4C4C4C,
- lightGray = 0x999999,
- cyan = 0x4C99B2,
- purple = 0xB266E5,
- blue = 0x3366CC,
- brown = 0x7F664C,
- green = 0x4CFF00,
- red = 0xFF0000,
- black = 0
- }
- function setSections()
- sections["power"] = { x = 2, y = 2, width = W-4, height = H/3, title = " POWER "}
- sections["stats"] = { x = 2, y = H/3 + 4, width = W-4, height = H/2, title = " STATS "}
- end
- function setStats(w, h)
- stats["currentRF"] = { x = w/15, y = h + 3, width = 15, height = 1, title = "RF: " }
- stats["maxRF"] = { x = w/15, y = h + 5, width = 15, height = 1, title = "Max RF: " }
- stats["tick"] = { x = w/15, y = h + 7, width = 15, height = 1, title = "RF/T: "}
- stats["minDelta"] = { x = w/3, y = h + 4, width = 10, height = 1, title = ""}
- stats["zeroDelta"] = { x = w/1.6-1, y = h + 4, width = 10, height = 1, title = ""}
- stats["maxDelta"] = { x = w/1.2, y = h + 4, width = 10, height = 1, title = ""}
- end
- function setButtons(w, h)
- buttons["resetButton"] = { x = w/1.2, y = h + 10, width = 13, height = 3, title = " RESET "}
- end
- function init()
- minPerTick = 0
- maxPerTick = 0
- prevEnergy = nil
- gpu.setResolution(80, 30)
- term.setCursorBlink(false)
- term.clear()
- W, H = gpu.getResolution()
- curColor = colors.white
- setSections()
- setStats(sections["stats"].width, sections["stats"].height)
- for name, data in pairs(sections) do
- printBorders(name)
- end
- --[[ setButtons(sections["stats"].width, sections["stats"].height)
- local button = buttons["resetButton"]
- drawBar(colors.red, button.x, button.y, button.width, button.height)
- gpu.setForeground(curColor)
- gpu.set(button.x, button.y + 1, button.title) --]]
- end
- function printBorders(sectionName)
- local s = sections[sectionName]
- gpu.setBackground(colors.gray)
- gpu.setForeground(curColor)
- gpu.fill(s.x, s.y, s.width, 1, " ")
- gpu.fill(s.x, s.y, 1, s.height, " ")
- gpu.fill(s.x, s.y + s.height, s.width, 1, " ")
- gpu.fill(s.x + s.width, s.y, 1, s.height + 1, " ")
- gpu.setBackground(colors.black)
- gpu.set(s.x + 2, s.y, s.title)
- end
- function convert(power)
- local greatest = 1
- local units = {}
- units[" "] = 1
- units["K"] = 10^3
- units["M"] = 10^6
- units["G"] = 10^9
- suffix = " "
- for name, value in pairs(units) do
- if (math.abs(power) >= value) then
- if (value > greatest) then
- greatest = value
- suffix = name
- end
- end
- end
- return string.format("%.2f%s", power/units[suffix], suffix)
- end
- function getColor(level)
- if (level < 0.25) then
- return colors.red
- end
- if (level > 0.25) and (level < 0.50) then
- return colors.orange
- end
- if (level > 0.50) and (level < 0.75) then
- return colors.yellow
- end
- return colors.green
- end
- function drawBar(color, x, y, w, h)
- gpu.setBackground(color)
- gpu.fill(x, y, w, h, " ")
- end
- function emitPower(percentage)
- if (percentage < 0.5) then
- component.redstone.setOutput(sides.front, 10)
- elseif (percentage > 0.95) then
- component.redstone.setOutput(sides.front, 0)
- end
- end
- function drawPower(w, h)
- if (maxPower ~= powercell.getMaxEnergy()) then
- init()
- maxPower = powercell.getMaxEnergy()
- end
- percentage = powercell.getEnergy()/powercell.getMaxEnergy()
- emitPower(percentage)
- barX = w/15
- barY = h/1.8
- barW = w-barX+1
- barH = h/2
- drawBar(colors.gray, barX, barY, barW, barH)
- drawBar(getColor(percentage), barX+2, barY+1, (barW-4)*percentage, barH-2)
- gpu.setForeground(colors.black)
- gpu.set(barX+((barW-4)*percentage)/2, barY+2, string.format("%.2f%%", percentage*100))
- end
- function getRFTColor(power)
- if (power > 0) then
- curColor = colors.green
- end
- if (power < 0) then
- curColor = colors.red
- end
- end
- function printDeltaBar(energyDelta)
- local minDelta = stats["minDelta"]
- local zeroDelta = stats["zeroDelta"]
- local maxDelta = stats["maxDelta"]
- local percentage = nil
- local width = nil
- drawBar(colors.gray, minDelta.x + 2, minDelta.y + 2, W - minDelta.x - (W - maxDelta.x), 3)
- if (energyDelta > 0) then
- percentage = energyDelta/maxPerTick
- if (percentage > 0.5) then
- curColor = colors.green
- elseif (percentage < 0.5) then
- curColor = colors.yellow
- end
- width = percentage*(maxDelta.x - zeroDelta.x)
- drawBar(curColor, zeroDelta.x, zeroDelta.y + 3, width, 1)
- elseif (energyDelta < 0) then
- percentage = energyDelta/minPerTick
- if (percentage > 0.5) then
- curColor = colors.red
- elseif (percentage < 0.5) then
- curColor = colors.orange
- end
- width = math.floor(percentage*(zeroDelta.x - minDelta.x))
- drawBar(curColor, zeroDelta.x-width+3, zeroDelta.y + 3, width-2, 1)
- end
- end
- function getStat(statName)
- curColor = colors.white
- if (statName == "currentRF") then
- return convert(powercell.getEnergy())
- end
- if (statName == "maxRF") then
- return convert(powercell.getMaxEnergy())
- end
- if (statName == "tick") then
- if (prevEnergy ~= nil) then
- local energyDelta = (powercell.getEnergy()-startPower)/((os.time()-startTime)/6)
- if (energyDelta > maxPerTick) then
- maxPerTick = energyDelta
- end
- if (energyDelta < minPerTick) then
- minPerTick = energyDelta
- end
- printDeltaBar(energyDelta)
- getRFTColor(energyDelta)
- prevEnergy = powercell.getEnergy()
- return convert(energyDelta)
- end
- prevEnergy = powercell.getEnergy()
- return "N/A"
- end
- if (statName == "minDelta") then
- curColor = colors.red
- return convert(minPerTick)
- end
- if (statName == "zeroDelta") then
- return 0
- end
- if (statName == "maxDelta") then
- curColor = colors.green
- return convert(maxPerTick)
- end
- end
- function printStats(statName)
- local s = stats[statName]
- local stat = getStat(statName)
- gpu.setBackground(colors.black)
- drawBar(colors.black, s.x, s.y, s.width, s.height)
- gpu.setForeground(curColor)
- gpu.set(s.x, s.y, s.title..stat)
- end
- function drawStats(w, h)
- for name, data in pairs(stats) do
- printStats(name)
- end
- end
- function getClick()
- local _, _, x, y = event.pull(1,touch)
- if (x == nil) or (y == nil) then
- return nil
- end
- local button = buttons["resetButton"]
- if (x >= button.x) and (y >= button.y) then
- if (x <= button.x + button.width) and (y <= button.y + button.height) then
- init()
- end
- end
- end
- init()
- while true do
- startTime = os.time()
- startPower = powercell.getEnergy()
- drawPower(sections["power"].width, sections["power"].height)
- drawStats(sections["stats"].width, sections["stats"].height)
- --getClick()
- os.sleep(1/20)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement