Skip to content

Wikigames: set initial currentState from Prefs#5354

Closed
cooltey wants to merge 16 commits into
mainfrom
use-saved-state-for-wikigames
Closed

Wikigames: set initial currentState from Prefs#5354
cooltey wants to merge 16 commits into
mainfrom
use-saved-state-for-wikigames

Conversation

@cooltey

@cooltey cooltey commented Feb 27, 2025

Copy link
Copy Markdown
Collaborator

What does this do?

This PR sets the current game state from the Prefs when the ViewModel is created.

Also moved the impression event to the end of onGameEnded() in the case of gameState being null.

https://phabricator.wikimedia.org/T387418

@Williamrai Williamrai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes looks good. I think with this change we can also remove this additional logic, since we are persisting the state.

else if (_gameState.value == null || ::currentState.isInitialized.not()) {
            "unknown"
        }

@Williamrai

Copy link
Copy Markdown
Collaborator

The changes looks good. I think with this change we can also remove this additional logic, since we are persisting the state.

else if (_gameState.value == null || ::currentState.isInitialized.not()) {
            "unknown"
        }

This has been resolved.

@cooltey cooltey requested a review from voyagerfan as a code owner February 28, 2025 20:44
@cooltey cooltey changed the title Use savedStateHandle for the events and currentState to prevent crashes Wikigames: Use savedStateHandle for the events and currentState to prevent crashes Feb 28, 2025
@cooltey cooltey added the Ready to merge PR passed design signoff and ready to be merged. label Mar 3, 2025
val langToState = totalState.langToState.toMutableMap()
langToState[wikiSite.languageCode] = currentState
Prefs.otdGameState = JsonUtil.encodeToString(TotalGameState(langToState)).orEmpty()
savedStateHandle[KEY_CURRENT_STATE] = JsonUtil.encodeToString(currentState)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire game state gets saved to Prefs (on the previous line). Do we really need to duplicate it into savedStateHandle?

@cooltey cooltey changed the title Wikigames: Use savedStateHandle for the events and currentState to prevent crashes Wikigames: set initial currentState from Prefs Mar 5, 2025
@cooltey cooltey requested review from Williamrai and dbrant March 5, 2025 00:42
@cooltey

cooltey commented Apr 2, 2025

Copy link
Copy Markdown
Collaborator Author

The current approach seems perfectly fine, so close this PR.

@cooltey cooltey closed this Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge PR passed design signoff and ready to be merged.

Development

Successfully merging this pull request may close these issues.

3 participants