teletilting

This commit is contained in:
Gavin McDonald
2025-06-27 18:14:06 -04:00
parent a0e4f54ed9
commit 2ae4c6a77b
7 changed files with 93 additions and 38 deletions

View File

@@ -2,7 +2,7 @@ import Deck from '@/lib/TarokkaDeck';
import generateID from '@/tools/simpleID';
import parseMilliseconds from '@/tools/parseMilliseconds';
import { HOUR, DAY } from '@/constants/time';
import { GameState, GameUpdate, Settings } from '@/types';
import { GameState, GameUpdate, Settings, Tilt } from '@/types';
const deck = new Deck();
@@ -91,6 +91,7 @@ export default class GameStore {
notes: true,
cardStyle: 'color',
},
tilts: Array.from({ length: 5 }, () => []),
};
this.totalCreated++;
@@ -157,6 +158,21 @@ export default class GameStore {
return this.gameUpdate(game);
}
tilt(playerID: string, cardIndex: number, { rotateX, rotateY }: Tilt) {
const game = this.getGameByPlayerID(playerID);
const cardTilts = game.tilts[cardIndex];
if (!cardTilts) throw new Error(`Card tilts ${cardIndex} not found`);
game.tilts[cardIndex] = [
...cardTilts.filter((tilt) => tilt.playerID !== playerID),
{ playerID, rotateX, rotateY },
];
game.lastUpdated = Date.now();
return this.gameUpdate(game);
}
updateSettings(gameID: string, settings: Settings) {
const game = this.getGame(gameID);
@@ -173,10 +189,18 @@ export default class GameStore {
return game;
}
gameUpdate(game: GameState): GameUpdate {
const { dmID, spectatorID, cards, settings } = game;
getGameByPlayerID(playerID: string): GameState {
const game = this.players.get(playerID);
return { dmID, spectatorID, cards, settings };
if (!game) throw new Error(`Player ${playerID} not found`);
return game;
}
gameUpdate(game: GameState): GameUpdate {
const { dmID, spectatorID, cards, settings, tilts } = game;
return { dmID, spectatorID, cards, settings, tilts };
}
playerExit(playerID: string): GameState | null {
@@ -185,9 +209,7 @@ export default class GameStore {
return null;
} else {
const game = this.players.get(playerID);
if (!game) throw new Error(`Player ${playerID} not found`);
const game = this.getGameByPlayerID(playerID);
this.players.delete(playerID);
return this.leaveGame(game, playerID);