Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require("event")
- local comp = require("component")
- local gpu = comp.gpu
- local w,h = gpu.getResolution()
- local setFG = gpu.setForeground
- local setBG = gpu.setBackground
- local a = true
- local b = false
- local ferms = {["front"] = 1, ["center"] = 2, ["back"] = 3}
- local squeez ={["front"] = 1, ["center"] = 2, ["back"] = 3}
- local tanks = {["oil"] = "e76", ["ethanol"] = "e76", ["diesel"] = "157"}
- local refs = {["front"] = 1, ["center"] = 2, ["back"] = 3}
- local battery = comp.tile_blockcapacitorbank_name
- local batteries = 34
- local chars = {c1 = "╔", c2 = "╗", c3 = "╝", c4 = "╚", h1 = "═", v1 = "║", t1 = "╩", t2 = "╦", t3 = "╠", t4 = "╣", x = "╬"}
- function getTD(tank, side)
- tInfo = comp.proxy(comp.get(tank)).getFluidInTank(side)
- return tInfo
- end
- function drawTanks()
- gpu.set(w/3, 4, chars.c1)
- gpu.fill((w/3)+1, 4, 105, 1, chars.h1)
- gpu.set((w/3)+33, 4, chars.t2)
- gpu.fill((w/3)+33, 5, 1, (h/1.55)-2, chars.v1)
- gpu.set((w/3)+34, 4, chars.t2)
- gpu.fill((w/3)+34, 5, 1, (h/1.55)-2, chars.v1)
- gpu.set((w/3)+70, 4, chars.t2)
- gpu.fill((w/3)+70, 5, 1, (h/1.55)-2, chars.v1)
- gpu.set((w/3)+71, 4, chars.t2)
- gpu.fill((w/3)+71, 5, 1, (h/1.55)-2, chars.v1)
- gpu.set(w-2, 4, chars.c2)
- gpu.fill(w/3, 5, 1, (h/1.55)-2, chars.v1)
- gpu.fill(w-2, 5, 1, (h/1.55)-2, chars.v1)
- gpu.set(w/3, h/1.55, chars.t3)
- gpu.set(w-2, h/1.55, chars.t4)
- gpu.fill((w/3)+1, h/1.55, 104, 1, chars.h1)
- gpu.set((w/3)+33, h/1.55, chars.x)
- gpu.set((w/3)+34, h/1.55, chars.x)
- gpu.set((w/3)+70, h/1.55, chars.x)
- gpu.set((w/3)+71, h/1.55, chars.x)
- gpu.set(w/3, (h/1.55)+3, chars.c4)
- gpu.fill((w/3)+1, (h/1.55)+3, 105, 1, chars.h1)
- gpu.set((w/3)+33, (h/1.55)+3, chars.t1)
- gpu.set((w/3)+34, (h/1.55)+3, chars.t1)
- gpu.set((w/3)+70, (h/1.55)+3, chars.t1)
- gpu.set((w/3)+71, (h/1.55)+3, chars.t1)
- gpu.set(w-2, (h/1.55)+3, chars.c3)
- end
- function drawBatt()
- gpu.set(3, 4, chars.c1)
- gpu.fill(4, 4, 47, 1, chars.h1)
- gpu.set(51, 4, chars.c2)
- gpu.set(51, h-3.8, chars.t4)
- gpu.fill(4, h-3.8, 47, 1, chars.h1)
- gpu.set(3, h-3.8, chars.t3)
- gpu.set(51, h-1, chars.c3)
- gpu.fill(4, h-1, 47, 1, chars.h1)
- gpu.set(3, h-1, chars.c4)
- gpu.fill(3, 5, 1, h-9, chars.v1)
- gpu.fill(51, 5, 1, h-9, chars.v1)
- gpu.fill(3, h-3, 1, 2, chars.v1)
- gpu.fill(51, h-3, 1, 2, chars.v1)
- end
- function drawButtons()
- end
- function initFrame()
- gpu.fill(1, 1, w, h, " ")
- setBG(0x000000)
- setFG(0xFFFFFF)
- gpu.set(1, 1, chars.c1)
- gpu.fill(2, 1, w-2, 1, chars.h1)
- gpu.set(1, 2, chars.v1)
- gpu.set(1, 3, chars.t3)
- gpu.set(w/2.7, 2, "ChaosBase v1.0 - Energy Monitor")
- gpu.set(w, 2, chars.v1)
- gpu.set(w, 3, chars.t4)
- gpu.fill(2, 3, w-2, 1, chars.h1)
- gpu.set(w, 1, chars.c2)
- gpu.set(1, h, chars.c4)
- gpu.set(w, h, chars.c3)
- gpu.fill(1, 4, 1, h-4, chars.v1)
- gpu.fill(w, 4, 1, h-4, chars.v1)
- gpu.fill(2, h, w-2, 1, chars.h1)
- drawTanks()
- drawBatt()
- end
- function isempty(s)
- return s == nil or s == ''
- end
- function percentage(machine, side)
- if isempty(side) then
- perc = math.floor(((machine.getEnergyStored() / machine.getMaxEnergyStored())*100)+0.05)
- else
- perc = math.floor(((getTD(machine, side)[1].amount / getTD(machine, side)[1].capacity)*100)+0.05)
- end
- return perc
- end
- function calcBar(percA, maxPerc)
- onePerc = maxPerc/100
- finalPerc = math.floor((onePerc*percA)+0.5)
- return finalPerc
- end
- function drawTankStats(x1, x2, x3, w, str, machine, side, color)
- if isempty(getTD(machine, side)[1].label)then
- gpu.set(x1, (h/1.55)+1, str)
- else
- gpu.set(x1, (h/1.55)+1, "Content: "..getTD(machine, side)[1].label)
- end
- if getTD(machine, side)[1].amount == 0 then
- gpu.set(x1, (h/1.55)+2, "% Filled: 0 ")
- gpu.set(x2, (h/1.55)+2, "Stored (B): 0 ")
- gpu.fill(x3, 5, w, 27, " ")
- elseif getTD(machine, side)[1].amount > 1 then
- gpu.set(x1, (h/1.55)+2, "% Filled: "..percentage(machine, side))
- for i = 1, calcBar(percentage(machine, side), 27) do
- setBG(color)
- gpu.fill(x3, 32-i, w, 1, " ")
- end
- setBG(0x000000)
- gpu.set(x2, (h/1.55)+2, "Stored (B): "..math.floor((getTD(machine, side)[1].amount /1000)+0.5))
- end
- end
- function comma_value(amount)
- local formatted = tostring(amount)
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- function drawBatteryStats(color1, color2, color3)
- gpu.set(5, h-3, "Type: EnderIO Capacity Bank")
- gpu.set(5, h-2, "% Filled: "..percentage(battery, nil))
- gpu.set(20, h-2, "Stored (MRF): "..comma_value(battery.getEnergyStored()*batteries))
- for i = 1, calcBar(percentage(battery, nil), 41) do
- if percentage(battery, nil) <1 then
- setBG(0x000000)
- elseif (percentage(battery, nil) >0 and percentage(battery, nil) <25) then
- setBG(0x000000)
- gpu.fill(4, 46-i, 47, 1, " ")
- setBG(color1)
- gpu.fill(4, 46-i, 47, 1, " ")
- elseif (percentage(battery, nil) >24 and percentage(battery, nil) <75) then
- setBG(0x000000)
- gpu.fill(4, 46-i, 47, 1, " ")
- setBG(color2)
- gpu.fill(4, 46-i, 47, 1, " ")
- elseif (percentage(battery, nil) >74) then
- setBG(0x000000)
- gpu.fill(4, 46-i, 47, 1, " ")
- setBG(color3)
- gpu.fill(4, 46-i, 47, 1, " ")
- end
- end
- setBG(0x000000)
- end
- function getValues()
- drawTankStats((w/3)+36, (w/3)+52, (w/3)+35, 35, "Content: Plant Oil", tanks.oil, 5, 0xFFFFC0)
- drawTankStats((w/3)+2, (w/3)+16, (w/3)+1, 32, "Content: Bio Diesel", tanks.diesel, 4, 0x664900)
- drawTankStats((w/3)+73, (w/3)+87, (w/3)+72, 33, "Content: Ethanole", tanks.ethanol, 4, 0xC3C3C3)
- drawBatteryStats(0xFF0000, 0xFFB600, 0x99B600)
- end
- while a == true do
- initFrame()
- a = false
- b = true
- end
- while b == true do
- getValues()
- os.sleep(0.25)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement