From 0263edf91d32f00fead8ae7ca2e660c098a9ce18 Mon Sep 17 00:00:00 2001 From: BenjaminAmos <24301287+BenjaminAmos@users.noreply.github.com> Date: Sun, 5 Nov 2023 16:40:53 +0000 Subject: [PATCH] fix: fix tutorial crash when waypoint removed (#691) --- .../game/tutorial/TutorialManager.java | 2 +- .../steps/FlyToHeroFirstWaypointStep.java | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/engine/src/main/java/org/destinationsol/game/tutorial/TutorialManager.java b/engine/src/main/java/org/destinationsol/game/tutorial/TutorialManager.java index 488f5f362..a826ed6a9 100644 --- a/engine/src/main/java/org/destinationsol/game/tutorial/TutorialManager.java +++ b/engine/src/main/java/org/destinationsol/game/tutorial/TutorialManager.java @@ -228,7 +228,7 @@ public void start() { solGame.get().getScreens().mapScreen.getCloseButton(), solGame.get().getScreens().mapScreen, "Close the map."), - new FlyToHeroFirstWaypointStep("Fly to your waypoint."), + new FlyToHeroFirstWaypointStep("Fly to your waypoint.", "Create a waypoint near your ship."), new ChangeTutorialSectionStep("Planets"), new FlyToPlanetSellingMercenariesStep("Head towards a planet.", "Look for the planetary station."), new ChangeTutorialSectionStep("Mercenaries"), diff --git a/engine/src/main/java/org/destinationsol/game/tutorial/steps/FlyToHeroFirstWaypointStep.java b/engine/src/main/java/org/destinationsol/game/tutorial/steps/FlyToHeroFirstWaypointStep.java index f218c9b0a..1a2f00292 100644 --- a/engine/src/main/java/org/destinationsol/game/tutorial/steps/FlyToHeroFirstWaypointStep.java +++ b/engine/src/main/java/org/destinationsol/game/tutorial/steps/FlyToHeroFirstWaypointStep.java @@ -25,24 +25,39 @@ * A tutorial step that completes when the player ship reaches a nearby spawned waypoint. */ public class FlyToHeroFirstWaypointStep extends FlyToWaypointStep { + private final String missingWaypointMessage; + @Inject protected FlyToHeroFirstWaypointStep() { throw new RuntimeException("Attempted to instantiate TutorialStep via DI. This is not supported."); } - public FlyToHeroFirstWaypointStep(String message) { + public FlyToHeroFirstWaypointStep(String message, String missingWaypointMessage) { super(Vector2.Zero, message); + this.missingWaypointMessage = missingWaypointMessage; } @Override public void start() { - waypoint = game.getHero().getWaypoints().get(0); - setTutorialText(message); + Hero hero = game.getHero(); + if (hero.getWaypoints().isEmpty()) { + setTutorialText(missingWaypointMessage); + } else { + waypoint = game.getHero().getWaypoints().get(0); + setTutorialText(message); + } } @Override public boolean checkComplete(float timeStep) { Hero hero = game.getHero(); + if (hero.getWaypoints().isEmpty()) { + setTutorialText(missingWaypointMessage); + return false; + } else { + setTutorialText(message); + } + if (!hero.getWaypoints().contains(waypoint) && hero.getWaypoints().size() > 0) { // Change the target waypoint just in-case the player removes it. waypoint = hero.getWaypoints().get(0);