diff --git a/game/game.js b/game/game.js index 9ca14d25d..74670ccdc 100644 --- a/game/game.js +++ b/game/game.js @@ -5,7 +5,7 @@ new Promise(resolve => { if ('__core-js_shared__' in window) resolve(null); else { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; + const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); const coreJSBundle = document.createElement('script'); coreJSBundle.onerror = coreJSBundle.onload = resolve; coreJSBundle.src = `${assetURL}game/core-js-bundle.js`; @@ -13,7 +13,7 @@ new Promise(resolve => { } }).then(() => { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; + const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); const userAgent = navigator.userAgent.toLowerCase(); const exit = () => { diff --git a/noname/init/cordova.js b/noname/init/cordova.js index b642fad9d..291d70906 100644 --- a/noname/init/cordova.js +++ b/noname/init/cordova.js @@ -4,6 +4,7 @@ import { Library as lib } from '../library/index.js'; import { Game as game } from '../game/index.js'; import { status as _status } from '../status/index.js'; import { UI as ui } from '../ui/index.js'; +import { nonameInitialized } from '../util/index.js'; export async function cordovaReady() { lib.path = (await import('../library/path.js')).default; @@ -62,7 +63,7 @@ export async function cordovaReady() { url = get.url(dev) + url; } var fileTransfer = new FileTransfer(); - folder = lib.assetURL + folder; + folder = nonameInitialized + folder; if (onprogress) { fileTransfer.onprogress = function (progressEvent) { onprogress(progressEvent.loaded, progressEvent.total); @@ -79,7 +80,7 @@ export async function cordovaReady() { }, onerror); }; game.readFile = function (filename, callback, onerror) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(filename, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); @@ -92,7 +93,7 @@ export async function cordovaReady() { }, onerror); }; game.readFileAsText = function (filename, callback, onerror) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(filename, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); @@ -114,7 +115,7 @@ export async function cordovaReady() { fileReader.readAsArrayBuffer(data, "UTF-8"); } else { - window.resolveLocalFileSystemURL(lib.assetURL + path, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + path, function (entry) { entry.getFile(name, { create: true }, function (fileEntry) { fileEntry.createWriter(function (fileWriter) { fileWriter.onwriteend = callback; @@ -126,7 +127,7 @@ export async function cordovaReady() { }); }; game.removeFile = function (dir, callback) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(dir, {}, function (fileEntry) { fileEntry.remove(); if (callback) callback(); @@ -135,7 +136,7 @@ export async function cordovaReady() { }; game.getFileList = (dir, success, failure) => { var files = [], folders = []; - window.resolveLocalFileSystemURL(lib.assetURL + dir, entry => { + window.resolveLocalFileSystemURL(nonameInitialized + dir, entry => { var dirReader = entry.createReader(); var entries = []; var readEntries = () => { @@ -174,7 +175,7 @@ export async function cordovaReady() { create: true }, resolve))).then(directoryEntry => access(directoryEntry, directory, createDirectory)); }; - return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, rootEntry => { + return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(nonameInitialized, rootEntry => { const createDirectory = () => { if (directoryList.length) access(rootEntry, directoryList.pop().split('/').reverse(), createDirectory); if (typeof callback == 'function') callback(); diff --git a/noname/util/index.js b/noname/util/index.js index 05fd85205..724ec163f 100644 --- a/noname/util/index.js +++ b/noname/util/index.js @@ -1,5 +1,5 @@ export const nonameInitialized = localStorage.getItem('noname_inited'); -export const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; +export const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); export const GeneratorFunction = (function* () { }).constructor; export const AsyncFunction = (async function () { }).constructor; export const userAgent = navigator.userAgent.toLowerCase();