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:
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user