Fix: some minor problems
This commit is contained in:
parent
59435bd2af
commit
1e080865ff
2 changed files with 4 additions and 3 deletions
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<button @click="$store.remoteState.giveTurnToNextPlayer()"
|
<button @click="$store.remoteState.giveTurnToNextPlayer()"
|
||||||
x-bind:disabled="$store.remoteState.currentPlayer !== $store.localState.id">I'm done!</button>
|
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">
|
<select x-model="$store.localState.nextPlayer">
|
||||||
<template
|
<template
|
||||||
x-for="playerId in Object.keys($store.remoteState.players).filter(id => id != $store.localState.id)"
|
x-for="playerId in Object.keys($store.remoteState.players).filter(id => id != $store.localState.id)"
|
||||||
|
|
3
index.js
3
index.js
|
@ -102,7 +102,7 @@ document.addEventListener('alpine:init', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
Alpine.effect(() => {
|
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 players = Object.keys(this.players).sort();
|
||||||
const nextPlayer = players[(players.indexOf(Alpine.store("localState").id) + 1) % players.length]
|
const nextPlayer = players[(players.indexOf(Alpine.store("localState").id) + 1) % players.length]
|
||||||
Alpine.store("localState").nextPlayer = nextPlayer;
|
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({
|
this._client.publish('im.dorian.whos-turn-is-it.players', JSON.stringify({
|
||||||
[Alpine.store("localState").id]: Alpine.store("localState").name,
|
[Alpine.store("localState").id]: Alpine.store("localState").name,
|
||||||
}), { qos:1, retain: true })
|
}), { qos:1, retain: true })
|
||||||
|
this._client.publish('im.dorian.whos-turn-is-it.currentPlayer', Alpine.store("localState").id, { qos:1, retain: true })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
Loading…
Reference in a new issue