Skip to content

Commit

Permalink
Make sure game will work on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvoorneveld committed Jan 20, 2022
1 parent 2f8ad57 commit 0d009c6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
19 changes: 14 additions & 5 deletions js/koi/gui/loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
* @param {HTMLElement} elementSlots The save slots element
* @param {HTMLElement} elementButtonSettings The element to build the settings button in
* @param {HTMLElement} wrapper The wrapper to toggle fullscreen on
* @param {Boolean} loadDiscord If set to true, the Discord button will be shown
* @param {Boolean} loadFullscreen If set to true, the Fullscreen button will be shown
* @constructor
*/
const Loader = function(
element,
elementGraphics,
elementSlots,
elementButtonSettings,
wrapper) {
wrapper,
loadFullscreen) {
this.element = element;
this.icon = new LoaderIcon();
this.elementSlots = elementSlots;
Expand All @@ -27,13 +30,18 @@ const Loader = function(
this.onContinue = null;
this.menu = null;
this.fullscreen = new LoaderFullscreen(wrapper);
this.loadFullscreen = loadFullscreen;
this.overlayCanvas = document.createElement("canvas");
this.element.appendChild(this.overlayCanvas);

this.slots = null;

element.appendChild(this.fullscreen.element);
element.appendChild(this.elementDiscord.element);

if(loadFullscreen) {
element.appendChild(this.fullscreen.element);
}

elementGraphics.appendChild(this.icon.element);

const loop = () => {
Expand Down Expand Up @@ -133,8 +141,9 @@ Loader.prototype.createButtonSettings = function() {
* Finish loading
*/
Loader.prototype.complete = function() {
this.fullscreen.setLoaded();

if(!this.loadFullscreen) {
this.fullscreen.setLoaded();
}
const onNewGame = index => {
this.onNewGame(index);
this.onFinish();
Expand Down Expand Up @@ -234,4 +243,4 @@ Loader.prototype.finish = function(weight) {
*/
Loader.prototype.createRequirement = function(weight) {
return new Loader.Requirement(this, weight);
};
};
9 changes: 6 additions & 3 deletions js/koi/gui/loader/loaderDiscord.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ LoaderDiscord.prototype.loadSVG = function() {
}, 1000 * this.FADE_IN_DELAY);

this.element.onclick = () => {
if (window["require"])
if (window["require"]) {
window["require"]("electron")["shell"]["openExternal"](this.URL);
else
} else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openDiscordHandler) {
window.webkit.messageHandlers.openDiscordHandler.postMessage({url: this.URL});
} else {
window.open(this.URL, "_blank");
}
};
};

Expand All @@ -50,4 +53,4 @@ LoaderDiscord.prototype.createElement = function() {
element.className = this.CLASS_INVISIBLE;

return element;
};
};
10 changes: 7 additions & 3 deletions js/koi/gui/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ Menu.prototype.LANGUAGES = [
* @param {AudioEngine} audioEngine The audio engine
* @param {Object} externalSettings The external settings object
* @param {AudioBank} audio Game audio
* @param {createFullscreenButton} If set to true, a fullscreen button will be created
* @returns {HTMLDivElement} The menu box
*/
Menu.prototype.createBox = function(
fullscreen,
audioEngine,
externalSettings,
audio) {
audio,
createFullscreenButton) {
const element = document.createElement("div");
const table = document.createElement("table");

Expand All @@ -84,7 +86,9 @@ Menu.prototype.createBox = function(
table.appendChild(this.languageChooser);

element.appendChild(table);
element.appendChild(this.createButtonFullscreen(fullscreen, audio));
if(createFullscreenButton) {
element.appendChild(this.createButtonFullscreen(fullscreen, audio));
}
element.appendChild(this.buttonBack);

return element;
Expand Down Expand Up @@ -371,4 +375,4 @@ Menu.prototype.toggle = function() {
this.hide();
else
this.show();
};
};
4 changes: 2 additions & 2 deletions js/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Language.prototype.load = function(onFinish, onFailure, file = this.file) {
request.open("GET", file, true);
request.onreadystatechange = () => {
if (request.readyState === 4) {
if (request.status === 200) {
if (request.responseText.length > 0) {
const data = JSON.parse(request.responseText);

this.add(data);
Expand All @@ -65,4 +65,4 @@ Language.prototype.load = function(onFinish, onFailure, file = this.file) {
};

request.send(null);
};
};
14 changes: 11 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const gl =
canvas.getContext("experimental-webgl", glParameters);
let chosenLocale = null;

/**
* Check if game is running within WKWebView on iOS.
*/

const RUNNING_ON_WEBVIEW_IOS = (window.webkit && window.webkit.messageHandlers) ? true : false;

/**
* Called when loading resources failed
*/
Expand Down Expand Up @@ -100,7 +106,8 @@ const loader = new Loader(
document.getElementById("loader-graphics"),
document.getElementById("loader-slots"),
document.getElementById("loader-button-settings"),
document.getElementById("wrapper"));
document.getElementById("wrapper"),
!RUNNING_ON_WEBVIEW_IOS);
let imperial = false;

if (gl &&
Expand Down Expand Up @@ -132,7 +139,8 @@ if (gl &&
chosenLocale,
audioEngine,
settings,
audio);
audio,
!RUNNING_ON_WEBVIEW_IOS);
let lastTime = null;
let koi = null;
let loaded = true;
Expand Down Expand Up @@ -330,4 +338,4 @@ if (gl &&
document.getElementById("code-icon-defs"));
}
else
onFailure();
onFailure();

0 comments on commit 0d009c6

Please sign in to comment.