fix : focus active player automatically on game load

This commit is contained in:
2024-08-03 17:50:33 +02:00
parent 5e992122d8
commit 9e1af6f3df
+13 -5
View File
@@ -233,7 +233,13 @@ onBeforeMount(async () => {
navigateTo("/lobby");
throw new Error("game not found");
}
focusedPlayer.value = selfPlayer.value ?? playerList.value![0];
if (game.value.started) {
focusedPlayer.value = game.value.teams.find(
(t) => t._id == game.value?.currentTurn.currentTeam
)?.players[0];
} else {
focusedPlayer.value = selfPlayer.value ?? playerList.value![0];
}
eventSource = subscribe(`/games/${gameId}/subscribe`);
eventSource.addEventListener("message", async (message) => {
@@ -264,10 +270,11 @@ const selfPlayer = computed(() =>
);
const isTurn = computed(
() =>
game.value &&
selfPlayer.value &&
game.value.teams.find((t) => t.players.includes(selfPlayer.value!))?._id ==
game.value.currentTurn.currentTeam
(game.value &&
selfPlayer.value &&
game.value.teams.find((t) => t.players.includes(selfPlayer.value!))
?._id == game.value.currentTurn.currentTeam) ??
false
);
const turnChangeAnimationSpeed = computed(
@@ -364,6 +371,7 @@ onUnmounted(() => {
:game="game"
@click="focusPlayer(p)"
:focused="focusedPlayer == p"
:is-self-turn="isTurn"
:self="selfPlayer == p"
>
</GamePlayerListElement>