-
Notifications
You must be signed in to change notification settings - Fork 11
Play App Architecture Overview
Current as of June 30, 2023:
This page describes the architecture of the play
app and the various components that exist within it. Generally, play
can be broken down into three important subcomponents:
In the Pregame
, the app is driven by user input, as they enter in a game code, input their name and select an avatar and update the backend with that information.
Once the app has received the required information from the user, the GameInProgress
branch is switched to. This side of the app is controlled via the backend subscription and is updated by the teacher on the host
app. This carries the user through the various stages of the game and into the leaderboard. When a game is ended, the play
drops back to the original SplashScreen
and the app is back in the Pregame
phase.
The hinge point between these two branches is the localStorage
object. When a player completes the Pregame
phase, their team data and the gameSession id is stored in their localStorage
. This data allows them to both subscribe to the gameSession
in the GameInProgress
phase, as well as rejoin and resubscribe in the event of a crash or navigation away from the page.
The overall structure of the app can be seen in the below diagram:
The flow of a game is thus:
- Player onboards through Pregame, entering a gamecode, their name and selecting an avatar. At this point, a call to the backend adds the team to the gameSession object and the required info for rejoining is stored in the
localStorage
. ThePregame
phase is now complete and the app navigates to/game
to beginGameInProgress
- Upon navigating to
/game
, thereact-router-dom
loader is triggered to load thelocalStorage
data and use it to subscribe to thegameSession
. The player is now in the lobby, awaiting the teacher to start the game by updating thegameSession
object. - Player will continue through until the end of the game, where the teacher updates the
gameSession
object state toFINISHED
and theplay
app will move back to thePregame
state on route/
. - If the player leaves the page and wants to rejoin, upon navigating to
/game
thereact-router-dom
will reload thelocalStorage
data and resubscribe accordingly. AhasRejoined
flag will be tripped to prevent duplicated behaviour (such as entering answers twice).