WIP Implementing player choosing funcionality in FE
This commit is contained in:
parent
df6c14df52
commit
a798ec1558
|
|
@ -1,3 +1,5 @@
|
||||||
|
const crypto = require("crypto");
|
||||||
|
|
||||||
const gameController = require("../controllers/GameControllerMongoose");
|
const gameController = require("../controllers/GameControllerMongoose");
|
||||||
const playerController = require("../controllers/PlayerControllerMongoose");
|
const playerController = require("../controllers/PlayerControllerMongoose");
|
||||||
|
|
||||||
|
|
@ -130,10 +132,14 @@ exports.handleMessage = ( gameSocketList, socket, dataRaw ) => {
|
||||||
gameController.findGameByIdAndSetStateAndPopulateBoard( socket.locals.game, "IN_PROGRESS" )
|
gameController.findGameByIdAndSetStateAndPopulateBoard( socket.locals.game, "IN_PROGRESS" )
|
||||||
.then( ( game ) => {
|
.then( ( game ) => {
|
||||||
gameOuter = game;
|
gameOuter = game;
|
||||||
let randomPlayerIndex = crypto.randomInt(0, game.players.length );
|
if( game.players.length > 0 ){
|
||||||
let randomPlayer = game.players[randomPlayerIndex];
|
let randomPlayerIndex = crypto.randomInt(0, game.players.length );
|
||||||
let otherPlayers = game.players.splice(randomPlayerIndex, 1);
|
let randomPlayer = game.players[randomPlayerIndex];
|
||||||
return playerController.setPlayerIsChoosingAndOthersNotChoosing( randomPlayer, otherPlayers );
|
let otherPlayers = game.players.splice(randomPlayerIndex, 1);
|
||||||
|
return playerController.setPlayerIsChoosingAndOthersNotChoosing( randomPlayer, otherPlayers );
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then( ( choosingPlayer ) => {
|
.then( ( choosingPlayer ) => {
|
||||||
let message = "Game is starting";
|
let message = "Game is starting";
|
||||||
|
|
@ -159,12 +165,12 @@ exports.handleMessage = ( gameSocketList, socket, dataRaw ) => {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "playerChooseBoardEntry":
|
case "playerChooseBoardEntry":
|
||||||
playerController.checkPlayerCanChoose()
|
playerController.checkPlayerCanChoose( socket.locals.player )
|
||||||
.then( ( canChoose ) => {
|
.then( ( player ) => {
|
||||||
if( canChoose ){
|
if( player.isChoosing ){
|
||||||
let message = `BoardEntry ${payload.boardEntryIndex} selected`;
|
let message = `Category ${payload.categoryIndex} with BoardEntry ${payload.boardEntryIndex} selected`;
|
||||||
let sendingData = { categoryIndex: payload.categoryIndex, boardEntryIndex: payload.boardEntryIndex };
|
let sendingData = { categoryIndex: payload.categoryIndex, boardEntryIndex: payload.boardEntryIndex, choosingPlayer: player._id.toString() };
|
||||||
sendAllPlayers( socket, gameSocketList, "boardEntrySelected", message, sendingData );
|
sendToHost( socket, gameSocketList, "playerChoseBoardEntry", message, sendingData );
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ const props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
playerChose: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(["boardEntryCardClicked", "boardEntryAnsweredClicked", "boardEntryAnsweredRevertClicked" ]);
|
const emit = defineEmits(["boardEntryCardClicked", "boardEntryAnsweredClicked", "boardEntryAnsweredRevertClicked" ]);
|
||||||
|
|
@ -60,6 +64,11 @@ function boardEntryAnsweredRevertClicked(){
|
||||||
<font-awesome-icon icon="fa-solid fa-square-minus" size="lg" />
|
<font-awesome-icon icon="fa-solid fa-square-minus" size="lg" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="playerChose !== false" class="position-absolute start-0 bottom-0 mb-2 w-100">
|
||||||
|
<span class="bg-pink-accent-primary p-1 ms-2 max-w-50" @click.stop="boardEntryAnsweredRevertClicked">
|
||||||
|
{{ props.playerChose.name }} chooses this
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<h5 class="mb-0 user-select-none">
|
<h5 class="mb-0 user-select-none">
|
||||||
{{ props.boardEntry.points }}
|
{{ props.boardEntry.points }}
|
||||||
</h5>
|
</h5>
|
||||||
|
|
@ -73,4 +82,7 @@ function boardEntryAnsweredRevertClicked(){
|
||||||
max-height: 20%;
|
max-height: 20%;
|
||||||
max-width: 90vw;
|
max-width: 90vw;
|
||||||
}
|
}
|
||||||
|
.max-w-50{
|
||||||
|
max-width: 50%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
@ -183,6 +183,18 @@ function setUpListeners(){
|
||||||
gameStore.players.splice( playerIndex, 1 );
|
gameStore.players.splice( playerIndex, 1 );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
gameStore.addSocketListener("playerChoseBoardEntry", ( data ) => {
|
||||||
|
let categoryIndex = data.payload.categoryIndex;
|
||||||
|
let boardEntryIndex = data.payload.boardEntryIndex;
|
||||||
|
let player = gameStore.players.find( playerEntry => playerEntry._id === data.payload.choosingPlayer );
|
||||||
|
if( player ){
|
||||||
|
gameStore.chosenEntry = {
|
||||||
|
player: player,
|
||||||
|
categoryIndex: categoryIndex,
|
||||||
|
boardEntryIndex: boardEntryIndex,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerBuzzered( data ){
|
function playerBuzzered( data ){
|
||||||
|
|
@ -395,6 +407,7 @@ onBeforeRouteLeave((to, from) => {
|
||||||
:isPlayerChoosing="gameStore.isPlayerChoosing"
|
:isPlayerChoosing="gameStore.isPlayerChoosing"
|
||||||
:anyPlayerIsAnswering="anyPlayerIsAnswering"
|
:anyPlayerIsAnswering="anyPlayerIsAnswering"
|
||||||
:isBeingPlayed="isBeingPlayed"
|
:isBeingPlayed="isBeingPlayed"
|
||||||
|
:chosenEntry="gameStore.chosenEntry"
|
||||||
@showBoard="showBoard"
|
@showBoard="showBoard"
|
||||||
@showQuestion="showQuestion"
|
@showQuestion="showQuestion"
|
||||||
@showAnswer="showAnswer"
|
@showAnswer="showAnswer"
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,19 @@ const props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
chosenEntry: Object,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(["boardEntryClicked", "questionAnswered", "questionAnsweredRevert" ])
|
const emit = defineEmits(["boardEntryClicked", "questionAnswered", "questionAnsweredRevert" ])
|
||||||
|
|
||||||
|
function playerChosenBoardEntry( categoryIndex, boardEntryIndex ){
|
||||||
|
if( props.chosenEntry !== undefined && ( props.chosenEntry.categoryIndex === categoryIndex || props.chosenEntry.boardEntryIndex === boardEntryIndex ) ){
|
||||||
|
return props.chosenEntry.player.name;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function boardEntryCardClicked( categoryIndex, boardEntryIndex ){
|
function boardEntryCardClicked( categoryIndex, boardEntryIndex ){
|
||||||
if( props.isHost || props.isPlayerChoosing ){
|
if( props.isHost || props.isPlayerChoosing ){
|
||||||
emit("boardEntryClicked", categoryIndex, boardEntryIndex);
|
emit("boardEntryClicked", categoryIndex, boardEntryIndex);
|
||||||
|
|
@ -49,6 +58,7 @@ function boardEntryCardClicked( categoryIndex, boardEntryIndex ){
|
||||||
:isPlayerChoosing="props.isPlayerChoosing"
|
:isPlayerChoosing="props.isPlayerChoosing"
|
||||||
:isBeingPlayed="props.isBeingPlayed"
|
:isBeingPlayed="props.isBeingPlayed"
|
||||||
:boardEntry="boardEntry"
|
:boardEntry="boardEntry"
|
||||||
|
:playerChose="playerChosenBoardEntry( categoryIndex, boardEntryIndex )"
|
||||||
@boardEntryCardClicked="boardEntryCardClicked( categoryIndex, boardEntryIndex )"
|
@boardEntryCardClicked="boardEntryCardClicked( categoryIndex, boardEntryIndex )"
|
||||||
@boardEntryAnsweredClicked="emit( 'questionAnswered', categoryIndex, boardEntryIndex )"
|
@boardEntryAnsweredClicked="emit( 'questionAnswered', categoryIndex, boardEntryIndex )"
|
||||||
@boardEntryAnsweredRevertClicked="emit( 'questionAnsweredRevert', categoryIndex, boardEntryIndex )"
|
@boardEntryAnsweredRevertClicked="emit( 'questionAnsweredRevert', categoryIndex, boardEntryIndex )"
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ const props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
chosenEntry: Object,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(["boardEntryClicked", "specificQuestionLayerSelected", "showBoard", "playerBuzzered", "playAudio", "stopAudio",
|
const emit = defineEmits(["boardEntryClicked", "specificQuestionLayerSelected", "showBoard", "playerBuzzered", "playAudio", "stopAudio",
|
||||||
|
|
@ -124,6 +125,7 @@ watch(
|
||||||
:isHost="props.isHost"
|
:isHost="props.isHost"
|
||||||
:isBeingPlayed="props.isBeingPlayed"
|
:isBeingPlayed="props.isBeingPlayed"
|
||||||
:isPlayerChoosing="props.isPlayerChoosing"
|
:isPlayerChoosing="props.isPlayerChoosing"
|
||||||
|
:chosenEntry="props.chosenEntry"
|
||||||
@boardEntryClicked="boardEntryClicked"
|
@boardEntryClicked="boardEntryClicked"
|
||||||
@questionAnswered="questionAnswered"
|
@questionAnswered="questionAnswered"
|
||||||
@questionAnsweredRevert="questionAnsweredRevert"
|
@questionAnsweredRevert="questionAnsweredRevert"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ export const useGameStore = defineStore('game', {
|
||||||
board: new Board( undefined, "New Board", []),
|
board: new Board( undefined, "New Board", []),
|
||||||
acceptAnswers: false,
|
acceptAnswers: false,
|
||||||
isPlayerChoosing: false,
|
isPlayerChoosing: false,
|
||||||
|
chosenEntry: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue