0
0
Fork 0

Update hand to display the most recent question when the hand area until they receive a new card from the mediums.

This commit is contained in:
Oliver-Akins 2021-01-03 15:59:12 -07:00
parent 1eac963bc5
commit d639ed4a48

View file

@ -1,20 +1,25 @@
<template> <template>
<div id="PlayerHand"> <div id="PlayerHand">
<div <div class="recentQuestion" v-if="mostRecentQuestion">
class="card" {{ mostRecentQuestion }}
v-for="cardIndex in questions.length" </div>
:key="`card_${cardIndex}`" <div class="hand" v-else>
@click.self="handleCardClick(cardIndex)" <div
> class="card"
<p class="card-text centre"> v-for="cardIndex in questions.length"
{{ questions[cardIndex - 1] }} :key="`card_${cardIndex}`"
</p> @click.self="handleCardClick(cardIndex)"
<button
class="card-button clickable"
@click.stop="sendCard(cardIndex)"
> >
{{ buttonLabel }} <p class="card-text centre">
</button> {{ questions[cardIndex - 1] }}
</p>
<button
class="card-button clickable"
@click.stop="sendCard(cardIndex)"
>
{{ buttonLabel }}
</button>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -23,15 +28,18 @@
export default { export default {
name: `PlayerHand`, name: `PlayerHand`,
components: {}, components: {},
data() {return {
mostRecentQuestion: null,
}},
computed: { computed: {
userRole() { userRole() {
return this.$store.state.role; return this.$store.state.role;
}, },
isGuesser() { isGuesser() {
return this.userRole == this.$store.state.guesser_name; return this.userRole === `guesser`;
}, },
isWriter() { isWriter() {
return this.userRole == this.$store.state.writer_name; return this.userRole === `writer`;
}, },
buttonLabel() { buttonLabel() {
if (this.isGuesser) { if (this.isGuesser) {
@ -49,18 +57,11 @@ export default {
methods: { methods: {
sendCard(cardIndex) { sendCard(cardIndex) {
// Determine what the source of the card is for the server to take
// appropriate action.
let role = `unknown`;
if (this.isGuesser)
role = `guesser`
else if (this.isWriter)
role = `writer`
// Create the data object for the server to receive // Create the data object for the server to receive
let data = { let data = {
game_code: this.$store.state.game_code,
text: this.questions[cardIndex - 1], text: this.questions[cardIndex - 1],
from: role, from: this.userRole,
team: this.$store.state.team, team: this.$store.state.team,
}; };
@ -68,13 +69,22 @@ export default {
// Discard the rest of the writer's hand // Discard the rest of the writer's hand
if (this.isWriter) { if (this.isWriter) {
this.$store.state.questions = []; this.mostRecentQuestion = data.text;
this.$store.commit(`replaceHand`, []);
}; };
// TODO -> send data to server this.$socket.client.emit(`SendCard`, data);
console.debug(data);
} }
}, },
mounted() {
if (this.isGuesser) {
console.debug(`Getting hand from server`);
this.$socket.client.emit(`GetHand`, {
game_code: this.$store.state.game_code,
team: this.$store.state.team
});
};
},
sockets: { sockets: {
UpdateHand(data) { UpdateHand(data) {
/** /**
@ -87,16 +97,18 @@ export default {
* } * }
*/ */
console.debug(`Updating hand.`); console.debug(`Updating hand.`);
console.debug(data);
switch (data.mode) { switch (data.mode) {
case `append`: case `append`:
// TODO -> Implement appending if (this.isWriter && this.mostRecentQuestion) {
this.mostRecentQuestion = null;
};
this.$store.commit(`appendToHand`, data.questions);
break; break;
case `replace`: case `replace`:
this.$store.state.questions = data.questions; this.$store.commit(`replaceHand`, data.questions);
break; break;
default: default:
console.error(`Server returned an unsupported mode.`); console.error(`Server returned an unsupported mode: ${data.mode}`);
}; };
}, },
}, },
@ -109,16 +121,29 @@ export default {
#PlayerHand { #PlayerHand {
background-color: var(--background2); background-color: var(--background2);
border-radius: 20px;
margin: 0 auto;
padding: 0px;
width: 95%;
}
.recentQuestion {
justify-content: center;
align-items: center;
display: flex;
height: 100%;
width: 100%;
}
.hand {
justify-content: space-evenly; justify-content: space-evenly;
flex-direction: row; flex-direction: row;
border-radius: 20px;
align-items: center; align-items: center;
flex-wrap: nowrap; flex-wrap: nowrap;
overflow-x: auto; overflow-x: auto;
margin: 0 auto;
display: flex; display: flex;
padding: 0px; height: 100%;
width: 95%; width: 100%;
} }
.card { .card {