SHOW:
|
|
- or go back to the newest paste.
| 1 | - | component = require("component") |
| 1 | + | component = require("component")
|
| 2 | - | gpu = component.gpu |
| 2 | + | gpu = component.gpu |
| 3 | - | e = require("event") |
| 3 | + | e = require("event")
|
| 4 | - | m = component.modem |
| 4 | + | m = component.modem |
| 5 | - | string = require("string") |
| 5 | + | string = require("string")
|
| 6 | - | term = require("term") |
| 6 | + | term = require("term")
|
| 7 | - | table = require("table") |
| 7 | + | table = require("table")
|
| 8 | - | c = false |
| 8 | + | c = false |
| 9 | - | x, y, length, n, l = 3, 3, 0, 3, 3 |
| 9 | + | x, y, length, n, l = 3, 3, 0, 3, 3 |
| 10 | - | j = 1 |
| 10 | + | j = 1 |
| 11 | - | |
| 11 | + | |
| 12 | - | m.open(2) |
| 12 | + | m.open(2) |
| 13 | - | m.broadcast(1, "nanomachines", "setResponsePort", 2) |
| 13 | + | m.broadcast(1, "nanomachines", "setResponsePort", 2) |
| 14 | - | e.pull("modem_message") |
| 14 | + | e.pull("modem_message")
|
| 15 | - | |
| 15 | + | |
| 16 | - | maxX, maxY, oX, oY = term.getViewport() |
| 16 | + | maxX, maxY, oX, oY = term.getViewport() |
| 17 | - | inList = {} |
| 17 | + | inList = {}
|
| 18 | - | |
| 18 | + | |
| 19 | - | function clear() |
| 19 | + | function clear() |
| 20 | - | gpu.fill(1, 1, maxX, maxY, " ") |
| 20 | + | gpu.fill(1, 1, maxX, maxY, " ") |
| 21 | end | |
| 22 | - | |
| 22 | + | |
| 23 | - | function printToMon(str, x, y) |
| 23 | + | function printToMon(str, x, y) |
| 24 | - | gpu.set(x, y, str) |
| 24 | + | gpu.set(x, y, str) |
| 25 | end | |
| 26 | - | |
| 26 | + | |
| 27 | - | function Input(num) |
| 27 | + | function Input(num) |
| 28 | - | m.broadcast(1, "nanomachines", "getInput", num) |
| 28 | + | m.broadcast(1, "nanomachines", "getInput", num) |
| 29 | - | _, c, j = e.pull("msg_recieved") |
| 29 | + | _, c, j = e.pull("msg_recieved")
|
| 30 | - | if c == true then |
| 30 | + | if c == true then |
| 31 | - | m.broadcast(1, "nanomachines", "setInput", num, false) |
| 31 | + | m.broadcast(1, "nanomachines", "setInput", num, false) |
| 32 | - | print("Turning input "..num.." off") |
| 32 | + | print("Turning input "..num.." off")
|
| 33 | - | e.pull("msg_recieved") |
| 33 | + | e.pull("msg_recieved")
|
| 34 | - | elseif c == false then |
| 34 | + | elseif c == false then |
| 35 | - | m.broadcast(1, "nanomachines", "setInput", num, true) |
| 35 | + | m.broadcast(1, "nanomachines", "setInput", num, true) |
| 36 | - | e.pull("msg_recieved") |
| 36 | + | e.pull("msg_recieved")
|
| 37 | - | print("Getting effects of input "..num.." now") |
| 37 | + | print("Getting effects of input "..num.." now")
|
| 38 | - | m.broadcast(1, "nanomachines", "getActiveEffects") |
| 38 | + | m.broadcast(1, "nanomachines", "getActiveEffects") |
| 39 | - | print("cont") |
| 39 | + | print("cont")
|
| 40 | - | _, inList = e.pull("effects_updated") |
| 40 | + | e.push("effects_table", inList)
|
| 41 | - | end |
| 41 | + | _, inList = e.pull("effects_updated")
|
| 42 | end | |
| 43 | - | |
| 43 | + | end |
| 44 | - | function inputList() |
| 44 | + | |
| 45 | - | m.broadcast(1, "nanomachines", "getTotalInputCount") |
| 45 | + | function inputList() |
| 46 | - | e.pull("updated_inputs") |
| 46 | + | m.broadcast(1, "nanomachines", "getTotalInputCount") |
| 47 | - | for i=1, inputs do |
| 47 | + | e.pull("updated_inputs")
|
| 48 | - | num = tostring(i) |
| 48 | + | for i=1, inputs do |
| 49 | - | msg = "Input: "..num |
| 49 | + | num = tostring(i) |
| 50 | - | print(msg.." registered") |
| 50 | + | msg = "Input: "..num |
| 51 | - | Input(i) |
| 51 | + | print(msg.." registered") |
| 52 | - | Input(i) |
| 52 | + | Input(i) |
| 53 | - | end |
| 53 | + | Input(i) |
| 54 | end | |
| 55 | - | |
| 55 | + | end |
| 56 | - | inputList() |
| 56 | + | |
| 57 | - | |
| 57 | + | inputList() |
| 58 | - | function list() |
| 58 | + | |
| 59 | - | clear() |
| 59 | + | function list() |
| 60 | - | x, y, length = 3, 3, 0 |
| 60 | + | clear() |
| 61 | - | for i,v in pairs(inList) do |
| 61 | + | x, y, length = 3, 3, 0 |
| 62 | - | print(v) |
| 62 | + | for i,v in pairs(inList) do |
| 63 | - | printToMon(v, x + length, y) |
| 63 | + | z, t = maxX - oX, maxY - oY |
| 64 | - | x = x + 3 + length |
| 64 | + | if x + string.len(v) >= z then |
| 65 | - | length = string.len(v) |
| 65 | + | y = y + 2 |
| 66 | - | z, t = maxX - oX, maxY - oY |
| 66 | + | x = 3 |
| 67 | - | if x + length >= z then |
| 67 | + | length = 0 |
| 68 | - | y = y + 2 |
| 68 | + | end |
| 69 | - | x = 3 |
| 69 | + | printToMon(v, x + length, y) |
| 70 | - | length = 0 |
| 70 | + | x = x + 3 + length |
| 71 | - | end |
| 71 | + | length = string.len(v) |
| 72 | - | end |
| 72 | + | end |
| 73 | end | |
| 74 | - | |
| 74 | + | |
| 75 | - | function mainScreen() |
| 75 | + | function mainScreen() |
| 76 | - | list() |
| 76 | + | list() |
| 77 | end | |
| 78 | - | |
| 78 | + | |
| 79 | - | while true do |
| 79 | + | while true do |
| 80 | - | mainScreen() |
| 80 | + | mainScreen() |
| 81 | - | printToMon("x", 32, 32) |
| 81 | + | printToMon("x", 3, 3)
|
| 82 | - | _, s, x, y, b, user = e.pull("touch") |
| 82 | + | _, s, x, y, b, user = e.pull("touch")
|
| 83 | - | printToMon("t", x, y) |
| 83 | + | printToMon("t", x, y)
|
| 84 | - | for i,v in pairs(inList) do |
| 84 | + | for i,v in pairs(inList) do |
| 85 | - | if l <= x and string.len(v) >= x and n == y then |
| 85 | + | if l <= x and string.len(v) >= x and n == y then |
| 86 | - | Input(i) |
| 86 | + | Input(i) |
| 87 | - | end |
| 87 | + | end |
| 88 | - | length = string.len(v) |
| 88 | + | length = string.len(v) |
| 89 | - | l = l + 3 + length |
| 89 | + | l = l + 3 + length |
| 90 | - | if l >= maxX then |
| 90 | + | if l >= maxX then |
| 91 | - | l = 3 |
| 91 | + | l = 3 |
| 92 | - | n = n + 2 |
| 92 | + | n = n + 2 |
| 93 | - | end |
| 93 | + | end |
| 94 | - | end |
| 94 | + | end |
| 95 | end |