viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]
Filename | |
---|---|
js/game.js |
diff --git a/js/game.js b/js/game.js index ba6238f..5b32ca1 100644 --- a/js/game.js +++ b/js/game.js @@ -413,7 +413,9 @@ function addListenersAnchors(anchors) } } /** - * Used to disable any links to save or inventory pages + * Used to disable any volatile links which might cause + * issues if clicked during rendering of the staging + * portion of a presentation. For example, saves screen links * in either the main-nav panel/main-nav bar or in the * game content area. The current place where this is used * is at the start of rendering a location. A location @@ -424,33 +426,29 @@ function addListenersAnchors(anchors) * Only after the last drawable x-present for a location * has completed are they renabled. */ -function disableSavesAndInventory() +function disableVolatileLinks() { - let save_links = sel('[href~="#saves"]'); - for (const save_link of save_links) { - save_link.classList.add('disabled'); - } - let inventory_links = sel('[href~="#inventory"]'); - for (const inventory_link of inventory_links) { - inventory_link.classList.add('disabled'); + for (let location_id of game.volatileLinks()) { + let volatile_links = sel(`[href~="#${location_id}"]`); + for (const volatile_link of volatile_links) { + volatile_link.classList.add('disabled'); + } } } /** - * Used to re-enable any disabled links to save or inventory pages + * Used to re-enable any disabled volatile links * in either the main-nav panel/main-nav bar or in the * game content area. The current place where this is used * is at the end of rendering a location. For why this is called, - * @see disableSavesAndInventory() + * @see disableVolatileLinks() */ -function enableSavesAndInventory() +function enableVolatileLinks() { - let save_links = sel('[href~="#saves"]'); - for (const save_link of save_links) { - save_link.classList.remove('disabled'); - } - let inventory_links = sel('[href~="#inventory"]'); - for (const inventory_link of inventory_links) { - inventory_link.classList.remove('disabled'); + for (let location_id of game.volatileLinks()) { + let volatile_links = sel(`[href~="#${location_id}"]`); + for (const volatile_link of volatile_links) { + volatile_link.classList.remove('disabled'); + } } } /** @@ -581,7 +579,7 @@ class Location */ async renderPresentation() { - disableSavesAndInventory(); + disableVolatileLinks(); let game_content = elt("game-content"); game_content.innerHTML = ""; game_content.scrollTop = 0; @@ -616,7 +614,9 @@ class Location this.prepareControls(); let anchors = sel("#game-content a, #game-content x-button"); addListenersAnchors(anchors); - enableSavesAndInventory(); + if (!game.volatileLinks().includes(mc().position)) { + enableVolatileLinks(); + } } /** * Prepares input, textareas, and select tags in the game so that they can @@ -913,6 +913,12 @@ class Game * @type {Boolean} */ is_here; + /** + * List of id's of buttons and links to disable during the staging + * phases of rendering a presentation or when viewing those locations. + * @type {Array} + */ + volatile_links = ['saves', 'inventory']; /** * Sets up a game object with empty history, an initialized main navigation, * and with objects and locations parsed out of the current HTML file @@ -1588,6 +1594,16 @@ class Game let location = this.locations[position]; location.renderPresentation(); } + /** + * Return the array of link ids which should be disable while performing + * the staging of a presentation + * + * @return {Array} + */ + volatileLinks() + { + return this.volatile_links; + } } /** * Module initialization function used to set up the game object corresponding @@ -1610,4 +1626,11 @@ async function initGame() game.takeTurn(""); game.clearHistory(); game.initializeScreen(); + /* + Any game specific customizations are assumed to be in the function + localInitGame if it exists + */ + if (typeof localInitGame == 'function') { + localInitGame(); + } }