-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGhostController.java
More file actions
168 lines (138 loc) · 3.24 KB
/
GhostController.java
File metadata and controls
168 lines (138 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
public class GhostController {
StickValues stickValues=new StickValues();
ButtonValues buttonValues=new ButtonValues();
private String instructions;
private int pos=0;
private int waitFor=0;
public GhostController(String str) {
instructions=str;
}
private String getNextValue() {
String value="";
while(pos<instructions.length())
{
if(instructions.charAt(pos)==' ')
{
pos+=1;
return value;
}
else if(pos==instructions.length()-1)
{
value+=instructions.charAt(pos);
pos+=1;
return value;
}
else
{
value+=instructions.charAt(pos);
}
pos+=1;
}
return "";
}
public boolean areInstructionsLeft() {
return pos<instructions.length();
}
public void update() {
if(areInstructionsLeft())
{
if(waitFor==0)
{
String val=getNextValue();
String beforeColon="";
String afterColon="";
boolean foundColon=false;
for(int i=0;i<val.length();i++)
{
if(!foundColon)
{
if(val.charAt(i)==':')
{
foundColon=true;
}
else
{
beforeColon+=val.charAt(i);
}
}
else
{
afterColon+=val.charAt(i);
}
}
if(foundColon)
{
if(afterColon.equals("true"))
{
buttonValues.setValue(beforeColon,true);
}
else if(afterColon.equals("false"))
{
buttonValues.setValue(beforeColon,false);
}
else
{
stickValues.setValue(beforeColon,Double.parseDouble(afterColon));
}
update();
}
else
{
waitFor=Integer.parseInt(beforeColon)-1;
}
}
else
{
waitFor-=1;
}
}
else
{
if(waitFor>0)
{
waitFor-=1;
}
else
{
buttonValues.reset();
stickValues.reset();
}
}
}
public double leftStickY() {
return stickValues.getValue(StickValues.leftStickY);
}
public double leftStickX() {
return stickValues.getValue(StickValues.leftStickX);
}
public double rightStickY() {
return stickValues.getValue(StickValues.rightStickY);
}
public double rightStickX() {
return stickValues.getValue(StickValues.rightStickX);
}
public boolean buttonA() {
return buttonValues.getValue(ButtonValues.buttonA);
}
public boolean buttonB() {
return buttonValues.getValue(ButtonValues.buttonB);
}
public boolean buttonX() {
return buttonValues.getValue(ButtonValues.buttonX);
}
public boolean buttonY() {
return buttonValues.getValue(ButtonValues.buttonY);
}
public boolean dpadUp() {
return buttonValues.getValue(ButtonValues.dpadUp);
}
public boolean dpadDown() {
return buttonValues.getValue(ButtonValues.dpadDown);
}
public boolean dpadLeft() {
return buttonValues.getValue(ButtonValues.dpadLeft);
}
public boolean dpadRight() {
return buttonValues.getValue(ButtonValues.dpadRight);
}
}