Fixes for bundle loading
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package lime.utils;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesInput;
|
||||
import haxe.io.Input;
|
||||
import haxe.zip.Reader;
|
||||
import lime.app.Future;
|
||||
import lime.utils.Bytes;
|
||||
import lime.utils.Bytes as LimeBytes;
|
||||
|
||||
#if sys
|
||||
import sys.io.File;
|
||||
@@ -26,6 +27,12 @@ class AssetBundle
|
||||
paths = new Array();
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:Bytes):AssetBundle
|
||||
{
|
||||
var input = new BytesInput(bytes);
|
||||
return __extractBundle(input);
|
||||
}
|
||||
|
||||
public static function fromFile(path:String):AssetBundle
|
||||
{
|
||||
#if sys
|
||||
@@ -36,13 +43,14 @@ class AssetBundle
|
||||
#end
|
||||
}
|
||||
|
||||
public static function loadFromBytes(bytes:Bytes):Future<AssetBundle>
|
||||
{
|
||||
return Future.withValue(fromBytes(bytes));
|
||||
}
|
||||
|
||||
public static function loadFromFile(path:String):Future<AssetBundle>
|
||||
{
|
||||
return Bytes.loadFromFile(path).then(function(bytes)
|
||||
{
|
||||
var input = new BytesInput(bytes);
|
||||
return Future.withValue(__extractBundle(input));
|
||||
});
|
||||
return LimeBytes.loadFromFile(path).then(loadFromBytes);
|
||||
}
|
||||
|
||||
@:noCompletion private static function __extractBundle(input:Input):AssetBundle
|
||||
@@ -55,7 +63,7 @@ class AssetBundle
|
||||
{
|
||||
if (entry.compressed)
|
||||
{
|
||||
var bytes:Bytes = entry.data;
|
||||
var bytes:LimeBytes = entry.data;
|
||||
bundle.data.set(entry.fileName, bytes.decompress(DEFLATE));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -566,6 +566,15 @@ class AssetLibrary
|
||||
{
|
||||
return Future.withValue(Type.createInstance(classTypes.get(id), []));
|
||||
}
|
||||
else if (cachedBytes.exists(id))
|
||||
{
|
||||
return Image.loadFromBytes(cachedBytes.get(id)).then(function (image)
|
||||
{
|
||||
cachedBytes.remove(id);
|
||||
cachedImages.set(id, image);
|
||||
return Future.withValue(image);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return Image.loadFromFile(paths.get(id));
|
||||
@@ -664,12 +673,14 @@ class AssetLibrary
|
||||
type = asset.type;
|
||||
switch(type)
|
||||
{
|
||||
#if !web
|
||||
case IMAGE:
|
||||
cachedImages.set(id, Image.fromBytes(data));
|
||||
case MUSIC, SOUND:
|
||||
cachedAudioBuffers.set(id, AudioBuffer.fromBytes(data));
|
||||
case FONT:
|
||||
cachedFonts.set(id, Font.fromBytes(data));
|
||||
#end
|
||||
case TEXT:
|
||||
cachedText.set(id, data != null ? Std.string(data) : null);
|
||||
default:
|
||||
|
||||
@@ -92,13 +92,17 @@ class AssetManifest
|
||||
manifest.libraryArgs = manifestData.libraryArgs;
|
||||
}
|
||||
|
||||
if (Reflect.hasField(manifestData, "version") && manifestData.version <= 2)
|
||||
if (Reflect.hasField(manifestData, "assets"))
|
||||
{
|
||||
manifest.assets = Unserializer.run(manifestData.assets);
|
||||
}
|
||||
else if (Reflect.hasField(manifestData, "assets") && Std.is(manifestData.assets, Array))
|
||||
{
|
||||
manifest.assets = cast manifestData.assets;
|
||||
var assets:Dynamic = manifestData.assets;
|
||||
if (Reflect.hasField(manifestData, "version") && manifestData.version <= 2)
|
||||
{
|
||||
manifest.assets = Unserializer.run(assets);
|
||||
}
|
||||
else
|
||||
{
|
||||
manifest.assets = assets;
|
||||
}
|
||||
}
|
||||
|
||||
if (Reflect.hasField(manifestData, "rootPath"))
|
||||
|
||||
Reference in New Issue
Block a user