AceDPDragon

Fluid Monitoring System (worknprogress)

Aug 21st, 2022 (edited)
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 KB | None | 0 0
  1. ------------------test zone---------------------
  2. local function getFluidList()
  3.     local list = {
  4.         { fluidName = "Water", fluidAmount = 64000, fluidCapacity = 64000 },        -- test fluid that is at 100% full
  5.         { fluidName = "Latex", fluidAmount = 48000, fluidCapacity = 64000 },        -- test fluid that is at 75% full      
  6.         { fluidName = "Lava", fluidAmount = 64000, fluidCapacity = 128000 },        -- test fluid that is at 50% full
  7.         { fluidName = "Steam", fluidAmount = 32000, fluidCapacity = 128000 },       -- test fluid that is at 25% full
  8.         { fluidName = "Menril Resin", fluidAmount = 10000, fluidCapacity = 16000 }, -- test fluid with a long name
  9.         { fluidName = "Molten Cobalt", fluidAmount = 42000, fluidCapacity = 69000 },-- test fluid with a long name
  10.         { fluidName = "Liquid Hydrofloric Acid", fluidAmount = 42000, fluidCapacity = 69000 },-- test fluid with a even longer name
  11.         { fluidName = "Liquid Uranium Hexaflorid", fluidAmount = 42000, fluidCapacity = 69000 },-- test fluid with a even longer name
  12.     }
  13.     return list
  14. end
  15.  
  16. local fluidList = getFluidList()
  17. term.clear()
  18. term.setCursorPos(1,1)
  19. for i=1, #fluidList do
  20.         local name = fluidList[i].fluidName
  21.         local amount = fluidList[i].fluidAmount
  22.         local capacity = fluidList[i].fluidCapacity
  23.         print(name..": "..tostring(amount).."/"..tostring(capacity))
  24.     end
  25. ----------- local variables ---------------------
  26. local mon = peripheral.find "monitor"
  27. local monName = peripheral.getName(mon)
  28.  
  29.  
  30. --monitor size--
  31. mon.setTextScale(0.5)
  32. local monX, monY = mon.getSize()
  33.  
  34.  
  35.  
  36. ----------- Functions ---------------------
  37. function clear()
  38.     mon.setBackgroundColor(colors.black)
  39.     mon.clear()
  40.     mon.setCursorPos(1,1)
  41. end
  42.    
  43. function draw_text(x, y, text, text_color, bg_color)
  44.     mon.setBackgroundColor(bg_color)
  45.     mon.setTextColor(text_color)
  46.     mon.setCursorPos(x,y)
  47.     mon.write(text)
  48. end
  49.  
  50. function draw_line(x, y, length, color)
  51.     mon.setBackgroundColor(color)
  52.     mon.setCursorPos(x,y)
  53.     mon.write(string.rep(" ", length))
  54. end
  55.  
  56. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  57.       draw_line(x, y, length, bg_color) --backgoround bar
  58.       local barSize = math.floor((minVal/maxVal) * length)
  59.       draw_line(x, y, barSize, bar_color) --progress so far
  60. end
  61.    
  62. ------------------Fluid Level---------------------
  63. clear()
  64. local fluidList = getFluidList()
  65. draw_text(2, 2, "Fluid Monitoring System", colors.yellow, colors.black)
  66. for i=1, #fluidList do
  67.     local name = fluidList[i].fluidName
  68.     local amount = fluidList[i].fluidAmount
  69.     local capacity = fluidList[i].fluidCapacity
  70.     local percent = math.floor((amount/capacity)*100)
  71.     draw_text(2, (3*i)+1, name, colors.yellow, colors.black)
  72.     if percent < 100 then
  73.         draw_text(monX-4, (3*i)+1, " "..percent.."%", colors.white, colors.black)
  74.     else
  75.         draw_text(monX-4, (3*i)+1, percent.."%", colors.white, colors.black)
  76.     end
  77.     if percent < 25 then
  78.         progress_bar(2, (3*i)+2, monX-2, amount, capacity, colors.red, colors.gray)
  79.     elseif percent < 50 then
  80.         progress_bar(2, (3*i)+2, monX-2, amount, capacity, colors.orange, colors.gray)
  81.     elseif percent < 75 then
  82.         progress_bar(2, (3*i)+2, monX-2, amount, capacity, colors.yellow, colors.gray)
  83.     elseif percent <= 100 then
  84.         progress_bar(2, (3*i)+2, monX-2, amount, capacity, colors.lime, colors.gray)
  85.     end
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment