SHOW:
|
|
- or go back to the newest paste.
1 | local mon = peripheral.wrap("top") | |
2 | local selected = 0 | |
3 | - | local names = {"Anti","FS","Xun","Ninjuni"} |
3 | + | local names = {"Anti","Gau","Xun","Ninjuni"} |
4 | - | local cableSide = "bottom" |
4 | + | local cableSide = "back" |
5 | ||
6 | local XunSwitchIn = colors.pink | |
7 | local XunToggleOut = colors.red | |
8 | local FSMainSwitchOut = colors.black | |
9 | ||
10 | local FSMainSwitchState = 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 ) then return 2 end |
28 | + | if ( FSMainSwitchState == false ) then return 2 end |
29 | if ( CheckSwitch(XunSwitchIn) ) then return 3 end | |
30 | return 4 | |
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 | |
59 | ||
60 | if ( XunNew ~= CheckSwitch(XunSwitchIn) ) then pulse(XunToggleOut) end | |
61 | ||
62 | if ( FSMainSwitchState ) then rs.setBundledOutput(cableSide,FSMainSwitchOut) | |
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 | |
72 | SetTrack(true,false) | |
73 | end | |
74 | if ( row == 2 ) then | |
75 | SetTrack(false,false) | |
76 | end | |
77 | if ( row == 3 ) then | |
78 | - | SetTrack(false,true) |
78 | + | SetTrack(true,true) |
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 |