From 26772d9d30214a8be89765cb932682560350f2d0 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sun, 23 Apr 2023 16:36:31 +0200 Subject: [PATCH] commit #7 --- src/clientGame.ts | 6 +++- src/components/Card.vue | 11 ++++++-- src/components/Game.vue | 14 ++++------ src/components/JoinScreen.vue | 2 +- src/components/LoginScreen.vue | 2 +- src/components/NumberCard.vue | 1 + src/components/PlayerCards.vue | 10 +++++++ src/components/SpecialCard.vue | 46 ++++++++++++++++++++++++++++++ src/icons.ts | 30 ++++++++++++++++++++ src/server/game.ts | 51 ++++++++++++++++++++++++++++------ src/server/trpc/game.ts | 10 +++++++ src/shared/constants.ts | 2 ++ src/shared/game/actions.ts | 4 +-- src/shared/game/cards.ts | 25 +++++++++++++++-- src/shared/game/state.ts | 39 ++++++++++++++++++++------ src/shared/lobbyCode.ts | 1 - src/specialCards.ts | 7 ----- 17 files changed, 216 insertions(+), 45 deletions(-) create mode 100644 src/components/SpecialCard.vue create mode 100644 src/icons.ts create mode 100644 src/shared/constants.ts delete mode 100644 src/shared/lobbyCode.ts delete mode 100644 src/specialCards.ts diff --git a/src/clientGame.ts b/src/clientGame.ts index db02d09..07ac7d7 100644 --- a/src/clientGame.ts +++ b/src/clientGame.ts @@ -2,10 +2,11 @@ import { defineStore } from "pinia" import { EventBusKey, useEventBus } from "@vueuse/core" import type { GameAction } from "./shared/game/actions" import { computed, reactive, readonly, ref } from "vue" -import { GameState, getUninitializedGameState, produceNewState } from "./shared/game/state" +import { GameState, getNumberCardsSum, getUninitializedGameState, produceNewState } from "./shared/game/state" import { trpcClient } from "./trpc" import { useAuth } from "./auth" import { read } from "fs" +import type { SpecialCardId } from "./shared/game/cards" const gameActionsBusKey = Symbol() as EventBusKey const useGameActionsBus = () => useEventBus(gameActionsBusKey) @@ -63,6 +64,8 @@ export const useGame = defineStore("game", () => { lobbyCode: readonly(lobbyCode), isActive: computed(() => lobbyCode.value !== null), isOwnGame: computed(() => state.value.players.findIndex(p => p.id === (auth.authenticatedUser?.id ?? "")) === 0), + isYourTurn: computed(() => state.value.activePlayerId === auth.requiredUser.id), + isBust: computed(() => getNumberCardsSum(state.value.players.find(p => p.id === auth.requiredUser.id)!.numberCards) > state.value.targetSum), state: readonly(state), actions: readonly(actions), join, @@ -75,6 +78,7 @@ export const useGame = defineStore("game", () => { start: () => trpcClient.game.start.mutate({ lobbyCode: lobbyCode.value! }), hit: () => trpcClient.game.hit.mutate({ lobbyCode: lobbyCode.value! }), stay: () => trpcClient.game.stay.mutate({ lobbyCode: lobbyCode.value! }), + useSpecialCard: (id: SpecialCardId) => trpcClient.game.useSpecialCard.mutate({ lobbyCode: lobbyCode.value!, specialCardId: id }), newRound: () => trpcClient.game.newRound.mutate({ lobbyCode: lobbyCode.value! }), create: () => trpcClient.createGame.mutate() } diff --git a/src/components/Card.vue b/src/components/Card.vue index 6cda4f7..e411d6b 100644 --- a/src/components/Card.vue +++ b/src/components/Card.vue @@ -1,5 +1,5 @@ @@ -38,6 +42,7 @@ icon: FunctionalComponent }>>, default: [] - } + }, + asButton: Boolean }) \ No newline at end of file diff --git a/src/components/Game.vue b/src/components/Game.vue index 45005d8..1479795 100644 --- a/src/components/Game.vue +++ b/src/components/Game.vue @@ -13,18 +13,18 @@