Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jobtalle committed Nov 4, 2021
2 parents 722a746 + be1a93d commit bd1d54d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
50 changes: 48 additions & 2 deletions js/koi/gui/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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);
Expand All @@ -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";
Expand All @@ -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)"],
Expand All @@ -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");

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions js/koi/koi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions js/koi/weather/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -119,6 +123,7 @@ if (gl &&
loader.fullscreen,
chosenLocale,
audioEngine,
settings,
audio);
let lastTime = null;
let koi = null;
Expand Down Expand Up @@ -203,7 +208,7 @@ if (gl &&

const loop = time => {
if (loaded) {
koi.render(.001 * (time - lastTime));
koi.render(.001 * (time - lastTime), settings);

lastTime = time;

Expand Down

0 comments on commit bd1d54d

Please sign in to comment.