mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
refactor redux data model
This commit is contained in:
parent
ae1bc3da38
commit
0ff391491d
243 changed files with 5212 additions and 5963 deletions
20
webclient/src/api/response/AdminResponseImpl.ts
Normal file
20
webclient/src/api/response/AdminResponseImpl.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import type { IAdminResponse } from '@app/websocket';
|
||||
import { ServerDispatch } from '@app/store';
|
||||
|
||||
export class AdminResponseImpl implements IAdminResponse {
|
||||
adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean): void {
|
||||
ServerDispatch.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
}
|
||||
|
||||
reloadConfig(): void {
|
||||
ServerDispatch.reloadConfig();
|
||||
}
|
||||
|
||||
shutdownServer(): void {
|
||||
ServerDispatch.shutdownServer();
|
||||
}
|
||||
|
||||
updateServerMessage(): void {
|
||||
ServerDispatch.updateServerMessage();
|
||||
}
|
||||
}
|
||||
125
webclient/src/api/response/GameResponseImpl.ts
Normal file
125
webclient/src/api/response/GameResponseImpl.ts
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import { Data } from '@app/types';
|
||||
import type { IGameResponse } from '@app/websocket';
|
||||
import { GameDispatch } from '@app/store';
|
||||
|
||||
export class GameResponseImpl implements IGameResponse {
|
||||
clearStore(): void {
|
||||
GameDispatch.clearStore();
|
||||
}
|
||||
|
||||
gameStateChanged(gameId: number, data: Data.Event_GameStateChanged): void {
|
||||
GameDispatch.gameStateChanged(gameId, data);
|
||||
}
|
||||
|
||||
playerJoined(gameId: number, playerProperties: Data.ServerInfo_PlayerProperties): void {
|
||||
GameDispatch.playerJoined(gameId, playerProperties);
|
||||
}
|
||||
|
||||
playerLeft(gameId: number, playerId: number, reason: number): void {
|
||||
GameDispatch.playerLeft(gameId, playerId, reason);
|
||||
}
|
||||
|
||||
playerPropertiesChanged(gameId: number, playerId: number, properties: Data.ServerInfo_PlayerProperties): void {
|
||||
GameDispatch.playerPropertiesChanged(gameId, playerId, properties);
|
||||
}
|
||||
|
||||
gameClosed(gameId: number): void {
|
||||
GameDispatch.gameClosed(gameId);
|
||||
}
|
||||
|
||||
gameHostChanged(gameId: number, hostId: number): void {
|
||||
GameDispatch.gameHostChanged(gameId, hostId);
|
||||
}
|
||||
|
||||
kicked(gameId: number): void {
|
||||
GameDispatch.kicked(gameId);
|
||||
}
|
||||
|
||||
gameSay(gameId: number, playerId: number, message: string): void {
|
||||
GameDispatch.gameSay(gameId, playerId, message);
|
||||
}
|
||||
|
||||
cardMoved(gameId: number, playerId: number, data: Data.Event_MoveCard): void {
|
||||
GameDispatch.cardMoved(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardFlipped(gameId: number, playerId: number, data: Data.Event_FlipCard): void {
|
||||
GameDispatch.cardFlipped(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardDestroyed(gameId: number, playerId: number, data: Data.Event_DestroyCard): void {
|
||||
GameDispatch.cardDestroyed(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardAttached(gameId: number, playerId: number, data: Data.Event_AttachCard): void {
|
||||
GameDispatch.cardAttached(gameId, playerId, data);
|
||||
}
|
||||
|
||||
tokenCreated(gameId: number, playerId: number, data: Data.Event_CreateToken): void {
|
||||
GameDispatch.tokenCreated(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardAttrChanged(gameId: number, playerId: number, data: Data.Event_SetCardAttr): void {
|
||||
GameDispatch.cardAttrChanged(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardCounterChanged(gameId: number, playerId: number, data: Data.Event_SetCardCounter): void {
|
||||
GameDispatch.cardCounterChanged(gameId, playerId, data);
|
||||
}
|
||||
|
||||
arrowCreated(gameId: number, playerId: number, data: Data.Event_CreateArrow): void {
|
||||
GameDispatch.arrowCreated(gameId, playerId, data);
|
||||
}
|
||||
|
||||
arrowDeleted(gameId: number, playerId: number, data: Data.Event_DeleteArrow): void {
|
||||
GameDispatch.arrowDeleted(gameId, playerId, data);
|
||||
}
|
||||
|
||||
counterCreated(gameId: number, playerId: number, data: Data.Event_CreateCounter): void {
|
||||
GameDispatch.counterCreated(gameId, playerId, data);
|
||||
}
|
||||
|
||||
counterSet(gameId: number, playerId: number, data: Data.Event_SetCounter): void {
|
||||
GameDispatch.counterSet(gameId, playerId, data);
|
||||
}
|
||||
|
||||
counterDeleted(gameId: number, playerId: number, data: Data.Event_DelCounter): void {
|
||||
GameDispatch.counterDeleted(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardsDrawn(gameId: number, playerId: number, data: Data.Event_DrawCards): void {
|
||||
GameDispatch.cardsDrawn(gameId, playerId, data);
|
||||
}
|
||||
|
||||
cardsRevealed(gameId: number, playerId: number, data: Data.Event_RevealCards): void {
|
||||
GameDispatch.cardsRevealed(gameId, playerId, data);
|
||||
}
|
||||
|
||||
zoneShuffled(gameId: number, playerId: number, data: Data.Event_Shuffle): void {
|
||||
GameDispatch.zoneShuffled(gameId, playerId, data);
|
||||
}
|
||||
|
||||
dieRolled(gameId: number, playerId: number, data: Data.Event_RollDie): void {
|
||||
GameDispatch.dieRolled(gameId, playerId, data);
|
||||
}
|
||||
|
||||
activePlayerSet(gameId: number, activePlayerId: number): void {
|
||||
GameDispatch.activePlayerSet(gameId, activePlayerId);
|
||||
}
|
||||
|
||||
activePhaseSet(gameId: number, phase: number): void {
|
||||
GameDispatch.activePhaseSet(gameId, phase);
|
||||
}
|
||||
|
||||
turnReversed(gameId: number, reversed: boolean): void {
|
||||
GameDispatch.turnReversed(gameId, reversed);
|
||||
}
|
||||
|
||||
zoneDumped(gameId: number, playerId: number, data: Data.Event_DumpZone): void {
|
||||
GameDispatch.zoneDumped(gameId, playerId, data);
|
||||
}
|
||||
|
||||
zonePropertiesChanged(gameId: number, playerId: number, data: Data.Event_ChangeZoneProperties): void {
|
||||
GameDispatch.zonePropertiesChanged(gameId, playerId, data);
|
||||
}
|
||||
}
|
||||
45
webclient/src/api/response/ModeratorResponseImpl.ts
Normal file
45
webclient/src/api/response/ModeratorResponseImpl.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { Data } from '@app/types';
|
||||
import type { IModeratorResponse } from '@app/websocket';
|
||||
import { ServerDispatch } from '@app/store';
|
||||
|
||||
export class ModeratorResponseImpl implements IModeratorResponse {
|
||||
banFromServer(userName: string): void {
|
||||
ServerDispatch.banFromServer(userName);
|
||||
}
|
||||
|
||||
banHistory(userName: string, banHistory: Data.ServerInfo_Ban[]): void {
|
||||
ServerDispatch.banHistory(userName, banHistory);
|
||||
}
|
||||
|
||||
viewLogs(logs: Data.ServerInfo_ChatMessage[]): void {
|
||||
ServerDispatch.viewLogs(logs);
|
||||
}
|
||||
|
||||
warnHistory(userName: string, warnHistory: Data.ServerInfo_Warning[]): void {
|
||||
ServerDispatch.warnHistory(userName, warnHistory);
|
||||
}
|
||||
|
||||
warnListOptions(warnList: Data.Response_WarnList[]): void {
|
||||
ServerDispatch.warnListOptions(warnList);
|
||||
}
|
||||
|
||||
warnUser(userName: string): void {
|
||||
ServerDispatch.warnUser(userName);
|
||||
}
|
||||
|
||||
grantReplayAccess(replayId: number, moderatorName: string): void {
|
||||
ServerDispatch.grantReplayAccess(replayId, moderatorName);
|
||||
}
|
||||
|
||||
forceActivateUser(usernameToActivate: string, moderatorName: string): void {
|
||||
ServerDispatch.forceActivateUser(usernameToActivate, moderatorName);
|
||||
}
|
||||
|
||||
getAdminNotes(userName: string, notes: string): void {
|
||||
ServerDispatch.getAdminNotes(userName, notes);
|
||||
}
|
||||
|
||||
updateAdminNotes(userName: string, notes: string): void {
|
||||
ServerDispatch.updateAdminNotes(userName, notes);
|
||||
}
|
||||
}
|
||||
49
webclient/src/api/response/RoomResponseImpl.ts
Normal file
49
webclient/src/api/response/RoomResponseImpl.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { Data, Enriched } from '@app/types';
|
||||
import type { IRoomResponse } from '@app/websocket';
|
||||
import { RoomsDispatch } from '@app/store';
|
||||
|
||||
export class RoomResponseImpl implements IRoomResponse {
|
||||
clearStore(): void {
|
||||
RoomsDispatch.clearStore();
|
||||
}
|
||||
|
||||
joinRoom(roomInfo: Data.ServerInfo_Room): void {
|
||||
RoomsDispatch.joinRoom(roomInfo);
|
||||
}
|
||||
|
||||
leaveRoom(roomId: number): void {
|
||||
RoomsDispatch.leaveRoom(roomId);
|
||||
}
|
||||
|
||||
updateRooms(rooms: Data.ServerInfo_Room[]): void {
|
||||
RoomsDispatch.updateRooms(rooms);
|
||||
}
|
||||
|
||||
updateGames(roomId: number, gameList: Data.ServerInfo_Game[]): void {
|
||||
RoomsDispatch.updateGames(roomId, gameList);
|
||||
}
|
||||
|
||||
addMessage(roomId: number, message: Enriched.Message): void {
|
||||
RoomsDispatch.addMessage(roomId, message);
|
||||
}
|
||||
|
||||
userJoined(roomId: number, user: Data.ServerInfo_User): void {
|
||||
RoomsDispatch.userJoined(roomId, user);
|
||||
}
|
||||
|
||||
userLeft(roomId: number, name: string): void {
|
||||
RoomsDispatch.userLeft(roomId, name);
|
||||
}
|
||||
|
||||
removeMessages(roomId: number, name: string, amount: number): void {
|
||||
RoomsDispatch.removeMessages(roomId, name, amount);
|
||||
}
|
||||
|
||||
gameCreated(roomId: number): void {
|
||||
RoomsDispatch.gameCreated(roomId);
|
||||
}
|
||||
|
||||
joinedGame(roomId: number, gameId: number): void {
|
||||
RoomsDispatch.joinedGame(roomId, gameId);
|
||||
}
|
||||
}
|
||||
232
webclient/src/api/response/SessionResponseImpl.ts
Normal file
232
webclient/src/api/response/SessionResponseImpl.ts
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
import { App, Data, Enriched } from '@app/types';
|
||||
import type { ISessionResponse } from '@app/websocket';
|
||||
import { GameDispatch, RoomsDispatch, ServerDispatch } from '@app/store';
|
||||
|
||||
export class SessionResponseImpl implements ISessionResponse {
|
||||
initialized(): void {
|
||||
ServerDispatch.initialized();
|
||||
}
|
||||
|
||||
connectionAttempted(): void {
|
||||
ServerDispatch.connectionAttempted();
|
||||
}
|
||||
|
||||
clearStore(): void {
|
||||
ServerDispatch.clearStore();
|
||||
}
|
||||
|
||||
loginSuccessful(options: Enriched.LoginSuccessContext): void {
|
||||
ServerDispatch.loginSuccessful(options);
|
||||
}
|
||||
|
||||
loginFailed(): void {
|
||||
ServerDispatch.loginFailed();
|
||||
}
|
||||
|
||||
connectionFailed(): void {
|
||||
ServerDispatch.connectionFailed();
|
||||
}
|
||||
|
||||
testConnectionSuccessful(): void {
|
||||
ServerDispatch.testConnectionSuccessful();
|
||||
}
|
||||
|
||||
testConnectionFailed(): void {
|
||||
ServerDispatch.testConnectionFailed();
|
||||
}
|
||||
|
||||
updateBuddyList(buddyList: Data.ServerInfo_User[]): void {
|
||||
ServerDispatch.updateBuddyList(buddyList);
|
||||
}
|
||||
|
||||
addToBuddyList(user: Data.ServerInfo_User): void {
|
||||
ServerDispatch.addToBuddyList(user);
|
||||
}
|
||||
|
||||
removeFromBuddyList(userName: string): void {
|
||||
ServerDispatch.removeFromBuddyList(userName);
|
||||
}
|
||||
|
||||
updateIgnoreList(ignoreList: Data.ServerInfo_User[]): void {
|
||||
ServerDispatch.updateIgnoreList(ignoreList);
|
||||
}
|
||||
|
||||
addToIgnoreList(user: Data.ServerInfo_User): void {
|
||||
ServerDispatch.addToIgnoreList(user);
|
||||
}
|
||||
|
||||
removeFromIgnoreList(userName: string): void {
|
||||
ServerDispatch.removeFromIgnoreList(userName);
|
||||
}
|
||||
|
||||
updateInfo(name: string, version: string): void {
|
||||
ServerDispatch.updateInfo(name, version);
|
||||
}
|
||||
|
||||
updateStatus(state: App.StatusEnum, description: string): void {
|
||||
if (state === App.StatusEnum.DISCONNECTED) {
|
||||
GameDispatch.clearStore();
|
||||
RoomsDispatch.clearStore();
|
||||
ServerDispatch.clearStore();
|
||||
}
|
||||
ServerDispatch.updateStatus(state, description);
|
||||
}
|
||||
|
||||
updateUser(user: Data.ServerInfo_User): void {
|
||||
ServerDispatch.updateUser(user);
|
||||
}
|
||||
|
||||
updateUsers(users: Data.ServerInfo_User[]): void {
|
||||
ServerDispatch.updateUsers(users);
|
||||
}
|
||||
|
||||
userJoined(user: Data.ServerInfo_User): void {
|
||||
ServerDispatch.userJoined(user);
|
||||
}
|
||||
|
||||
userLeft(userName: string): void {
|
||||
ServerDispatch.userLeft(userName);
|
||||
}
|
||||
|
||||
serverMessage(message: string): void {
|
||||
ServerDispatch.serverMessage(message);
|
||||
}
|
||||
|
||||
accountAwaitingActivation(options: Enriched.PendingActivationContext): void {
|
||||
ServerDispatch.accountAwaitingActivation(options);
|
||||
}
|
||||
|
||||
accountActivationSuccess(): void {
|
||||
ServerDispatch.accountActivationSuccess();
|
||||
}
|
||||
|
||||
accountActivationFailed(): void {
|
||||
ServerDispatch.accountActivationFailed();
|
||||
}
|
||||
|
||||
registrationRequiresEmail(): void {
|
||||
ServerDispatch.registrationRequiresEmail();
|
||||
}
|
||||
|
||||
registrationSuccess(): void {
|
||||
ServerDispatch.registrationSuccess();
|
||||
}
|
||||
|
||||
registrationFailed(reason: string, endTime?: number): void {
|
||||
ServerDispatch.registrationFailed(reason, endTime);
|
||||
}
|
||||
|
||||
registrationEmailError(error: string): void {
|
||||
ServerDispatch.registrationEmailError(error);
|
||||
}
|
||||
|
||||
registrationPasswordError(error: string): void {
|
||||
ServerDispatch.registrationPasswordError(error);
|
||||
}
|
||||
|
||||
registrationUserNameError(error: string): void {
|
||||
ServerDispatch.registrationUserNameError(error);
|
||||
}
|
||||
|
||||
resetPasswordChallenge(): void {
|
||||
ServerDispatch.resetPasswordChallenge();
|
||||
}
|
||||
|
||||
resetPassword(): void {
|
||||
ServerDispatch.resetPassword();
|
||||
}
|
||||
|
||||
resetPasswordSuccess(): void {
|
||||
ServerDispatch.resetPasswordSuccess();
|
||||
}
|
||||
|
||||
resetPasswordFailed(): void {
|
||||
ServerDispatch.resetPasswordFailed();
|
||||
}
|
||||
|
||||
accountPasswordChange(): void {
|
||||
ServerDispatch.accountPasswordChange();
|
||||
}
|
||||
|
||||
accountEditChanged(realName?: string, email?: string, country?: string): void {
|
||||
ServerDispatch.accountEditChanged({ realName, email, country });
|
||||
}
|
||||
|
||||
accountImageChanged(avatarBmp: Uint8Array): void {
|
||||
ServerDispatch.accountImageChanged({ avatarBmp });
|
||||
}
|
||||
|
||||
getUserInfo(userInfo: Data.ServerInfo_User): void {
|
||||
ServerDispatch.getUserInfo(userInfo);
|
||||
}
|
||||
|
||||
getGamesOfUser(userName: string, response: Data.Response_GetGamesOfUser): void {
|
||||
ServerDispatch.gamesOfUser(userName, response);
|
||||
}
|
||||
|
||||
gameJoined(gameJoinedData: Data.Event_GameJoined): void {
|
||||
GameDispatch.gameJoined(gameJoinedData);
|
||||
}
|
||||
|
||||
notifyUser(notification: Data.Event_NotifyUser): void {
|
||||
ServerDispatch.notifyUser(notification);
|
||||
}
|
||||
|
||||
playerPropertiesChanged(gameId: number, playerId: number, payload: Data.Event_PlayerPropertiesChanged): void {
|
||||
if (payload.playerProperties) {
|
||||
GameDispatch.playerPropertiesChanged(gameId, playerId, payload.playerProperties);
|
||||
}
|
||||
}
|
||||
|
||||
serverShutdown(data: Data.Event_ServerShutdown): void {
|
||||
ServerDispatch.serverShutdown(data);
|
||||
}
|
||||
|
||||
userMessage(messageData: Data.Event_UserMessage): void {
|
||||
ServerDispatch.userMessage(messageData);
|
||||
}
|
||||
|
||||
addToList(list: string, userName: string): void {
|
||||
ServerDispatch.addToList(list, userName);
|
||||
}
|
||||
|
||||
removeFromList(list: string, userName: string): void {
|
||||
ServerDispatch.removeFromList(list, userName);
|
||||
}
|
||||
|
||||
deleteServerDeck(deckId: number): void {
|
||||
ServerDispatch.deckDelete(deckId);
|
||||
}
|
||||
|
||||
updateServerDecks(deckList: Data.Response_DeckList): void {
|
||||
ServerDispatch.backendDecks(deckList);
|
||||
}
|
||||
|
||||
uploadServerDeck(path: string, treeItem: Data.ServerInfo_DeckStorage_TreeItem): void {
|
||||
ServerDispatch.deckUpload(path, treeItem);
|
||||
}
|
||||
|
||||
createServerDeckDir(path: string, dirName: string): void {
|
||||
ServerDispatch.deckNewDir(path, dirName);
|
||||
}
|
||||
|
||||
deleteServerDeckDir(path: string): void {
|
||||
ServerDispatch.deckDelDir(path);
|
||||
}
|
||||
|
||||
replayList(matchList: Data.ServerInfo_ReplayMatch[]): void {
|
||||
ServerDispatch.replayList(matchList);
|
||||
}
|
||||
|
||||
replayAdded(matchInfo: Data.ServerInfo_ReplayMatch): void {
|
||||
ServerDispatch.replayAdded(matchInfo);
|
||||
}
|
||||
|
||||
replayModifyMatch(gameId: number, doNotHide: boolean): void {
|
||||
ServerDispatch.replayModifyMatch(gameId, doNotHide);
|
||||
}
|
||||
|
||||
replayDeleteMatch(gameId: number): void {
|
||||
ServerDispatch.replayDeleteMatch(gameId);
|
||||
}
|
||||
}
|
||||
23
webclient/src/api/response/index.ts
Normal file
23
webclient/src/api/response/index.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import type { IWebClientResponse } from '@app/websocket';
|
||||
|
||||
import { SessionResponseImpl } from './SessionResponseImpl';
|
||||
import { RoomResponseImpl } from './RoomResponseImpl';
|
||||
import { GameResponseImpl } from './GameResponseImpl';
|
||||
import { AdminResponseImpl } from './AdminResponseImpl';
|
||||
import { ModeratorResponseImpl } from './ModeratorResponseImpl';
|
||||
|
||||
export { SessionResponseImpl } from './SessionResponseImpl';
|
||||
export { RoomResponseImpl } from './RoomResponseImpl';
|
||||
export { GameResponseImpl } from './GameResponseImpl';
|
||||
export { AdminResponseImpl } from './AdminResponseImpl';
|
||||
export { ModeratorResponseImpl } from './ModeratorResponseImpl';
|
||||
|
||||
export function createWebClientResponse(): IWebClientResponse {
|
||||
return {
|
||||
session: new SessionResponseImpl(),
|
||||
room: new RoomResponseImpl(),
|
||||
game: new GameResponseImpl(),
|
||||
admin: new AdminResponseImpl(),
|
||||
moderator: new ModeratorResponseImpl(),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue