FeanorWasWrong

06tankStats.lua

Jan 22nd, 2021 (edited)
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. --Author: Richard Worring                                   --
  2. --Date: 17.06.2019 
  3. --Modified Last: 23.01.2021                                     --
  4.                                                             --
  5. --URL: pastebin get uvNaK9yg 06Tank.lua -f                  --
  6. ----------------------------------------------------------
  7.  
  8. local term = require"term"
  9. local component = require"component"
  10. local sides = require"sides"
  11.  
  12. local gpu = component.gpu
  13. local tank = component.tank_controller
  14.  
  15.  
  16. gpu.setResolution(120, 40)
  17. local w, h = gpu.getResolution()
  18.  
  19. gpu.is_palette = true
  20.  
  21. local ARRoldAmount = {}
  22. for i = 0,5 do
  23.     ARRoldAmount[i] = 0
  24. end
  25.  
  26.  
  27. gpu.setBackground(1, true)
  28. term.clear()
  29.  
  30. --Get stats of tanks
  31.     while true do
  32.     i = 5
  33.         for sides = 0,5 do
  34.            
  35.             if type(tank.getFluidInTank(sides)) == "table" then
  36.                 tanks = {}             
  37.                 for a,b in ipairs(tank.getFluidInTank(sides))
  38.                 do
  39.                     tanks[a] = {}
  40.                     tanks[a].name = b.name
  41.                     tanks[a].label = b.label
  42.                     tanks[a].unit = b.unit
  43.                     tanks[a].level = b.amount
  44.                     tanks[a].capacity = b.capacity
  45.                     vTLvl = b.amount / b.capacity
  46.                     vDeltaTLvl = (b.amount - ARRoldAmount[sides])*10  -- *10 because the os sleeps for 0.1 seconds
  47.                     gpu.fill(6, i+1, w, h/18, " ")
  48.                     if b.label == nil then
  49.                         gpu.set(6, i+1, "Der Tank an der Seite "..sides.." ist leer.")
  50.                     elseif b.amount <= (b.capacity * 0.05) then
  51.                         gpu.set(6, i+1, "Der "..b.label.." Tank an der Seite "..sides.." ist unter 5% gefüllt.")
  52.                     else
  53.                         if b.label == "Lubricant" then
  54.                             gpu.setBackground(0xFFDB40)
  55.                             gpu.setForeground(1, true)
  56.                         elseif b.label == "Jet Fuel" then
  57.                             gpu.setBackground(0xFF2480)
  58.                             gpu.setForeground(15, true)
  59.                         elseif b.label == "Water" then
  60.                             gpu.setBackground(0x0000FF)
  61.                             gpu.setForeground(15, true)
  62.                         else
  63.                             gpu.setBackground(15, true)
  64.                             gpu.setForeground(1, true)
  65.                         end
  66.                         --Display the bar
  67.                         gpu.fill(5, i+1, ((w - 5) * vTLvl), h/18, " ")
  68.                         --Display the delta of the fuel
  69.                         if b.amount <= (b.capacity * 0.3) then
  70.                             gpu.setBackground(1, true)
  71.                             gpu.setForeground(15, true)
  72.                             gpu.set(((w * vTLvl) + 5), i+1, ""..vDeltaTLvl.."mB/Sec")
  73.                         else
  74.                             gpu.set((((w - 5) * vTLvl) * 0.5), i+1, ""..vDeltaTLvl.."mB/Sec")
  75.                         end
  76.                         gpu.setBackground(1, true)
  77.                         gpu.setForeground(15, true)
  78.                         gpu.set(6, i, ""..b.label)
  79.                         gpu.set((w - 25), i, ""..b.amount.."/"..b.capacity.."mB")
  80.                     end
  81.                     gpu.setBackground(1, true)
  82.                     gpu.setForeground(15, true)
  83.                     i = i + 5
  84.                     ARRoldAmount[sides] = b.amount
  85.                 end
  86.             else
  87.                 print("No Tank detected")
  88.             end
  89.         end
  90.         vDeltaTLvl = 0
  91.         os.sleep(0.1)
  92.     end
  93.    
  94.  
  95.  
  96.  
  97. --[[ChangeLog
  98. 23.01.2021 changed vOldAmount to vars[sides.."oldAmount"]
  99.     failed
  100. 23.01.2021 changed from vars to array for oldAmount
  101. 23.01.2021 changed low level message
  102. 23.01.2021 added if for b.label is empty
  103. 23.01.2021 changed the MB/Min to MB/Sec because the os sleeps for 2 seconds
  104. 23.01.2021 added a "clearline" row 52
  105. ]]--
Add Comment
Please, Sign In to add comment