Feat: diffrent visuals

This commit is contained in:
Dorian Zedler 2022-12-29 17:59:24 +01:00
parent 1e080865ff
commit cc1714d2a6
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 21 additions and 8 deletions

View file

@ -5,6 +5,18 @@
line-height: 1.2; line-height: 1.2;
} }
@keyframes blinker {
50% {
opacity: 0;
}
}
.timer.my-turn {
color: #0f0;
animation: blinker 1s linear infinite;
}
.timer.over { .timer.over {
color: #f00; color: #f00;
} }

View file

@ -16,13 +16,13 @@
<div x-data> <div x-data>
<div x-show="$store.localState.joined"> <div x-show="$store.localState.joined">
<hgroup> <hgroup>
<h1 x-text="'Currently playing: ' + $store.remoteState.players[$store.remoteState.currentPlayer]"> <h1 x-text="'Currently playing: ' + ($store.remoteState.isMyTurn ? 'YOU!':$store.remoteState.players[$store.remoteState.currentPlayer])">
</h1> </h1>
<h2 x-text="'I am ' + $store.localState.name"></h2> <h2 x-text="'You are ' + $store.localState.name"></h2>
</hgroup> </hgroup>
<div x-data="Timer"> <div x-data="Timer">
<p :class="time < 0 ? 'timer over':'timer'" x-text="time + 's'"></p> <p :class="'timer' + ($store.remoteState.isMyTurn ? ' my-turn':'') + (time < 0 ? ' over':'')" x-text="time + 's'"></p>
</div> </div>
<button @click="$store.remoteState.giveTurnToNextPlayer()" <button @click="$store.remoteState.giveTurnToNextPlayer()"

View file

@ -20,7 +20,7 @@ function Timer() {
time: 0, time: 0,
init() { init() {
setInterval(() => { setInterval(() => {
this.time = parseInt((30000 - ((new Date()).getTime() - Alpine.store("remoteState").lastPlayerSwitch)) / 1000); this.time = parseInt((90000 - ((new Date()).getTime() - Alpine.store("remoteState").lastPlayerSwitch)) / 1000);
}, 1000); }, 1000);
}, },
} }
@ -43,9 +43,6 @@ document.addEventListener('alpine:init', () => {
} }
}) })
Alpine.effect(() => {
console.log(this.nextPlayer)
})
this.restore(); this.restore();
}, },
@ -82,6 +79,7 @@ document.addEventListener('alpine:init', () => {
currentPlayer: null, currentPlayer: null,
lastPlayerSwitch: 0, lastPlayerSwitch: 0,
connected: false, connected: false,
isMyTurn: false,
_client: null, _client: null,
init() { init() {
@ -97,7 +95,10 @@ document.addEventListener('alpine:init', () => {
Alpine.effect(() => { Alpine.effect(() => {
this.lastPlayerSwitch = new Date().getTime(); this.lastPlayerSwitch = new Date().getTime();
if(this.currentPlayer == Alpine.store("localState").id) { if(this.currentPlayer == Alpine.store("localState").id) {
alert("It's your turn!") this.isMyTurn = true;
}
else {
this.isMyTurn = false;
} }
}) })