Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by User.
- --- DateTime: 08.05.2019 15:06
- ---
- local comp = require("component")
- local event = require("event")
- local gtBattBuf = comp.gt_batterybuffer
- local sides = require("sides")
- local rs = comp.redstone
- local gpu = comp.gpu
- local w,h = gpu.maxResolution()
- local colors = {
- white = 0xffffff,
- orange = 0xff9200,
- magenta = 0xff00ff,
- lightblue = 0x99dbff,
- yellow = 0xffff00,
- lime = 0x00ff00,
- pink = 0xffb6bf,
- gray = 0x787878,
- silver = 0xc3c3c3,
- cyan = 0x00ffff,
- purple = 0x990080,
- blue = 0x0000ff,
- brown = 0x992440,
- green = 0x009200,
- red = 0xff0000,
- black = 0x000000
- }
- --CONFIG BEGIN
- local backgroundColor = 0x26261b
- local mainTextColor = 0x7f1ae5
- local storageColor = colors.red
- local inputColor = colors.green
- local outputColor = colors.blue
- local runningIndicatorColor = 0xbfff00
- local numderLineStorageColor = colors.red
- local numderLineIOColor = colors.cyan
- local backgroundDiagramColor = colors.black
- local redstoneIOControlSide = sides.south
- local head = "MAIN POWER SYSTEM" -- 32 chars max
- --CONFIG END
- local headOffSet = math.modf((32-string.len(head))/2)
- local clear = " "
- local diagramPosX = 5
- local diagramSizeX = w-9
- local diagramPosY = 11
- local diagramSizeY = h-11
- local capacity
- local maxEnergyOutput
- local stepSizeCap
- local stepSizeIO
- local int_stepSizeCap
- local int_stepSizeIO
- function numPoints(s)
- x = string.len(s)
- r = ""
- if (x <= 3) then
- return s
- end
- if (x % 3 == 0) then
- for i = 1, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- else
- r = r .. string.sub(s, 1, x % 3) .. "."
- for i = 1 + x % 3, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- end
- return string.sub(r, 1, string.len(r) - 1)
- end
- function mark(n)
- local s = string.sub(numPoints(tostring(n)), 1, 3)
- if n < 1000 and n > 0 then
- s = s .. " "
- elseif n < 1000000 then
- --k
- s = s .. "K"
- elseif n < 1000000000 then
- --m
- s = s .. "M"
- elseif n < 1000000000000 then
- --b
- s = s .. "B"
- elseif n < 1000000000000000 then
- --t
- s = s .. "T"
- else
- s = "err"
- end
- return s
- end
- function drawNext(storage, input, output)
- local st = math.modf(storage / stepSizeCap)
- local i = math.modf(input / stepSizeIO)
- local o = math.modf(output / stepSizeIO)
- mass = { { st, storageColor }, { i, inputColor }, { o, outputColor } }
- table.sort(mass,
- function(a, b)
- return a[1] > b[1]
- end
- )
- gpu.copy(diagramPosX + 1, diagramPosY, diagramSizeX - 1, diagramSizeY, -1, 0)
- for k, v in ipairs(mass) do
- if k == 1 then
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY, 1, diagramSizeY - v[1], " ")
- end
- gpu.setBackground(v[2])
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - v[1], 1, v[1], " ")
- end
- gpu.setBackground(backgroundColor)
- end
- function init()
- local temp = 0
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundColor)
- gpu.fill(1, 1, w, h, ' ')
- gpu.set(headOffSet, 1, head)
- capacity = gtBattBuf.getEUMaxStored()
- for i = 1, 16 do
- temp = gtBattBuf.getMaxBatteryCharge(i)
- if temp ~= nil then
- capacity = capacity + temp
- end
- end
- if maxEnergyOutput == nil then
- maxEnergyOutput = 32768*16
- end
- stepSizeCap = capacity / diagramSizeY
- stepSizeIO = maxEnergyOutput / diagramSizeY
- int_stepSizeCap = math.modf(stepSizeCap)
- int_stepSizeIO = math.modf(stepSizeIO)
- gpu.set(1, 3, "EU energy max " .. numPoints(tostring(capacity)) .. clear)
- gpu.setForeground(storageColor)
- gpu.set(1, 2, "EU energy store ")
- gpu.setForeground(inputColor)
- gpu.set(1, 4, "EU energy in ")
- gpu.setForeground(outputColor)
- gpu.set(1, 5, "EU energy out ")
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX, diagramPosY, diagramSizeX, diagramSizeY, " ")
- gpu.setBackground(backgroundColor)
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = diagramPosY + diagramSizeY - 1, diagramPosY, -1 do
- gpu.set(1, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setForeground(numderLineIOColor)
- temp = int_stepSizeIO
- for i = diagramPosY + diagramSizeY - 1, diagramPosY, -1 do
- gpu.set(diagramPosX+diagramSizeX, i, mark(temp))
- temp = temp + int_stepSizeIO
- end
- gpu.setForeground(mainTextColor)
- end
- function blink(flag)
- if flag then
- color = gpu.setBackground(runningIndicatorColor)
- gpu.set(1, 1, " ")
- gpu.setBackground(backgroundColor)
- else
- gpu.set(1, 1, " ")
- end
- return not flag
- end
- function loop()
- local preCapacity = capacity
- local temp = 0
- local flag = true
- local input = 0
- local output = 0
- local n = 0
- local energyStored = 0
- local filter = function(name, ...) if name == "touch" then return true else return false end end
- while true do
- if event.pullFiltered(0.05, filter) == "touch" then
- w,h = gpu.maxResolution()
- if gpu.getViewport() ~= w then
- gpu.setViewport(w, h)
- gpu.set(1, 10, " ")
- else
- gpu.setViewport(32, 10)
- w, h = 32, 10;
- end
- end
- temp = gtBattBuf.getMaxBatteryCharge(n % 16 + 1)
- if temp ~= nil then
- capacity = capacity + temp
- end
- if n % 16 == 0 then
- capacity = capacity + gtBattBuf.getEUMaxStored()
- if n ~= 0 and capacity ~= preCapacity then
- preCapacity = capacity
- stepSizeCap = capacity / diagramSizeY
- int_stepSizeCap = math.modf(stepSizeCap)
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = diagramPosY + diagramSizeY - 1, diagramPosY, -1 do
- gpu.set(1, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setForeground(mainTextColor)
- gpu.set(17, 3, numPoints(tostring(capacity)) .. clear)
- end
- end
- input = input + gtBattBuf.getEUInputAverage()
- output = output + gtBattBuf.getEUOutputAverage()
- temp = gtBattBuf.getBatteryCharge(n % 16 + 1)
- if (temp ~= nil) then
- energyStored = energyStored + temp;
- end
- if n % 16 == 0 then
- if n ~= 0 then
- energyStored = energyStored + gtBattBuf.getEUStored()
- gpu.setForeground(storageColor)
- gpu.set(17, 2, numPoints(tostring(energyStored)) .. clear)
- gpu.setForeground(mainTextColor)
- if energyStored / capacity <= 0.10 then
- rs.setOutput(redstoneIOControlSide, 15)
- elseif energyStored / capacity >= 0.90 then
- rs.setOutput(redstoneIOControlSide, 0)
- end
- if rs.getOutput(redstoneIOControlSide) == 0 then
- gpu.set(1, h, "Energy Generation Disable")
- else
- gpu.set(1, h, "Energy Generation Enable ")
- end
- input = math.modf(input / 16)
- output = math.modf(output / 16)
- gpu.setForeground(inputColor)
- gpu.set(17, 4, numPoints(tostring(input)) .. clear)
- gpu.setForeground(outputColor)
- gpu.set(17, 5, numPoints(tostring(output)) .. clear)
- gpu.setForeground(mainTextColor)
- drawNext(energyStored, input, output)
- end
- input = 0
- output = 0
- energyStored = 0
- capacity = 0
- end
- flag = blink(flag)
- n = n + 1
- end
- end
- init()
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement