From c1b69da322e62a508c990180fe7c9c547f3f9207 Mon Sep 17 00:00:00 2001 From: MajorDzaster Date: Thu, 28 Sep 2023 18:30:36 +1000 Subject: [PATCH] Revert "Implemented the wave timer pausing when the pause menu is opened. ISSUE: The wave timer entity isn't present in MainGameScreen, so it can't be passed to the pause menu at present. Fixing this is the next objective for this task." This reverts commit e0957973bdbd1b9fdb0f827d961f28fccdb59601. --- .../maingame/MainGamePauseDisplay.java | 7 +++--- .../pausemenu/PauseMenuTimeStopComponent.java | 11 +------- .../game/components/tasks/SpawnWaveTask.java | 25 +++---------------- .../entities/factories/PauseMenuFactory.java | 6 ++--- .../csse3200/game/screens/MainGameScreen.java | 5 +--- 5 files changed, 10 insertions(+), 44 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java index cf2f129ed..eb8a0b273 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java @@ -19,12 +19,11 @@ public class MainGamePauseDisplay extends UIComponent { private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class); private static final float Z_INDEX = 2f; private Table table; + private GdxGame game; - private Entity waveSpawner; - public MainGamePauseDisplay(GdxGame screenSwitchHandle, Entity waveSpawner) { + public MainGamePauseDisplay(GdxGame screenSwitchHandle) { game = screenSwitchHandle; - this.waveSpawner = waveSpawner; } @Override @@ -46,7 +45,7 @@ private void addActors() { @Override public void changed(ChangeEvent changeEvent, Actor actor) { logger.debug("Pause button clicked"); - PauseMenuFactory.createPauseMenu(game, waveSpawner); + PauseMenuFactory.createPauseMenu(game); } }); diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java index 6503add30..285fad8e2 100644 --- a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java @@ -11,14 +11,7 @@ public class PauseMenuTimeStopComponent extends Component { private Array freezeList; - private Entity waveSpawner; - - /** - * Initialises the component. - * @param waveSpawner The entity that controls the wave spawning timer. - */ - public PauseMenuTimeStopComponent(Entity waveSpawner) { - this.waveSpawner = waveSpawner; + public PauseMenuTimeStopComponent() { } /** @@ -26,7 +19,6 @@ public PauseMenuTimeStopComponent(Entity waveSpawner) { */ @Override public void create() { - waveSpawner.getEvents().trigger("toggleWaveTimer"); freezeList = ServiceLocator.getEntityService().getEntities(); for (Entity pauseTarget : freezeList) { if (pauseTarget.getId() != getEntity().getId()) { @@ -41,7 +33,6 @@ public void create() { */ @Override public void dispose() { - waveSpawner.getEvents().trigger("toggleWaveTimer"); for (Entity pauseTarget : freezeList) { pauseTarget.setEnabled(true); } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java index 4150363aa..d6c4a3d85 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java @@ -12,8 +12,6 @@ public class SpawnWaveTask extends DefaultTask implements PriorityTask { private final GameTime globalTime; private long endTime = 0; private final int SPAWNING_INTERVAL = 10; - private boolean wavesPaused = false; - private long pauseTime = 0; public SpawnWaveTask() { this.globalTime = ServiceLocator.getTimeSource(); } @@ -27,30 +25,13 @@ public int getPriority() { public void start() { super.start(); endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000); - this.owner.getEntity().getEvents().addListener("toggleWaveTimer", this::toggleWaveTimer); } @Override public void update() { - if (!wavesPaused) { - if (globalTime.getTime() >= endTime) { - this.owner.getEntity().getEvents().trigger("spawnWave"); - endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time - } - } - } - - /** - * Function for pausing the wave timer when the pause menu is opened, and resuming it when the pause menu is closed. - */ - private void toggleWaveTimer() { - if (!wavesPaused) { - pauseTime = globalTime.getTime(); - wavesPaused = true; - } else { - // Offsets the next wave spawn by however long the game was paused. - endTime += globalTime.getTime() - pauseTime; - wavesPaused = false; + if (globalTime.getTime() >= endTime) { + this.owner.getEntity().getEvents().trigger("spawnWave"); + endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time } } } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java index bfd524ee7..fdb3a4204 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java @@ -12,13 +12,11 @@ public class PauseMenuFactory { /** * Creates the pause menu - * @param game The Gdx game instance that handles screen changes. - * @param waveSpawner The entity that handles the wave spawn timer * @return entity */ - public static Entity createPauseMenu(GdxGame game, Entity waveSpawner) { + public static Entity createPauseMenu(GdxGame game) { Entity pauseMenu = new Entity() - .addComponent(new PauseMenuTimeStopComponent(waveSpawner)) + .addComponent(new PauseMenuTimeStopComponent()) .addComponent(new PauseMenuRenderComponent()) .addComponent(new PauseMenuContinueButton()) .addComponent(new PauseMenuSettingsButton(game)) diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 77bdd47ea..a56755b6e 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -202,10 +202,7 @@ private void createUI() { .addComponent(new MainGameActions(this.game)) .addComponent(new MainGameExitDisplay()) .addComponent(new MainGameLoseDisplay()) - // WHERE'S THE WAVE SPAWNER, HOW IS THIS GAME FUNCTIONING WHEN IT DOESN'T EVEN MAKE A WAVE SPAWNER - // I'm told there's a new entity for the SpawnWaveTask, maybe it'll actually be accessible in this class. - // fyi there REALLY shouldn't be a null arg, but I need to push this before I can fix the issue. - .addComponent(new MainGamePauseDisplay(this.game, null)) + .addComponent(new MainGamePauseDisplay(this.game)) .addComponent(new Terminal()) .addComponent(inputComponent) .addComponent(new TerminalDisplay());