The 'Playground' link is still active only if there is an active game session. Otherwise, the playground link is inactive
When the user clicks on the 'Playground' link they are either directed to the game_creation URL or the game_progress URL, depending on the game state and if the player has a character associated with it.
State Check and URL Determination:
If the game session's state is CHARACTER_CREATION:
If the player has a character: The URL for the game's progress view (game_session.get_absolute_url()) is assigned to game_session_url.
If the player does not have a character: The URL for the character creation view is generated using reverse and assigned to game_session_url.
If the game session's state is not CHARACTER_CREATION, it defaults to the game's progress URL.
Note: get_absolute_url is a method in the GameSession model that retrieves the game_progress URL
When directed to the character_creation URL, you are presented with two options (for now) of character archetypes. When you confirm your selection and submit, you are redirected to the game_progress view. Both users must select a character before the game_session state transitions from "CHARACTER_CREATION" to "REGULAR_TURN"
About the character_creation_view:
GET Method Handling:
The get method handles HTTP GET requests.
It first tries to fetch a GameSession object using the game_id passed in the URL.
If the game session's state is not CHARACTER_CREATION, it redirects the user to the game's progress view using game_session.get_absolute_url().
If the game session is in the CHARACTER_CREATION state, it creates and displays the CharacterSelectionForm.
If the GameSession object cannot be found (i.e., DoesNotExist exception), it displays an error message and redirects the user to a game list view.
POST Method Handling:
The post method handles HTTP POST requests, typically form submissions.
Similar to the get method, it checks the state of the GameSession. If it's not in CHARACTER_CREATION, it redirects to the game progress view.
If the form submission is valid, it either gets or creates a Player object for the current user and saves the selected character to this player.
It then fetches all players associated with the current game session and checks if there are exactly two players. If both players have selected a character, it transitions the game session to the REGULAR_TURN state and saves the game session.
If the GameSession object cannot be found or there are not exactly two players, it displays an error message and redirects the user accordingly.
Test:
Create a matched user and trigger the url domain/api/notify-matches. This will initialize the game and set the game_session state transitions from 'INITIALIZING' to 'CHARACTER_CREATION'
User1 and User2 should have the 'Playground' link active on their dashboard. Click on the 'Playground' link and they both should be redirected to the game_creation URL.
User1 selects a character and clicks confirm. The game_session state should still be set to 'CHARACTER_CREATION.' Once User1 click confirm, they are redirected to the game_progress URL
User2 selects a character and clicks confirm. The game_session state should now be set to 'REGULAR_TURN' since both users have selected a character. User2 is now directed to the game_progress URL
I made a few changes to the playground link:
The 'Playground' link is still active only if there is an active game session. Otherwise, the playground link is inactive
When the user clicks on the 'Playground' link they are either directed to the game_creation URL or the game_progress URL, depending on the game state and if the player has a character associated with it.
State Check and URL Determination:
Note: get_absolute_url is a method in the GameSession model that retrieves the game_progress URL
When directed to the character_creation URL, you are presented with two options (for now) of character archetypes. When you confirm your selection and submit, you are redirected to the game_progress view. Both users must select a character before the game_session state transitions from "CHARACTER_CREATION" to "REGULAR_TURN"
About the character_creation_view: GET Method Handling:
POST Method Handling:
Test: