mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-02-13 09:46:07 +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;
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
109
src/Sky.hx
109
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<FileEntry> {
|
||||
var entry:ManifestEntry = find(path);
|
||||
var entry:ManifestEntry = find(path.toLowerCase());
|
||||
if (entry == null)
|
||||
throw new NotFound(path);
|
||||
return cast entry.contents.copy();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue