gcivil-nyu-org / INET-Monday-Fall2023-Team-5

3 stars 5 forks source link

Leuber develop #267

Closed ll4407 closed 12 months ago

ll4407 commented 12 months ago

I made a few changes to the playground link:

  1. The 'Playground' link is still active only if there is an active game session. Otherwise, the playground link is inactive

    Screenshot 2023-11-22 at 3 06 04 PM
  2. 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.
Screenshot 2023-11-22 at 3 01 27 PM

Note: get_absolute_url is a method in the GameSession model that retrieves the game_progress URL

Screenshot 2023-11-22 at 9 44 49 AM

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"

Screenshot 2023-11-22 at 9 23 13 AM

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.
Screenshot 2023-11-22 at 3 28 27 PM Screenshot 2023-11-22 at 3 27 18 PM

Test:

  1. 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'
  2. 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.
  3. 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
  4. 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
AndresZarta commented 12 months ago

Beautiful!