Added Modularity to Input Checker.

- Added onHold
 - Added onRelease
 - Added ManualTesting Class in the tests
 - Added Unimplemented new methods to classes
 #story[1006]
This commit is contained in:
Fan-Wu Yang
2017-07-24 02:03:33 +12:00
parent f9b2a62f8d
commit d6d195f381
12 changed files with 143 additions and 13 deletions
@@ -33,9 +33,6 @@ public class App extends Application {
Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800);
InputChecker inputChecker = new InputChecker();
inputChecker.runWithScene(scene);
stage.setScene(scene);
stage.setTitle("RaceVision - Team 7");
stage.show();
@@ -7,6 +7,8 @@ import seng302.gameController.Keys.KeyFactory;
import java.util.HashMap;
import static javafx.application.Application.launch;
/**
* Class for checking what keys are currently being used
*/
@@ -21,12 +23,18 @@ public class InputChecker {
scene.setOnKeyPressed(event -> {
String codeString = event.getCode().toString();
if (!currentlyActiveKeys.containsKey(codeString)) {
ControlKey controlKey = KeyFactory.getKey(codeString);
controlKey.onAction();
currentlyActiveKeys.put(codeString, true);
}
});
scene.setOnKeyReleased(event ->
currentlyActiveKeys.remove(event.getCode().toString())
scene.setOnKeyReleased(event -> {
String codeString = event.getCode().toString();
ControlKey controlKey = KeyFactory.getKey(codeString);
controlKey.onRelease();
currentlyActiveKeys.remove(event.getCode().toString());
}
);
new AnimationTimer() {
@@ -35,7 +43,8 @@ public class InputChecker {
for (String key: currentlyActiveKeys.keySet()){
ControlKey controlKey = KeyFactory.getKey(key);
if (controlKey != null){
controlKey.onAction();
controlKey.onHold();
System.out.println(controlKey.toString() + " is Pressed.");
}
}
// for (String key : InputKeys.stringKeysMap.keySet()){
@@ -63,4 +72,5 @@ public class InputChecker {
return false;
}
}
}
@@ -20,8 +20,26 @@ public abstract class ControlKey {
this.keyCode = keyCode;
}
/**
* To String method
* @return returns the name of the key
*/
public String toString(){
return this.name;
}
/**
* What this key should do when the command is issued for it to do its job.
*/
public abstract void onAction();//may want to make it take in a visualiser and stuff in the future.
/**
* What to do when the key is held
*/
public abstract void onHold();
/**
* What to do when the key is released.
*/
public abstract void onRelease();
}
@@ -21,4 +21,14 @@ public class DownWindKey extends ControlKey {
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -21,4 +21,14 @@ public class SailsToggleKey extends ControlKey {
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -21,4 +21,14 @@ public class TackGybeKey extends ControlKey {
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -21,4 +21,14 @@ public class UpWindKey extends ControlKey {
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -21,4 +21,14 @@ public class VMGKey extends ControlKey{
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -15,4 +15,14 @@ public class ZoomInKey extends ControlKey {
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -21,4 +21,14 @@ public class ZoomOutKey extends ControlKey{
public void onAction() {
}
@Override
public void onHold() {
}
@Override
public void onRelease() {
}
}
@@ -0,0 +1,42 @@
package seng302;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import seng302.gameController.InputChecker;
/**
* Start to manually test the game controller
*/
public class GameControllerManualTest extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
Platform.exit();
System.exit(0);
}
});
GridPane root = new GridPane();
Scene scene = new Scene(root, 1200, 800);
InputChecker inputChecker = new InputChecker();
inputChecker.runWithScene(scene);
stage.setScene(scene);
stage.setTitle("RaceVision - Team 7 - Input Tester Manual Test");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}