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),
)
socket.on("manager:abortQuiz", () => Manager.abortQuiz(gameState, io, socket))
socket.on("manager:nextQuestion", () =>
Manager.nextQuestion(gameState, io, socket),
)

View File

@@ -1,7 +1,7 @@
import { GAME_STATE_INIT } from "../quizz.config.js"
import { startRound } from "../utils/round.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"
const Manager = {
@@ -77,6 +77,18 @@ const Manager = {
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) => {
if (!game.questions[game.currentQuestion + 1]) {
socket.emit("game:status", {

View File

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

View File

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