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