feat: Update routing and websocket configuration for game state management
This commit is contained in:
2
env.d.ts
vendored
2
env.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare global {
|
||||
interface Window { __RUNTIME_CONFIG__?: { API_URL?: string } }
|
||||
interface Window { __RUNTIME_CONFIG__?: { API_URL?: string; WEBSOCKET_URL?: string } }
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -74,7 +74,6 @@
|
||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
@@ -2575,7 +2574,6 @@
|
||||
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
@@ -2626,7 +2624,6 @@
|
||||
"integrity": "sha512-PC0PDZfJg8sP7cmKe6L3QIL8GZwU5aRvUFedqSIpw3B+QjRSUZeeITC2M5XKeMXEzL6wccN196iy3JLwKNvDVA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.48.1",
|
||||
"@typescript-eslint/types": "8.48.1",
|
||||
@@ -2844,7 +2841,6 @@
|
||||
"integrity": "sha512-iHmwV3QcVGGvSC1BG5bZ4z6iwa1SOpAPWmnjOErd4Ske+lZua5K9TtAVdx0gMBClJ28DViCbSmZitjWZsWO3LA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@rolldown/pluginutils": "1.0.0-beta.50"
|
||||
},
|
||||
@@ -3231,7 +3227,6 @@
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -3323,7 +3318,6 @@
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz",
|
||||
"integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.4",
|
||||
@@ -3406,7 +3400,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.9.0",
|
||||
"caniuse-lite": "^1.0.30001759",
|
||||
@@ -3874,7 +3867,6 @@
|
||||
"integrity": "sha512-BhHmn2yNOFA9H9JmmIVKJmd288g9hrVRDkdoIgRCRuSySRUHH7r/DI6aAXW9T1WwUuY3DFgrcaqB+deURBLR5g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -3935,7 +3927,6 @@
|
||||
"integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"eslint-config-prettier": "bin/cli.js"
|
||||
},
|
||||
@@ -3983,7 +3974,6 @@
|
||||
"integrity": "sha512-SbR9ZBUFKgvWAbq3RrdCtWaW0IKm6wwUiApxf3BVTNfqUIo4IQQmreMg2iHFJJ6C/0wss3LXURBJ1OwS/MhFcQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.4.0",
|
||||
"natural-compare": "^1.4.0",
|
||||
@@ -4665,7 +4655,6 @@
|
||||
"integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"jiti": "lib/jiti-cli.mjs"
|
||||
}
|
||||
@@ -5351,7 +5340,6 @@
|
||||
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
@@ -5396,7 +5384,6 @@
|
||||
"resolved": "https://registry.npmjs.org/quasar/-/quasar-2.18.6.tgz",
|
||||
"integrity": "sha512-ZlK+vJXOBPSFDCNQDBDNwSI+AHoqaFPxK8ve6mhsYLhMKWI5b8zsGY9VU1xYjngO2aBvU4fvGWXy4tTbzrBk8Q==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">= 10.18.1",
|
||||
"npm": ">= 6.13.4",
|
||||
@@ -6157,7 +6144,6 @@
|
||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -6262,7 +6248,6 @@
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -6393,7 +6378,6 @@
|
||||
"integrity": "sha512-tI2l/nFHC5rLh7+5+o7QjKjSR04ivXDF4jcgV0f/bTQ+OJiITy5S6gaynVsEM+7RqzufMnVbIon6Sr5x1SDYaQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.25.0",
|
||||
"fdir": "^6.5.0",
|
||||
@@ -6644,7 +6628,6 @@
|
||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -6664,7 +6647,6 @@
|
||||
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.25.tgz",
|
||||
"integrity": "sha512-YLVdgv2K13WJ6n+kD5owehKtEXwdwXuj2TTyJMsO7pSeKw2bfRNZGjhB7YzrpbMYj5b5QsUebHpOqR3R3ziy/g==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/compiler-dom": "3.5.25",
|
||||
"@vue/compiler-sfc": "3.5.25",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
window.__RUNTIME_CONFIG__ = {
|
||||
API_URL: "http://localhost:9000"
|
||||
API_URL: "http://localhost:9000",
|
||||
WEBSOCKET_API_URL: "ws://localhost:9000/websocket"
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
window.__RUNTIME_CONFIG__ = {
|
||||
API_URL: "${API_URL}"
|
||||
API_URL: "${API_URL}",
|
||||
WEBSOCKET_API_URL: "${WEBSOCKET_API_URL}"
|
||||
};
|
||||
|
||||
|
||||
@@ -13,38 +13,45 @@ const ig = useIngame()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-layout>
|
||||
<q-page-container>
|
||||
<q-page class="game-field-background vh-100 ingame-side-shadow">
|
||||
<div class="py-5 container-xxl">
|
||||
|
||||
<q-row class="q-gutter-md q-mx-md">
|
||||
<q-col cols="4" class="mt-5 text-start">
|
||||
<div class="fit row wrap justify-center items-center content-start">
|
||||
<div class="mt-5 ml-4 self-start col-2">
|
||||
<TurnC v-if="(ig.data as GameInfo)?.playerQueue" :queue="(ig.data as GameInfo).playerQueue!"/>
|
||||
</q-col>
|
||||
|
||||
<q-col cols="4" class="text-center">
|
||||
<ScoreboardC v-if="(ig.data as GameInfo)?.currentRound" :current-round="(ig.data as GameInfo).currentRound!" />
|
||||
|
||||
<div class="d-flex justify-content-center g-3 mb-5">
|
||||
<PlayedCardsC v-if="(ig.data as GameInfo)?.currentTrick" :trick="(ig.data as GameInfo).currentTrick!" />
|
||||
</div>
|
||||
</q-col>
|
||||
|
||||
<div class="text-center col-6">
|
||||
<ScoreboardC v-if="(ig.data as GameInfo)?.currentRound" :current-round="(ig.data as GameInfo).currentRound!" />
|
||||
</div>
|
||||
|
||||
|
||||
<q-col cols="4" class="mt-5 text-end">
|
||||
<div class="mt-5 ml-4 self-end col-2" style="margin-left: 6em">
|
||||
<GameInfoC v-if="(ig.data as GameInfo)?.currentRound"
|
||||
:first-card="(ig.data as GameInfo).currentTrick?.firstCard ?? null"
|
||||
:trumpsuit="(ig.data as GameInfo).currentRound!.trumpSuit"/>
|
||||
</q-col>
|
||||
</q-row>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<q-row justify="center" class="q-gutter-sm mt-4 bottom-div" style="backdrop-filter: blur(4px); margin-left: 0; margin-right: 0;">
|
||||
<q-col cols="12" class="flex justify-center">
|
||||
<HandC v-if="(ig.data as GameInfo)?.hand && (ig.data as GameInfo)?.self" :hand="(ig.data as GameInfo).hand!" :self="(ig.data as GameInfo).self"/>
|
||||
</q-col>
|
||||
</q-row>
|
||||
<div class="fit row wrap justify-center items-center content-start">
|
||||
<div class="mt-4 ml-4 col-3 justify-content-center">
|
||||
<div class="d-flex justify-content-center g-3 mb-5">
|
||||
<PlayedCardsC v-if="(ig.data as GameInfo)?.currentTrick" :trick="(ig.data as GameInfo).currentTrick!" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="q-gutter-sm mt-4 bottom-div justify-content-center row" style="backdrop-filter: blur(4px); margin-left: 0; margin-right: 0;">
|
||||
<div class="flex justify-center col-12">
|
||||
<HandC v-if="(ig.data as GameInfo)?.hand && (ig.data as GameInfo)?.self"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</q-page>
|
||||
</q-page-container>
|
||||
</q-layout>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
@@ -59,4 +66,15 @@ const ig = useIngame()
|
||||
.ingame-side-shadow {
|
||||
box-shadow: 0 1px 15px 0 #000000
|
||||
}
|
||||
.bottom-div {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
max-width: 1400px;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -11,7 +11,7 @@ const {trumpsuit, firstCard} = toRefs(props)
|
||||
|
||||
|
||||
const trumpName = computed(() => {
|
||||
switch (trumpsuit.value.path.charAt(trumpsuit.value.path.length - 1)) {
|
||||
switch (trumpsuit.value.identifier.charAt(1) as string) {
|
||||
case 'S':
|
||||
return 'Spades'
|
||||
case 'H':
|
||||
@@ -36,14 +36,12 @@ const trumpName = computed(() => {
|
||||
|
||||
<div class="q-mt-md">
|
||||
<div class="text-subtitle1 q-mb-xs q-font-medium">First Card</div>
|
||||
<div id="first-card-container" class="q-pa-sm bg-grey-2 rounded shadow-2"
|
||||
<div id="first-card-container" class="q-pa-sm rounded shadow-2"
|
||||
style="display:inline-block;">
|
||||
<q-img v-if="firstCard" :src="firstCard.path" alt="First Card" class="firstbox"
|
||||
style="width: 80px; border-radius: 6px;"/>
|
||||
<div v-else class="q-pa-sm"
|
||||
style="width: 80px; height: 120px; display:flex; align-items:center; justify-content:center; border-radius:6px; background: #ffffff; color: #666;">
|
||||
No image
|
||||
</div>
|
||||
<q-img v-else src="/images/cards/1B.png" alt="First Card" class="firstbox"
|
||||
style="width: 80px; border-radius: 6px;"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
<script lang="ts" setup>
|
||||
import {toRefs} from 'vue'
|
||||
import type {Hand, Player} from "@/types/GameSubTypes.ts";
|
||||
import {useWebSocket} from "@/composables/useWebsocket.ts";
|
||||
import {useIngame} from "@/composables/useIngame.ts";
|
||||
import type {GameInfo} from "@/types/GameTypes.ts";
|
||||
import {useQuasar} from "quasar";
|
||||
|
||||
const wb = useWebSocket()
|
||||
const wi = useIngame()
|
||||
const $q = useQuasar();
|
||||
|
||||
const props = defineProps<{
|
||||
hand: Hand
|
||||
isHandInactive?: boolean
|
||||
self: Player | null
|
||||
}>()
|
||||
|
||||
const { hand, isHandInactive, self } = toRefs(props)
|
||||
|
||||
function handlePlayCard(element: any, index: number | null) {
|
||||
function handlePlayCard(index: number | null) {
|
||||
if (index === null) return
|
||||
if (isHandInactive?.value) return
|
||||
isHandInactive.value = true
|
||||
|
||||
const wiggleKeyframes = [
|
||||
{ transform: 'translateX(0)' },
|
||||
@@ -34,9 +27,11 @@ function handlePlayCard(element: any, index: number | null) {
|
||||
};
|
||||
|
||||
wb.sendAndWait("PlayCard", { cardindex: index })
|
||||
.catch(() => {
|
||||
element.animate(wiggleKeyframes, wiggleTiming);
|
||||
isHandInactive.value = false;
|
||||
.catch((error) => {
|
||||
$q.notify({
|
||||
message: "Error playing card: " + error.message,
|
||||
color: "negative"
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -52,16 +47,16 @@ function getCardImagePath(cardPath: string) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="bottom-div hand-container">
|
||||
<div id="card-slide" :class="'ingame-cards-slide ' + (isHandInactive ? 'inactive' : '' )">
|
||||
<div class="hand-container">
|
||||
<div id="card-slide" class="ingame-cards-slide">
|
||||
<div class="cards-row">
|
||||
<div v-for="card in hand.cards" :key="card.identifier" class="handcard">
|
||||
<div class="card-btn" @click="handlePlayCard(this, card.idx)" aria-label="Play card">
|
||||
<q-img :src="getCardImagePath(card.path)" :alt="card.identifier" class="card" />
|
||||
<div v-for="card in (<GameInfo>wi.data)?.hand?.cards" :key="card.identifier" class="handcard">
|
||||
<div class="card-btn" aria-label="Play card">
|
||||
<q-img :src="getCardImagePath(card.path)" v-on:click="handlePlayCard(card.idx)" :alt="card.identifier" class="card" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="self?.dogLife" class="dog-actions">
|
||||
<div v-if="(<GameInfo>wi.data)?.self?.dogLife" class="dog-actions">
|
||||
<q-btn color="negative" label="Skip Turn" @click="handleSkipDogLife" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,12 +6,15 @@ const props = defineProps<{ trick: Trick }>()
|
||||
const {trick } = toRefs(props)
|
||||
|
||||
const playedCards = computed(() => {
|
||||
return [...trick.value.cards].map(card => {
|
||||
return {
|
||||
cardId: card[1].path,
|
||||
player: card[0].name
|
||||
}
|
||||
if (!trick.value) return []
|
||||
let result: { cardId: string, player: string }[] = []
|
||||
for (const key in trick.value.cards) {
|
||||
result.push({
|
||||
cardId: trick.value.cards[key]?.path ?? '',
|
||||
player: key
|
||||
})
|
||||
}
|
||||
return result;
|
||||
})
|
||||
|
||||
function getCardImagePath(cardPath: string) {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import type {Round} from "@/types/GameSubTypes.ts";
|
||||
import {computed, type ComputedRef} from "vue";
|
||||
|
||||
interface PlayerScore { name: string; tricks: number }
|
||||
const props = defineProps<{ currentRound: Round }>()
|
||||
const playerScores: PlayerScore[] = props.currentRound.playersIn.map(player => {
|
||||
const playerScores: ComputedRef<PlayerScore[]> = computed(() => {
|
||||
return props.currentRound.playersIn.map(player => {
|
||||
return {
|
||||
name: player.name,
|
||||
tricks: props.currentRound.trickList.filter(trick => {
|
||||
return trick.winner?.id === player.id
|
||||
}).length
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import {computed, toRefs} from 'vue'
|
||||
import type {PlayerQueue} from "@/types/GameSubTypes.ts";
|
||||
import {useIngame} from "@/composables/useIngame.ts";
|
||||
import type {GameInfo} from "@/types/GameTypes.ts";
|
||||
|
||||
const props = defineProps<{
|
||||
queue: PlayerQueue
|
||||
}>()
|
||||
|
||||
const safeNextPlayers = computed(() => props.queue.players ?? [])
|
||||
const ig = useIngame()
|
||||
const currentPlayer = computed(() => (<GameInfo>ig.data).playerQueue.currentPlayer)
|
||||
const queue = computed(() => { return (<GameInfo>ig.data).playerQueue.queue ?? []})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-card flat class="turn-tracker-container q-pa-md">
|
||||
<q-card flat class="turn-tracker-container q-pa-md no-background">
|
||||
<q-card-section>
|
||||
<div class="text-subtitle2 q-mb-xs">Current Player</div>
|
||||
<div id="current-player-name" class="text-h6 text-weight-bold text-positive">{{
|
||||
props.queue.currentPlayer?.name
|
||||
currentPlayer?.name
|
||||
}}</div>
|
||||
|
||||
<div v-if="safeNextPlayers.length > 0" class="q-mt-md">
|
||||
<div v-if="queue.length > 0" class="q-mt-md">
|
||||
<div id="next-players-text" class="text-subtitle2 q-mb-xs">Next Players</div>
|
||||
<q-list id="next-players-container" dense>
|
||||
<q-item v-for="player in safeNextPlayers" :key="player.id">
|
||||
<q-item v-for="player in queue" :key="player.id">
|
||||
<q-item-section>
|
||||
<div class="text-body1 text-primary">{{ player.name }}</div>
|
||||
</q-item-section>
|
||||
@@ -35,4 +35,7 @@ const safeNextPlayers = computed(() => props.queue.players ?? [])
|
||||
.turn-tracker-container {
|
||||
max-width: 320px;
|
||||
}
|
||||
.no-background {
|
||||
background: none !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import type {LobbyInfo} from "@/types/GameTypes.ts";
|
||||
import type {User} from "@/types/GameSubTypes.ts";
|
||||
import {useIngame} from "@/composables/useIngame.ts";
|
||||
import type {LobbyInfo} from "@/types/GameTypes.ts";
|
||||
import {useWebSocket} from "@/composables/useWebsocket.ts";
|
||||
import {computed} from "vue";
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
lobbyInfo: LobbyInfo
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(e: 'kick-player', user: User): void;
|
||||
(e: 'start-game'): void;
|
||||
(e: 'leave-game', user: User): void;
|
||||
}>();
|
||||
|
||||
const isHost = props.lobbyInfo.self.host;
|
||||
|
||||
const players = props.lobbyInfo.users;
|
||||
|
||||
const lobbyName = `${props.lobbyInfo.gameId}`;
|
||||
const wb = useWebSocket()
|
||||
const ig = useIngame();
|
||||
const maxPlayers = computed(() => (<LobbyInfo>ig.data).maxPlayers);
|
||||
const isHost = computed(() => (<LobbyInfo>ig.data).self.host);
|
||||
const players = computed(() => {
|
||||
return (<LobbyInfo>ig.data).users;
|
||||
})
|
||||
const lobbyName = `${ig.data?.gameId}`;
|
||||
|
||||
const handleKickPlayer = (user: User) => {
|
||||
if (isHost) {
|
||||
@@ -26,7 +22,7 @@ const handleKickPlayer = (user: User) => {
|
||||
|
||||
const handleStartGame = () => {
|
||||
if (isHost) {
|
||||
emit('start-game');
|
||||
wb.send("StartGame", {})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,14 +40,14 @@ const profileIcon = 'person';
|
||||
<q-btn
|
||||
color="negative"
|
||||
label="Exit"
|
||||
@click="handleLeaveGame(props.lobbyInfo.self)"
|
||||
@click="handleLeaveGame((<LobbyInfo>ig.data).self)"
|
||||
class="q-ml-auto"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="row q-pb-md">
|
||||
<div class="col text-center text-subtitle1">
|
||||
Players: {{ players.length }} / {{ props.lobbyInfo.maxPlayers }}
|
||||
Players: {{ players.length }} / {{ maxPlayers }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -65,7 +61,7 @@ const profileIcon = 'person';
|
||||
|
||||
<q-card-section>
|
||||
<div class="text-h6">
|
||||
{{ player.username }} <q-badge v-if="player.id === props.lobbyInfo.self.id" color="orange" align="middle" class="q-ml-xs">
|
||||
{{ player.username }} <q-badge v-if="player.id === (<LobbyInfo>ig.data).self.id" color="orange" align="middle" class="q-ml-xs">
|
||||
(You)
|
||||
</q-badge>
|
||||
<q-badge v-else-if="player.host" color="blue" align="middle" class="q-ml-xs">
|
||||
@@ -76,10 +72,10 @@ const profileIcon = 'person';
|
||||
|
||||
<q-card-actions align="center" v-if="isHost">
|
||||
<q-btn
|
||||
v-if="player.id !== props.lobbyInfo.self.id"
|
||||
v-if="player.id !== (<LobbyInfo>ig.data).self.id"
|
||||
color="negative"
|
||||
label="Remove"
|
||||
@click="handleKickPlayer(props.lobbyInfo.self)"
|
||||
@click="handleKickPlayer((<LobbyInfo>ig.data).self)"
|
||||
class="full-width"
|
||||
/>
|
||||
<q-btn
|
||||
|
||||
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
|
||||
import {ref, type Ref} from 'vue'
|
||||
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo, WonInfo} from "@/types/GameTypes.ts";
|
||||
import axios from "axios";
|
||||
import {initWebSocket} from "@/services/ws.ts";
|
||||
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
@@ -14,8 +15,8 @@ export const useIngame = defineStore('ingame', () => {
|
||||
data.value = newData;
|
||||
}
|
||||
|
||||
function requestGame(gameId: string) {
|
||||
axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
|
||||
async function requestGame(gameId: string) {
|
||||
await axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
|
||||
setIngame(response.data.state, response.data.data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,14 +18,15 @@ export const useUserInfo = defineStore('userInfo', () => {
|
||||
gameId.value = id;
|
||||
}
|
||||
|
||||
function requestState() {
|
||||
axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
async function requestState() {
|
||||
await axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
console.log("STATUS DATA:" + response.data.status + response.data.inGame)
|
||||
username.value = response.data.username;
|
||||
if (response.data.ingame) {
|
||||
if (response.data.gameId) {
|
||||
console.log("GAMEID:" + response.data.gameId)
|
||||
gameId.value = response.data.gameId;
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
|
||||
@@ -20,8 +20,8 @@ const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
app.use(pinia)
|
||||
const ingameStore = useIngame();
|
||||
initWebSocket(ingameStore)
|
||||
const ui = useIngame();
|
||||
initWebSocket(ui);
|
||||
app.use(router)
|
||||
app.use(Quasar, {
|
||||
plugins: {
|
||||
|
||||
@@ -9,13 +9,14 @@ import { useUserInfo } from "@/composables/useUserInfo";
|
||||
import rulesView from "../components/Rules.vue";
|
||||
import LobbyView from "@/views/LobbyView.vue";
|
||||
import GameView from "@/views/Game.vue"
|
||||
import Game from "@/views/Game.vue";
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/mainmenu/',
|
||||
path: '/',
|
||||
component: MainMenuView,
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
@@ -52,9 +53,9 @@ const router = createRouter({
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
{
|
||||
path: '/lobby',
|
||||
name: 'lobby',
|
||||
component: LobbyView,
|
||||
path: '/game',
|
||||
name: 'game',
|
||||
component: Game,
|
||||
meta: {requiresAuth: true }
|
||||
}
|
||||
],
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
// Reads runtime configuration injected into window.__RUNTIME_CONFIG__ (created by env.js at container start)
|
||||
|
||||
declare global {
|
||||
interface Window { __RUNTIME_CONFIG__?: { API_URL?: string } }
|
||||
interface Window { __RUNTIME_CONFIG__?: { API_URL?: string; WEBSOCKET_URL?: string } }
|
||||
}
|
||||
|
||||
const runtime = (globalThis as any).__RUNTIME_CONFIG__ || {};
|
||||
|
||||
export const API_URL = runtime.API_URL || (import.meta.env.VITE_API_URL as string) || 'http://localhost:9000';
|
||||
export const WEBSOCKET_URL = runtime.API_URL || (import.meta.env.VITE_WEBSOCKET_URL as string) || 'http://localhost:9000';
|
||||
|
||||
export function getApiUrl(): string {
|
||||
return API_URL;
|
||||
}
|
||||
|
||||
export function getWebsocketUrl(): string {
|
||||
return WEBSOCKET_URL;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import {useIngame} from "@/composables/useIngame.ts";
|
||||
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo, WonInfo} from "@/types/GameTypes.ts";
|
||||
import router from "@/router";
|
||||
|
||||
const api = window.__RUNTIME_CONFIG__?.API_URL;
|
||||
const api = "localhost:9000"
|
||||
|
||||
// ---------- Types ---------------------------------------------------------
|
||||
|
||||
@@ -107,7 +108,9 @@ function setupSocketHandlers(socket: WebSocket) {
|
||||
}
|
||||
|
||||
if (state && stateData) {
|
||||
console.debug("[WS] State change:", state, stateData);
|
||||
if(uState) {
|
||||
console.debug("[WS] State change cascade:", state, stateData);
|
||||
uState.setIngame(state, stateData);
|
||||
}
|
||||
}
|
||||
@@ -164,7 +167,7 @@ function setupSocketHandlers(socket: WebSocket) {
|
||||
}
|
||||
|
||||
// You redirect here — if you don’t want auto reconnect, keep as is.
|
||||
location.href = "/mainmenu";
|
||||
router.replace("/");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ type Player = {
|
||||
|
||||
type PlayerQueue = {
|
||||
currentPlayer: Player | null
|
||||
players: Player[]
|
||||
queue: Player[]
|
||||
}
|
||||
|
||||
type PodiumPlayer = {
|
||||
@@ -34,7 +34,7 @@ type Round = {
|
||||
}
|
||||
|
||||
type Trick = {
|
||||
cards: Map<Player, Card>
|
||||
cards: { [key: string]: Card} | null
|
||||
firstCard: Card | null
|
||||
winner: Player | null
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const createGameQuasar = async () => {
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
router.push("/lobby")
|
||||
router.replace("/game")
|
||||
}).catch((err) => {
|
||||
console.log("ERROR:" + err)
|
||||
}).finally(() =>
|
||||
|
||||
@@ -1,26 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import {useWebSocket} from "@/composables/useWebsocket.ts";
|
||||
import {useIngame} from "@/composables/useIngame.ts";
|
||||
import Ingame from "@/components/Ingame.vue";
|
||||
import {useUserInfo} from "@/composables/useUserInfo.ts";
|
||||
import router from "@/router";
|
||||
import LobbyComponent from "@/components/lobby/LobbyComponent.vue";
|
||||
import {storeToRefs} from "pinia";
|
||||
import {useQuasar} from "quasar";
|
||||
|
||||
const wb = useWebSocket()
|
||||
const ig = useIngame()
|
||||
const { state } = storeToRefs(ig)
|
||||
const ui = useUserInfo()
|
||||
const $q = useQuasar();
|
||||
|
||||
ui.requestState()
|
||||
if (ui.gameId) {
|
||||
ig.requestGame(ui.gameId)
|
||||
ui.requestState().then(() => {
|
||||
if (ui.gameId == null) {
|
||||
$q.notify({
|
||||
message: "You're not in any game!",
|
||||
color: "negative"
|
||||
|
||||
})
|
||||
} else {
|
||||
ig.requestGame(ui.gameId).then(() => {
|
||||
wb.connect()
|
||||
} else {
|
||||
router.replace("/")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="lobby-background">
|
||||
<Ingame v-if="ig.state === 'InGame'" />
|
||||
<Ingame v-if="state === 'InGame'"/>
|
||||
<lobby-component v-if="state === 'Lobby'"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -28,6 +39,6 @@ if (ui.gameId) {
|
||||
.lobby-background {
|
||||
background-color: var(--body-background-color);
|
||||
width: 100%;
|
||||
min-height:100vh;
|
||||
min-height: 100vh;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -22,7 +22,7 @@ const startGameQuasar = async() => {
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
router.push("/lobby")
|
||||
router.replace("/game")
|
||||
}).catch(() => {
|
||||
$q.notify({
|
||||
message: `Lobby "${lobbyCode.value}" nicht gefunden`,
|
||||
|
||||
@@ -80,7 +80,7 @@ const onSubmit = () => {
|
||||
loginError.value = ''
|
||||
axios.post(`${api}/login`, {username: username.value, password: password.value}, {withCredentials: true}).then((response) => {
|
||||
uInfo.setUserInfo(response.data.user.username, response.data.user.id)
|
||||
router.push("/mainmenu")
|
||||
router.push("/")
|
||||
}).catch(() => {
|
||||
loginError.value = 'Invalid username or password'
|
||||
}).finally(() =>
|
||||
|
||||
Reference in New Issue
Block a user