From bffa58e8386d7d764995657443a17166c259fda7 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 12 Nov 2022 14:04:42 +0530 Subject: [PATCH] make work on js --- src/MarbleWorld.hx | 9 ++- src/ResourceLoader.hx | 4 +- src/Sky.hx | 109 ++++++++++++++++++----------------- src/fs/ManifestBuilder.hx | 3 +- src/fs/ManifestFileSystem.hx | 18 +++--- src/fs/TorqueFileSystem.hx | 2 + 6 files changed, 77 insertions(+), 68 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 57233005..5ac00b74 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -205,9 +205,15 @@ class MarbleWorld extends Scheduler { this._loadingLength = resourceLoadFuncs.length; fwd(); }); + this.resourceLoadFuncs.push(fwd -> this.loadMusic(fwd)); this._loadingLength = resourceLoadFuncs.length; } + public function loadMusic(onFinish:Void->Void) { + var musicFileName = 'sound/' + this.mission.missionInfo.music; + ResourceLoader.load(musicFileName).entry.load(onFinish); + } + public function postInit() { this._ready = true; this.playGui.init(this.scene2d); @@ -262,8 +268,7 @@ class MarbleWorld extends Scheduler { "particles/smoke.png", "particles/spark.png", "particles/star.png", - "particles/twirl.png", - "skies/sky_day.dml" + "particles/twirl.png" ]; for (file in filestoload) { diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index f538fae8..10197fa4 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -162,9 +162,7 @@ class ResourceLoader { static function preloadMusic(onFinish:Void->Void) { var worker = new ResourceLoaderWorker(onFinish); worker.loadFile("sound/shell.ogg"); - worker.loadFile("sound/groovepolice.ogg"); - worker.loadFile("sound/classic vibe.ogg"); - worker.loadFile("sound/beach party.ogg"); + worker.loadFile("sound/pianoforte.ogg"); worker.run(); } diff --git a/src/Sky.hx b/src/Sky.hx index a0ce3c5f..0d0d1b9d 100644 --- a/src/Sky.hx +++ b/src/Sky.hx @@ -67,70 +67,73 @@ class Sky extends Object { dmlPath = StringTools.replace(dmlPath, "data/", ""); #end if (ResourceLoader.fileSystem.exists(dmlPath)) { - var dmlFile = ResourceLoader.fileSystem.get(dmlPath).getText(); - var dmlDirectory = Path.directory(dmlPath); - var lines = dmlFile.split('\n').map(x -> x.toLowerCase()); - var skyboxImages = []; + var dmlFileEntry = ResourceLoader.fileSystem.get(dmlPath); + dmlFileEntry.load(() -> { + var dmlFile = dmlFileEntry.getText(); + var dmlDirectory = Path.directory(dmlPath); + var lines = dmlFile.split('\n').map(x -> x.toLowerCase()); + var skyboxImages = []; - // 5: bottom, to be rotated/flipped - // 0: front - var skyboxIndices = [3, 1, 2, 0, 4, 5]; + // 5: bottom, to be rotated/flipped + // 0: front + var skyboxIndices = [3, 1, 2, 0, 4, 5]; - var filestoload = []; - for (i in 0...6) { - var line = StringTools.trim(lines[i]); - var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line); - if (filenames.length != 0) { - filestoload.push(filenames[0]); - } - } - - var worker = new ResourceLoaderWorker(() -> { + var filestoload = []; for (i in 0...6) { var line = StringTools.trim(lines[i]); var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line); - if (filenames.length == 0) { - var pixels = Texture.fromColor(0).capturePixels(0, 0); - skyboxImages.push(pixels); - // var tex = new h3d.mat.Texture(); - // skyboxImages.push(new BitmapData(128, 128)); - } else { - var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap(); - var pixels = image.getPixels(); - skyboxImages.push(pixels); + if (filenames.length != 0) { + filestoload.push(filenames[0]); } } - var maxwidth = 0; - var maxheight = 0; - for (texture in skyboxImages) { - if (texture.height > maxheight) - maxheight = texture.height; - if (texture.width > maxwidth) - maxwidth = texture.width; - } - Util.flipImage(skyboxImages[0], true, false); - Util.flipImage(skyboxImages[4], true, false); - Util.rotateImage(skyboxImages[5], Math.PI); - Util.flipImage(skyboxImages[5], true, false); - Util.rotateImage(skyboxImages[1], -Math.PI / 2); - Util.flipImage(skyboxImages[1], true, false); - Util.rotateImage(skyboxImages[2], Math.PI); - Util.flipImage(skyboxImages[2], true, false); - Util.rotateImage(skyboxImages[3], Math.PI / 2); - Util.flipImage(skyboxImages[3], true, false); + var worker = new ResourceLoaderWorker(() -> { + for (i in 0...6) { + var line = StringTools.trim(lines[i]); + var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line); + if (filenames.length == 0) { + var pixels = Texture.fromColor(0).capturePixels(0, 0); + skyboxImages.push(pixels); + // var tex = new h3d.mat.Texture(); + // skyboxImages.push(new BitmapData(128, 128)); + } else { + var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap(); + var pixels = image.getPixels(); + skyboxImages.push(pixels); + } + } + var maxwidth = 0; + var maxheight = 0; + for (texture in skyboxImages) { + if (texture.height > maxheight) + maxheight = texture.height; + if (texture.width > maxwidth) + maxwidth = texture.width; + } - var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]); - for (i in 0...6) { - cubemaptexture.uploadPixels(skyboxImages[skyboxIndices[i]], 0, i); + Util.flipImage(skyboxImages[0], true, false); + Util.flipImage(skyboxImages[4], true, false); + Util.rotateImage(skyboxImages[5], Math.PI); + Util.flipImage(skyboxImages[5], true, false); + Util.rotateImage(skyboxImages[1], -Math.PI / 2); + Util.flipImage(skyboxImages[1], true, false); + Util.rotateImage(skyboxImages[2], Math.PI); + Util.flipImage(skyboxImages[2], true, false); + Util.rotateImage(skyboxImages[3], Math.PI / 2); + Util.flipImage(skyboxImages[3], true, false); + + var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]); + for (i in 0...6) { + cubemaptexture.uploadPixels(skyboxImages[skyboxIndices[i]], 0, i); + } + onFinish(cubemaptexture); + }); + + for (file in filestoload) { + worker.loadFile(file); } - onFinish(cubemaptexture); + worker.run(); }); - - for (file in filestoload) { - worker.loadFile(file); - } - worker.run(); } else { onFinish(null); } diff --git a/src/fs/ManifestBuilder.hx b/src/fs/ManifestBuilder.hx index bd2ccdc7..577aaacb 100644 --- a/src/fs/ManifestBuilder.hx +++ b/src/fs/ManifestBuilder.hx @@ -130,12 +130,13 @@ class ManifestBuilder { // try later with another fs if (!StringTools.startsWith(file.fullPath, basePath)) continue; - var info = {path: file.relPath, original: file.relPath}; + var info = {path: file.relPath.toLowerCase(), original: file.relPath}; out.push(info); var f = fs.get(file.relPath); // convert if (f.originalFile != null && f.originalFile != f.file) { info.original = f.relPath; info.path = StringTools.startsWith(f.file, fs.baseDir) ? f.file.substr(fs.baseDir.length) : f.file; + info.path = info.path.toLowerCase(); } } diff --git a/src/fs/ManifestFileSystem.hx b/src/fs/ManifestFileSystem.hx index 1443095a..29a4ee23 100644 --- a/src/fs/ManifestFileSystem.hx +++ b/src/fs/ManifestFileSystem.hx @@ -173,7 +173,7 @@ class ManifestEntry extends FileEntry { private function _exists(name:String):Bool { if (isDir) { for (c in contents) - if (c.name == name) + if (c.name.toLowerCase() == name.toLowerCase()) return true; } return false; @@ -182,7 +182,7 @@ class ManifestEntry extends FileEntry { private function _get(name:String):ManifestEntry { if (isDir) { for (c in contents) - if (c.name == name) + if (c.name.toLowerCase() == name.toLowerCase()) return c; } return null; @@ -268,7 +268,7 @@ class ManifestFileSystem implements FileSystem { } var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original); r.contents.push(entry); - manifest.set(path, entry); + manifest.set(path.toLowerCase(), entry); } switch (_manifest.get(0)) { @@ -299,7 +299,7 @@ class ManifestFileSystem implements FileSystem { // JSON var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString()); for (entry in json) { - insert(entry.path, baseDir + entry.path, entry.original); + insert(entry.path.toLowerCase(), baseDir + entry.path, entry.original); } } } @@ -314,8 +314,8 @@ class ManifestFileSystem implements FileSystem { private function find(path:String):ManifestEntry { var r = root; - for (p in splitPath(path)) { - r = r._get(p); + for (p in splitPath(path.toLowerCase())) { + r = r._get(p.toLowerCase()); if (r == null) return null; } @@ -323,11 +323,11 @@ class ManifestFileSystem implements FileSystem { } public function exists(path:String) { - return find(path) != null; + return find(path.toLowerCase()) != null; } public function get(path:String) { - var entry:ManifestEntry = find(path); + var entry:ManifestEntry = find(path.toLowerCase()); if (entry == null) throw new NotFound(path); return entry; @@ -339,7 +339,7 @@ class ManifestFileSystem implements FileSystem { } public function dir(path:String):Array { - var entry:ManifestEntry = find(path); + var entry:ManifestEntry = find(path.toLowerCase()); if (entry == null) throw new NotFound(path); return cast entry.contents.copy(); diff --git a/src/fs/TorqueFileSystem.hx b/src/fs/TorqueFileSystem.hx index 215cc53c..4158cba9 100644 --- a/src/fs/TorqueFileSystem.hx +++ b/src/fs/TorqueFileSystem.hx @@ -3,6 +3,7 @@ package fs; import hxd.fs.LocalFileSystem; class TorqueFileSystem extends LocalFileSystem { + #if hl override function checkPath(path:String) { // make sure the file is loaded with correct case ! var baseDir = new haxe.io.Path(path).dir; @@ -44,4 +45,5 @@ class TorqueFileSystem extends LocalFileSystem { fileCache.set(path.toLowerCase(), {r: e}); return e; } + #end }