Feat : add surrender button
release-tag / release-image (push) Successful in 51s

This commit is contained in:
2024-08-27 13:08:15 +02:00
parent b5d89d4fe9
commit 29cd28953d
2 changed files with 31 additions and 9 deletions
+11
View File
@@ -80,6 +80,17 @@ export async function leaveGame(game: string) {
); );
} }
export async function surrender(game: string) {
const config = useRuntimeConfig();
const res = await $fetch<Game>(
config.public.endpoint + `/games/${game}/surrender`,
{
method: "POST",
credentials: "include",
}
);
}
export async function kickPlayer(game: string, playerId: string) { export async function kickPlayer(game: string, playerId: string) {
const config = useRuntimeConfig(); const config = useRuntimeConfig();
const res = await $fetch<Game>( const res = await $fetch<Game>(
+20 -9
View File
@@ -8,6 +8,7 @@ import {
joinGame, joinGame,
deleteGame, deleteGame,
leaveGame, leaveGame,
surrender,
} from "~/netcode"; } from "~/netcode";
import { delay } from "~/netcode/events"; import { delay } from "~/netcode/events";
import { import {
@@ -262,7 +263,14 @@ onUnmounted(() => {
<!-- <LoadingScreen v-if="!loaded"></LoadingScreen> --> <!-- <LoadingScreen v-if="!loaded"></LoadingScreen> -->
<footer> <footer>
<GameModalOptionsDialog></GameModalOptionsDialog> <div>
<GameModalOptionsDialog></GameModalOptionsDialog>
<GameModalConfigureDialog
v-if="game && game.owner.userId == authStore.selfUser.userId"
:game="game"
></GameModalConfigureDialog>
</div>
<ClientOnly> <ClientOnly>
<div id="turn_buttons" v-if="game"> <div id="turn_buttons" v-if="game">
<template v-if="game.started"> <template v-if="game.started">
@@ -284,26 +292,29 @@ onUnmounted(() => {
> >
Start game Start game
</button> </button>
<GameModalConfigureDialog :game="game"></GameModalConfigureDialog>
</template> </template>
<button <button
class="end_turn_button turn_icon" class="end_turn_button turn_icon"
@click="joinGame(game._id)" @click="joinGame(game._id)"
v-else-if=" v-else-if="!selfPlayer"
playerList?.every(
(p) => p.user.userId != authStore.selfUser.userId
)
"
> >
Join game Join game
</button> </button>
<button v-else @click="leaveGame(game._id)">Leave game</button> <button v-else @click="leaveGame(game._id)">Leave game</button>
</template> </template>
</div> </div>
<div>
<button
v-if="game && game.started && selfPlayer"
class="red"
@click="surrender(game._id)"
>
Surrender
</button>
<button @click="navigateTo('/lobby')">Return to lobby</button>
</div>
</ClientOnly> </ClientOnly>
<button @click="navigateTo('/lobby')">Return to lobby</button>
</footer> </footer>
</div> </div>
</template> </template>