Advertisement
FeanorWasWrong

TESTtankstats.lua

Sep 28th, 2019 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. --Author: Richard Worring                                   --
  2. --Date: 17.06.2019                                          --
  3.                                                             --
  4. --URL: UWMH9HmT pastebin                                    --
  5. ----------------------------------------------------------
  6.  
  7. local term = require"term"
  8. local component = require"component"
  9. local sides = require"sides"
  10.  
  11. local gpu = component.gpu
  12. local tank = component.tank_controller
  13.  
  14.  
  15. gpu.setResolution(120, 40)
  16. local w, h = gpu.getResolution()
  17.  
  18. gpu.is_palette = true
  19.  
  20. local vOldAmount = 0
  21.  
  22.  
  23.  
  24. function stats()
  25. --Get stats of tanks
  26.     for sides = 0,5 do
  27.         if type(tank.getFluidInTank(sides)) == "table" then
  28.            
  29.             tanks = {}              --Why?!
  30.            
  31.             for a,b in ipairs(tank.getFluidInTank(sides))
  32.             do
  33.                 tanks[a] = {}
  34.                 tanks[a].name = b.name
  35.                 tanks[a].label = b.label
  36.                 tanks[a].unit = b.unit
  37.                 tanks[a].level = b.amount
  38.                 tanks[a].capacity = b.capacity
  39.                 vTLvl = b.amount / b.capacity
  40.                 vDeltaTLvl = (b.amount - vOldAmount) * 12
  41.                 if b.amount == 0 then
  42.                     gpu.set(6, i+1, "Der Tank an der Seite "..sides.." ist leer.")
  43.                 else
  44.                     if b.label == "Lubricant" then
  45.                         gpu.setBackground(0xFFDB40)
  46.                         gpu.setForeground(1, true)
  47.                     elseif b.label == "Jet Fuel" then
  48.                         gpu.setBackground(0xFF2480)
  49.                         gpu.setForeground(15, true)
  50.                     elseif b.label == "Water" then
  51.                         gpu.setBackground(0x0000FF)
  52.                         gpu.setForeground(15, true)
  53.                     else
  54.                         gpu.setBackground(15, true)
  55.                         gpu.setForeground(1, true)
  56.                     end
  57.                     --Display the bar
  58.                     gpu.fill(5, i+1, ((w - 5) * vTLvl), h/18, " ")
  59.                     --Display the delta of the fuel
  60.                     if b.amount <= (b.capacity * 0.3) then
  61.                         gpu.setBackground(1, true)
  62.                         gpu.setForeground(15, true)
  63.                         gpu.set(((w * vTLvl) + 5), i+1, ""..vDeltaTLvl.."mB/Min")
  64.                     else
  65.                         gpu.set((((w - 5) * vTLvl) * 0.5), i+1, ""..vDeltaTLvl.."mB/Min")
  66.                     end
  67.                     --Set background and display label and level of fuel
  68.                     --gpu.setBackground(1, true)
  69.                     --gpu.setForeground(15, true)
  70.                     gpu.set(6, i, ""..b.label)
  71.                     gpu.set((w - 25), i, ""..b.amount.."/"..b.capacity.."mB")
  72.                    
  73.                 end
  74.                
  75.                 i = i + 5
  76.                 vOldAmount = b.amount
  77.             end
  78.             term.clear()
  79.         else
  80.             print("No Tank detected")
  81.         end
  82.     end
  83. end
  84.  
  85. --function fTankEmpty(sides)
  86. --  print("Tank an der Seite"..sides.."leer.")
  87. --  return true
  88. --end
  89.  
  90.  
  91. --Loop for updates
  92. while true do
  93.     gpu.setBackground(1, true)
  94.     i = 5
  95.    
  96.     stats()
  97.    
  98.     os.sleep(0.1)
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement