modaq
Version:
Quiz Bowl Reader using TypeScript, React, and MobX
88 lines • 3.94 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.onQBJFileChange = exports.onPivotChange = exports.onSubmit = exports.loadPacket = exports.hideDialog = void 0;
const ImportFromQBJDialogState_1 = require("../../state/ImportFromQBJDialogState");
const QBJ = __importStar(require("../../qbj/QBJ"));
const AppState_1 = require("../../state/AppState");
require("../../IResult");
require("../../state/GameState");
require("../../state/PacketState");
function hideDialog() {
AppState_1.AppState.instance.uiState.clearPacketStatus();
AppState_1.AppState.instance.uiState.dialogState.hideImportFromQBJDialog();
}
exports.hideDialog = hideDialog;
function loadPacket(packet) {
var _a;
(_a = AppState_1.AppState.instance.uiState.dialogState.importFromQBJDialog) === null || _a === void 0 ? void 0 : _a.setPacket(packet);
}
exports.loadPacket = loadPacket;
function onSubmit() {
const appState = AppState_1.AppState.instance;
const dialogState = appState.uiState.dialogState.importFromQBJDialog;
if (dialogState == undefined) {
return;
}
dialogState.resetConvertErrorMessage();
if (dialogState.match == undefined) {
dialogState.setConvertErrorMessage("A valid QBJ match must be loaded.", ImportFromQBJDialogState_1.ImportFromQBJPivotKey.Match);
return;
}
else if (dialogState.packet == undefined) {
dialogState.setConvertErrorMessage("A valid packet must be loaded.", ImportFromQBJDialogState_1.ImportFromQBJPivotKey.Packet);
return;
}
const gameResult = QBJ.fromQBJ(dialogState.match, dialogState.packet, dialogState.customizeGameFormat.gameFormat);
if (!gameResult.success) {
dialogState.setConvertErrorMessage(gameResult.message);
return;
}
appState.setGame(gameResult.value);
hideDialog();
}
exports.onSubmit = onSubmit;
function onPivotChange(pivotKey) {
var _a;
(_a = AppState_1.AppState.instance.uiState.dialogState.importFromQBJDialog) === null || _a === void 0 ? void 0 : _a.setPivotKey(pivotKey);
}
exports.onPivotChange = onPivotChange;
function onQBJFileChange(file) {
var _a;
const fileReader = new FileReader();
fileReader.onload = onLoadQBJ;
(_a = AppState_1.AppState.instance.uiState.dialogState.importFromQBJDialog) === null || _a === void 0 ? void 0 : _a.resetQbjStatus();
// QBJ isn't a generally defined file type, so looking at file.type gives us nothing.
fileReader.readAsText(file);
}
exports.onQBJFileChange = onQBJFileChange;
function onLoadQBJ(event) {
if (event.target == undefined || event.target.result == undefined || typeof event.target.result !== "string") {
return;
}
const match = JSON.parse(event.target.result);
const dialogState = AppState_1.AppState.instance.uiState.dialogState.importFromQBJDialog;
if (dialogState == undefined) {
return;
}
dialogState.setMatch(match);
}
//# sourceMappingURL=ImportFromQBJDialogController.js.map