diff --git a/js/koi/gui/menu/menu.js b/js/koi/gui/menu/menu.js index da712591..71992f48 100644 --- a/js/koi/gui/menu/menu.js +++ b/js/koi/gui/menu/menu.js @@ -4,6 +4,7 @@ * @param {LoaderFullscreen} fullscreen The fullscreen object * @param {String} locale The locale string * @param {AudioEngine} audioEngine The audio engine + * @param {Object} externalSettings The external settings object * @param {AudioBank} audio Game audio * @constructor */ @@ -12,10 +13,11 @@ const Menu = function( fullscreen, locale, audioEngine, + externalSettings, audio) { this.buttonBack = this.createButtonExit(audio); this.languageChooser = this.createLanguageChooser(locale); - this.box = this.createBox(fullscreen, audioEngine, audio); + this.box = this.createBox(fullscreen, audioEngine, externalSettings, audio); this.element = element; this.element.onclick = this.hide.bind(this); this.element.appendChild(this.box); @@ -26,6 +28,7 @@ Menu.prototype.CLASS_VISIBLE = "visible"; Menu.prototype.LANG_TITLE = "MENU"; Menu.prototype.LANG_VOLUME = "VOLUME"; Menu.prototype.LANG_GRASS_AUDIO = "TOGGLE_GRASS_AUDIO"; +Menu.prototype.LANG_FLASHES = "TOGGLE_FLASHES"; Menu.prototype.LANG_FULLSCREEN = "TOGGLE_FULLSCREEN"; Menu.prototype.LANG_MENU = "MENU"; Menu.prototype.LANG_LANGUAGE = "LANGUAGE"; @@ -34,6 +37,7 @@ Menu.prototype.LANG_EXIT = "BACK"; Menu.prototype.KEY_VOLUME = "volume"; Menu.prototype.KEY_LANGUAGE = "language"; Menu.prototype.KEY_GRASS_AUDIO = "grass-audio"; +Menu.prototype.KEY_FLASHES = "flashes"; Menu.prototype.LANGUAGES = [ ["en", "English"], ["de", "Deutsch (German)"], @@ -55,10 +59,15 @@ Menu.prototype.LANGUAGES = [ * Create the menu box * @param {LoaderFullscreen} fullscreen The fullscreen object * @param {AudioEngine} audioEngine The audio engine + * @param {Object} externalSettings The external settings object * @param {AudioBank} audio Game audio * @returns {HTMLDivElement} The menu box */ -Menu.prototype.createBox = function(fullscreen, audioEngine, audio) { +Menu.prototype.createBox = function( + fullscreen, + audioEngine, + externalSettings, + audio) { const element = document.createElement("div"); const table = document.createElement("table"); @@ -69,6 +78,7 @@ Menu.prototype.createBox = function(fullscreen, audioEngine, audio) { table.appendChild(this.createVolumeSlider(audioEngine)); table.appendChild(this.createGrassAudioToggle(audioEngine)); + table.appendChild(this.createFlashToggle(externalSettings)); table.appendChild(this.languageChooser); element.appendChild(table); @@ -193,6 +203,42 @@ Menu.prototype.createGrassAudioToggle = function(audioEngine) { return row; }; +/** + * Create the thunderstorm flash toggle + * @param {Object} externalSettings The external settings object + * @returns {HTMLTableRowElement} The effect toggle + */ +Menu.prototype.createFlashToggle = function(externalSettings) { + const row = document.createElement("tr"); + const label = document.createElement("label"); + const element = document.createElement("input"); + + element.type = "checkbox"; + element.checked = true; + + if (window["localStorage"].getItem(this.KEY_FLASHES)) { + element.checked = window["localStorage"].getItem(this.KEY_FLASHES) === "true"; + + externalSettings.flash = element.checked; + } + else + element.checked = true; + + element.onchange = () => { + window["localStorage"].setItem(this.KEY_FLASHES, element.checked.toString()); + + externalSettings.flash = element.checked; + }; + + label.appendChild(document.createTextNode(language.get(this.LANG_FLASHES))); + label.appendChild(element); + + row.appendChild(this.createTD(label)); + row.appendChild(this.createTD(element)); + + return row; +} + /** * Create a language chooser * @param {String} locale The locale string diff --git a/js/koi/koi.js b/js/koi/koi.js index 981cc5da..98243ad6 100644 --- a/js/koi/koi.js +++ b/js/koi/koi.js @@ -475,8 +475,9 @@ Koi.prototype.update = function() { /** * Render the scene * @param {Number} deltaTime The amount of time passed since the last frame + * @param {Object} externalSettings The external settings object */ -Koi.prototype.render = function(deltaTime) { +Koi.prototype.render = function(deltaTime, externalSettings) { this.time += Math.min(this.FRAME_TIME_MAX, deltaTime); while (this.time > this.UPDATE_RATE) { @@ -562,7 +563,8 @@ Koi.prototype.render = function(deltaTime) { // Render weather effects this.weatherFilterChanged = this.weather.render( this.systems.drops, - time); + time, + externalSettings.flash); // Disable Z buffer this.systems.gl.disable(this.systems.gl.DEPTH_TEST); diff --git a/js/koi/weather/weather.js b/js/koi/weather/weather.js index 68cd1765..76c6fe84 100644 --- a/js/koi/weather/weather.js +++ b/js/koi/weather/weather.js @@ -247,9 +247,10 @@ Weather.prototype.interpolateFilter = function(transition) { * Render weather effects * @param {Drops} drops The drops renderer * @param {Number} time The interpolation factor + * @param {boolean} flashes True if flashes should render * @returns {Boolean} True if the filter color has changed */ -Weather.prototype.render = function(drops, time) { +Weather.prototype.render = function(drops, time, flashes) { const transition = this.transitionPrevious + (this.transition - this.transitionPrevious) * time; this.gl.enable(this.gl.BLEND); @@ -274,7 +275,7 @@ Weather.prototype.render = function(drops, time) { this.gl.disable(this.gl.BLEND); - if (this.lightning !== 0 && this.state.state === this.state.ID_THUNDERSTORM) { + if (flashes && this.lightning !== 0 && this.state.state === this.state.ID_THUNDERSTORM) { const lighting = this.lightningPrevious + (this.lightning - this.lightningPrevious) * time; const power = this.SAMPLER_LIGHTING.sample(lighting); diff --git a/js/main.js b/js/main.js index 59094205..57436eac 100644 --- a/js/main.js +++ b/js/main.js @@ -104,6 +104,10 @@ if (gl && language.load(() => { imperial = language.get("UNIT_LENGTH") === "ft"; + const settings = { + flash: true + }; + let session = new Session(); let slot = null; const slotNames = ["session", "session2", "session3"]; @@ -119,6 +123,7 @@ if (gl && loader.fullscreen, chosenLocale, audioEngine, + settings, audio); let lastTime = null; let koi = null; @@ -203,7 +208,7 @@ if (gl && const loop = time => { if (loaded) { - koi.render(.001 * (time - lastTime)); + koi.render(.001 * (time - lastTime), settings); lastTime = time;