Advertisement
levshx

InterfaceEssentia.lua

Jan 23rd, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local aspects = require("aspect")
  3. local me = component.me_interface
  4. local gpu = component.gpu
  5.  
  6. local aspectKeyTable = {}
  7. local aspectTable = {}
  8.  
  9. local w, h = gpu.getResolution()
  10.  
  11. local x = 1
  12. local y = 1
  13.  
  14. local width = math.floor(w / 3)
  15. local height = 3
  16.  
  17. local paddingX = 2
  18. local paddingY = math.floor(height / 2)
  19.  
  20. local cursorX = x + paddingX
  21. local cursorY = y + paddingY
  22. local cursorEnd = width - paddingX
  23.  
  24. print("screenSize:" .. w .. "x" .. h)
  25.  
  26. for _, b in pairs(aspects) do
  27.     aspectKeyTable[b.name] = b
  28. end
  29.  
  30. function aspectSort(a, b)
  31.     if not a.amount then
  32.         return false
  33.     elseif not b.amount then
  34.         return true
  35.     elseif a.amount > b.amount then
  36.         return true
  37.     end
  38.     return false
  39. end
  40.  
  41. function updateAspectAmount()
  42.     local networkAspects = me.getFluidsInNetwork()
  43.     aspectTable = {}
  44.     for i = 1, #networkAspects do
  45.         if networkAspects[i] and networkAspects[i].amount then
  46.             local item = aspectKeyTable[networkAspects[i].name]
  47.             item.amount = math.floor(networkAspects[i].amount / 128)
  48.             table.insert(aspectTable, item)
  49.         end
  50.     end
  51.  
  52.     table.sort(aspectTable, aspectSort)
  53. end
  54.  
  55. function resetValues()
  56.     x = 1
  57.     y = 1
  58.  
  59.     paddingX = 2
  60.     paddingY = math.floor(height / 2)
  61.  
  62.     cursorX = x + paddingX
  63.     cursorY = y + paddingY
  64.     cursorEnd = width - paddingX
  65. end
  66.  
  67. gpu.setBackground(0x000000)
  68. gpu.fill(1, 1, w, h, " ")
  69.  
  70. while true do
  71.     updateAspectAmount()
  72.     resetValues()
  73.  
  74.     for i = 1, #aspectTable do
  75.         local aspect = aspectTable[i]
  76.         gpu.setBackground(aspect.background)
  77.         gpu.setForeground(aspect.foreground)
  78.         gpu.fill(x, y, width, height, " ")
  79.         gpu.set(cursorX, cursorY, aspect.label)
  80.  
  81.         if (aspect.amount) then
  82.             local amountStr = tostring(aspect.amount)
  83.             local length = string.len(amountStr)
  84.  
  85.             gpu.set(cursorEnd - length, cursorY, amountStr)
  86.         end
  87.  
  88.         y = y + height
  89.         if y + height > h then
  90.             y = 1
  91.             x = x + width
  92.             cursorEnd = x + width - paddingX
  93.         end
  94.  
  95.         cursorX = x + paddingX
  96.         cursorY = y + paddingY
  97.  
  98.         if x > w then
  99.             break
  100.         end
  101.     end
  102.     os.sleep(1)
  103. end
  104.  
  105. gpu.setBackground(0x000000)
  106. gpu.setForeground(0xffffff)
  107. gpu.fill(1, 1, w, h, " ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement