Skip to content

Commit

Permalink
fix: fix tutorial crash when waypoint removed (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminAmos authored Nov 5, 2023
1 parent 971155f commit 0263edf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0263edf

Please sign in to comment.