mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 15:49:28 -08:00
Support Game Events (#5087)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
36
webclient/src/websocket/events/game/index.ts
Normal file
36
webclient/src/websocket/events/game/index.ts
Normal 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'),
|
||||
};
|
||||
6
webclient/src/websocket/events/game/joinGame.ts
Normal file
6
webclient/src/websocket/events/game/joinGame.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { GamePersistence } from '../../persistence';
|
||||
import { PlayerGamePropertiesData } from '../session/interfaces';
|
||||
|
||||
export function joinGame(playerGamePropertiesData: PlayerGamePropertiesData): void {
|
||||
GamePersistence.joinGame(playerGamePropertiesData);
|
||||
}
|
||||
7
webclient/src/websocket/events/game/leaveGame.ts
Normal file
7
webclient/src/websocket/events/game/leaveGame.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { LeaveGameReason } from 'types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
|
||||
export function leaveGame(reason: LeaveGameReason): void {
|
||||
GamePersistence.leaveGame(reason);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './common';
|
||||
export * from './room';
|
||||
export * from './session';
|
||||
export * from './game';
|
||||
|
||||
12
webclient/src/websocket/persistence/GamePersistence.ts
Normal file
12
webclient/src/websocket/persistence/GamePersistence.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -2,3 +2,4 @@ export { AdminPersistence } from './AdminPresistence';
|
||||
export { RoomPersistence } from './RoomPersistence';
|
||||
export { SessionPersistence } from './SessionPersistence';
|
||||
export { ModeratorPersistence } from './ModeratorPresistence';
|
||||
export { GamePersistence } from './GamePersistence';
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user