Fix: some minor problems

This commit is contained in:
Dorian Zedler 2022-12-29 17:42:47 +01:00
parent 59435bd2af
commit 1e080865ff
Signed by: dorian
GPG Key ID: 989DE36109AFA354
2 changed files with 4 additions and 3 deletions

View File

@ -27,7 +27,7 @@
<button @click="$store.remoteState.giveTurnToNextPlayer()"
x-bind:disabled="$store.remoteState.currentPlayer !== $store.localState.id">I'm done!</button>
<p>Player after me:</p>
<p>Player after me: <b x-text="$store.remoteState.players[$store.localState.nextPlayer]"></b> </p>
<select x-model="$store.localState.nextPlayer">
<template
x-for="playerId in Object.keys($store.remoteState.players).filter(id => id != $store.localState.id)"

View File

@ -24,7 +24,7 @@ function Timer() {
}, 1000);
},
}
}
}
document.addEventListener('alpine:init', () => {
console.log("Alpine.js is ready to go!")
@ -102,7 +102,7 @@ document.addEventListener('alpine:init', () => {
})
Alpine.effect(() => {
if(Alpine.store("localState").nextPlayer == null || !Object.keys(this.players).includes(Alpine.store("localState").nextPlayer)) {
if(Alpine.store("localState").nextPlayer == null || Alpine.store("localState").nextPlayer == Alpine.store("localState").id || !Object.keys(this.players).includes(Alpine.store("localState").nextPlayer)) {
const players = Object.keys(this.players).sort();
const nextPlayer = players[(players.indexOf(Alpine.store("localState").id) + 1) % players.length]
Alpine.store("localState").nextPlayer = nextPlayer;
@ -160,6 +160,7 @@ document.addEventListener('alpine:init', () => {
this._client.publish('im.dorian.whos-turn-is-it.players', JSON.stringify({
[Alpine.store("localState").id]: Alpine.store("localState").name,
}), { qos:1, retain: true })
this._client.publish('im.dorian.whos-turn-is-it.currentPlayer', Alpine.store("localState").id, { qos:1, retain: true })
}
})
})