mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +00:00
make work on js
This commit is contained in:
parent
7408afa680
commit
bffa58e838
6 changed files with 77 additions and 68 deletions
|
|
@ -205,9 +205,15 @@ class MarbleWorld extends Scheduler {
|
||||||
this._loadingLength = resourceLoadFuncs.length;
|
this._loadingLength = resourceLoadFuncs.length;
|
||||||
fwd();
|
fwd();
|
||||||
});
|
});
|
||||||
|
this.resourceLoadFuncs.push(fwd -> this.loadMusic(fwd));
|
||||||
this._loadingLength = resourceLoadFuncs.length;
|
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() {
|
public function postInit() {
|
||||||
this._ready = true;
|
this._ready = true;
|
||||||
this.playGui.init(this.scene2d);
|
this.playGui.init(this.scene2d);
|
||||||
|
|
@ -262,8 +268,7 @@ class MarbleWorld extends Scheduler {
|
||||||
"particles/smoke.png",
|
"particles/smoke.png",
|
||||||
"particles/spark.png",
|
"particles/spark.png",
|
||||||
"particles/star.png",
|
"particles/star.png",
|
||||||
"particles/twirl.png",
|
"particles/twirl.png"
|
||||||
"skies/sky_day.dml"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for (file in filestoload) {
|
for (file in filestoload) {
|
||||||
|
|
|
||||||
|
|
@ -162,9 +162,7 @@ class ResourceLoader {
|
||||||
static function preloadMusic(onFinish:Void->Void) {
|
static function preloadMusic(onFinish:Void->Void) {
|
||||||
var worker = new ResourceLoaderWorker(onFinish);
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
worker.loadFile("sound/shell.ogg");
|
worker.loadFile("sound/shell.ogg");
|
||||||
worker.loadFile("sound/groovepolice.ogg");
|
worker.loadFile("sound/pianoforte.ogg");
|
||||||
worker.loadFile("sound/classic vibe.ogg");
|
|
||||||
worker.loadFile("sound/beach party.ogg");
|
|
||||||
worker.run();
|
worker.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
109
src/Sky.hx
109
src/Sky.hx
|
|
@ -67,70 +67,73 @@ class Sky extends Object {
|
||||||
dmlPath = StringTools.replace(dmlPath, "data/", "");
|
dmlPath = StringTools.replace(dmlPath, "data/", "");
|
||||||
#end
|
#end
|
||||||
if (ResourceLoader.fileSystem.exists(dmlPath)) {
|
if (ResourceLoader.fileSystem.exists(dmlPath)) {
|
||||||
var dmlFile = ResourceLoader.fileSystem.get(dmlPath).getText();
|
var dmlFileEntry = ResourceLoader.fileSystem.get(dmlPath);
|
||||||
var dmlDirectory = Path.directory(dmlPath);
|
dmlFileEntry.load(() -> {
|
||||||
var lines = dmlFile.split('\n').map(x -> x.toLowerCase());
|
var dmlFile = dmlFileEntry.getText();
|
||||||
var skyboxImages = [];
|
var dmlDirectory = Path.directory(dmlPath);
|
||||||
|
var lines = dmlFile.split('\n').map(x -> x.toLowerCase());
|
||||||
|
var skyboxImages = [];
|
||||||
|
|
||||||
// 5: bottom, to be rotated/flipped
|
// 5: bottom, to be rotated/flipped
|
||||||
// 0: front
|
// 0: front
|
||||||
var skyboxIndices = [3, 1, 2, 0, 4, 5];
|
var skyboxIndices = [3, 1, 2, 0, 4, 5];
|
||||||
|
|
||||||
var filestoload = [];
|
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(() -> {
|
|
||||||
for (i in 0...6) {
|
for (i in 0...6) {
|
||||||
var line = StringTools.trim(lines[i]);
|
var line = StringTools.trim(lines[i]);
|
||||||
var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line);
|
var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line);
|
||||||
if (filenames.length == 0) {
|
if (filenames.length != 0) {
|
||||||
var pixels = Texture.fromColor(0).capturePixels(0, 0);
|
filestoload.push(filenames[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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Util.flipImage(skyboxImages[0], true, false);
|
var worker = new ResourceLoaderWorker(() -> {
|
||||||
Util.flipImage(skyboxImages[4], true, false);
|
for (i in 0...6) {
|
||||||
Util.rotateImage(skyboxImages[5], Math.PI);
|
var line = StringTools.trim(lines[i]);
|
||||||
Util.flipImage(skyboxImages[5], true, false);
|
var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line);
|
||||||
Util.rotateImage(skyboxImages[1], -Math.PI / 2);
|
if (filenames.length == 0) {
|
||||||
Util.flipImage(skyboxImages[1], true, false);
|
var pixels = Texture.fromColor(0).capturePixels(0, 0);
|
||||||
Util.rotateImage(skyboxImages[2], Math.PI);
|
skyboxImages.push(pixels);
|
||||||
Util.flipImage(skyboxImages[2], true, false);
|
// var tex = new h3d.mat.Texture();
|
||||||
Util.rotateImage(skyboxImages[3], Math.PI / 2);
|
// skyboxImages.push(new BitmapData(128, 128));
|
||||||
Util.flipImage(skyboxImages[3], true, false);
|
} 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]);
|
Util.flipImage(skyboxImages[0], true, false);
|
||||||
for (i in 0...6) {
|
Util.flipImage(skyboxImages[4], true, false);
|
||||||
cubemaptexture.uploadPixels(skyboxImages[skyboxIndices[i]], 0, i);
|
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 {
|
} else {
|
||||||
onFinish(null);
|
onFinish(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,12 +130,13 @@ class ManifestBuilder {
|
||||||
// try later with another fs
|
// try later with another fs
|
||||||
if (!StringTools.startsWith(file.fullPath, basePath))
|
if (!StringTools.startsWith(file.fullPath, basePath))
|
||||||
continue;
|
continue;
|
||||||
var info = {path: file.relPath, original: file.relPath};
|
var info = {path: file.relPath.toLowerCase(), original: file.relPath};
|
||||||
out.push(info);
|
out.push(info);
|
||||||
var f = fs.get(file.relPath); // convert
|
var f = fs.get(file.relPath); // convert
|
||||||
if (f.originalFile != null && f.originalFile != f.file) {
|
if (f.originalFile != null && f.originalFile != f.file) {
|
||||||
info.original = f.relPath;
|
info.original = f.relPath;
|
||||||
info.path = StringTools.startsWith(f.file, fs.baseDir) ? f.file.substr(fs.baseDir.length) : f.file;
|
info.path = StringTools.startsWith(f.file, fs.baseDir) ? f.file.substr(fs.baseDir.length) : f.file;
|
||||||
|
info.path = info.path.toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ class ManifestEntry extends FileEntry {
|
||||||
private function _exists(name:String):Bool {
|
private function _exists(name:String):Bool {
|
||||||
if (isDir) {
|
if (isDir) {
|
||||||
for (c in contents)
|
for (c in contents)
|
||||||
if (c.name == name)
|
if (c.name.toLowerCase() == name.toLowerCase())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -182,7 +182,7 @@ class ManifestEntry extends FileEntry {
|
||||||
private function _get(name:String):ManifestEntry {
|
private function _get(name:String):ManifestEntry {
|
||||||
if (isDir) {
|
if (isDir) {
|
||||||
for (c in contents)
|
for (c in contents)
|
||||||
if (c.name == name)
|
if (c.name.toLowerCase() == name.toLowerCase())
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -268,7 +268,7 @@ class ManifestFileSystem implements FileSystem {
|
||||||
}
|
}
|
||||||
var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original);
|
var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original);
|
||||||
r.contents.push(entry);
|
r.contents.push(entry);
|
||||||
manifest.set(path, entry);
|
manifest.set(path.toLowerCase(), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_manifest.get(0)) {
|
switch (_manifest.get(0)) {
|
||||||
|
|
@ -299,7 +299,7 @@ class ManifestFileSystem implements FileSystem {
|
||||||
// JSON
|
// JSON
|
||||||
var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString());
|
var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString());
|
||||||
for (entry in json) {
|
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 {
|
private function find(path:String):ManifestEntry {
|
||||||
var r = root;
|
var r = root;
|
||||||
for (p in splitPath(path)) {
|
for (p in splitPath(path.toLowerCase())) {
|
||||||
r = r._get(p);
|
r = r._get(p.toLowerCase());
|
||||||
if (r == null)
|
if (r == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -323,11 +323,11 @@ class ManifestFileSystem implements FileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exists(path:String) {
|
public function exists(path:String) {
|
||||||
return find(path) != null;
|
return find(path.toLowerCase()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(path:String) {
|
public function get(path:String) {
|
||||||
var entry:ManifestEntry = find(path);
|
var entry:ManifestEntry = find(path.toLowerCase());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
throw new NotFound(path);
|
throw new NotFound(path);
|
||||||
return entry;
|
return entry;
|
||||||
|
|
@ -339,7 +339,7 @@ class ManifestFileSystem implements FileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dir(path:String):Array<FileEntry> {
|
public function dir(path:String):Array<FileEntry> {
|
||||||
var entry:ManifestEntry = find(path);
|
var entry:ManifestEntry = find(path.toLowerCase());
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
throw new NotFound(path);
|
throw new NotFound(path);
|
||||||
return cast entry.contents.copy();
|
return cast entry.contents.copy();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package fs;
|
||||||
import hxd.fs.LocalFileSystem;
|
import hxd.fs.LocalFileSystem;
|
||||||
|
|
||||||
class TorqueFileSystem extends LocalFileSystem {
|
class TorqueFileSystem extends LocalFileSystem {
|
||||||
|
#if hl
|
||||||
override function checkPath(path:String) {
|
override function checkPath(path:String) {
|
||||||
// make sure the file is loaded with correct case !
|
// make sure the file is loaded with correct case !
|
||||||
var baseDir = new haxe.io.Path(path).dir;
|
var baseDir = new haxe.io.Path(path).dir;
|
||||||
|
|
@ -44,4 +45,5 @@ class TorqueFileSystem extends LocalFileSystem {
|
||||||
fileCache.set(path.toLowerCase(), {r: e});
|
fileCache.set(path.toLowerCase(), {r: e});
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue