From ce1bcf9c2cfc8e4fdbce1e313f16a26135be0c0a Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 13 Feb 2023 19:48:39 +0530 Subject: [PATCH] make work on js --- src/DtsObject.hx | 2 +- src/Http.hx | 14 ++++++++++---- src/MarbleWorld.hx | 6 ++++-- src/Marbleland.hx | 9 +++++++++ src/Mission.hx | 6 +++++- src/ResourceLoader.hx | 2 ++ 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/DtsObject.hx b/src/DtsObject.hx index 1c2bb5df..6bbf75b9 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -907,7 +907,7 @@ class DtsObject extends GameObject { } } - if (!this.isInstanced) { + if (!this.isInstanced && !this.isTSStatic) { for (i in 0...this.materials.length) { var info = this.materialInfos.get(this.materials[i]); if (info == null) diff --git a/src/Http.hx b/src/Http.hx index 44295956..f0663c00 100644 --- a/src/Http.hx +++ b/src/Http.hx @@ -1,7 +1,6 @@ package src; import src.Console; -import sys.thread.FixedThreadPool; typedef HttpRequest = { var url:String; @@ -55,6 +54,7 @@ class Http { } #end + // Returns HTTPRequest on sys, Int on js public static function get(url:String, callback:haxe.io.Bytes->Void, errCallback:String->Void) { var req = { url: url, @@ -67,7 +67,9 @@ class Http { requests.add(req); return req; #else - js.Browser.window.fetch(url).then(r -> r.arrayBuffer().then(b -> callback(haxe.io.Bytes.ofData(b))), e -> errCallback(e.toString())); + return js.Browser.window.setTimeout(() -> { + js.Browser.window.fetch(url).then(r -> r.arrayBuffer().then(b -> callback(haxe.io.Bytes.ofData(b))), e -> errCallback(e.toString())); + }, 75); #end } @@ -80,11 +82,15 @@ class Http { #end } + #if sys public static function cancel(req:HttpRequest) { - #if sys cancellationMutex.acquire(); req.cancelled = true; cancellationMutex.release(); - #end } + #else + public static function cancel(req:Int) { + js.Browser.window.clearTimeout(req); + } + #end } diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index a92f4322..c77abe0d 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1021,7 +1021,7 @@ class MarbleWorld extends Scheduler { this.addDtsObject(tsShape, () -> { tsShape.setTransform(mat); onFinish(); - }); + }, true); } public function addParticleEmitterNode(element:MissionElementParticleEmitterNode) { @@ -1053,7 +1053,7 @@ class MarbleWorld extends Scheduler { }); } - public function addDtsObject(obj:DtsObject, onFinish:Void->Void) { + public function addDtsObject(obj:DtsObject, onFinish:Void->Void, isTsStatic:Bool = false) { function parseIfl(path:String, onFinish:Array->Void) { ResourceLoader.load(path).entry.load(() -> { var text = ResourceLoader.getFileEntry(path).entry.getText(); @@ -1116,6 +1116,8 @@ class MarbleWorld extends Scheduler { for (texPath in texToLoad) { if (haxe.io.Path.extension(texPath) == "ifl") { + if (isTsStatic) + obj.useInstancing = false; worker.addTask(fwd -> { parseIfl(texPath, keyframes -> { var innerWorker = new ResourceLoaderWorker(() -> { diff --git a/src/Marbleland.hx b/src/Marbleland.hx index 0a15e59b..3a8d368b 100644 --- a/src/Marbleland.hx +++ b/src/Marbleland.hx @@ -80,10 +80,19 @@ class Marbleland { switch (game) { case 'gold': goldMissions.sort((x, y) -> x.title > y.title ? 1 : (x.title < y.title ? -1 : 0)); + for (i in 0...goldMissions.length - 1) { + @:privateAccess goldMissions[i].next = goldMissions[i + 1]; + } case 'platinum': platinumMissions.sort((x, y) -> x.title > y.title ? 1 : (x.title < y.title ? -1 : 0)); + for (i in 0...platinumMissions.length - 1) { + @:privateAccess platinumMissions[i].next = platinumMissions[i + 1]; + } case 'ultra': ultraMissions.sort((x, y) -> x.title > y.title ? 1 : (x.title < y.title ? -1 : 0)); + for (i in 0...ultraMissions.length - 1) { + @:privateAccess ultraMissions[i].next = ultraMissions[i + 1]; + } } } diff --git a/src/Mission.hx b/src/Mission.hx index 1c59eec8..2539b9a4 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -46,7 +46,11 @@ class Mission { var imgFileEntry:hxd.fs.FileEntry; + #if sys static var _previewRequest:HttpRequest; + #else + static var _previewRequest:Int; + #end public function new() {} @@ -164,7 +168,7 @@ class Mission { onLoaded(Tile.fromBitmap(img)); return null; } else { - if (_previewRequest != null && !_previewRequest.fulfilled) { + if (_previewRequest != null #if sys && !_previewRequest.fulfilled #end) { Http.cancel(_previewRequest); // Cancel the previous request to save dequeing } _previewRequest = Marbleland.getMissionImage(this.id, (im) -> { diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index a12731e9..d892fc5a 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -461,7 +461,9 @@ class ResourceLoader { zipFilesystem.clear(); // We are only allowed to load one zip for (entry in entries) { var fname = entry.fileName.toLowerCase(); + #if sys fname = "data/" + fname; + #end if (exists(fname)) continue; Console.log("Loaded zip entry: " + fname);