Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Redcontrol v1.1 by qwertyMAN
- local term = require("term")
- local event = require("event")
- local component = require("component")
- local redstone = component.redstone
- local gpu = component.gpu
- local disp = {gpu.getResolution()}
- local Foreground = gpu.getForeground()
- local Background = gpu.getBackground()
- local string = string
- local my_address = 1
- local address = {}
- local red = {}
- local bundled = {}
- local save_red = {}
- local save_bundled = {}
- local name = "Redcontrol v1.1 by qwertyMAN"
- local exit = false
- local width = 87
- local height = 20
- local timeout = 1
- local color = {
- [0] = 0xffffff,
- [1] = 0xff7f00,
- [2] = 0xff00ff,
- [3] = 0x7f7fff,
- [4] = 0xffff00,
- [5] = 0x7fff00,
- [6] = 0xff7fff,
- [7] = 0x7f7f7f,
- [8] = 0xbfbfbf,
- [9] = 0x007fff,
- [10] = 0x7f007f,
- [11] = 0x0000ff,
- [12] = 0x7f3f00,
- [13] = 0x00ff00,
- [14] = 0xff0000,
- [15] = 0x000000,
- back = 0x000000,
- foreg = 0xffffff
- }
- local sides = {
- [0] = "down ",
- [1] = "up ",
- [2] = "back ",
- [3] = "front",
- [4] = "left ",
- [5] = "right"
- }
- local function draw()
- term.clear()
- gpu.set(2, 1, name)
- local n,m = string.len(#address),string.len(my_address)
- gpu.set(width-10-n-m, 1, tostring(my_address .. "/" .. #address))
- gpu.setBackground(color[4])
- gpu.setForeground(color[15])
- gpu.set(width-8, 1, "<")
- gpu.set(width-6, 1, ">")
- gpu.setBackground(color[14])
- gpu.set(width-4, 1, " X")
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- for i=0,5 do
- local y = 4+i*3
- red[i] = redstone.getInput(i)
- bundled[i] = redstone.getBundledInput(i)
- save_red[i] = red[i]
- save_bundled[i] = {}
- gpu.set(2, y-1, sides[i])
- gpu.setBackground(color[14])
- if redstone.getOutput(i)==0 then
- gpu.set(2, y, " ")
- else
- gpu.setForeground(color[15])
- gpu.set(2, y, "G")
- end
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- if red[i]==0 then
- gpu.set(3, y, " ")
- else
- gpu.setBackground(color[14])
- gpu.set(3, y, " ")
- gpu.set(3, y, tostring(red[i]))
- gpu.setBackground(color.back)
- end
- for j=0, 15 do
- save_bundled[i][j] = bundled[i][j]
- gpu.setBackground(color[j])
- if redstone.getBundledOutput(i,j)==0 then
- gpu.set(7+j*5, y, " ")
- else
- if j==10 or j==11 or j==15 then
- gpu.setForeground(color[0])
- else
- gpu.setForeground(color[15])
- end
- gpu.set(7+j*5, y, "G")
- end
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- if bundled[i][j]==0 then
- gpu.set(8+j*5, y, " ")
- else
- gpu.setBackground(color[j])
- gpu.set(8+j*5, y, " ")
- if not (j==10 or j==11 or j==15) then
- gpu.setForeground(color[15])
- end
- gpu.set(8+j*5, y, tostring(bundled[i][j]))
- end
- end
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- end
- end
- local function changed(_,add,side)
- if redstone.address == add then
- red[side] = redstone.getInput(side)
- bundled[side] = redstone.getBundledInput(side)
- local y = 4+side*3
- if red[side]~= save_red[side] then
- if red[side]==0 then
- gpu.set(3, y, " ")
- else
- gpu.setBackground(color[14])
- gpu.set(3, y, " ")
- gpu.set(3, y, tostring(red[side]))
- gpu.setBackground(color.back)
- end
- else
- for i=0, #bundled[side] do
- if bundled[side][i]~=save_bundled[side][i] then
- if bundled[side][i]==0 then
- gpu.set(8+i*5, y, " ")
- else
- gpu.setBackground(color[i])
- gpu.set(8+i*5, y, " ")
- if not (i==10 or i==11 or i==15) then
- gpu.setForeground(color[15])
- end
- gpu.set(8+i*5, y, tostring(bundled[side][i]))
- gpu.setForeground(color.foreg)
- gpu.setBackground(color.back)
- end
- break
- end
- end
- end
- save_red[side] = red[side]
- save_bundled[side] = {}
- for i=0, 15 do
- save_bundled[side][i] = bundled[side][i]
- end
- end
- end
- local function added(_,add)
- table.insert(address,add)
- local n,m = string.len(#address),string.len(my_address)
- gpu.set(width-10-n-m, 1, tostring(my_address .. "/" .. #address))
- end
- local function removed(_,add)
- for i=1, #address do
- if address[i]==add then
- if redstone.address == add then
- if i == 1 then
- redstone = component.proxy(address[my_address+1])
- else
- my_address = my_address - 1
- redstone = component.proxy(address[my_address])
- end
- draw()
- end
- table.remove(address,i)
- break
- end
- end
- local n,m = string.len(#address),string.len(my_address)
- gpu.set(width-10-n-m, 1, tostring(my_address .. "/" .. #address))
- end
- local function touch(_,_,x,y)
- local side = (y-4)/3
- if side==math.modf(side) then
- if x<5 and x>1 then
- gpu.setBackground(color[14])
- if redstone.getOutput(side)==0 then
- redstone.setOutput(side,15)
- gpu.setForeground(color[15])
- gpu.set(2, y, "G")
- else
- redstone.setOutput(side,0)
- gpu.set(2, y, " ")
- end
- gpu.setBackground(color.back)
- elseif y==1 then
- if x==width-8 then
- if my_address == 1 then
- my_address = #address
- else
- my_address = my_address-1
- end
- redstone = component.proxy(address[my_address])
- draw()
- elseif x==width-6 then
- if my_address == #address then
- my_address = 1
- else
- my_address = my_address+1
- end
- redstone = component.proxy(address[my_address])
- draw()
- elseif x>width-5 then
- exit = true
- end
- else
- local n = math.modf((x-7)/5)
- gpu.setBackground(color[n])
- if redstone.getBundledOutput(side,n)==0 then
- redstone.setBundledOutput(side,n,255)
- if n==10 or n==11 or n==15 then
- gpu.setForeground(color[0])
- else
- gpu.setForeground(color[15])
- end
- gpu.set(7+n*5, y, "G")
- else
- redstone.setBundledOutput(side,n,0)
- gpu.set(7+n*5, y, " ")
- end
- end
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- end
- end
- local function start()
- event.shouldInterrupt = function() return false end
- event.listen("touch", touch)
- event.listen("redstone_changed", changed)
- event.listen("component_added", added, nil,"redstone")
- event.listen("component_removed", removed, nil,"redstone")
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- gpu.setResolution(width, height)
- for add in component.list("redstone") do
- table.insert(address,add)
- end
- redstone = component.proxy(address[my_address])
- for i=1, #address do
- if address[i] == redstone.address then
- my_address = i
- break
- end
- end
- draw()
- while true do
- os.sleep(timeout)
- if exit then
- break
- end
- end
- event.ignore("touch", touch)
- event.ignore("redstone_changed", changed)
- event.ignore("component_added", added)
- event.ignore("component_removed", removed)
- term.clear()
- print("Good bye!")
- os.sleep(1)
- gpu.setBackground(Background)
- gpu.setForeground(Foreground)
- gpu.setResolution(disp[1], disp[2])
- term.clear()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement