Add Manager Skip button on quiz

This commit is contained in:
Ralex91
2024-02-08 19:37:15 +01:00
parent 8a9b8df7d2
commit 324316bc38
4 changed files with 25 additions and 1 deletions

View File

@@ -40,6 +40,8 @@ io.on("connection", (socket) => {
Player.selectedAnswer(gameState, io, socket, answerKey), Player.selectedAnswer(gameState, io, socket, answerKey),
) )
socket.on("manager:abortQuiz", () => Manager.abortQuiz(gameState, io, socket))
socket.on("manager:nextQuestion", () => socket.on("manager:nextQuestion", () =>
Manager.nextQuestion(gameState, io, socket), Manager.nextQuestion(gameState, io, socket),
) )

View File

@@ -1,7 +1,7 @@
import { GAME_STATE_INIT } from "../quizz.config.js" import { GAME_STATE_INIT } from "../quizz.config.js"
import { startRound } from "../utils/round.js" import { startRound } from "../utils/round.js"
import generateRoomId from "../utils/generateRoomId.js" import generateRoomId from "../utils/generateRoomId.js"
import { cooldown, sleep } from "../utils/cooldown.js" import { abortCooldown, cooldown, sleep } from "../utils/cooldown.js"
import deepClone from "../utils/deepClone.js" import deepClone from "../utils/deepClone.js"
const Manager = { const Manager = {
@@ -77,6 +77,18 @@ const Manager = {
startRound(game, io, socket) startRound(game, io, socket)
}, },
abortQuiz: (game, io, socket) => {
if (!game.started) {
return
}
if (socket.id !== game.manager) {
return
}
abortCooldown(game, io, game.room)
},
showLoaderboard: (game, io, socket) => { showLoaderboard: (game, io, socket) => {
if (!game.questions[game.currentQuestion + 1]) { if (!game.questions[game.currentQuestion + 1]) {
socket.emit("game:status", { socket.emit("game:status", {

View File

@@ -10,6 +10,7 @@ import {
SFX_RESULTS_SOUND, SFX_RESULTS_SOUND,
} from "@/constants" } from "@/constants"
import useSound from "use-sound" import useSound from "use-sound"
import { usePlayerContext } from "@/context/player"
const calculatePercentages = (objectResponses) => { const calculatePercentages = (objectResponses) => {
const keys = Object.keys(objectResponses) const keys = Object.keys(objectResponses)
@@ -37,6 +38,7 @@ export default function Answers({
data: { question, answers, image, time, responses, correct }, data: { question, answers, image, time, responses, correct },
}) { }) {
const { socket } = useSocketContext() const { socket } = useSocketContext()
const { player } = usePlayerContext()
const [percentages, setPercentages] = useState([]) const [percentages, setPercentages] = useState([])
const [cooldown, setCooldown] = useState(time) const [cooldown, setCooldown] = useState(time)
@@ -58,6 +60,10 @@ export default function Answers({
) )
const handleAnswer = (answer) => { const handleAnswer = (answer) => {
if (!player) {
return
}
socket.emit("player:selectedAnswer", answer) socket.emit("player:selectedAnswer", answer)
sfxPop() sfxPop()
} }

View File

@@ -63,6 +63,10 @@ export default function Manager() {
socket.emit("manager:startGame") socket.emit("manager:startGame")
break break
case "SELECT_ANSWER":
socket.emit("manager:abortQuiz")
break
case "SHOW_RESPONSES": case "SHOW_RESPONSES":
socket.emit("manager:showLeaderboard") socket.emit("manager:showLeaderboard")
break break