Update error emits and change the hand drawing method.
This commit is contained in:
parent
41d1a4f4d9
commit
52ec31eb0b
1 changed files with 12 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { games, log } from '../main';
|
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
|
import { conf, games, log } from '../main';
|
||||||
|
|
||||||
export default (io: Server, socket: Socket, data: SendCard) => {
|
export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -7,7 +7,7 @@ export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
// Assert game exists
|
// Assert game exists
|
||||||
if (!games[data.game_code]) {
|
if (!games[data.game_code]) {
|
||||||
log.debug(`Can't send a card in a game that doesn't exist: ${data.game_code}`);
|
log.debug(`Can't send a card in a game that doesn't exist: ${data.game_code}`);
|
||||||
socket.emit(`Error`, {
|
socket.emit(`UpdateHand`, {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: `Game with code ${data.game_code} could not be found`,
|
message: `Game with code ${data.game_code} could not be found`,
|
||||||
source: `SendCard`
|
source: `SendCard`
|
||||||
|
|
@ -25,6 +25,7 @@ export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
team.selectQuestion(data.text);
|
team.selectQuestion(data.text);
|
||||||
|
|
||||||
socket.emit(`UpdateHand`, {
|
socket.emit(`UpdateHand`, {
|
||||||
|
status: 200,
|
||||||
mode: "replace",
|
mode: "replace",
|
||||||
questions: []
|
questions: []
|
||||||
});
|
});
|
||||||
|
|
@ -37,16 +38,18 @@ export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
|
|
||||||
// Update the team's hand
|
// Update the team's hand
|
||||||
team.removeCard(data.text);
|
team.removeCard(data.text);
|
||||||
team.addCardsToHand(game.questions.draw(1));
|
team.addCardsToHand(game.questions.draw(conf.game.hand_size - team.hand.length));
|
||||||
|
|
||||||
// send the question text to the writer player
|
// send the question text to the writer player
|
||||||
io.to(`${game.id}:${data.team}:writer`).emit(`UpdateHand`, {
|
io.to(`${game.id}:${team.id}:writer`).emit(`UpdateHand`, {
|
||||||
|
status: 200,
|
||||||
mode: "append",
|
mode: "append",
|
||||||
questions: data.text
|
questions: [data.text]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Alert all the guessers of the
|
// Alert all the guessers of the team
|
||||||
io.to(`${game.id}:${data.team}:guesser`).emit(`UpdateHand`, {
|
io.to(`${game.id}:${team.id}:guesser`).emit(`UpdateHand`, {
|
||||||
|
status: 200,
|
||||||
mode: "replace",
|
mode: "replace",
|
||||||
questions: team.hand
|
questions: team.hand
|
||||||
});
|
});
|
||||||
|
|
@ -55,7 +58,7 @@ export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
|
|
||||||
else {
|
else {
|
||||||
game.log.warn(`Unknown role in the "from" property: ${data.from}`);
|
game.log.warn(`Unknown role in the "from" property: ${data.from}`);
|
||||||
socket.emit(`Error`, {
|
socket.emit(`UpdateHand`, {
|
||||||
status: 400,
|
status: 400,
|
||||||
message: `Unknown role in the "from" property: ${data.from}`,
|
message: `Unknown role in the "from" property: ${data.from}`,
|
||||||
source: `SendCard`
|
source: `SendCard`
|
||||||
|
|
@ -64,7 +67,7 @@ export default (io: Server, socket: Socket, data: SendCard) => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
socket.emit(`Error`, {
|
socket.emit(`UpdateHand`, {
|
||||||
status: 500,
|
status: 500,
|
||||||
message: `${err.name}: ${err.message}`,
|
message: `${err.name}: ${err.message}`,
|
||||||
source: `SendCard`,
|
source: `SendCard`,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue