Skip to content

Commit

Permalink
Add option to pause the practice timer while near a checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bobofromkirby64 committed Mar 6, 2024
1 parent 02f7236 commit 0d69a77
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Content/Text/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"SpeedrunUtils_PauseOptions": "SpeedrunUtils Options",
"SpeedrunUtils_RecollectItems": "Recollect Collectibles",
"SpeedrunUtils_PracticeTimer": "Practice Timer",
"SpeedrunUtils_PracticeTimer_PauseInMenu": "Pause the timer while the menu is open"
"SpeedrunUtils_PracticeTimer_PauseInMenu": "Pause practice timer while menu is open",
"SpeedrunUtils_PracticeTimer_PauseNearCheckpoint": "Pause practice timer while near a checkpoint"
},
"Dialog":
{
Expand Down
28 changes: 18 additions & 10 deletions Source/Actors/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ private Vec3 SolidWaistTestPos
private Vec3 SolidHeadTestPos
=> Position + Vec3.UnitZ * 10;

public bool InCheckpointRange = false;

private bool InFeatherState
=> stateMachine.State == States.FeatherStart
|| stateMachine.State == States.Feather;
Expand All @@ -188,17 +190,16 @@ public bool IsAbleToPause
&& stateMachine.State != States.Cassette
&& stateMachine.State != States.Dead;

public bool IsMidPickup
=> stateMachine.State == States.StrawbGet
|| stateMachine.State == States.Cassette;

public bool IsActive
=> stateMachine.State != States.StrawbGet
&& stateMachine.State != States.Cassette
&& stateMachine.State != States.StrawbReveal
&& stateMachine.State != States.Respawn
&& stateMachine.State != States.Dead;
public bool IsMidPickup
=> stateMachine.State == States.StrawbGet
|| stateMachine.State == States.Cassette;

public bool IsActive
=> stateMachine.State != States.StrawbGet
&& stateMachine.State != States.Cassette
&& stateMachine.State != States.StrawbReveal
&& stateMachine.State != States.Respawn
&& stateMachine.State != States.Dead;

public Player()
{
Expand Down Expand Up @@ -391,12 +392,19 @@ public override void Update()
// pickups
if (IsAbleToPickup)
{
InCheckpointRange = false;

foreach (var actor in World.All<IPickup>())
{
if (actor is IPickup pickup)
{
if ((SolidWaistTestPos - actor.Position).LengthSquared() < pickup.PickupRadius * pickup.PickupRadius)
{
if (actor is Checkpoint)
InCheckpointRange = true;

pickup.Pickup(this);
}
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion Source/Data/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ public void ResetSpeedrunPracticeTime()
/// </summary>
public bool SpeedrunPracticeTimer { get; set; } = false;

// If the Speedrun Timer should be paused when it is in "practice" mode and the pause menu is open
// If the Speedrun Timer should be paused when practice mode is enabled and the pause menu is open
public bool SpeedrunPracticeTimerPauseInMenu { get; set; } = false;

// If the Speedrun Timer should be paused when practice mode is enabled and the player is within range of a checkpoint
public bool SpeedrunPracticeTimerPauseNearCheckpoint { get; set; } = false;

/// <summary>
/// 0-10 Music volume level
/// </summary>
Expand Down Expand Up @@ -187,6 +190,11 @@ public void ToggleSpeedrunPracticeTimerPauseInMenu()
SpeedrunPracticeTimerPauseInMenu = !SpeedrunPracticeTimerPauseInMenu;
}

public void ToggleSpeedrunPracticeTimerPauseNearCheckpoint()
{
SpeedrunPracticeTimerPauseNearCheckpoint = !SpeedrunPracticeTimerPauseNearCheckpoint;
}

public TimeSpan GetCurrentDisplayTime()
{
return SpeedrunPracticeTimer
Expand Down
10 changes: 8 additions & 2 deletions Source/Scenes/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public enum EntryReasons { Entered, Returned, Respawned }

private bool IsPlayerActive => Get<Player>() is {} player && player.IsActive;

private bool IsPlayerInCheckpointRange => Get<Player>() is {} player && player.InCheckpointRange;

private bool IsPauseEnabled
{
get
Expand Down Expand Up @@ -98,6 +100,7 @@ public World(EntryInfo entry)
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_RecollectItems"), Save.Instance.ToggleSpeedrunRecollectItems, () => Save.Instance.SpeedrunRecollectItems));
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer"), Save.Instance.ToggleSpeedrunPracticeTime, () => Save.Instance.SpeedrunPracticeTimer));
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer_PauseInMenu"), Save.Instance.ToggleSpeedrunPracticeTimerPauseInMenu, () => Save.Instance.SpeedrunPracticeTimerPauseInMenu));
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer_PauseNearCheckpoint"), Save.Instance.ToggleSpeedrunPracticeTimerPauseNearCheckpoint, () => Save.Instance.SpeedrunPracticeTimerPauseNearCheckpoint));

pauseMenu.Title = Loc.Str("PauseTitle");
pauseMenu.Add(new Menu.Option(Loc.Str("PauseResume"), () => SetPaused(false)));
Expand Down Expand Up @@ -300,8 +303,11 @@ public override void Update()
Game.Instance.Music.Set("at_baddy", 1);
}

// increment practice timer (if not in the ending area)
if (IsPlayerActive && !IsInEndingArea && !(Save.Instance.SpeedrunPracticeTimerPauseInMenu && Paused))
// increment practice timer
if (IsPlayerActive &&
!IsInEndingArea &&
!(Save.Instance.SpeedrunPracticeTimerPauseNearCheckpoint && IsPlayerInCheckpointRange) &&
!(Save.Instance.SpeedrunPracticeTimerPauseInMenu && Paused))
{
Save.CurrentRecord.SpeedrunPracticeTime += TimeSpan.FromSeconds(Time.Delta);
}
Expand Down

0 comments on commit 0d69a77

Please sign in to comment.