Support Game Events (#5087)

This commit is contained in:
Zach H
2024-08-24 17:31:20 -07:00
committed by GitHub
parent bbe125beee
commit 248ea82573
9 changed files with 77 additions and 3 deletions

View File

@@ -33,3 +33,10 @@ export interface JoinGameParams {
overrideRestrictions: boolean;
joinAsJudge: boolean;
}
export enum LeaveGameReason {
OTHER = 1,
USER_KICKED = 2,
USER_LEFT = 3,
USER_DISCONNECTED = 4
}

View File

@@ -0,0 +1,36 @@
import { ProtobufEvents } from '../../services/ProtobufService';
import { joinGame } from './joinGame';
import { leaveGame } from './leaveGame';
export const GameEvents: ProtobufEvents = {
'.Event_Join.ext': () => joinGame,
'.Event_Leave.ext': () => leaveGame,
'.Event_GameClosed.ext': () => console.log('Event_GameClosed.ext'),
'.Event_GameHostChanged.ext': () => console.log('Event_GameHostChanged.ext'),
'.Event_Kicked.ext': () => console.log('Event_Kicked.ext'),
'.Event_GameStateChanged.ext': () => console.log('Event_GameStateChanged.ext'),
// '.Event_PlayerPropertiesChanged.ext': () => console.log("Event_PlayerProperties.ext"),
'.Event_GameSay.ext': () => console.log('Event_GameSay.ext'),
'.Event_CreateArrow.ext': () => console.log('Event_CreateArrow.ext'),
'.Event_DeleteArrow.ext': () => console.log('Event_DeleteArrow.ext'),
'.Event_CreateCounter.ext': () => console.log('Event_CreateCounter.ext'),
'.Event_SetCounter.ext': () => console.log('Event_SetCounter.ext'),
'.Event_DelCounter.ext': () => console.log('Event_DelCounter.ext'),
'.Event_DrawCards.ext': () => console.log('Event_DrawCards.ext'),
'.Event_RevealCards.ext': () => console.log('Event_RevealCards.ext'),
'.Event_Shuffle.ext': () => console.log('Event_Shuffle.ext'),
'.Event_RollDie.ext': () => console.log('Event_Roll.ext'),
'.Event_MoveCard.ext': () => console.log('Event_MoveCard.ext'),
'.Event_FlipCard.ext': () => console.log('Event_FlipCard.ext'),
'.Event_DestroyCard.ext': () => console.log('Event_DestroyCard.ext'),
'.Event_AttachCard.ext': () => console.log('Event_AttachCard.ext'),
'.Event_CreateToken.ext': () => console.log('Event_CreateToken.ext'),
'.Event_SetCardAttribute.ext': () => console.log('Event_SetCardAttribute.ext'),
'.Event_SetCardCounter.ext': () => console.log('Event_SetCardCounter.ext'),
'.Event_SetActivePlayer.ext': () => console.log('Event_SetActivePlayer.ext'),
'.Event_SetActivePhase.ext': () => console.log('Event_SetActivePhase.ext'),
'.Event_DumpZone.ext': () => console.log('Event_DumpZone.ext'),
'.Event_ChangeZoneProperties.ext': () => console.log('Event_ChangeZoneProperties.ext'),
'.Event_ReverseTurn.ext': () => console.log('Event_ReverseTurn.ext'),
};

View File

@@ -0,0 +1,6 @@
import { GamePersistence } from '../../persistence';
import { PlayerGamePropertiesData } from '../session/interfaces';
export function joinGame(playerGamePropertiesData: PlayerGamePropertiesData): void {
GamePersistence.joinGame(playerGamePropertiesData);
}

View File

@@ -0,0 +1,7 @@
import { LeaveGameReason } from 'types';
import { GamePersistence } from '../../persistence';
export function leaveGame(reason: LeaveGameReason): void {
GamePersistence.leaveGame(reason);
}

View File

@@ -1,3 +1,4 @@
export * from './common';
export * from './room';
export * from './session';
export * from './game';

View File

@@ -0,0 +1,12 @@
import { PlayerGamePropertiesData } from '../events/session/interfaces';
import { LeaveGameReason } from '../../types';
export class GamePersistence {
static joinGame(playerGamePropertiesData: PlayerGamePropertiesData) {
console.log('joinGame', playerGamePropertiesData);
}
static leaveGame(reason: LeaveGameReason) {
console.log('leaveGame', reason);
}
}

View File

@@ -10,7 +10,7 @@ import {
UserMessageData
} from '../events/session/interfaces';
import NormalizeService from '../utils/NormalizeService';
import { DeckList } from '../../types/deckList';
import { DeckList } from 'types';
import { common } from 'protobufjs';
import IBytesValue = common.IBytesValue;

View File

@@ -2,3 +2,4 @@ export { AdminPersistence } from './AdminPresistence';
export { RoomPersistence } from './RoomPersistence';
export { SessionPersistence } from './SessionPersistence';
export { ModeratorPersistence } from './ModeratorPresistence';
export { GamePersistence } from './GamePersistence';

View File

@@ -1,6 +1,6 @@
import protobuf from 'protobufjs';
import { CommonEvents, RoomEvents, SessionEvents } from '../events';
import { CommonEvents, GameEvents, RoomEvents, SessionEvents } from '../events';
import { SessionPersistence } from '../persistence';
import { WebClient } from '../WebClient';
import { SessionCommands } from 'websocket';
@@ -95,7 +95,7 @@ export class ProtobufService {
this.processSessionEvent(msg.sessionEvent, msg);
break;
case this.controller.ServerMessage.MessageType.GAME_EVENT_CONTAINER:
console.log(msg);
this.processGameEvent(msg.gameEvent, msg);
break;
default:
console.log(msg);
@@ -128,6 +128,10 @@ export class ProtobufService {
this.processEvent(response, SessionEvents, raw);
}
private processGameEvent(response: any, raw: any): void {
this.processEvent(response, GameEvents, raw);
}
private processEvent(response: any, events: ProtobufEvents, raw: any) {
for (const event in events) {
const payload = response[event];