@quizpot/quizcore 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +582 -0
- package/dist/index.d.cts +472 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +472 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +522 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/events/client/host/kick-player.d.ts +0 -8
- package/dist/events/client/host/kick-player.d.ts.map +0 -1
- package/dist/events/client/host/kick-player.js +0 -4
- package/dist/events/client/host/next-step.d.ts +0 -5
- package/dist/events/client/host/next-step.d.ts.map +0 -1
- package/dist/events/client/host/next-step.js +0 -3
- package/dist/events/client/host/start-lobby.d.ts +0 -6
- package/dist/events/client/host/start-lobby.d.ts.map +0 -1
- package/dist/events/client/host/start-lobby.js +0 -4
- package/dist/events/client/player/submit-answer.d.ts +0 -9
- package/dist/events/client/player/submit-answer.d.ts.map +0 -1
- package/dist/events/client/player/submit-answer.js +0 -4
- package/dist/events/server/lobby-deleted.d.ts +0 -8
- package/dist/events/server/lobby-deleted.d.ts.map +0 -1
- package/dist/events/server/lobby-deleted.js +0 -4
- package/dist/events/server/lobby-joined.d.ts +0 -14
- package/dist/events/server/lobby-joined.d.ts.map +0 -1
- package/dist/events/server/lobby-joined.js +0 -18
- package/dist/events/server/lobby-status-update.d.ts +0 -32
- package/dist/events/server/lobby-status-update.d.ts.map +0 -1
- package/dist/events/server/lobby-status-update.js +0 -4
- package/dist/events/server/player-answer-result.d.ts +0 -11
- package/dist/events/server/player-answer-result.d.ts.map +0 -1
- package/dist/events/server/player-answer-result.js +0 -4
- package/dist/events/server/player-joined.d.ts +0 -9
- package/dist/events/server/player-joined.d.ts.map +0 -1
- package/dist/events/server/player-joined.js +0 -4
- package/dist/events/server/player-kicked.d.ts +0 -6
- package/dist/events/server/player-kicked.d.ts.map +0 -1
- package/dist/events/server/player-kicked.js +0 -4
- package/dist/events/server/player-left.d.ts +0 -9
- package/dist/events/server/player-left.d.ts.map +0 -1
- package/dist/events/server/player-left.js +0 -4
- package/dist/events/server/player-update.d.ts +0 -9
- package/dist/events/server/player-update.d.ts.map +0 -1
- package/dist/events/server/player-update.js +0 -4
- package/dist/events/server/update-lobby-answers.d.ts +0 -8
- package/dist/events/server/update-lobby-answers.d.ts.map +0 -1
- package/dist/events/server/update-lobby-answers.js +0 -4
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -25
- package/dist/managers/lobby-manager.d.ts +0 -12
- package/dist/managers/lobby-manager.d.ts.map +0 -1
- package/dist/managers/lobby-manager.js +0 -112
- package/dist/types/events.d.ts +0 -16
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js +0 -1
- package/dist/types/lobby.d.ts +0 -42
- package/dist/types/lobby.d.ts.map +0 -1
- package/dist/types/lobby.js +0 -10
- package/dist/types/question.d.ts +0 -106
- package/dist/types/question.d.ts.map +0 -1
- package/dist/types/question.js +0 -22
- package/dist/types/questions/multiple-choice.d.ts +0 -51
- package/dist/types/questions/multiple-choice.d.ts.map +0 -1
- package/dist/types/questions/multiple-choice.js +0 -21
- package/dist/types/questions/short-answer.d.ts +0 -34
- package/dist/types/questions/short-answer.d.ts.map +0 -1
- package/dist/types/questions/short-answer.js +0 -11
- package/dist/types/questions/true-false.d.ts +0 -36
- package/dist/types/questions/true-false.d.ts.map +0 -1
- package/dist/types/questions/true-false.js +0 -12
- package/dist/types/quizfile.d.ts +0 -79
- package/dist/types/quizfile.d.ts.map +0 -1
- package/dist/types/quizfile.js +0 -23
- package/dist/types/quizstep.d.ts +0 -73
- package/dist/types/quizstep.d.ts.map +0 -1
- package/dist/types/quizstep.js +0 -7
- package/dist/types/quiztheme.d.ts +0 -7
- package/dist/types/quiztheme.d.ts.map +0 -1
- package/dist/types/quiztheme.js +0 -5
- package/dist/types/slide.d.ts +0 -18
- package/dist/types/slide.d.ts.map +0 -1
- package/dist/types/slide.js +0 -9
- package/dist/types/slides/comparison.d.ts +0 -9
- package/dist/types/slides/comparison.d.ts.map +0 -1
- package/dist/types/slides/comparison.js +0 -7
- package/dist/types/slides/titleImageTextSlide.d.ts +0 -9
- package/dist/types/slides/titleImageTextSlide.d.ts.map +0 -1
- package/dist/types/slides/titleImageTextSlide.js +0 -7
- package/dist/types/slides/titleSlide.d.ts +0 -8
- package/dist/types/slides/titleSlide.d.ts.map +0 -1
- package/dist/types/slides/titleSlide.js +0 -6
- package/dist/util/guards.d.ts +0 -18
- package/dist/util/guards.d.ts.map +0 -1
- package/dist/util/guards.js +0 -15
- package/dist/util/names/additives.json +0 -23
- package/dist/util/names/animals.json +0 -23
- package/dist/util/names/colors.json +0 -14
- package/dist/util/names/names.d.ts +0 -4
- package/dist/util/names/names.d.ts.map +0 -1
- package/dist/util/names/names.js +0 -31
- package/dist/util/sanitizer.d.ts +0 -3
- package/dist/util/sanitizer.d.ts.map +0 -1
- package/dist/util/sanitizer.js +0 -18
- package/dist/util/score.d.ts +0 -11
- package/dist/util/score.d.ts.map +0 -1
- package/dist/util/score.js +0 -33
- package/dist/util/validator.d.ts +0 -14
- package/dist/util/validator.d.ts.map +0 -1
- package/dist/util/validator.js +0 -27
package/dist/util/names/names.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import animals from "./animals.json";
|
|
2
|
-
import additives from "./additives.json";
|
|
3
|
-
import colors from "./colors.json";
|
|
4
|
-
export const generateName = () => {
|
|
5
|
-
const animal = animals[Math.floor(Math.random() * animals.length)];
|
|
6
|
-
const additive = additives[Math.floor(Math.random() * additives.length)];
|
|
7
|
-
const color = colors[Math.floor(Math.random() * colors.length)];
|
|
8
|
-
return `${color}${additive}${animal}`;
|
|
9
|
-
};
|
|
10
|
-
export const generateUniqueName = (players) => {
|
|
11
|
-
const maxPossible = animals.length * additives.length * colors.length;
|
|
12
|
-
if (players.length >= maxPossible) {
|
|
13
|
-
throw new Error("No unique names available");
|
|
14
|
-
}
|
|
15
|
-
const existingNames = new Set(players.map((p) => p.name));
|
|
16
|
-
for (let i = 0; i < 100; i++) {
|
|
17
|
-
const candidate = generateName();
|
|
18
|
-
if (!existingNames.has(candidate))
|
|
19
|
-
return candidate;
|
|
20
|
-
}
|
|
21
|
-
for (const c of colors) {
|
|
22
|
-
for (const ad of additives) {
|
|
23
|
-
for (const an of animals) {
|
|
24
|
-
const candidate = `${c}${ad}${an}`;
|
|
25
|
-
if (!existingNames.has(candidate))
|
|
26
|
-
return candidate;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
throw new Error("No unique names available"); // Fallback
|
|
31
|
-
};
|
package/dist/util/sanitizer.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../../src/util/sanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3D,eAAO,MAAM,gBAAgB,GAAI,UAAU,QAAQ,KAAG,YAmBrD,CAAC"}
|
package/dist/util/sanitizer.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { isMultipleChoice, isShortAnswer, isTrueFalse } from "./guards";
|
|
2
|
-
export const sanitizeQuestion = (question) => {
|
|
3
|
-
if (isMultipleChoice(question)) {
|
|
4
|
-
return {
|
|
5
|
-
...question,
|
|
6
|
-
choices: question.choices.map(({ text }) => ({ text })),
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
if (isTrueFalse(question)) {
|
|
10
|
-
const { answer, ...sanitized } = question;
|
|
11
|
-
return sanitized;
|
|
12
|
-
}
|
|
13
|
-
if (isShortAnswer(question)) {
|
|
14
|
-
const { answers, ...sanitized } = question;
|
|
15
|
-
return sanitized;
|
|
16
|
-
}
|
|
17
|
-
throw new Error("Invalid question type");
|
|
18
|
-
};
|
package/dist/util/score.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Answer } from "./validator";
|
|
2
|
-
import { QuizFile } from "../types/quizfile";
|
|
3
|
-
import { Question } from "../types/question";
|
|
4
|
-
export declare const calculateScore: (player: {
|
|
5
|
-
score: number;
|
|
6
|
-
streak: number;
|
|
7
|
-
}, question: Question, answer: Answer, quiz: QuizFile) => {
|
|
8
|
-
newScore: number;
|
|
9
|
-
pointsAwarded: number;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=score.d.ts.map
|
package/dist/util/score.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/util/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK7C,eAAO,MAAM,cAAc,GACzB,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACzC,UAAU,QAAQ,EAClB,QAAQ,MAAM,EACd,MAAM,QAAQ,KACb;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAmC3C,CAAC"}
|
package/dist/util/score.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const BASE_SCORE = 500;
|
|
2
|
-
const TIME_BONUS_MAX = 500;
|
|
3
|
-
export const calculateScore = (player, question, answer, quiz) => {
|
|
4
|
-
if (!answer.isCorrect)
|
|
5
|
-
return { newScore: player.score, pointsAwarded: 0 };
|
|
6
|
-
const multipliers = {
|
|
7
|
-
noPoints: 0,
|
|
8
|
-
normalPoints: 1,
|
|
9
|
-
doublePoints: 2,
|
|
10
|
-
};
|
|
11
|
-
const pointMultiplier = multipliers[question.points] ?? 1;
|
|
12
|
-
if (pointMultiplier === 0)
|
|
13
|
-
return { newScore: player.score, pointsAwarded: 0 };
|
|
14
|
-
let timeBonus = 0;
|
|
15
|
-
if (question.timeLimit > 0) {
|
|
16
|
-
const timeLimitMs = question.timeLimit * 1000;
|
|
17
|
-
const timeTaken = Math.max(0, Math.min(answer.timeTaken, timeLimitMs));
|
|
18
|
-
const timeRemainingRatio = 1 - (timeTaken / timeLimitMs);
|
|
19
|
-
timeBonus = TIME_BONUS_MAX * timeRemainingRatio;
|
|
20
|
-
}
|
|
21
|
-
let questionScore = (BASE_SCORE + timeBonus) * pointMultiplier;
|
|
22
|
-
if (player.streak >= 2) {
|
|
23
|
-
const totalQuestions = quiz.steps.filter(s => s.type === "question").length;
|
|
24
|
-
const dynamicCap = Math.min(1.2 + Math.max(0, totalQuestions - 5) * 0.02, 1.5);
|
|
25
|
-
const streakMultiplier = Math.min(1 + (player.streak - 1) * 0.05, dynamicCap);
|
|
26
|
-
questionScore *= streakMultiplier;
|
|
27
|
-
}
|
|
28
|
-
const finalPoints = Math.trunc(questionScore);
|
|
29
|
-
return {
|
|
30
|
-
newScore: player.score + finalPoints,
|
|
31
|
-
pointsAwarded: finalPoints
|
|
32
|
-
};
|
|
33
|
-
};
|
package/dist/util/validator.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ShortAnswerQuestionAnswer } from "../types/questions/short-answer";
|
|
2
|
-
import { TrueFalseQuestionAnswer } from "../types/questions/true-false";
|
|
3
|
-
import { MultipleChoiceQuestionAnswer } from "../types/questions/multiple-choice";
|
|
4
|
-
import { Question } from "../types/question";
|
|
5
|
-
export type SubmittedAnswer = MultipleChoiceQuestionAnswer | TrueFalseQuestionAnswer | ShortAnswerQuestionAnswer;
|
|
6
|
-
export interface Answer {
|
|
7
|
-
playerId: string;
|
|
8
|
-
submission: SubmittedAnswer;
|
|
9
|
-
timeTaken: number;
|
|
10
|
-
isCorrect: boolean;
|
|
11
|
-
pointsAwarded: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const isCorrect: (question: Question, submission: SubmittedAnswer) => boolean;
|
|
14
|
-
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/util/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,MAAM,eAAe,GACvB,4BAA4B,GAC5B,uBAAuB,GACvB,yBAAyB,CAAC;AAE9B,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,eAAe,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,SAAS,GAAI,UAAU,QAAQ,EAAE,YAAY,eAAe,KAAG,OA+B3E,CAAC"}
|
package/dist/util/validator.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { isMultipleChoice, isShortAnswer, isTrueFalse } from "../util/guards";
|
|
2
|
-
;
|
|
3
|
-
export const isCorrect = (question, submission) => {
|
|
4
|
-
if (isMultipleChoice(question) && submission.type === "multiple-choice") {
|
|
5
|
-
if (question.matchAll) {
|
|
6
|
-
const correctIndices = question.choices
|
|
7
|
-
.map((c, i) => (c.correct ? i : -1))
|
|
8
|
-
.filter((i) => i !== -1);
|
|
9
|
-
return (submission.choices.length === correctIndices.length &&
|
|
10
|
-
submission.choices.every((index) => correctIndices.includes(index)));
|
|
11
|
-
}
|
|
12
|
-
if (submission.choices.length === 0)
|
|
13
|
-
return false;
|
|
14
|
-
return submission.choices.every(index => {
|
|
15
|
-
const choice = question.choices[index];
|
|
16
|
-
return choice ? choice.correct : false;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (isTrueFalse(question) && submission.type === "true-false") {
|
|
20
|
-
return question.answer === submission.answer;
|
|
21
|
-
}
|
|
22
|
-
if (isShortAnswer(question) && submission.type === "short-answer") {
|
|
23
|
-
const playerAns = submission.answer.trim().toLowerCase();
|
|
24
|
-
return question.answers.some(ans => ans.trim().toLowerCase() === playerAns);
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
};
|