make work on js

This commit is contained in:
RandomityGuy 2023-02-13 19:48:39 +05:30
parent 266a29afc4
commit ce1bcf9c2c
6 changed files with 31 additions and 8 deletions

View file

@ -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)

View file

@ -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
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
}
public static function cancel(req:HttpRequest) {
#if sys
public static function cancel(req:HttpRequest) {
cancellationMutex.acquire();
req.cancelled = true;
cancellationMutex.release();
}
#else
public static function cancel(req:Int) {
js.Browser.window.clearTimeout(req);
}
#end
}
}

View file

@ -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<String>->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(() -> {

View file

@ -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];
}
}
}

View file

@ -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) -> {

View file

@ -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);