shared/interfaces/game.ts
RedisPlayerInfo represents information about game player for TBL app redis
Properties |
|
avatar |
avatar:
|
Type : string
|
Optional |
avatar |
background |
background:
|
Type : string
|
Optional |
background |
clientId |
clientId:
|
Type : string
|
exists for any (per game randomly generated) |
customAvatar |
customAvatar:
|
Type : literal type
|
Optional |
custom avatar |
emoji |
emoji:
|
Type : string
|
Optional |
emoji |
frame |
frame:
|
Type : string
|
Optional |
frame |
guestId |
guestId:
|
Type : string
|
Optional |
exists for guests user |
highScores |
highScores:
|
Type : LooseObject
|
Optional |
skill highscore for registered players |
isConnected |
isConnected:
|
Type : boolean
|
connection state |
joined |
joined:
|
Type : Date | string
|
kicked |
kicked:
|
Type : Date | string
|
Optional |
kicked date |
name |
name:
|
Type : string
|
player name |
userId |
userId:
|
Type : string
|
Optional |
exists for logged in user |
import { LooseObject } from '../common/types';
import { AbstractJwtPayload } from '../interfaces/auth';
/**
* AbstractRegionGame Interface used by core to keep in core redis running games
*/
export interface AbstractRegionGame {
/** game code */
readonly gameCode: string;
/** game region code */
readonly region: string;
}
/**
* AbstractGameClient interface is game JWT payload.
* It generated by core on game create/join, used to create websocket connection with TBL app and contains required information to identify connection information.
*/
export interface AbstractGameClient extends AbstractJwtPayload {
/** game region code */
readonly region: string;
/** redis game code */
readonly gameCode: string;
/** unique "per game" random uuid v4 */
readonly clientId: string;
/** is host flag */
readonly isHost: boolean;
}
/**
* Abstract Class vs Class challenge interface
*/
export interface AbstractCvcChallenge {
/** challenge game code */
readonly challengerGameCode: number;
/** challenge key */
challengeKey: string;
}
/**
* Abstract Number Generator interface
*/
export interface AbstractNumberGenerator {
/** achievement level */
achievementLevel?: string;
/** game topic code */
topic: string;
/** game subtopic code */
subtopic?: string;
/** game type */
type?: string;
/** primary flag */
primary: boolean;
/** number generator name */
name: string;
/** flexible other fields */
[key: string]: any;
}
/**
* Abstract Game Skill interface
* Skill fully defines game logic
*/
export interface AbstractGameSkill {
/** skill user readable name */
readonly name?: string;
/** skill type (math-topic class identificator) */
readonly type: string;
/** number generator */
readonly numberGenerator: AbstractNumberGenerator;
/** skill topic (user readable = category name) */
readonly topic?: string;
}
/**
* Abstract Game Type interface
*/
export interface AbstractGameType extends AbstractGameSkill {
// /** game type */
// readonly type: string;
/** game equation type */
readonly equationType?: string;
// /** game number generator */
// readonly numberGenerator: AbstractNumberGenerator;
/** game class vs class challenge if exists */
readonly cvcChallenge?: AbstractCvcChallenge;
/** game language */
readonly language: string;
/** flexible other fields */
[key: string]: any;
}
/**
* AccuracyStats interface contains information to calculate round or game accuracy
*/
export interface AccuracyStats {
/** number of correct answers for accuracy */
correctAnswers: number;
/** number of wrong answers for accuracy */
wrongAnswers: number;
}
export interface AbstractGame {
/** game type */
gameType: AbstractGameType;
/** flexible other fields */
[key: string]: any;
}
/**
* AbstractGameRoundsInfo interface contains information about game rounds
*/
export interface AbstractGameRoundsInfo {
/** number of rounds in game */
readonly rounds: number;
/** round duration in seconds */
readonly roundDuration: number;
}
/**
* AbstractQuestionBody interface contains information about answered question and answer
*/
export interface AbstractQuestionBody {
/** question type */
type: string;
/** question correct answer */
answer: number;
/** player's answer */
playerAnswer: number;
/** flag if player answered correct */
correct: boolean;
/** time takes player to answer */
time: number;
/** flexible other fields */
[key: string]: any;
}
/**
* AbstractRoundQuestion interface contains information about question
*/
export interface AbstractRoundQuestion {
/** question first number */
number1: number;
/** question second number */
number2: number;
/** question correct answer */
answer: number;
/** flexible other types */
[key: string]: any;
}
/**
* AbstractGameAnswer interface contains detailed information about question, answer, game and player
*/
export interface AbstractGameAnswer {
/** redis game code */
gameCode: string | number;
/** player name who answered */
playerName: string;
/** user id who answered */
userId: string | null;
/** client id (per game random id) who answered */
clientId: string;
/** answer round number */
round: number;
/** question and answer details */
questionBody: AbstractQuestionBody;
/** booster score for answer */
boosterScore?: number;
/** number of answer in total player's answers in game */
answerCount: number;
}
/**
* AbstractLeaderboardRecord interface contains information about game leaderboard record
*/
export interface AbstractLeaderboardRecord extends AccuracyStats {
/** player name */
name: string;
/** player client id (per game random) */
clientId: string;
/** player avatar */
avatar: string;
/** player custom avatar */
customAvatar?: { [key: string]: string };
/** player avatar background */
background?: string;
/** player avatar frame */
frame?: string;
/** player score */
score: number;
// /** number of player's correct answers in game */
// correctAnswers: number;
// /** number of player's wrong answers in game */
// wrongAnswers: number;
/** player stats grouped by round */
rounds: RedisPlayerRoundStats[];
/** player answers */
questions?: AbstractGameAnswer[];
/** player highscore data */
highscore: LooseObject;
}
/**
* RedisTeacherData interface contains information about teacher may be required on game run
*/
export interface RedisTeacherData {
/** teacher's classes codes */
classes: string[];
}
/**
* RedisHostInfo represents information about game host for TBL app redis
*/
export interface RedisHostInfo {
/** host game client id */
clientId: string;
/** flag if host is connected to websocket */
isConnected: boolean;
/** date of last host disconnect from game */
lastDisconnect: Date | string;
}
/**
* RedisPlayerInfo represents information about game player for TBL app redis
*/
export interface RedisPlayerInfo {
/** player name */
name: string;
/** connection state */
isConnected: boolean;
/** exists for logged in user */
readonly userId?: string;
/** exists for guests user */
readonly guestId?: string;
/** exists for any (per game randomly generated) */
clientId: string;
/** avatar */
avatar?: string;
/** custom avatar */
customAvatar?: { [key: string]: string };
/** background */
background?: string;
/** frame */
frame?: string;
/** emoji */
emoji?: string;
// joined date
readonly joined: Date | string;
/** kicked date */
kicked?: Date | string;
/** skill highscore for registered players */
highScores?: LooseObject;
}
/**
* RedisGameRound represents information about game round for TBL app redis
*/
export interface RedisGameRound {
/** round start date */
started: Date | string;
/** round end date */
endTime: Date | string;
/** number of round in game */
round: number;
/** flag if round is ended */
hasEnded: boolean | Date | string;
/** total number of game rounds */
rounds: number;
/** pregenerated round questions */
questions: AbstractRoundQuestion[];
}
/**
* RedisGameStats represents information about game itself for TBL app redis
*/
export interface RedisGameStats {
/** game start date */
started: Date | string | null;
/** game finish date */
finished: Date | string | null;
/** game rounds information */
rounds: RedisGameRound[];
}
/**
* RedisPlayerRoundStats represents information about combined player stats per round
*/
export interface RedisPlayerRoundStats extends AccuracyStats {
/** score in round */
score: number;
/** booster score in round */
boosterScore?: number;
// /** number of correct answers */
// correctAnswers: number;
// /** number of wrong answers */
// wrongAnswers: number;
}
/**
* RedisPlayerStats represents information about combined player stats for all game
*/
export interface RedisPlayerStats extends AccuracyStats {
/** score */
score: number;
/** booster score */
boosterScore?: number;
// /** number of correct answers */
// correctAnswers: number;
// /** number of wrong answers */
// wrongAnswers: number;
/** per round detailed stats */
rounds: RedisPlayerRoundStats[];
/** per round arrays of answers */
answers: any[];
/** flat array of all answers (builds automatically on demand) */
results?: AbstractGameAnswer[];
/** xp points collected at game for registered players */
xp?: number;
}
/**
* RedisGame represents information about game in TBL app (saved in TBL redis)
*/
export interface RedisGame {
/** game region */
readonly region: string;
/** creator (host) user id */
readonly userId: string;
/** creator (host) role */
readonly creatorRole: string;
/** exists for cases when game creator is teacher */
teacherData?: RedisTeacherData;
/** creation date */
readonly created: Date | string;
/** start date */
started: Date | string;
/** end date */
finished: Date | string;
/** flag if game is demo */
readonly demo: boolean;
/**
* redis games code is join code
* it replaced with permanent, when game saved to mongo
* it is not readonly, because on reading from redis and
* unjson to object - it may be recognized as number
* so there is a manual convertion of this code on reading
*/
code: string;
/** mongo code for finished game */
mongoCode?: string;
/** game type */
readonly gameType: AbstractGameType;
/** game players */
players: RedisPlayerInfo[];
/** game rounds fillup on game run */
readonly gameRounds: RedisGameRound[];
/** game round info - number/duration defined on creation */
readonly round: AbstractGameRoundsInfo;
/** redis flag of saved to mongo or not */
saved: boolean;
/** global flag */
readonly global?: boolean;
/** grade details */
readonly grade?: string | number;
/** public flag */
readonly publicGame?: boolean;
/** public settings */
readonly publicGameSettings?: LooseObject;
/** require login flag */
requireLogin: boolean;
/** class code */
classCode?: string;
/** game metadata */
readonly metaData?: LooseObject;
}
/**
* TBLGameCreateDTO used in core to combine all game/host info into single pack
* and send it regional redis, and in tbl - to unpack game/host data into
* "game-required" keys and hashes
*/
export interface TBLGameCreateDTO {
/** redis game info */
game: RedisGame;
/** game host info - clientId {string} when host is teacher, and RedisPlayerInfo object if host is student or parent */
host: string | RedisPlayerInfo;
}
/**
* TBLGameEndDTO used in tbl to combine all game/players stats into single pack
* so core can download it from regional redis in single request, and in core
* to save game to mongo
*/
export interface TBLGameEndDTO {
/** redis game info */
info: RedisGame;
/** game stats */
stats: RedisGameStats;
/** host info */
host: RedisHostInfo;
/** players stats */
pstats: {
[clientId: string]: RedisPlayerStats;
};
/** players info */
players: RedisPlayerInfo[];
}