mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-23 07:03:54 -07:00
remove type aliases
This commit is contained in:
parent
141f0e59f5
commit
cea9ae62d8
58 changed files with 412 additions and 455 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import { ArrowInfo, CardInfo, CounterInfo, PlayerProperties, ProtoInit } from 'types';
|
||||
import { ProtoInit } from 'types';
|
||||
import type { ServerInfo_Card } from 'generated/proto/serverinfo_card_pb';
|
||||
import type { ServerInfo_Counter } from 'generated/proto/serverinfo_counter_pb';
|
||||
import type { ServerInfo_Arrow } from 'generated/proto/serverinfo_arrow_pb';
|
||||
import type { ServerInfo_PlayerProperties } from 'generated/proto/serverinfo_playerproperties_pb';
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { ServerInfo_CardSchema } from 'generated/proto/serverinfo_card_pb';
|
||||
import { ServerInfo_CounterSchema } from 'generated/proto/serverinfo_counter_pb';
|
||||
|
|
@ -7,7 +11,7 @@ import { ServerInfo_ArrowSchema } from 'generated/proto/serverinfo_arrow_pb';
|
|||
import { ServerInfo_PlayerPropertiesSchema } from 'generated/proto/serverinfo_playerproperties_pb';
|
||||
import { GameEntry, GamesState, PlayerEntry, ZoneEntry } from '../game.interfaces';
|
||||
|
||||
export function makeCard(overrides: ProtoInit<CardInfo> = {}): CardInfo {
|
||||
export function makeCard(overrides: ProtoInit<ServerInfo_Card> = {}): ServerInfo_Card {
|
||||
return create(ServerInfo_CardSchema, {
|
||||
id: 1,
|
||||
name: 'Test Card',
|
||||
|
|
@ -30,7 +34,7 @@ export function makeCard(overrides: ProtoInit<CardInfo> = {}): CardInfo {
|
|||
});
|
||||
}
|
||||
|
||||
export function makeCounter(overrides: ProtoInit<CounterInfo> = {}): CounterInfo {
|
||||
export function makeCounter(overrides: ProtoInit<ServerInfo_Counter> = {}): ServerInfo_Counter {
|
||||
return create(ServerInfo_CounterSchema, {
|
||||
id: 1,
|
||||
name: 'Life',
|
||||
|
|
@ -41,7 +45,7 @@ export function makeCounter(overrides: ProtoInit<CounterInfo> = {}): CounterInfo
|
|||
});
|
||||
}
|
||||
|
||||
export function makeArrow(overrides: ProtoInit<ArrowInfo> = {}): ArrowInfo {
|
||||
export function makeArrow(overrides: ProtoInit<ServerInfo_Arrow> = {}): ServerInfo_Arrow {
|
||||
return create(ServerInfo_ArrowSchema, {
|
||||
id: 1,
|
||||
startPlayerId: 1,
|
||||
|
|
@ -68,7 +72,7 @@ export function makeZoneEntry(overrides: Partial<ZoneEntry> = {}): ZoneEntry {
|
|||
};
|
||||
}
|
||||
|
||||
export function makePlayerProperties(overrides: ProtoInit<PlayerProperties> = {}): PlayerProperties {
|
||||
export function makePlayerProperties(overrides: ProtoInit<ServerInfo_PlayerProperties> = {}): ServerInfo_PlayerProperties {
|
||||
return create(ServerInfo_PlayerPropertiesSchema, {
|
||||
playerId: 1,
|
||||
spectator: false,
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
import {
|
||||
AttachCardData,
|
||||
ChangeZonePropertiesData,
|
||||
CreateArrowData,
|
||||
CreateCounterData,
|
||||
CreateTokenData,
|
||||
DelCounterData,
|
||||
DeleteArrowData,
|
||||
DestroyCardData,
|
||||
DrawCardsData,
|
||||
DumpZoneData,
|
||||
FlipCardData,
|
||||
GameStateChangedData,
|
||||
MoveCardData,
|
||||
PlayerProperties,
|
||||
RevealCardsData,
|
||||
RollDieData,
|
||||
SetCardAttrData,
|
||||
SetCardCounterData,
|
||||
SetCounterData,
|
||||
ShuffleData,
|
||||
} from 'types';
|
||||
import type { Event_AttachCard } from 'generated/proto/event_attach_card_pb';
|
||||
import type { Event_ChangeZoneProperties } from 'generated/proto/event_change_zone_properties_pb';
|
||||
import type { Event_CreateArrow } from 'generated/proto/event_create_arrow_pb';
|
||||
import type { Event_CreateCounter } from 'generated/proto/event_create_counter_pb';
|
||||
import type { Event_CreateToken } from 'generated/proto/event_create_token_pb';
|
||||
import type { Event_DelCounter } from 'generated/proto/event_del_counter_pb';
|
||||
import type { Event_DeleteArrow } from 'generated/proto/event_delete_arrow_pb';
|
||||
import type { Event_DestroyCard } from 'generated/proto/event_destroy_card_pb';
|
||||
import type { Event_DrawCards } from 'generated/proto/event_draw_cards_pb';
|
||||
import type { Event_DumpZone } from 'generated/proto/event_dump_zone_pb';
|
||||
import type { Event_FlipCard } from 'generated/proto/event_flip_card_pb';
|
||||
import type { Event_GameStateChanged } from 'generated/proto/event_game_state_changed_pb';
|
||||
import type { Event_MoveCard } from 'generated/proto/event_move_card_pb';
|
||||
import type { ServerInfo_PlayerProperties } from 'generated/proto/serverinfo_playerproperties_pb';
|
||||
import type { Event_RevealCards } from 'generated/proto/event_reveal_cards_pb';
|
||||
import type { Event_RollDie } from 'generated/proto/event_roll_die_pb';
|
||||
import type { Event_SetCardAttr } from 'generated/proto/event_set_card_attr_pb';
|
||||
import type { Event_SetCardCounter } from 'generated/proto/event_set_card_counter_pb';
|
||||
import type { Event_SetCounter } from 'generated/proto/event_set_counter_pb';
|
||||
import type { Event_Shuffle } from 'generated/proto/event_shuffle_pb';
|
||||
import { GameEntry } from './game.interfaces';
|
||||
import { Types } from './game.types';
|
||||
|
||||
|
|
@ -50,13 +48,13 @@ export const Actions = {
|
|||
hostId,
|
||||
}),
|
||||
|
||||
gameStateChanged: (gameId: number, data: GameStateChangedData) => ({
|
||||
gameStateChanged: (gameId: number, data: Event_GameStateChanged) => ({
|
||||
type: Types.GAME_STATE_CHANGED,
|
||||
gameId,
|
||||
data,
|
||||
}),
|
||||
|
||||
playerJoined: (gameId: number, playerProperties: PlayerProperties) => ({
|
||||
playerJoined: (gameId: number, playerProperties: ServerInfo_PlayerProperties) => ({
|
||||
type: Types.PLAYER_JOINED,
|
||||
gameId,
|
||||
playerProperties,
|
||||
|
|
@ -69,7 +67,7 @@ export const Actions = {
|
|||
reason,
|
||||
}),
|
||||
|
||||
playerPropertiesChanged: (gameId: number, playerId: number, properties: PlayerProperties) => ({
|
||||
playerPropertiesChanged: (gameId: number, playerId: number, properties: ServerInfo_PlayerProperties) => ({
|
||||
type: Types.PLAYER_PROPERTIES_CHANGED,
|
||||
gameId,
|
||||
playerId,
|
||||
|
|
@ -81,112 +79,112 @@ export const Actions = {
|
|||
gameId,
|
||||
}),
|
||||
|
||||
cardMoved: (gameId: number, playerId: number, data: MoveCardData) => ({
|
||||
cardMoved: (gameId: number, playerId: number, data: Event_MoveCard) => ({
|
||||
type: Types.CARD_MOVED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardFlipped: (gameId: number, playerId: number, data: FlipCardData) => ({
|
||||
cardFlipped: (gameId: number, playerId: number, data: Event_FlipCard) => ({
|
||||
type: Types.CARD_FLIPPED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardDestroyed: (gameId: number, playerId: number, data: DestroyCardData) => ({
|
||||
cardDestroyed: (gameId: number, playerId: number, data: Event_DestroyCard) => ({
|
||||
type: Types.CARD_DESTROYED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardAttached: (gameId: number, playerId: number, data: AttachCardData) => ({
|
||||
cardAttached: (gameId: number, playerId: number, data: Event_AttachCard) => ({
|
||||
type: Types.CARD_ATTACHED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
tokenCreated: (gameId: number, playerId: number, data: CreateTokenData) => ({
|
||||
tokenCreated: (gameId: number, playerId: number, data: Event_CreateToken) => ({
|
||||
type: Types.TOKEN_CREATED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardAttrChanged: (gameId: number, playerId: number, data: SetCardAttrData) => ({
|
||||
cardAttrChanged: (gameId: number, playerId: number, data: Event_SetCardAttr) => ({
|
||||
type: Types.CARD_ATTR_CHANGED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardCounterChanged: (gameId: number, playerId: number, data: SetCardCounterData) => ({
|
||||
cardCounterChanged: (gameId: number, playerId: number, data: Event_SetCardCounter) => ({
|
||||
type: Types.CARD_COUNTER_CHANGED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
arrowCreated: (gameId: number, playerId: number, data: CreateArrowData) => ({
|
||||
arrowCreated: (gameId: number, playerId: number, data: Event_CreateArrow) => ({
|
||||
type: Types.ARROW_CREATED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
arrowDeleted: (gameId: number, playerId: number, data: DeleteArrowData) => ({
|
||||
arrowDeleted: (gameId: number, playerId: number, data: Event_DeleteArrow) => ({
|
||||
type: Types.ARROW_DELETED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
counterCreated: (gameId: number, playerId: number, data: CreateCounterData) => ({
|
||||
counterCreated: (gameId: number, playerId: number, data: Event_CreateCounter) => ({
|
||||
type: Types.COUNTER_CREATED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
counterSet: (gameId: number, playerId: number, data: SetCounterData) => ({
|
||||
counterSet: (gameId: number, playerId: number, data: Event_SetCounter) => ({
|
||||
type: Types.COUNTER_SET,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
counterDeleted: (gameId: number, playerId: number, data: DelCounterData) => ({
|
||||
counterDeleted: (gameId: number, playerId: number, data: Event_DelCounter) => ({
|
||||
type: Types.COUNTER_DELETED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardsDrawn: (gameId: number, playerId: number, data: DrawCardsData) => ({
|
||||
cardsDrawn: (gameId: number, playerId: number, data: Event_DrawCards) => ({
|
||||
type: Types.CARDS_DRAWN,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
cardsRevealed: (gameId: number, playerId: number, data: RevealCardsData) => ({
|
||||
cardsRevealed: (gameId: number, playerId: number, data: Event_RevealCards) => ({
|
||||
type: Types.CARDS_REVEALED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
zoneShuffled: (gameId: number, playerId: number, data: ShuffleData) => ({
|
||||
zoneShuffled: (gameId: number, playerId: number, data: Event_Shuffle) => ({
|
||||
type: Types.ZONE_SHUFFLED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
dieRolled: (gameId: number, playerId: number, data: RollDieData) => ({
|
||||
dieRolled: (gameId: number, playerId: number, data: Event_RollDie) => ({
|
||||
type: Types.DIE_ROLLED,
|
||||
gameId,
|
||||
playerId,
|
||||
|
|
@ -211,14 +209,14 @@ export const Actions = {
|
|||
reversed,
|
||||
}),
|
||||
|
||||
zoneDumped: (gameId: number, playerId: number, data: DumpZoneData) => ({
|
||||
zoneDumped: (gameId: number, playerId: number, data: Event_DumpZone) => ({
|
||||
type: Types.ZONE_DUMPED,
|
||||
gameId,
|
||||
playerId,
|
||||
data,
|
||||
}),
|
||||
|
||||
zonePropertiesChanged: (gameId: number, playerId: number, data: ChangeZonePropertiesData) => ({
|
||||
zonePropertiesChanged: (gameId: number, playerId: number, data: Event_ChangeZoneProperties) => ({
|
||||
type: Types.ZONE_PROPERTIES_CHANGED,
|
||||
gameId,
|
||||
playerId,
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
import {
|
||||
AttachCardData,
|
||||
ChangeZonePropertiesData,
|
||||
CreateArrowData,
|
||||
CreateCounterData,
|
||||
CreateTokenData,
|
||||
DelCounterData,
|
||||
DeleteArrowData,
|
||||
DestroyCardData,
|
||||
DrawCardsData,
|
||||
DumpZoneData,
|
||||
FlipCardData,
|
||||
GameStateChangedData,
|
||||
MoveCardData,
|
||||
PlayerProperties,
|
||||
RevealCardsData,
|
||||
RollDieData,
|
||||
SetCardAttrData,
|
||||
SetCardCounterData,
|
||||
SetCounterData,
|
||||
ShuffleData,
|
||||
} from 'types';
|
||||
import type { Event_AttachCard } from 'generated/proto/event_attach_card_pb';
|
||||
import type { Event_ChangeZoneProperties } from 'generated/proto/event_change_zone_properties_pb';
|
||||
import type { Event_CreateArrow } from 'generated/proto/event_create_arrow_pb';
|
||||
import type { Event_CreateCounter } from 'generated/proto/event_create_counter_pb';
|
||||
import type { Event_CreateToken } from 'generated/proto/event_create_token_pb';
|
||||
import type { Event_DelCounter } from 'generated/proto/event_del_counter_pb';
|
||||
import type { Event_DeleteArrow } from 'generated/proto/event_delete_arrow_pb';
|
||||
import type { Event_DestroyCard } from 'generated/proto/event_destroy_card_pb';
|
||||
import type { Event_DrawCards } from 'generated/proto/event_draw_cards_pb';
|
||||
import type { Event_DumpZone } from 'generated/proto/event_dump_zone_pb';
|
||||
import type { Event_FlipCard } from 'generated/proto/event_flip_card_pb';
|
||||
import type { Event_GameStateChanged } from 'generated/proto/event_game_state_changed_pb';
|
||||
import type { Event_MoveCard } from 'generated/proto/event_move_card_pb';
|
||||
import type { ServerInfo_PlayerProperties } from 'generated/proto/serverinfo_playerproperties_pb';
|
||||
import type { Event_RevealCards } from 'generated/proto/event_reveal_cards_pb';
|
||||
import type { Event_RollDie } from 'generated/proto/event_roll_die_pb';
|
||||
import type { Event_SetCardAttr } from 'generated/proto/event_set_card_attr_pb';
|
||||
import type { Event_SetCardCounter } from 'generated/proto/event_set_card_counter_pb';
|
||||
import type { Event_SetCounter } from 'generated/proto/event_set_counter_pb';
|
||||
import type { Event_Shuffle } from 'generated/proto/event_shuffle_pb';
|
||||
import { store } from 'store/store';
|
||||
import { Actions } from './game.actions';
|
||||
import { GameEntry } from './game.interfaces';
|
||||
|
|
@ -45,11 +43,11 @@ export const Dispatch = {
|
|||
store.dispatch(Actions.gameHostChanged(gameId, hostId));
|
||||
},
|
||||
|
||||
gameStateChanged: (gameId: number, data: GameStateChangedData) => {
|
||||
gameStateChanged: (gameId: number, data: Event_GameStateChanged) => {
|
||||
store.dispatch(Actions.gameStateChanged(gameId, data));
|
||||
},
|
||||
|
||||
playerJoined: (gameId: number, playerProperties: PlayerProperties) => {
|
||||
playerJoined: (gameId: number, playerProperties: ServerInfo_PlayerProperties) => {
|
||||
store.dispatch(Actions.playerJoined(gameId, playerProperties));
|
||||
},
|
||||
|
||||
|
|
@ -57,7 +55,7 @@ export const Dispatch = {
|
|||
store.dispatch(Actions.playerLeft(gameId, playerId, reason));
|
||||
},
|
||||
|
||||
playerPropertiesChanged: (gameId: number, playerId: number, properties: PlayerProperties) => {
|
||||
playerPropertiesChanged: (gameId: number, playerId: number, properties: ServerInfo_PlayerProperties) => {
|
||||
store.dispatch(Actions.playerPropertiesChanged(gameId, playerId, properties));
|
||||
},
|
||||
|
||||
|
|
@ -65,67 +63,67 @@ export const Dispatch = {
|
|||
store.dispatch(Actions.kicked(gameId));
|
||||
},
|
||||
|
||||
cardMoved: (gameId: number, playerId: number, data: MoveCardData) => {
|
||||
cardMoved: (gameId: number, playerId: number, data: Event_MoveCard) => {
|
||||
store.dispatch(Actions.cardMoved(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardFlipped: (gameId: number, playerId: number, data: FlipCardData) => {
|
||||
cardFlipped: (gameId: number, playerId: number, data: Event_FlipCard) => {
|
||||
store.dispatch(Actions.cardFlipped(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardDestroyed: (gameId: number, playerId: number, data: DestroyCardData) => {
|
||||
cardDestroyed: (gameId: number, playerId: number, data: Event_DestroyCard) => {
|
||||
store.dispatch(Actions.cardDestroyed(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardAttached: (gameId: number, playerId: number, data: AttachCardData) => {
|
||||
cardAttached: (gameId: number, playerId: number, data: Event_AttachCard) => {
|
||||
store.dispatch(Actions.cardAttached(gameId, playerId, data));
|
||||
},
|
||||
|
||||
tokenCreated: (gameId: number, playerId: number, data: CreateTokenData) => {
|
||||
tokenCreated: (gameId: number, playerId: number, data: Event_CreateToken) => {
|
||||
store.dispatch(Actions.tokenCreated(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardAttrChanged: (gameId: number, playerId: number, data: SetCardAttrData) => {
|
||||
cardAttrChanged: (gameId: number, playerId: number, data: Event_SetCardAttr) => {
|
||||
store.dispatch(Actions.cardAttrChanged(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardCounterChanged: (gameId: number, playerId: number, data: SetCardCounterData) => {
|
||||
cardCounterChanged: (gameId: number, playerId: number, data: Event_SetCardCounter) => {
|
||||
store.dispatch(Actions.cardCounterChanged(gameId, playerId, data));
|
||||
},
|
||||
|
||||
arrowCreated: (gameId: number, playerId: number, data: CreateArrowData) => {
|
||||
arrowCreated: (gameId: number, playerId: number, data: Event_CreateArrow) => {
|
||||
store.dispatch(Actions.arrowCreated(gameId, playerId, data));
|
||||
},
|
||||
|
||||
arrowDeleted: (gameId: number, playerId: number, data: DeleteArrowData) => {
|
||||
arrowDeleted: (gameId: number, playerId: number, data: Event_DeleteArrow) => {
|
||||
store.dispatch(Actions.arrowDeleted(gameId, playerId, data));
|
||||
},
|
||||
|
||||
counterCreated: (gameId: number, playerId: number, data: CreateCounterData) => {
|
||||
counterCreated: (gameId: number, playerId: number, data: Event_CreateCounter) => {
|
||||
store.dispatch(Actions.counterCreated(gameId, playerId, data));
|
||||
},
|
||||
|
||||
counterSet: (gameId: number, playerId: number, data: SetCounterData) => {
|
||||
counterSet: (gameId: number, playerId: number, data: Event_SetCounter) => {
|
||||
store.dispatch(Actions.counterSet(gameId, playerId, data));
|
||||
},
|
||||
|
||||
counterDeleted: (gameId: number, playerId: number, data: DelCounterData) => {
|
||||
counterDeleted: (gameId: number, playerId: number, data: Event_DelCounter) => {
|
||||
store.dispatch(Actions.counterDeleted(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardsDrawn: (gameId: number, playerId: number, data: DrawCardsData) => {
|
||||
cardsDrawn: (gameId: number, playerId: number, data: Event_DrawCards) => {
|
||||
store.dispatch(Actions.cardsDrawn(gameId, playerId, data));
|
||||
},
|
||||
|
||||
cardsRevealed: (gameId: number, playerId: number, data: RevealCardsData) => {
|
||||
cardsRevealed: (gameId: number, playerId: number, data: Event_RevealCards) => {
|
||||
store.dispatch(Actions.cardsRevealed(gameId, playerId, data));
|
||||
},
|
||||
|
||||
zoneShuffled: (gameId: number, playerId: number, data: ShuffleData) => {
|
||||
zoneShuffled: (gameId: number, playerId: number, data: Event_Shuffle) => {
|
||||
store.dispatch(Actions.zoneShuffled(gameId, playerId, data));
|
||||
},
|
||||
|
||||
dieRolled: (gameId: number, playerId: number, data: RollDieData) => {
|
||||
dieRolled: (gameId: number, playerId: number, data: Event_RollDie) => {
|
||||
store.dispatch(Actions.dieRolled(gameId, playerId, data));
|
||||
},
|
||||
|
||||
|
|
@ -141,11 +139,11 @@ export const Dispatch = {
|
|||
store.dispatch(Actions.turnReversed(gameId, reversed));
|
||||
},
|
||||
|
||||
zoneDumped: (gameId: number, playerId: number, data: DumpZoneData) => {
|
||||
zoneDumped: (gameId: number, playerId: number, data: Event_DumpZone) => {
|
||||
store.dispatch(Actions.zoneDumped(gameId, playerId, data));
|
||||
},
|
||||
|
||||
zonePropertiesChanged: (gameId: number, playerId: number, data: ChangeZonePropertiesData) => {
|
||||
zonePropertiesChanged: (gameId: number, playerId: number, data: Event_ChangeZoneProperties) => {
|
||||
store.dispatch(Actions.zonePropertiesChanged(gameId, playerId, data));
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { ArrowInfo, CardInfo, CounterInfo, PlayerProperties } from 'types';
|
||||
import type { ServerInfo_Card } from 'generated/proto/serverinfo_card_pb';
|
||||
import type { ServerInfo_Counter } from 'generated/proto/serverinfo_counter_pb';
|
||||
import type { ServerInfo_Arrow } from 'generated/proto/serverinfo_arrow_pb';
|
||||
import type { ServerInfo_PlayerProperties } from 'generated/proto/serverinfo_playerproperties_pb';
|
||||
|
||||
export interface GamesState {
|
||||
games: { [gameId: number]: GameEntry };
|
||||
|
|
@ -29,14 +32,14 @@ export interface GameEntry {
|
|||
|
||||
/** Normalized from ServerInfo_Player — keyed collections for O(1) lookup. */
|
||||
export interface PlayerEntry {
|
||||
properties: PlayerProperties;
|
||||
properties: ServerInfo_PlayerProperties;
|
||||
deckList: string;
|
||||
/** Zones keyed by zone name (e.g. "hand", "deck", "table"). */
|
||||
zones: { [zoneName: string]: ZoneEntry };
|
||||
/** Player-level counters (e.g. life) keyed by counter id. */
|
||||
counters: { [counterId: number]: CounterInfo };
|
||||
counters: { [counterId: number]: ServerInfo_Counter };
|
||||
/** Arrows keyed by arrow id. */
|
||||
arrows: { [arrowId: number]: ArrowInfo };
|
||||
arrows: { [arrowId: number]: ServerInfo_Arrow };
|
||||
}
|
||||
|
||||
/** Normalized from ServerInfo_Zone — card list is an ordered array matching proto. */
|
||||
|
|
@ -48,7 +51,7 @@ export interface ZoneEntry {
|
|||
/** Authoritative card count (used for hidden zones where cardList may be empty). */
|
||||
cardCount: number;
|
||||
/** Ordered card list; may be empty for hidden zones with no dump active. */
|
||||
cards: CardInfo[];
|
||||
cards: ServerInfo_Card[];
|
||||
alwaysRevealTopCard: boolean;
|
||||
alwaysLookAtTopCard: boolean;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { CardAttribute, PlayerInfo } from 'types';
|
||||
import { CardAttribute } from 'generated/proto/card_attributes_pb';
|
||||
import type { ServerInfo_Player } from 'generated/proto/serverinfo_player_pb';
|
||||
import { gamesReducer } from './game.reducer';
|
||||
import { Types } from './game.types';
|
||||
import {
|
||||
|
|
@ -68,7 +69,7 @@ describe('2B: Game state & player management', () => {
|
|||
const card = makeCard({ id: 5 });
|
||||
const counter = makeCounter({ id: 2 });
|
||||
const arrow = makeArrow({ id: 3 });
|
||||
const playerList: PlayerInfo[] = [
|
||||
const playerList: ServerInfo_Player[] = [
|
||||
create(ServerInfo_PlayerSchema, {
|
||||
properties: makePlayerProperties({ playerId: 7 }),
|
||||
deckList: 'some deck',
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
import {
|
||||
ArrowInfo,
|
||||
CardAttribute,
|
||||
CardCounterInfo,
|
||||
CardInfo,
|
||||
CounterInfo,
|
||||
PlayerInfo,
|
||||
PlayerProperties,
|
||||
} from 'types';
|
||||
import { CardAttribute } from 'generated/proto/card_attributes_pb';
|
||||
import type { ServerInfo_CardCounter } from 'generated/proto/serverinfo_cardcounter_pb';
|
||||
import type { ServerInfo_Card } from 'generated/proto/serverinfo_card_pb';
|
||||
import type { ServerInfo_Counter } from 'generated/proto/serverinfo_counter_pb';
|
||||
import type { ServerInfo_Arrow } from 'generated/proto/serverinfo_arrow_pb';
|
||||
import type { ServerInfo_Player } from 'generated/proto/serverinfo_player_pb';
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { ServerInfo_CardSchema } from 'generated/proto/serverinfo_card_pb';
|
||||
import { ServerInfo_CardCounterSchema } from 'generated/proto/serverinfo_cardcounter_pb';
|
||||
|
|
@ -77,7 +74,7 @@ function removeGame(state: GamesState, gameId: number): GamesState {
|
|||
}
|
||||
|
||||
/** Converts the proto PlayerInfo[] array into the keyed PlayerEntry map used in the store. */
|
||||
function normalizePlayers(playerList: PlayerInfo[]): { [playerId: number]: PlayerEntry } {
|
||||
function normalizePlayers(playerList: ServerInfo_Player[]): { [playerId: number]: PlayerEntry } {
|
||||
const players: { [playerId: number]: PlayerEntry } = {};
|
||||
for (const player of playerList) {
|
||||
const playerId = player.properties.playerId;
|
||||
|
|
@ -95,12 +92,12 @@ function normalizePlayers(playerList: PlayerInfo[]): { [playerId: number]: Playe
|
|||
};
|
||||
}
|
||||
|
||||
const counters: { [counterId: number]: CounterInfo } = {};
|
||||
const counters: { [counterId: number]: ServerInfo_Counter } = {};
|
||||
for (const counter of player.counterList) {
|
||||
counters[counter.id] = counter;
|
||||
}
|
||||
|
||||
const arrows: { [arrowId: number]: ArrowInfo } = {};
|
||||
const arrows: { [arrowId: number]: ServerInfo_Arrow } = {};
|
||||
for (const arrow of player.arrowList) {
|
||||
arrows[arrow.id] = arrow;
|
||||
}
|
||||
|
|
@ -123,7 +120,7 @@ function buildEmptyCard(
|
|||
y: number,
|
||||
faceDown: boolean,
|
||||
providerId: string
|
||||
): CardInfo {
|
||||
): ServerInfo_Card {
|
||||
return create(ServerInfo_CardSchema, {
|
||||
id,
|
||||
name,
|
||||
|
|
@ -209,7 +206,7 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
return state;
|
||||
}
|
||||
const newPlayer: PlayerEntry = {
|
||||
properties: playerProperties as PlayerProperties,
|
||||
properties: playerProperties,
|
||||
deckList: '',
|
||||
zones: {},
|
||||
counters: {},
|
||||
|
|
@ -269,8 +266,8 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
}
|
||||
|
||||
// Locate card in source zone (by id for visible zones, by position for hidden)
|
||||
let removedCard: CardInfo | undefined;
|
||||
let newSourceCards: CardInfo[];
|
||||
let removedCard: ServerInfo_Card | undefined;
|
||||
let newSourceCards: ServerInfo_Card[];
|
||||
if (cardId >= 0) {
|
||||
removedCard = sourceZoneEntry.cards.find(c => c.id === cardId);
|
||||
newSourceCards = sourceZoneEntry.cards.filter(c => c.id !== cardId);
|
||||
|
|
@ -283,7 +280,7 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
}
|
||||
|
||||
const effectiveNewId = newCardId >= 0 ? newCardId : (removedCard?.id ?? -1);
|
||||
const movedCard: CardInfo = removedCard
|
||||
const movedCard: ServerInfo_Card = removedCard
|
||||
? {
|
||||
...removedCard,
|
||||
id: effectiveNewId,
|
||||
|
|
@ -426,7 +423,7 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
return state;
|
||||
}
|
||||
|
||||
const newCard: CardInfo = create(ServerInfo_CardSchema, {
|
||||
const newCard: ServerInfo_Card = create(ServerInfo_CardSchema, {
|
||||
id: cardId,
|
||||
name: cardName,
|
||||
x,
|
||||
|
|
@ -472,7 +469,7 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
return state;
|
||||
}
|
||||
|
||||
const attrPatch: Partial<CardInfo> = {};
|
||||
const attrPatch: Partial<ServerInfo_Card> = {};
|
||||
switch (attribute as CardAttribute) {
|
||||
case CardAttribute.AttrTapped: attrPatch.tapped = attrValue === '1'; break;
|
||||
case CardAttribute.AttrAttacking: attrPatch.attacking = attrValue === '1'; break;
|
||||
|
|
@ -510,7 +507,7 @@ export const gamesReducer = (state: GamesState = initialState, action: GameActio
|
|||
}
|
||||
|
||||
const card = zone.cards[cardIdx];
|
||||
let newCounterList: CardCounterInfo[];
|
||||
let newCounterList: ServerInfo_CardCounter[];
|
||||
if (counterValue <= 0) {
|
||||
newCounterList = card.counterList.filter(c => c.id !== counterId);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { CardInfo } from 'types';
|
||||
import type { ServerInfo_Card } from 'generated/proto/serverinfo_card_pb';
|
||||
import { GamesState, GameEntry, PlayerEntry, ZoneEntry } from './game.interfaces';
|
||||
|
||||
interface State {
|
||||
games: GamesState;
|
||||
}
|
||||
|
||||
const EMPTY_ARRAY: CardInfo[] = [];
|
||||
const EMPTY_ARRAY: ServerInfo_Card[] = [];
|
||||
const EMPTY_OBJECT = {} as Record<string, never>;
|
||||
|
||||
export const Selectors = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue