Skip to content

Commit

Permalink
fix: handle if no previous states
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonHough committed Jun 10, 2024
1 parent 819e7c5 commit 15ab895
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void Initialize()

private void OnStateChanged(StateType current, StateType previous)
{
backButton.gameObject.SetActive(!CanShowBackButton(current));
backButton.gameObject.SetActive(CanShowBackButton(current, previous));
saveButton.gameObject.SetActive(current == StateType.Editor);

if (current == StateType.End)
Expand All @@ -112,9 +112,9 @@ private void OnStateChanged(StateType current, StateType previous)
}
}

private bool CanShowBackButton(StateType current)
private bool CanShowBackButton(StateType current, StateType previous)
{
return current == StateType.LoginWithCodeFromEmail || current == StateType.AvatarSelection;
return current != startingState && current != previous;
}

public void OnCustomizeDraft(string avatarId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ protected void ClearPreviousStates()
public void GoToPreviousState()
{
var previousState = currentState;

if (currentState == StateType.None || previousStates.Count == 0) return;

DeactivateState(stateTypeMap[previousState]);

if (previousStates.Count == 0)
{
return;
}
currentState = previousStates.Pop();
if (currentState != StateType.None)
{
ActivateState(stateTypeMap[currentState]);
StateChanged?.Invoke(currentState, previousState);
}
ActivateState(stateTypeMap[currentState]);
StateChanged?.Invoke(currentState, previousState);
}

private void ActivateState(State state)
Expand Down

0 comments on commit 15ab895

Please sign in to comment.