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:
parent
1eac963bc5
commit
d639ed4a48
1 changed files with 61 additions and 36 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="PlayerHand">
|
<div id="PlayerHand">
|
||||||
|
<div class="recentQuestion" v-if="mostRecentQuestion">
|
||||||
|
{{ mostRecentQuestion }}
|
||||||
|
</div>
|
||||||
|
<div class="hand" v-else>
|
||||||
<div
|
<div
|
||||||
class="card"
|
class="card"
|
||||||
v-for="cardIndex in questions.length"
|
v-for="cardIndex in questions.length"
|
||||||
|
|
@ -17,21 +21,25 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue