View difference between Paste ID: tE06gPGW and EG29K9Rh
SHOW: | | - or go back to the newest paste.
1
local mon = peripheral.wrap("top")
2
local selected = 0
3-
local names = {"Anti","Gau","Xun","Ninjuni"}
3+
local names = {"Gau","Xun","FS"}
4-
local cableSide = "back"
4+
local cableSide = "bottom"
5
6-
local XunSwitchIn = colors.pink
6+
local GauSwitchIn = colors.pink
7-
local XunToggleOut = colors.red
7+
local GauToggleOut = colors.red
8-
local FSMainSwitchOut = colors.black
8+
local XunMainSwitchOut = colors.black
9
10-
local FSMainSwitchState = false
10+
local XunMainSwitchState = false
11
12
function SetColor(row)
13
	if ( selected == row ) then
14
		mon.setTextColor(colors.black)
15
		mon.setBackgroundColor(colors.white)
16
	else
17
		mon.setTextColor(colors.white)
18
		mon.setBackgroundColor(colors.black)
19
	end
20
end
21
22
function CheckSwitch(color)
23
	local state = rs.getBundledInput(cableSide)
24
	return colors.test(state,color)
25
end
26
27
function getSelected()
28-
	if ( FSMainSwitchState == false ) then return 2 end
28+
	if ( XunMainSwitchState == true ) then return 2 end
29-
	if ( CheckSwitch(XunSwitchIn) ) then return 3 end
29+
	if ( CheckSwitch(GauSwitchIn) ) then return 1 end
30-
	return 4
30+
	return 3
31
end
32
33
function FindSelected()
34
	selected = getSelected()
35
end
36
37
function DrawScreen()
38
	if ( selected == 0 ) then FindSelected() end
39
	mon.clear()
40
	for row = 1,#names do
41
		mon.setCursorPos(1,row)
42
		SetColor(row)
43
		mon.write(names[row])
44
	end
45
	SetColor(-1)
46
end
47
48
function pulse(color)
49
	local oldColor = rs.getBundledOutput(cableSide)
50
	local newColor = colors.combine(color,oldColor)
51
	rs.setBundledOutput(cableSide,newColor)
52
	os.sleep(0.2)
53
	rs.setBundledOutput(cableSide,oldColor)
54
55
end
56
57
function SetTrack(FSnew,XunNew)
58-
	FSMainSwitchState = FSnew
58+
	XunMainSwitchState = FSnew
59
	
60-
	if ( XunNew ~= CheckSwitch(XunSwitchIn) ) then pulse(XunToggleOut) end
60+
	if ( XunNew ~= CheckSwitch(GauSwitchIn) ) then pulse(GauToggleOut) end
61
	
62-
	if ( FSMainSwitchState ) then rs.setBundledOutput(cableSide,FSMainSwitchOut)
62+
	if ( XunMainSwitchState ) then rs.setBundledOutput(cableSide,XunMainSwitchOut)
63
	else rs.setBundledOutput(cableSide,0) end
64
65
end
66
67
function NewTrack(row)
68
	if ( row > #names ) then return end
69
	if ( row == selected ) then return end
70
	
71-
	if ( row == 1 or row == 4 ) then
71+
	if ( row == 1 ) then
72
		SetTrack(false,true)
73
	end
74
	if ( row == 2 ) then
75
		SetTrack(true,false)
76
	end
77
	if ( row == 3 ) then
78-
		SetTrack(true,true)
78+
79
	end
80
	selected = row
81
	DrawScreen()
82
end
83
84
85
print("Railcontroler. Right click on monitor name to select track")
86
DrawScreen()
87
while true do
88
	event,p1,p2,p3 = os.pullEvent()
89
	if ( event == "monitor_touch" ) then NewTrack(p3) end
90
	if ( event == "redstone" ) then 
91
		FindSelected()
92
		DrawScreen()
93
	end
94
	
95
end