Global

Members

(constant) DISCONNECTED_TIMEOUT_MS :number

Time until an instance is deleted after a user disconnects and fails to reconnect (in milliseconds)
Type:
  • number
Source:

(constant) GAME_END_TIMEOUT_MS :number

Time between game end and instance deletion (in milliseconds)
Type:
  • number
Source:

(constant) gameInstancesByGameCode :Record.<number, Types.GameInstance>

Type:
  • Record.<number, Types.GameInstance>
Source:

(constant) gameInstancesByPlayerUUID :Record.<Types.UUID, Types.GameInstance>

Type:
  • Record.<Types.UUID, Types.GameInstance>
Source:

(constant) gameState :Object

Store for data related to current state of game
Type:
  • Object
Source:

(constant) mouseState :Object

Type:
  • Object
Source:

(constant) tarotMap

Create a hashmap for all tarot cards that can be indexed by card name
Source:

Methods

acceptRequest(webSocketRequest) → {Types.WSConnection}

Accepts a given WebSocket connection request, and annotates it with a UUID and empty profile
Parameters:
Name Type Description
webSocketRequest Types.WSRequest inbound WebSocket request object
Source:
Returns:
newly created WebSocket connection
Type
Types.WSConnection

alertUpdateInstance(gameInstance)

Passes down current game instance meta-data to all child connections, namely the game code and list of all profiles member to the instance
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to target child connections of
Source:

animateNextFrame(stars, canvasContext)

Handles animation of each frame; individually moves stars forward a step in the direction of the camera. Self-invoking.
Parameters:
Name Type Description
stars Array.<Star> array of stars to animate
canvasContext CanvasRenderingContext2D 2D canvas context to render onto
Source:

animateSingleStar(star, canvasContext, cameraX, cameraY)

Handles animation of a single star for a single frame
Parameters:
Name Type Description
star Star individual star to animate
canvasContext CanvasRenderingContext2D 2D canvas context to render onto
cameraX number x coordinate of viewing position
cameraY number y coordinate of viewing position
Source:

areCardsEqual(card1, card2) → {boolean}

Determines if two different card objects represent the same card
Parameters:
Name Type Description
card1 Types.Card card to compare
card2 Types.Card card to compare
Source:
Returns:
true if the two cards represent the same card (i.e., same values); false otherwise
Type
boolean

areUnorderedArrsEqual(arr1, arr2) → {boolean}

Determines if two arrays are equal as sets
Parameters:
Name Type Description
arr1 Array.<any> array of objects to compare
arr2 Array.<any> array of objects to compare
Source:
Returns:
true if arrays are equal as sets; false otherwise
Type
boolean

attachProfileImageAndListener()

Displays user's profile image in appropriate location on UI, and attachs listeners to allow user to upload their own image after the game has already started
Source:

attemptRejoin(webSocketConnection, playerUUIDopt) → {boolean}

Handles request where a user has a remaining UUID from their own sessionStorage and wants to rejoin the game instance associated to that UUID; authenticates that connection is appropriate and facilitates reconciliation
Parameters:
Name Type Attributes Description
webSocketConnection Types.WSConnection connection of requester
playerUUID Types.UUID <optional>
unique identifier passed by user
Source:
Returns:
success status of rejoin attempt (i.e., true iff instance rejoined)
Type
boolean

attributeChangedCallback()

Refreshes display whenever UUID is updated
Source:

attributeChangedCallback()

Updates card whenever attributes change
Source:

attributeChangedCallback()

Refreshes display whenever UUID is updated
Source:

calculateGameWinnerProfile(gameInstance) → {Types.ServerToClientProfile}

Returns profile of user who has a higher score
Parameters:
Name Type Description
gameInstance Types.GameInstance target game instance
Source:
Returns:
profile of game winner
Type
Types.ServerToClientProfile

cancelDisconnectedInstanceCloseTimeout(gameInstance)

Cancels any existing timesout that would close a game instance due to players losing connection
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to protect from closing
Source:

cardClickHandler(event)

Handles gameplay progression on card click event by generating a random card name/image, and random luck points with corresponding UI updates
Parameters:
Name Type Description
event MouseEvent click event
Source:

chooseIfCardIsUpsideDown() → {boolean}

Randomly decides if a card should be displayed upside down, currently implemented as a 50/50 chance
Source:
Returns:
true if card is upside down, false otherwise
Type
boolean

cleanGameState(playerUUID, gameState) → {Types.GameState}

Strips sensitive data (i.e., currently-selected card) from a specific game state object so that it can be sent downstream to the specified user without fear that it exposes behind-the-screens info
Parameters:
Name Type Description
playerUUID Types.UUID user who the game state is destined for
gameState Types.GameState initial (dirty) game state
Source:
Returns:
game state cleaned of any data that should be private to the given user
Type
Types.GameState

(async) clientInitialization()

Automates initialization of browser and navigation to versus page, to be run before each test
Source:

closeInstance(gameInstance)

Completely closes out and deletes a game instance, alerting any member players
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to close
Source:

connectedCallback()

Initializes display and sets listener to update whenever new information exists
Source:

connectedCallback()

Initializes display of card
Source:

connectedCallback()

Initializes display and sets listener to update whenever new information exists
Source:

createInstance(webSocketConnection)

Creates a new game instance and links it to given player
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection to attach to the game instance
Source:

createNewRound(gameInstance) → {Types.RoundState}

Creates and returns a new round state
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to determine if world event should be used
Source:
Returns:
blank round state
Type
Types.RoundState

(async) defaultInitialization()

Automates initialization of browser and navigation to game page, to be run before each test
Source:

(async) defaultTeardown()

Source:

disconnectedCallback()

Destructs listeners
Source:

disconnectedCallback()

Destructs listeners
Source:

displayMessage(message)

Displays message to game screen as if it were spoken by the wizard, resetting back to instructions after MESSAGE_DISPLAY_LENGTH_MS milliseconds
Parameters:
Name Type Description
message string message to be displayed by wizard
Source:

endGame()

When game is over (i.e., all four cards chosen), saves data and redirects users to results screen
Source:

endGame(gameInstance)

Ends game instance, deciding and sending winner to each child connection
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to end
Source:

endRound(gameInstance)

Ends game round, deciding and sending winner to each child connection along with the specific card chosen by each opposing player
Parameters:
Name Type Description
gameInstance Types.GameInstance targeted game instance
Source:

(async) flipCard(targetSide) → {Promise.<void>}

Flips card to targeted side and returns promise that resolves when transition (i.e., flip) is completed
Parameters:
Name Type Description
targetSide 'front' | 'back' side that card will be flipped to
Source:
Returns:
promise that resolves when transition complete
Type
Promise.<void>

forceRefreshGameState(webSocketConnection)

Forces a client user to completely refresh/rerender their game instance, used when a user reconnects or to handle errors
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection to force refresh state to
Source:

generateCardsWithListeners(numCards) → {Array.<HTMLDivElement>}

Creates a list of card elements to be shown on game board, attaching click-event listeners to each to facilitate game logic
Parameters:
Name Type Description
numCards number number of cards to generate
Source:
Returns:
array of card container elements
Type
Array.<HTMLDivElement>

generateStars(numStars) → {Array.<Star>}

Creates and returns new Star objects, each including initial x, y, & z positions
Parameters:
Name Type Description
numStars number number of stars to create
Source:
Returns:
array of newly created stars
Type
Array.<Star>

generateUniqueCards(cardList, n) → {Array.<Array.<Types.Card>>}

Generates two sets of n mutually-unique cards
Parameters:
Name Type Description
cardList Array.<Types.Card> list of cards to pull from
n number integer size of each set
Source:
Returns:
two lists of n mutually-unique cards
Type
Array.<Array.<Types.Card>>

generateUniqueGameCode(rangeLo, rangeHi, currentGameCodes) → {number}

Creates and returns random unique game code for each game instance
Parameters:
Name Type Description
rangeLo number lowest allowed game code (inclusive)
rangeHi number highest allowed game code (inclusive)
currentGameCodes Array.<number> games currently in use (i.e., to avoid)
Source:
Returns:
newly generated unique game code
Type
number

(async) getCardTranslationPromise() → {Promise.<void>}

Returns promise last attached to call of translateToContainer function; can be used to ensure that translation has completed before proceeding with further animations
Source:
Returns:
promise that resolves when animation complete
Type
Promise.<void>

getCurMoveLuck(isCardUpsideDown) → {number}

Gets weighted luck for current move triggered by choosing a card. Namely, an upside-down card corresponds to a negative luck score while normal cards correspond to positive scores. Magnitude of luck is based off the percent of bar currently filled, with max value MAX_LUCK_MAGNITUDE_PER_MOVE.
Parameters:
Name Type Description
isCardUpsideDown boolean whether card is an upside-down unlucky card
Source:
Returns:
luck score in range [-MAX_LUCK_MAG, MAX_LUCK_MAG]
Type
number

getCurPercentOfBarFill() → {number}

For the animated sliding luck bar on the bottom of game screen, calculates the current percent of the bar filled by the animation
Source:
Returns:
value between 0 and 1 with 0 representing an empty bar
Type
number

getCurrentRoundState(gameInstance) → {Types.RoundState}

Returns the last entry in list of round states from a game instance
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to target
Source:
Returns:
most recent (current) round attached to gameInstance
Type
Types.RoundState

getMultiplierWorldEvent(card1, card2, worldEvent) → {Types.Card}

Determines the multiplier for a given matchup between two cards (Positive multiplier implies that card1 has a suite-based advantage over card2)
Parameters:
Name Type Description
card1 Types.Card card to compare, target of multiplier
card2 Types.Card card to compare
worldEvent string current worldEvent for the round
Source:
Returns:
matchup multiplier for card1 with reference to card2
Type
Types.Card

getNumActivePlayers(gameInstance) → {number}

For a given game, returns the number of connections (i.e., players) that are currently live connections
Parameters:
Name Type Description
gameInstance Types.GameInstance queried game instance
Source:
Returns:
number of live connections in the moment
Type
number

getOtherPlayer(gameInstance, webSocketConnection) → {Types.WSConnection}

Determines the opponent of a given player in a game instance
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to target
webSocketConnection Types.WSConnection non-target player of game instance
Source:
Returns:
other player in game instance
Type
Types.WSConnection

getPercentOpacity(star) → {number}

Calculates appropriate current opacity for a star, based off its z position
Parameters:
Name Type Description
star Star target star
Source:
Returns:
percent opacity in range [0, 1]
Type
number

getRandomSuite() → {string}

Source:
Returns:
random suite from SUITES object
Type
string

getRandomValue(lo, hi) → {number}

Returns a random number in a range
Parameters:
Name Type Description
lo number integer low value (inclusive)
hi number integer high value(inclusive)
Source:
Returns:
random integer between lo and hi, inclusive
Type
number

getRandomWorldEvent(gameInstance) → {Types.worldEvent}

Gives a random World Event
Parameters:
Name Type Description
gameInstance Types.GameInstance the game instance getting the world event
Source:
Returns:
World Event
Type
Types.worldEvent

getRoundWinnerUUID(gameInstance) → {Types.UUID}

Determines which of two users wins a round
Parameters:
Name Type Description
gameInstance Types.GameInstance the round's game instance
Source:
Returns:
winning user UUID1 and UUID2
Type
Types.UUID

getUniqueCard() → {Card}

Picks a card that has not yet been chosen
Source:
Returns:
card not currently present in state.chosenCards
Type
Card

getWinningCard(card1, card2, worldEvent) → {Types.Card}

Determines the winner between 2 cards given a world event
Parameters:
Name Type Description
card1 Types.Card the first card to compare
card2 Types.Card the second card to compare
worldEvent string the current round's world event
Source:
Returns:
winning card
Type
Types.Card

handleChatMessage(webSocketConnection, messageContents)

Validates and relays chat message from client
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection sending chat message
messageContents string text content of message being received
Source:

handleInitialization(webSocketConnection, playerUUIDopt)

Attempts to force user back through rejoin logic, and creates a new instance for them if that fails
Parameters:
Name Type Attributes Description
webSocketConnection Types.WSConnection connection of requester
playerUUID Types.UUID <optional>
unique identifier passed by the user from their sessionStorage
Source:

handleJoinInstance(webSocketConnection, gameCode)

For a given connection, joins the game instance corresponding to the gameCode
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection that should join the game instance
gameCode number game code corresponding to game instance to join
Source:

handleRequest(webSocketRequest)

Handles a new request to the WebSocket server; always tries to accept
Parameters:
Name Type Description
webSocketRequest Types.WSRequest inbound WebSocket request object
Source:

handleResize(starBgCanvasEl)

(Re)sizes canvas element to always cover the entire client screen
Parameters:
Name Type Description
starBgCanvasEl HTMLCanvasElement canvas element to resize
Source:

handleSelectCard(webSocketConnection, selectedCard)

Handles logic when a client selects a card during a round, including validation, updates to game/round state, and sending of notification to opposing client
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection that selected card
selectedCard Types.Card card selected by client
Source:

handleStartGame(webSocketConnection)

Start game by sending 'start_game' code to all child connections of game instance hosted by a specific connection
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection member to game instance to start
Source:

handleUpdateProfile(webSocketConnection, profile)

Attaches new profile information to a connection, preserving the initial UUID
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection to attach new profile to
profile Types.ClientToServerProfile well-formed new profile data object
Source:

handleWindowSizeChange()

Handles window size change
Source:

init()

Initializes game board and gameplay
Source:

init()

Initializes and pulls together all required files for versus mode to work; only necessary to import this file
Source:

initializeHowToModal()

Initializes event listener for opening how to modal; closing is handled by default through HTML form element
Source:

isCardValid(card) → {boolean}

Ensures that card object is well-formed and valid
Parameters:
Name Type Description
card Types.Card card object to test
Source:
Returns:
true if card is valid; false if invalid
Type
boolean

leaveInstance(webSocketConnection)

For a given connection, leaves the game instance they are currently member to
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connnection that should leave its game instance
Source:

removeStars()

Remove the stary background
Source:

sendMessage(webSocketConnection, message)

For a given connection, sends stringified version of object for re-parsing on other side
Parameters:
Name Type Description
webSocketConnection Types.WSConnection connection across which to send message
message Types.ServerToClientMessage well-formed message object to send
Source:

setLuck(luck)

Updates luck value to game state and corresponding visual output
Parameters:
Name Type Description
luck number new luck value
Source:

setScreenWidth(newScreenWidth)

Parameters:
Name Type Description
newScreenWidth
Source:

starsInit()

Creates and attaches canvas element to page, and then initializes animation and appropriate event listeners
Source:

startDisconnectedInstanceCloseTimeout(gameInstance)

Starts the timer to close out a game instance, to be used when a player loses connections
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to close
Source:

startNewRound(gameInstance)

Instantiates new round on a game instance
Parameters:
Name Type Description
gameInstance Types.GameInstance game instance to start a new round on
Source:

(async) translateToContainer(containerEl) → {Promise.<void>}

Animates card sliding into a container; at the end of the animation, the card will be moved into the container in the DOM as well
Parameters:
Name Type Description
containerEl HTMLElement container that element should end up in
Source:
Returns:
Type
Promise.<void>

updateButtonVisibility(chosenCards, idx)

Update button visibility - should not show the previous button when on the first card and should not show the next button on the last card
Parameters:
Name Type Description
chosenCards
idx * index of current card when in mobile mode
Source:

updateMobileCard(chosenCards, idx, mobileCard, tarotMap, fortuneTellings)

Display the current card on the mobile side
Parameters:
Name Type Description
chosenCards
idx
mobileCard
tarotMap
fortuneTellings
Source:

updateMousePosition(event)

Updates mouse x and y positions as relative percents of total screen size in mouseState object, using the center of the screen as the (0, 0) origin
Parameters:
Name Type Description
event MouseEvent mouse movement event passed by listener; passive
Source:

Type Definitions

Card

Data store for each card
Type:
Source:

Card

Data store for each card
Type:
  • Object
Source:

Card

Type:
  • Object
Source:

Card

Type:
  • Object
Source:

ClientToServerMessage

Type:
  • Object | Object | Object | Object | Object | Object
Source:

ClientToServerMessage

Type:
  • Object | Object | Object | Object | Object | Object
Source:

ClientToServerProfile

Type:
  • Object
Source:

ClientToServerProfile

Type:
  • Object
Source:

GameInstance

Type:
  • Object
Source:

GameState

Type:
  • Object
Source:

GameState

Type:
  • Object
Source:

IndeterminateCard

Type:
Source:

PlayerGameState

Type:
  • Object
Source:

PlayerGameState

Type:
  • Object
Source:

RoundState

Type:
  • Object
Source:

RoundState

Type:
  • Object
Source:

ServerToClientMessage

Type:
  • Object | Object | Object | Object | Object | Object | Object | Object | Object | Object | Object | Object
Source:

ServerToClientMessage

Type:
  • Object | Object | Object | Object | Object | Object | Object | Object | Object | Object | Object | Object
Source:

ServerToClientProfile

Type:
  • Object
Source:

ServerToClientProfile

Type:
  • Object
Source:

Star

Type:
  • Object
Source:

UUID

Type:
  • string | null
Source:

UUID

Type:
  • string
Source:

UUID

Type:
  • string | null
Source:

UUID

Type:
  • string
Source:

WSConnection

Type:
  • any
Source:

WSRequest

Type:
  • any
Source: