Advertisement
Chaos234

Untitled

Sep 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.83 KB | None | 0 0
  1. local event = require("event")
  2. local comp = require("component")
  3. local gpu = comp.gpu
  4. local w,h = gpu.getResolution()
  5.  
  6. local setFG = gpu.setForeground
  7. local setBG = gpu.setBackground
  8.  
  9. local a = true
  10. local b = false
  11.  
  12. local ferms = {["front"] = 1, ["center"] = 2, ["back"] = 3}
  13. local squeez ={["front"] = 1, ["center"] = 2, ["back"] = 3}
  14. local tanks = {["oil"] = "e76", ["ethanol"] = "e76", ["diesel"] = "157"}
  15. local refs = {["front"] = 1, ["center"] = 2, ["back"] = 3}
  16. local battery = comp.tile_blockcapacitorbank_name
  17. local batteries = 34
  18. local chars = {c1 = "╔", c2 = "╗", c3 = "╝", c4 = "╚", h1 = "═", v1 = "║", t1 = "╩", t2 = "╦", t3 = "╠", t4 = "╣", x = "╬"}
  19.  
  20. function getTD(tank, side)
  21.   tInfo = comp.proxy(comp.get(tank)).getFluidInTank(side)
  22.   return tInfo
  23. end
  24.  
  25. function drawTanks()
  26.   gpu.set(w/3, 4, chars.c1)
  27.   gpu.fill((w/3)+1, 4, 105, 1, chars.h1)
  28.  
  29.   gpu.set((w/3)+33, 4, chars.t2)
  30.   gpu.fill((w/3)+33, 5, 1, (h/1.55)-2, chars.v1)
  31.   gpu.set((w/3)+34, 4, chars.t2)
  32.   gpu.fill((w/3)+34, 5, 1, (h/1.55)-2, chars.v1)
  33.  
  34.   gpu.set((w/3)+70, 4, chars.t2)
  35.   gpu.fill((w/3)+70, 5, 1, (h/1.55)-2, chars.v1)
  36.   gpu.set((w/3)+71, 4, chars.t2)
  37.   gpu.fill((w/3)+71, 5, 1, (h/1.55)-2, chars.v1)
  38.  
  39.   gpu.set(w-2, 4, chars.c2)
  40.  
  41.   gpu.fill(w/3, 5, 1, (h/1.55)-2, chars.v1)
  42.   gpu.fill(w-2, 5, 1, (h/1.55)-2, chars.v1)
  43.  
  44.   gpu.set(w/3, h/1.55, chars.t3)
  45.   gpu.set(w-2, h/1.55, chars.t4)
  46.   gpu.fill((w/3)+1, h/1.55, 104, 1, chars.h1)
  47.   gpu.set((w/3)+33, h/1.55, chars.x)
  48.   gpu.set((w/3)+34, h/1.55, chars.x)
  49.   gpu.set((w/3)+70, h/1.55, chars.x)
  50.   gpu.set((w/3)+71, h/1.55, chars.x)
  51.  
  52.   gpu.set(w/3, (h/1.55)+3, chars.c4)
  53.   gpu.fill((w/3)+1, (h/1.55)+3, 105, 1, chars.h1)
  54.  
  55.   gpu.set((w/3)+33, (h/1.55)+3, chars.t1)
  56.   gpu.set((w/3)+34, (h/1.55)+3, chars.t1)
  57.   gpu.set((w/3)+70, (h/1.55)+3, chars.t1)
  58.   gpu.set((w/3)+71, (h/1.55)+3, chars.t1)
  59.  
  60.   gpu.set(w-2, (h/1.55)+3, chars.c3)
  61. end
  62.  
  63. function drawBatt()
  64.   gpu.set(3, 4, chars.c1)
  65.   gpu.fill(4, 4, 47, 1, chars.h1)
  66.   gpu.set(51, 4, chars.c2)
  67.   gpu.set(51, h-3.8, chars.t4)
  68.   gpu.fill(4, h-3.8, 47, 1, chars.h1)
  69.   gpu.set(3, h-3.8, chars.t3)
  70.   gpu.set(51, h-1, chars.c3)
  71.   gpu.fill(4, h-1, 47, 1, chars.h1)
  72.   gpu.set(3, h-1, chars.c4)
  73.   gpu.fill(3, 5, 1, h-9, chars.v1)
  74.   gpu.fill(51, 5, 1, h-9, chars.v1)
  75.   gpu.fill(3, h-3, 1, 2, chars.v1)
  76.   gpu.fill(51, h-3, 1, 2, chars.v1)
  77. end
  78.  
  79. function drawButtons()
  80.  
  81. end
  82.  
  83. function initFrame()
  84.   gpu.fill(1, 1, w, h, " ")
  85.   setBG(0x000000)
  86.   setFG(0xFFFFFF)
  87.   gpu.set(1, 1, chars.c1)
  88.   gpu.fill(2, 1, w-2, 1, chars.h1)
  89.   gpu.set(1, 2, chars.v1)
  90.   gpu.set(1, 3, chars.t3)
  91.   gpu.set(w/2.7, 2, "ChaosBase v1.0 - Energy Monitor")
  92.   gpu.set(w, 2, chars.v1)
  93.   gpu.set(w, 3, chars.t4)
  94.   gpu.fill(2, 3, w-2, 1, chars.h1)
  95.   gpu.set(w, 1, chars.c2)
  96.   gpu.set(1, h, chars.c4)
  97.   gpu.set(w, h, chars.c3)
  98.   gpu.fill(1, 4, 1, h-4, chars.v1)
  99.   gpu.fill(w, 4, 1, h-4, chars.v1)
  100.   gpu.fill(2, h, w-2, 1, chars.h1)
  101.   drawTanks()
  102.   drawBatt()
  103. end
  104.  
  105. function isempty(s)
  106.   return s == nil or s == ''
  107. end
  108.  
  109. function percentage(machine, side)
  110.   if isempty(side) then
  111.     perc = math.floor(((machine.getEnergyStored() / machine.getMaxEnergyStored())*100)+0.05)
  112.   else
  113.     perc = math.floor(((getTD(machine, side)[1].amount / getTD(machine, side)[1].capacity)*100)+0.05)
  114.   end
  115.  
  116.   return perc
  117. end
  118.  
  119. function calcBar(percA, maxPerc)
  120.     onePerc = maxPerc/100
  121.     finalPerc = math.floor((onePerc*percA)+0.5)
  122.     return finalPerc
  123. end
  124.  
  125. function drawTankStats(x1, x2, x3, w, str, machine, side, color)
  126.   if isempty(getTD(machine, side)[1].label)then
  127.     gpu.set(x1, (h/1.55)+1, str)
  128.   else
  129.     gpu.set(x1, (h/1.55)+1, "Content: "..getTD(machine, side)[1].label)
  130.   end
  131.  
  132.   if getTD(machine, side)[1].amount == 0 then
  133.     gpu.set(x1, (h/1.55)+2, "% Filled: 0  ")
  134.     gpu.set(x2, (h/1.55)+2, "Stored (B): 0   ")
  135.     gpu.fill(x3, 5, w, 27, " ")
  136.   elseif getTD(machine, side)[1].amount > 1 then
  137.     gpu.set(x1, (h/1.55)+2, "% Filled: "..percentage(machine, side))
  138.    
  139.     for i = 1, calcBar(percentage(machine, side), 27) do
  140.       setBG(color)
  141.       gpu.fill(x3, 32-i, w, 1, " ")
  142.     end
  143.    
  144.     setBG(0x000000)
  145.    
  146.     gpu.set(x2, (h/1.55)+2, "Stored (B): "..math.floor((getTD(machine, side)[1].amount /1000)+0.5))  
  147.   end
  148. end
  149.  
  150. function comma_value(amount)
  151.   local formatted = tostring(amount)
  152.   while true do  
  153.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  154.     if (k==0) then
  155.       break
  156.     end
  157.   end
  158.   return formatted
  159. end
  160.  
  161. function drawBatteryStats(color1, color2, color3)
  162.   gpu.set(5, h-3, "Type: EnderIO Capacity Bank")
  163.   gpu.set(5, h-2, "% Filled: "..percentage(battery, nil))
  164.   gpu.set(20, h-2, "Stored (MRF): "..comma_value(battery.getEnergyStored()*batteries))
  165.   for i = 1, calcBar(percentage(battery, nil), 41) do
  166.     if percentage(battery, nil) <1 then
  167.         setBG(0x000000)
  168.     elseif (percentage(battery, nil) >0 and percentage(battery, nil) <25) then
  169.       setBG(0x000000)
  170.       gpu.fill(4, 46-i, 47, 1, " ")
  171.       setBG(color1)
  172.       gpu.fill(4, 46-i, 47, 1, " ")
  173.     elseif (percentage(battery, nil) >24 and percentage(battery, nil) <75) then
  174.       setBG(0x000000)
  175.       gpu.fill(4, 46-i, 47, 1, " ")
  176.       setBG(color2)
  177.       gpu.fill(4, 46-i, 47, 1, " ")
  178.     elseif (percentage(battery, nil) >74) then
  179.       setBG(0x000000)
  180.       gpu.fill(4, 46-i, 47, 1, " ")
  181.       setBG(color3)
  182.       gpu.fill(4, 46-i, 47, 1, " ")
  183.     end
  184.   end
  185.   setBG(0x000000)
  186. end
  187.  
  188. function getValues()
  189.  
  190.   drawTankStats((w/3)+36, (w/3)+52, (w/3)+35, 35, "Content: Plant Oil", tanks.oil, 5, 0xFFFFC0)
  191.   drawTankStats((w/3)+2, (w/3)+16, (w/3)+1, 32, "Content: Bio Diesel", tanks.diesel, 4, 0x664900)
  192.   drawTankStats((w/3)+73, (w/3)+87, (w/3)+72, 33, "Content: Ethanole", tanks.ethanol, 4, 0xC3C3C3)
  193.   drawBatteryStats(0xFF0000, 0xFFB600, 0x99B600)  
  194. end
  195.  
  196. while a == true do
  197.   initFrame()
  198.   a = false
  199.   b = true
  200. end
  201.  
  202. while b == true do
  203.   getValues()
  204.   os.sleep(0.25)
  205. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement