ControllerClient can retrieve valid protocol code from each key press
- ControlKey now includes protocolCode property - RaceController now fires action with each key press - Shift toggles sail state appropriately #story[1089]
This commit is contained in:
@@ -101,6 +101,7 @@ public class RaceController extends Controller {
|
||||
if(controlKey != null) {
|
||||
try {
|
||||
controllerClient.sendKey(controlKey);
|
||||
controlKey.onAction(); // Change key state if applicable
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ public class ControllerClient {
|
||||
*/
|
||||
public void sendKey(ControlKey key) throws IOException {
|
||||
// TODO - get and send action number currently corresponding to key (context dependent)
|
||||
System.out.println(key.toString());
|
||||
System.out.println(key.toString() + ": " + key.getProtocolCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,29 @@ import javafx.scene.input.KeyCode;
|
||||
public abstract class ControlKey {
|
||||
|
||||
private String name;
|
||||
protected int protocolCode;
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
* Constructor for key state with specified protocol code
|
||||
* @param name of action
|
||||
* @param protocolCode -1 if not sent
|
||||
*/
|
||||
public ControlKey(String name, int protocolCode) {
|
||||
this.name = name;
|
||||
this.protocolCode = protocolCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for key state not sent over network
|
||||
* @param name name of the key
|
||||
*/
|
||||
public ControlKey(String name){
|
||||
this.name = name;
|
||||
this.protocolCode = -1;
|
||||
}
|
||||
|
||||
public int getProtocolCode() {
|
||||
return protocolCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DownWindKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public DownWindKey(String name) {
|
||||
super(name);
|
||||
super(name, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,12 +11,15 @@ public class SailsToggleKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public SailsToggleKey(String name) {
|
||||
super(name);
|
||||
super(name, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle command associated with sails key
|
||||
*/
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
protocolCode = protocolCode == 2? 1 : 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TackGybeKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public TackGybeKey(String name) {
|
||||
super(name);
|
||||
super(name, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ public class UpWindKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public UpWindKey(String name) {
|
||||
super(name);
|
||||
super(name, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ public class VMGKey extends ControlKey{
|
||||
* @param name name of the key
|
||||
*/
|
||||
public VMGKey(String name) {
|
||||
super(name);
|
||||
super(name, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user