Move the questions storage from the hand data object to the VueX store
This commit is contained in:
parent
95a1bfe8a3
commit
fcc6712e23
2 changed files with 20 additions and 10 deletions
|
|
@ -23,9 +23,6 @@
|
||||||
export default {
|
export default {
|
||||||
name: `PlayerHand`,
|
name: `PlayerHand`,
|
||||||
components: {},
|
components: {},
|
||||||
data() {return {
|
|
||||||
questions: [],
|
|
||||||
}},
|
|
||||||
computed: {
|
computed: {
|
||||||
userRole() {
|
userRole() {
|
||||||
return this.$store.state.role;
|
return this.$store.state.role;
|
||||||
|
|
@ -45,6 +42,9 @@ export default {
|
||||||
return `Unknown Role`
|
return `Unknown Role`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
questions() {
|
||||||
|
return this.$store.state.questions;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sendCard(cardIndex) {
|
sendCard(cardIndex) {
|
||||||
|
|
@ -68,7 +68,7 @@ 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.questions = [];
|
this.$store.state.questions = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO -> send data to server
|
// TODO -> send data to server
|
||||||
|
|
@ -76,19 +76,28 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sockets: {
|
sockets: {
|
||||||
NewCard(data) {
|
UpdateHand(data) {
|
||||||
/**
|
/**
|
||||||
* Triggered when the client gets a new card for their hand, if the
|
* Triggered when the client gets a new card for their hand, if the
|
||||||
* "from" property is set to either of the
|
* "from" property is set to either of the
|
||||||
*
|
*
|
||||||
* data = {
|
* data = {
|
||||||
* text: string,
|
* questions: String[],
|
||||||
* from: "guesser" | "writer" | "deck",
|
* mode: "append"|"replace",
|
||||||
* team: 1 | 2,
|
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
console.debug(`Got a new card from the ${data.from} on team ${data.team}`);
|
console.debug(`Updating hand.`);
|
||||||
this.questions.push(data.text);
|
console.debug(data);
|
||||||
|
switch (data.mode) {
|
||||||
|
case `append`:
|
||||||
|
// TODO -> Implement appending
|
||||||
|
break;
|
||||||
|
case `replace`:
|
||||||
|
this.$store.state.questions = data.questions;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(`Server returned an unsupported mode.`);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ export default new Vuex.Store({
|
||||||
id: null,
|
id: null,
|
||||||
players: [],
|
players: [],
|
||||||
chosen_object: null,
|
chosen_object: null,
|
||||||
|
questions: [],
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
teamName(state) {
|
teamName(state) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue