Implemented awarding multiple players for non-buzzer questions
This commit is contained in:
parent
5ef8ea86bb
commit
58f8fedaec
|
|
@ -86,29 +86,6 @@ exports.checkPlayerAcceptAnswers = ( playerId ) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a player is allowed to choose a BoardEntry
|
|
||||||
* @param {String} playerId
|
|
||||||
* @returns A promise which resolves with wheter the player is allowed to choose a BoardEntry or not. Rejects if an error occurs.
|
|
||||||
*/
|
|
||||||
exports.checkPlayerCanChoose = ( playerId ) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
PlayerModel.findById( playerId )
|
|
||||||
.then( ( player ) => {
|
|
||||||
if( player ){
|
|
||||||
resolve( player.isChoosing );
|
|
||||||
} else {
|
|
||||||
let playerNotFoundError = new Error(`No player found with id "${playerId}"`);
|
|
||||||
playerNotFoundError.name = "NotFoundError";
|
|
||||||
reject(playerNotFoundError);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch( ( err ) => {
|
|
||||||
reject( err );
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a player is allowed to currently answer a question and sets it to the specified value
|
* Checks if a player is allowed to currently answer a question and sets it to the specified value
|
||||||
* @param {String} playerId
|
* @param {String} playerId
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ const PlayerSchema = new Schema({
|
||||||
name: { type: String, required: true, maxLength: 100 },
|
name: { type: String, required: true, maxLength: 100 },
|
||||||
points: { type: Number },
|
points: { type: Number },
|
||||||
acceptAnswers: { type: Boolean, default: false },
|
acceptAnswers: { type: Boolean, default: false },
|
||||||
isChoosing: { type: Boolean, default: false },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Export model
|
// Export model
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ exports.handleMessage = ( gameSocketList, socket, dataRaw ) => {
|
||||||
throw new Error("Player not found");
|
throw new Error("Player not found");
|
||||||
} else {
|
} else {
|
||||||
let message = `Player ${payload.playerName} got ${payload.pointsAdjustment} points`;
|
let message = `Player ${payload.playerName} got ${payload.pointsAdjustment} points`;
|
||||||
let sendingData = { players: game.players, acceptAnswers: game.acceptAnswers }
|
let sendingData = { adjustedPlayer: game.players[playerIndex], acceptAnswers: game.acceptAnswers }
|
||||||
sendAllPlayers( socket, gameSocketList, "pointsAdjusted", message, sendingData );
|
sendAllPlayers( socket, gameSocketList, "pointsAdjusted", message, sendingData );
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,21 +10,21 @@ import { useGameStore } from '@/stores/GameStore';
|
||||||
import Board from '@/models/Board';
|
import Board from '@/models/Board';
|
||||||
import BoardEntry from '@/models/BoardEntry';
|
import BoardEntry from '@/models/BoardEntry';
|
||||||
|
|
||||||
import BuzzerSound from "../../assets/sounds/buzzbuzz.mp3";
|
// import HardBuzzerSound from "../../assets/sounds/buzzbuzz.mp3";
|
||||||
import NoBuzzerSound from "../../assets/sounds/dingdongy.mp3";
|
import BuzzerSound from "../../assets/sounds/dingdongy.mp3";
|
||||||
import CorrectAudio from "../../assets/sounds/correct.mp3";
|
// import CorrectAudio from "../../assets/sounds/correct.mp3";
|
||||||
import WrongAudio from "../../assets/sounds/wrong.mp3";
|
// import WrongAudio from "../../assets/sounds/wrong.mp3";
|
||||||
|
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
let navbarHeight = ref(0);
|
let navbarHeight = ref(0);
|
||||||
let boardIsLoading = ref( true );
|
let boardIsLoading = ref( true );
|
||||||
let buzzBuzz = new Audio( BuzzerSound );
|
let buzzBuzz = new Audio( BuzzerSound );
|
||||||
buzzBuzz.volume = 0.3
|
buzzBuzz.volume = 0.5
|
||||||
let buzzNoBuzz = new Audio( NoBuzzerSound );
|
// let buzzNoBuzz = new Audio( NoBuzzerSound );
|
||||||
buzzNoBuzz.volume = 0.7
|
// buzzNoBuzz.volume = 0.7
|
||||||
let answerCorrectAudio = new Audio( CorrectAudio );
|
// let answerCorrectAudio = new Audio( CorrectAudio );
|
||||||
let answerWrongAudio = new Audio( WrongAudio );
|
// let answerWrongAudio = new Audio( WrongAudio );
|
||||||
|
|
||||||
|
|
||||||
let protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
|
let protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
|
||||||
|
|
@ -98,10 +98,9 @@ function setUpListeners(){
|
||||||
boardSelected();
|
boardSelected();
|
||||||
});
|
});
|
||||||
gameStore.addSocketListener("pointsAdjusted", ( data ) => {
|
gameStore.addSocketListener("pointsAdjusted", ( data ) => {
|
||||||
gameStore.players = data.payload.players;
|
gameStore.setPlayerPoints( data.payload.adjustedPlayer );
|
||||||
let self = data.payload.players.find( playerEntry => playerEntry._id === gameStore.playerId );
|
if( gameStore.playerId === data.payload.adjustedPlayer._id ){
|
||||||
if( self ){
|
gameStore.acceptAnswers = data.payload.acceptAnswers && data.payload.adjustedPlayer.acceptAnswers;
|
||||||
gameStore.acceptAnswers = data.payload.acceptAnswers && self.acceptAnswers;
|
|
||||||
} else {
|
} else {
|
||||||
gameStore.acceptAnswers = data.payload.acceptAnswers;
|
gameStore.acceptAnswers = data.payload.acceptAnswers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ export const useGameStore = defineStore('game', {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
setPlayerPoints( adjustedPlayer ){
|
||||||
|
let playerToAdjustIndex = this.players.findIndex( playersEntry => playersEntry._id === adjustedPlayer._id );
|
||||||
|
if( playerToAdjustIndex !== -1 ){
|
||||||
|
this.players[playerToAdjustIndex].points = adjustedPlayer.points;
|
||||||
|
this.players[playerToAdjustIndex].isAnswering = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
setPlayerOnIndexChoosing( playerId ){
|
setPlayerOnIndexChoosing( playerId ){
|
||||||
let playerIndex = this.players.findIndex( playerEntry => playerEntry._id === playerId );
|
let playerIndex = this.players.findIndex( playerEntry => playerEntry._id === playerId );
|
||||||
for( let i in this.players ){
|
for( let i in this.players ){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue