Add board options for losing points on wrong answer
This commit is contained in:
parent
ef56c1d9c1
commit
b082c47b11
|
|
@ -54,6 +54,7 @@ exports.addBoard = ( postObject, ownerId ) => {
|
||||||
ownerId: ownerId,
|
ownerId: ownerId,
|
||||||
name: postObject.boardName,
|
name: postObject.boardName,
|
||||||
categories: postObject.categories,
|
categories: postObject.categories,
|
||||||
|
options: postObject.options,
|
||||||
});
|
});
|
||||||
return newBoard.save();
|
return newBoard.save();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const BoardSchema = new Schema({
|
||||||
ownerId: { type: Schema.Types.ObjectId, ref: "User", required: true },
|
ownerId: { type: Schema.Types.ObjectId, ref: "User", required: true },
|
||||||
name: { type: String, required: true, maxLength: 100 },
|
name: { type: String, required: true, maxLength: 100 },
|
||||||
categories: { type: [Object], required: false, default: [] },
|
categories: { type: [Object], required: false, default: [] },
|
||||||
|
options: { type: Object, required: true, default: { losePointsOnWrong: false, lossMultiplier: 1 } } //TODO Why not saved?
|
||||||
});
|
});
|
||||||
|
|
||||||
// Virtual for player's URL
|
// Virtual for player's URL
|
||||||
|
|
@ -17,6 +18,7 @@ BoardSchema.virtual("url").get(function () {
|
||||||
BoardSchema.virtual("setFromPostObject").set( function( postObject ){
|
BoardSchema.virtual("setFromPostObject").set( function( postObject ){
|
||||||
this.name = postObject.boardName;
|
this.name = postObject.boardName;
|
||||||
this.categories = postObject.categories;
|
this.categories = postObject.categories;
|
||||||
|
this.options = postObject.options;
|
||||||
})
|
})
|
||||||
|
|
||||||
// Export model
|
// Export model
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ $font-family-base: "Urbanist";
|
||||||
|
|
||||||
$enable-caret: false;
|
$enable-caret: false;
|
||||||
|
|
||||||
|
$form-check-input-checked-bg-color: $pink-accent-primary;
|
||||||
|
$form-switch-color: $body-color;
|
||||||
|
|
||||||
|
|
||||||
// 2. Include any default variable overrides here
|
// 2. Include any default variable overrides here
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ if( route.params.boardId !== undefined ){
|
||||||
boardIsLoading.value = false;
|
boardIsLoading.value = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
gameCreationStore.board = new Board( undefined, "New Board", [] );
|
gameCreationStore.board = new Board();
|
||||||
selectedObject.value = gameCreationStore.board;
|
selectedObject.value = gameCreationStore.board;
|
||||||
boardIsLoading.value = false;
|
boardIsLoading.value = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -453,6 +453,7 @@ onBeforeRouteLeave((to, from) => {
|
||||||
<PlayersView
|
<PlayersView
|
||||||
:players="gameStore.players"
|
:players="gameStore.players"
|
||||||
:questionPoints="(isBoardSelected ? 0 : Number(selectedObject.points) )"
|
:questionPoints="(isBoardSelected ? 0 : Number(selectedObject.points) )"
|
||||||
|
:boardOptions="gameStore.board.options"
|
||||||
:answerInteraction="(isBoardSelected ? '' : selectedObject.answer.answerInteraction )"
|
:answerInteraction="(isBoardSelected ? '' : selectedObject.answer.answerInteraction )"
|
||||||
:isHost="gameStore.isHost"
|
:isHost="gameStore.isHost"
|
||||||
:acceptAnswers="gameStore.acceptAnswers"
|
:acceptAnswers="gameStore.acceptAnswers"
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ function deleteCategoryButtonClicked( cIndex ){
|
||||||
<input v-model="gameCreationStore.board.boardName" class="form-control bg-dark-blue" type="text">
|
<input v-model="gameCreationStore.board.boardName" class="form-control bg-dark-blue" type="text">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="form-label fs-4 mt-3">Categories</label>
|
<h4 class="mt-3">Categories</h4>
|
||||||
<div v-if="gameCreationStore.board.categories.length === 0">No categories yet</div>
|
<div v-if="gameCreationStore.board.categories.length === 0">No categories yet</div>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div v-for="( category, categoryListIndex ) in gameCreationStore.board.categories" :key="category.categoryName">
|
<div v-for="( category, categoryListIndex ) in gameCreationStore.board.categories" :key="category.categoryName">
|
||||||
|
|
@ -77,6 +77,27 @@ function deleteCategoryButtonClicked( cIndex ){
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 class="mt-3">Options</h4>
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" v-model="gameCreationStore.board.options.losePointsOnWrong" id="lose-points-on-wrong">
|
||||||
|
<label class="form-check-label" for="lose-points-on-wrong">
|
||||||
|
Lose Points on Wrong Answer
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<template v-if="gameCreationStore.board.options.losePointsOnWrong">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" v-model="gameCreationStore.board.options.onlyOnBuzzer" id="only-on-buzzer-type">
|
||||||
|
<label class="form-check-label" for="only-on-buzzer-type">
|
||||||
|
Only on Buzzer Answer Type
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="form-label" for="loss-multiplier">Loss Multiplier</label>
|
||||||
|
<input v-model="gameCreationStore.board.options.lossMultiplier" class="form-control bg-dark-blue" type="number" step="0.5" min="0" id="loss-multiplier">
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,7 @@ function answerTextUpdated(){
|
||||||
class="buzzer d-flex justify-content-center align-items-center rounded-circle shadow m-2"
|
class="buzzer d-flex justify-content-center align-items-center rounded-circle shadow m-2"
|
||||||
:class="[ { 'buzzer-answering': props.playerIsAnswering }, { 'bg-gray': !props.acceptAnswers && !props.playerIsAnswering } ]"
|
:class="[ { 'buzzer-answering': props.playerIsAnswering }, { 'bg-gray': !props.acceptAnswers && !props.playerIsAnswering } ]"
|
||||||
@click="buzzeredTheBuzzBuzz"
|
@click="buzzeredTheBuzzBuzz"
|
||||||
>
|
>Buzzer</div>
|
||||||
Buzzer
|
|
||||||
</div>
|
|
||||||
<div v-else class="d-flex justify-content-center align-items-center w-100 h-100 m-3">
|
<div v-else class="d-flex justify-content-center align-items-center w-100 h-100 m-3">
|
||||||
<div class="w-100">
|
<div class="w-100">
|
||||||
<label for="textarea-player-input" class="form-label">Answer:</label>
|
<label for="textarea-player-input" class="form-label">Answer:</label>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const props = defineProps({
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
questionPoints: Number,
|
questionPoints: Number,
|
||||||
|
boardOptions: Object,
|
||||||
answerInteraction: {
|
answerInteraction: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "buzzerInteraction"
|
default: "buzzerInteraction"
|
||||||
|
|
@ -36,7 +37,18 @@ function manualPointsAdjustment( playerId, playerName, arePointsAdded ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function answerRuled( playerId, playerName, isAnswerCorrect ){
|
function answerRuled( playerId, playerName, isAnswerCorrect ){
|
||||||
let points = ( isAnswerCorrect ? props.questionPoints : 0 );
|
let points = 0;
|
||||||
|
if( isAnswerCorrect ){
|
||||||
|
points = props.questionPoints;
|
||||||
|
} else if(
|
||||||
|
props.boardOptions.losePointsOnWrong &&
|
||||||
|
(
|
||||||
|
!props.boardOptions.onlyOnBuzzer ||
|
||||||
|
props.answerInteraction === "buzzerInteraction"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
points = Math.round(props.questionPoints * props.boardOptions.lossMultiplier * -1);
|
||||||
|
}
|
||||||
let reopenQuestion;
|
let reopenQuestion;
|
||||||
if( ["buzzerInteraction"].includes( props.answerInteraction ) ){
|
if( ["buzzerInteraction"].includes( props.answerInteraction ) ){
|
||||||
reopenQuestion = !isAnswerCorrect;
|
reopenQuestion = !isAnswerCorrect;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
export default class Board{
|
export default class Board{
|
||||||
|
|
||||||
constructor( id, name, categories ){
|
constructor( id = undefined, name = "New Board", categories = [], options = { losePointsOnWrong: false, lossMultiplier: 1, onlyOnBuzzer: true } ){
|
||||||
this.boardId = id;
|
this.boardId = id;
|
||||||
this.boardName = name;
|
this.boardName = name;
|
||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
|
this.options = options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@ export function boardResponseToBoardModel( boardResponse ){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Board( boardResponse._id, boardResponse.name, categories );
|
return new Board( boardResponse._id, boardResponse.name, categories, boardResponse.options );
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openModal( modalId ){
|
export function openModal( modalId ){
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ const uService = new UserService();
|
||||||
export const useGameCreationStore = defineStore('gameCreation', {
|
export const useGameCreationStore = defineStore('gameCreation', {
|
||||||
state: ()=>{
|
state: ()=>{
|
||||||
return {
|
return {
|
||||||
board: new Board( undefined, "New Board", []),
|
board: new Board(),
|
||||||
images: [],
|
images: [],
|
||||||
audios: [],
|
audios: [],
|
||||||
answerImages: [],
|
answerImages: [],
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ export const useGameStore = defineStore('game', {
|
||||||
gameService: gService,
|
gameService: gService,
|
||||||
//concrete Game Data
|
//concrete Game Data
|
||||||
currentQuestion: {},
|
currentQuestion: {},
|
||||||
board: new Board( undefined, "New Board", []),
|
board: new Board(),
|
||||||
acceptAnswers: false,
|
acceptAnswers: false,
|
||||||
isPlayerChoosing: false,
|
isPlayerChoosing: false,
|
||||||
chosenEntry: undefined,
|
chosenEntry: undefined,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue