Skip to content

Commit

Permalink
Merge pull request #657 from UQcsse3200/Moral-polish-test
Browse files Browse the repository at this point in the history
Moral polish test
  • Loading branch information
ImLeiSu authored Oct 17, 2024
2 parents 95153f8 + 0445441 commit 1ea74d1
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 419 deletions.
2 changes: 0 additions & 2 deletions source/core/src/main/com/csse3200/game/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ private Screen newScreen(ScreenType screenType) {
return new SettingsScreen(this);
case LOAD_GAME:
return new LoadGameScreen(this);
case CUTSCENE:
return new CutsceneScreen(this, CutsceneType.MORAL_2);
case MORAL_SCENE_1:
return new CutsceneScreen(this, CutsceneType.MORAL_1);
case MORAL_SCENE_2:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class TextDisplay extends UIComponent {
private long lastUpdate = 0L;
private final long delay = 100L;

private InputListener inputListener;

// Displaying variables
private boolean visible;
public Label label;
Expand Down Expand Up @@ -284,11 +286,9 @@ public void update() {
* of the text or clear the textbox from the screen
*/
private void setupInputListener() {
logger.info(TextDisplay.this.screen);
stage.addListener(new InputListener() {
inputListener = new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {

if (TextDisplay.this.screen.equals("cutscene")) {
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("we've pressed enter");
Expand All @@ -299,7 +299,7 @@ public boolean keyDown(InputEvent event, int keycode) {
return true;
} else if (TextDisplay.this.screen.equals("moralDecision")) {
Cutscene currentCutscene = ServiceLocator.getCurrentCutscene();
Boolean atEnd = currentCutscene.isAtEnd();
boolean atEnd = currentCutscene.isAtEnd();
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("at moral in textDisplay");
if (!atEnd) {
Expand All @@ -308,13 +308,11 @@ public boolean keyDown(InputEvent event, int keycode) {
label.setText(currentCutscene.currentText);
}
} else if (keycode == Input.Keys.Y && atEnd) {
logger.info("WE'RE ALMOST THERE");
currentCutscene = ServiceLocator.getCurrentCutscene();
currentCutscene.setTextForScene(currentCutscene.currentScene);

ServiceLocator.getDayNightService().getEvents().trigger("YesAtMoralDecision");
} else if (keycode == Input.Keys.N && atEnd) {
logger.info("WE'RE ALMOST THERE NO");
currentCutscene = ServiceLocator.getCurrentCutscene();
currentCutscene.setTextForScene(currentCutscene.currentScene);

Expand All @@ -324,7 +322,6 @@ public boolean keyDown(InputEvent event, int keycode) {
} else if (TextDisplay.this.screen.equals("backstory")) {
// Handling for backstory cutscenes
Cutscene currentCutscene = ServiceLocator.getCurrentCutscene();
Boolean atEnd = currentCutscene.isAtEnd();

// Check if the current text is "Press Enter to continue"
if (label.getText().toString().equals("Press Enter to continue")) {
Expand All @@ -339,11 +336,9 @@ public boolean keyDown(InputEvent event, int keycode) {
// Continue through the backstory cutscene normally
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("at backstory in textDisplay");
if (!atEnd) {
logger.info("parsing through backstory");
currentCutscene.setTextForScene(currentCutscene.currentScene);
label.setText(currentCutscene.currentText);
}
logger.info("parsing through backstory");
currentCutscene.setTextForScene(currentCutscene.currentScene);
label.setText(currentCutscene.currentText);
}
}
return true;
Expand All @@ -367,10 +362,15 @@ public boolean keyDown(InputEvent event, int keycode) {
}
return false;
}
});
};
stage.addListener(inputListener);
}






/**
* Overrides the draw method from the Actor class.
* This method is responsible for rendering the component.
Expand Down Expand Up @@ -448,5 +448,16 @@ private void setUpBackstoryLayout() {
// Add stack to the table
table.add(stack).padTop(100).size((int) (Gdx.graphics.getWidth() * 0.6), (int) (Gdx.graphics.getHeight() * 0.15));
}

/**
* Class used in unit tests to simulate keypress
* @param keycode: keycode realting to the key pressed
* @return whether the key was pressed
*/
public boolean simulateKeyPress(int keycode) {
InputEvent event = new InputEvent(); // Create a dummy InputEvent
event.setType(InputEvent.Type.keyDown);
return inputListener.keyDown(event, keycode);
}
}

Loading

0 comments on commit 1ea74d1

Please sign in to comment.