modaq
Version:
Quiz Bowl Reader using TypeScript, React, and MobX
100 lines • 4.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUpgradedFormatVersion = exports.createMACFGameFormat = exports.getKnownFormats = exports.UndefinedGameFormat = exports.StandardPowersMACFGameFormat = exports.PACEGameFormat = exports.ACFGameFormat = void 0;
require("./IGameFormat");
// We can't rely on a currentVersion we fill in, so these have to be manually tracked if there are breaking changes
const currentVersion = "2024-03-20";
exports.ACFGameFormat = {
bonusesBounceBack: false,
displayName: "ACF",
minimumOvertimeQuestionCount: 1,
overtimeIncludesBonuses: false,
negValue: -5,
powers: [],
regulationTossupCount: 20,
timeoutsAllowed: 1,
pronunciationGuideMarkers: ['("', '")'],
pairTossupsBonuses: false,
version: currentVersion,
};
exports.PACEGameFormat = {
bonusesBounceBack: false,
displayName: "PACE",
minimumOvertimeQuestionCount: 1,
overtimeIncludesBonuses: false,
negValue: 0,
powers: [{ marker: "(*)", points: 20 }],
regulationTossupCount: 20,
timeoutsAllowed: 1,
pronunciationGuideMarkers: ['("', '")'],
pairTossupsBonuses: false,
version: currentVersion,
};
exports.StandardPowersMACFGameFormat = Object.assign(Object.assign({}, createMACFGameFormat([{ marker: "(*)", points: 15 }])), { displayName: "mACF with powers" });
exports.UndefinedGameFormat = {
bonusesBounceBack: false,
displayName: "Freeform format",
minimumOvertimeQuestionCount: 1,
overtimeIncludesBonuses: false,
negValue: -5,
powers: [{ marker: "(*)", points: 15 }],
regulationTossupCount: 999,
timeoutsAllowed: 999,
pronunciationGuideMarkers: ['("', '")'],
pairTossupsBonuses: false,
version: currentVersion,
};
function getKnownFormats() {
return [exports.ACFGameFormat, exports.StandardPowersMACFGameFormat, exports.PACEGameFormat, exports.UndefinedGameFormat];
}
exports.getKnownFormats = getKnownFormats;
function createMACFGameFormat(powers) {
return Object.assign(Object.assign({}, exports.ACFGameFormat), { powers });
}
exports.createMACFGameFormat = createMACFGameFormat;
function getUpgradedFormatVersion(format) {
if (format.version === currentVersion) {
return format;
}
updatePowerMarkers(format);
// We need to compare the fields between the given format and the current format, so we need to iterate over them.
// This requires using the array/dictionary syntax for accessing fields, which requires using any.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const defaultFormat = exports.UndefinedGameFormat;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const formatObject = format;
for (const key of Object.keys(defaultFormat)) {
if (key === "displayName" || key === "pronunciationGuideMarkers") {
continue;
}
if (formatObject[key] == undefined) {
throwInvalidGameFormatError(`Game format uses an incompatible version (${format.version}). Unknown setting "${key}".`);
}
else if (typeof formatObject[key] !== typeof defaultFormat[key]) {
throwInvalidGameFormatError(`Game format uses an incompatible version (${format.version}). "${key}" is an incompatible type.`);
}
}
return format;
}
exports.getUpgradedFormatVersion = getUpgradedFormatVersion;
function updatePowerMarkers(gameFormat) {
if (gameFormat.powers != undefined ||
gameFormat.pointsForPowers == undefined ||
gameFormat.powerMarkers == undefined) {
return;
}
if (gameFormat.powerMarkers.length < gameFormat.pointsForPowers.length) {
throwInvalidGameFormatError("Game format is invalid. Some power markers don't have point values.");
}
gameFormat.powers = [];
for (let i = 0; i < gameFormat.powerMarkers.length; i++) {
gameFormat.powers.push({
marker: gameFormat.powerMarkers[i],
points: gameFormat.pointsForPowers[i],
});
}
}
function throwInvalidGameFormatError(message) {
throw new Error(`${message}. Export your game and see if you can update your format manually, or reset your game`);
}
//# sourceMappingURL=GameFormats.js.map