2021-04-05 15:18:26 +02:00
|
|
|
const GAME_LOADING_ERROR_MSG = "Game loading failed, please retry later.";
|
2021-04-01 22:29:18 +02:00
|
|
|
|
2021-04-05 15:18:26 +02:00
|
|
|
async function play (game) {
|
|
|
|
console.log("Opening game " + game + "...");
|
2021-04-01 22:29:18 +02:00
|
|
|
try {
|
|
|
|
await import(`./games/${game}/game.js`)
|
2021-04-05 15:18:26 +02:00
|
|
|
.then(({ default: Game }) => {
|
|
|
|
const game = new Game();
|
|
|
|
$("body").append("<div class=\"modal\" id=\"modal_game\" tabindex=\"-1\" role=\"dialog\" data-backdrop=\"static\" style=\"display: none; min-width: 100%; margin: 0px;\"><div class=\"modal-dialog\" role=\"document\" style=\"min-width: 100%; margin: 0;\"><div class=\"modal-content\" style=\"min-height: 100vh;\" id=\"modal_game_content\"></div></div></div>");
|
|
|
|
$("#modal_game_content").append(`<div class="modal-header"><h5 class="modal-title" style="color: black">${game.title}</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body" id="modal_game_body"></div>`);
|
|
|
|
$("#modal_game_body").append(`<div id="game_content" style="text-align: center"></div><p style="text-align: right; color: black;">Game by <a style="color: blue" target="_blank" href="${game.author_url}">${game.author}</a></p>`);
|
|
|
|
$("#modal_game").modal("show");
|
|
|
|
game.initialize($("#game_content"));
|
|
|
|
});
|
|
|
|
$("#modal_game").on("hidden.bs.modal", function (e) {
|
2021-04-01 22:29:18 +02:00
|
|
|
$("#modal_game").remove();
|
2021-04-05 15:18:26 +02:00
|
|
|
});
|
2021-04-01 22:29:18 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
toastr.error(GAME_LOADING_ERROR_MSG);
|
|
|
|
}
|
2021-03-26 16:23:19 +01:00
|
|
|
}
|
|
|
|
|
2021-04-01 22:29:18 +02:00
|
|
|
window.play = play;
|
2021-04-05 15:18:26 +02:00
|
|
|
window.GAME_LOADING_ERROR_MSG = GAME_LOADING_ERROR_MSG;
|