Working on Assets so it can be extended
This commit is contained in:
120
lime/Assets.hx
120
lime/Assets.hx
@@ -51,7 +51,7 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
return library.exists (symbolName, type);
|
return library.exists (symbolName, cast type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, BINARY)) {
|
if (library.exists (symbolName, cast AssetType.BINARY)) {
|
||||||
|
|
||||||
if (library.isLocal (symbolName, BINARY)) {
|
if (library.isLocal (symbolName, cast AssetType.BINARY)) {
|
||||||
|
|
||||||
return library.getBytes (symbolName);
|
return library.getBytes (symbolName);
|
||||||
|
|
||||||
@@ -142,9 +142,9 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, IMAGE)) {
|
if (library.exists (symbolName, cast AssetType.IMAGE)) {
|
||||||
|
|
||||||
if (library.isLocal (symbolName, IMAGE)) {
|
if (library.isLocal (symbolName, cast AssetType.IMAGE)) {
|
||||||
|
|
||||||
var imageData = library.getImageData (symbolName);
|
var imageData = library.getImageData (symbolName);
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ class Assets {
|
|||||||
* @param id The ID or asset path for the music track
|
* @param id The ID or asset path for the music track
|
||||||
* @return A new Sound object
|
* @return A new Sound object
|
||||||
*/
|
*/
|
||||||
public static function getMusic (id:String, useCache:Bool = true):Dynamic /*Sound*/ {
|
/*public static function getMusic (id:String, useCache:Bool = true):Dynamic {
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
@@ -224,9 +224,9 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, MUSIC)) {
|
if (library.exists (symbolName, cast AssetType.MUSIC)) {
|
||||||
|
|
||||||
if (library.isLocal (symbolName, MUSIC)) {
|
if (library.isLocal (symbolName, cast AssetType.MUSIC)) {
|
||||||
|
|
||||||
var sound = library.getMusic (symbolName);
|
var sound = library.getMusic (symbolName);
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ class Assets {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,7 +310,7 @@ class Assets {
|
|||||||
* @param id The ID or asset path for the sound
|
* @param id The ID or asset path for the sound
|
||||||
* @return A new Sound object
|
* @return A new Sound object
|
||||||
*/
|
*/
|
||||||
public static function getSound (id:String, useCache:Bool = true):Dynamic /*Sound*/ {
|
/*public static function getSound (id:String, useCache:Bool = true):Dynamic {
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
@@ -334,9 +334,9 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, SOUND)) {
|
if (library.exists (symbolName, cast AssetType.SOUND)) {
|
||||||
|
|
||||||
if (library.isLocal (symbolName, SOUND)) {
|
if (library.isLocal (symbolName, cast AssetType.SOUND)) {
|
||||||
|
|
||||||
var sound = library.getSound (symbolName);
|
var sound = library.getSound (symbolName);
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ class Assets {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,9 +391,9 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, TEXT)) {
|
if (library.exists (symbolName, cast AssetType.TEXT)) {
|
||||||
|
|
||||||
if (library.isLocal (symbolName, TEXT)) {
|
if (library.isLocal (symbolName, cast AssetType.TEXT)) {
|
||||||
|
|
||||||
return library.getText (symbolName);
|
return library.getText (symbolName);
|
||||||
|
|
||||||
@@ -473,7 +473,7 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
return library.isLocal (symbolName, type);
|
return library.isLocal (symbolName, cast type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ class Assets {
|
|||||||
|
|
||||||
for (library in libraries) {
|
for (library in libraries) {
|
||||||
|
|
||||||
var libraryItems = library.list (type);
|
var libraryItems = library.list (cast type);
|
||||||
|
|
||||||
if (libraryItems != null) {
|
if (libraryItems != null) {
|
||||||
|
|
||||||
@@ -563,7 +563,7 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, BINARY)) {
|
if (library.exists (symbolName, cast AssetType.BINARY)) {
|
||||||
|
|
||||||
library.loadBytes (symbolName, handler);
|
library.loadBytes (symbolName, handler);
|
||||||
return;
|
return;
|
||||||
@@ -612,7 +612,7 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, IMAGE)) {
|
if (library.exists (symbolName, cast AssetType.IMAGE)) {
|
||||||
|
|
||||||
if (useCache && cache.enabled) {
|
if (useCache && cache.enabled) {
|
||||||
|
|
||||||
@@ -679,7 +679,7 @@ class Assets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function loadMusic (id:String, handler:Dynamic /*Sound*/ -> Void, useCache:Bool = true):Void {
|
/*public static function loadMusic (id:String, handler:Dynamic -> Void, useCache:Bool = true):Void {
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
@@ -704,11 +704,11 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, MUSIC)) {
|
if (library.exists (symbolName, cast AssetType.MUSIC)) {
|
||||||
|
|
||||||
if (useCache && cache.enabled) {
|
if (useCache && cache.enabled) {
|
||||||
|
|
||||||
library.loadMusic (symbolName, function (sound:Dynamic /*Sound*/):Void {
|
library.loadMusic (symbolName, function (sound:Dynamic):Void {
|
||||||
|
|
||||||
cache.sound.set (id, sound);
|
cache.sound.set (id, sound);
|
||||||
handler (sound);
|
handler (sound);
|
||||||
@@ -739,10 +739,10 @@ class Assets {
|
|||||||
|
|
||||||
handler (null);
|
handler (null);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public static function loadSound (id:String, handler:Dynamic /*Sound*/ -> Void, useCache:Bool = true):Void {
|
/*public static function loadSound (id:String, handler:Dynamic -> Void, useCache:Bool = true):Void {
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
@@ -767,11 +767,11 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, SOUND)) {
|
if (library.exists (symbolName, cast AssetType.SOUND)) {
|
||||||
|
|
||||||
if (useCache && cache.enabled) {
|
if (useCache && cache.enabled) {
|
||||||
|
|
||||||
library.loadSound (symbolName, function (sound:Dynamic /*Sound*/):Void {
|
library.loadSound (symbolName, function (sound:Dynamic):Void {
|
||||||
|
|
||||||
cache.sound.set (id, sound);
|
cache.sound.set (id, sound);
|
||||||
handler (sound);
|
handler (sound);
|
||||||
@@ -802,7 +802,7 @@ class Assets {
|
|||||||
|
|
||||||
handler (null);
|
handler (null);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public static function loadText (id:String, handler:String -> Void):Void {
|
public static function loadText (id:String, handler:String -> Void):Void {
|
||||||
@@ -817,7 +817,7 @@ class Assets {
|
|||||||
|
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
|
||||||
if (library.exists (symbolName, TEXT)) {
|
if (library.exists (symbolName, cast AssetType.TEXT)) {
|
||||||
|
|
||||||
library.loadText (symbolName, handler);
|
library.loadText (symbolName, handler);
|
||||||
return;
|
return;
|
||||||
@@ -943,7 +943,7 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function exists (id:String, type:AssetType):Bool {
|
public function exists (id:String, type:String):Bool {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -964,11 +964,11 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getMusic (id:String):Dynamic /*Sound*/ {
|
//public function getMusic (id:String):Dynamic /*Sound*/ {
|
||||||
|
|
||||||
return getSound (id);
|
// return getSound (id);
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
public function getPath (id:String):String {
|
public function getPath (id:String):String {
|
||||||
@@ -978,11 +978,11 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getSound (id:String):Dynamic /*Sound*/ {
|
//public function getSound (id:String):Dynamic /*Sound*/ {
|
||||||
|
|
||||||
return null;
|
// return null;
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
public function getText (id:String):String {
|
public function getText (id:String):String {
|
||||||
@@ -1010,14 +1010,14 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isLocal (id:String, type:AssetType):Bool {
|
public function isLocal (id:String, type:String):Bool {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function list (type:AssetType):Array<String> {
|
public function list (type:String):Array<String> {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -1045,18 +1045,18 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function loadMusic (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
//public function loadMusic (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
||||||
|
|
||||||
handler (getMusic (id));
|
// handler (getMusic (id));
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
public function loadSound (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
//public function loadSound (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
||||||
|
|
||||||
handler (getSound (id));
|
// handler (getSound (id));
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
public function loadText (id:String, handler:String -> Void):Void {
|
public function loadText (id:String, handler:String -> Void):Void {
|
||||||
@@ -1163,33 +1163,15 @@ class AssetCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AssetData {
|
@:enum abstract AssetType(String) {
|
||||||
|
|
||||||
|
var BINARY = "binary";
|
||||||
public var id:String;
|
var FONT = "font";
|
||||||
public var path:String;
|
var IMAGE = "image";
|
||||||
public var type:AssetType;
|
var MUSIC = "music";
|
||||||
|
var SOUND = "sound";
|
||||||
public function new () {
|
var TEMPLATE = "template";
|
||||||
|
var TEXT = "text";
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum AssetType {
|
|
||||||
|
|
||||||
BINARY;
|
|
||||||
FONT;
|
|
||||||
IMAGE;
|
|
||||||
MOVIE_CLIP;
|
|
||||||
MUSIC;
|
|
||||||
SOUND;
|
|
||||||
TEMPLATE;
|
|
||||||
TEXT;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,13 +107,14 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function exists (id:String, type:AssetType):Bool {
|
public override function exists (id:String, type:String):Bool {
|
||||||
|
|
||||||
|
var requestedType = cast (type, AssetType);
|
||||||
var assetType = this.type.get (id);
|
var assetType = this.type.get (id);
|
||||||
|
|
||||||
if (assetType != null) {
|
if (assetType != null) {
|
||||||
|
|
||||||
if (assetType == type || ((type == SOUND || type == MUSIC) && (assetType == MUSIC || assetType == SOUND))) {
|
if (assetType == requestedType || ((requestedType == SOUND || requestedType == MUSIC) && (assetType == MUSIC || assetType == SOUND))) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
if ((assetType == BINARY || assetType == TEXT) && type == BINARY) {
|
if ((assetType == BINARY || assetType == TEXT) && requestedType == BINARY) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (type == BINARY || type == null) {
|
if (requestedType == BINARY || requestedType == null) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -249,7 +250,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function getMusic (id:String):Dynamic /*Sound*/ {
|
/*public override function getMusic (id:String):Dynamic {
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
@@ -257,10 +258,10 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#elseif openfl_html5
|
#elseif openfl_html5
|
||||||
|
|
||||||
/*var sound = new Sound ();
|
//var sound = new Sound ();
|
||||||
sound.__buffer = true;
|
//sound.__buffer = true;
|
||||||
sound.load (new URLRequest (path.get (id)));
|
//sound.load (new URLRequest (path.get (id)));
|
||||||
return sound;*/
|
//return sound;
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
#elseif js
|
#elseif js
|
||||||
@@ -276,7 +277,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public override function getPath (id:String):String {
|
public override function getPath (id:String):String {
|
||||||
@@ -294,7 +295,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function getSound (id:String):Dynamic /*Sound*/ {
|
/*public override function getSound (id:String):Dynamic {
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
@@ -313,7 +314,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public override function getText (id:String):String {
|
public override function getText (id:String):String {
|
||||||
@@ -366,11 +367,13 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function isLocal (id:String, type:AssetType):Bool {
|
public override function isLocal (id:String, type:String):Bool {
|
||||||
|
|
||||||
|
var requestedType = cast (type, AssetType);
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
if (type != AssetType.MUSIC && type != AssetType.SOUND) {
|
if (requestedType != AssetType.MUSIC && requestedType != AssetType.SOUND) {
|
||||||
|
|
||||||
return className.exists (id);
|
return className.exists (id);
|
||||||
|
|
||||||
@@ -383,13 +386,14 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function list (type:AssetType):Array<String> {
|
public override function list (type:String):Array<String> {
|
||||||
|
|
||||||
|
var requestedType = cast (type, AssetType);
|
||||||
var items = [];
|
var items = [];
|
||||||
|
|
||||||
for (id in this.type.keys ()) {
|
for (id in this.type.keys ()) {
|
||||||
|
|
||||||
if (type == null || exists (id, type)) {
|
if (requestedType == null || exists (id, type)) {
|
||||||
|
|
||||||
items.push (id);
|
items.push (id);
|
||||||
|
|
||||||
@@ -523,21 +527,21 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
public override function loadMusic (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
/*public override function loadMusic (id:String, handler:Dynamic -> Void):Void {
|
||||||
|
|
||||||
#if (flash || js)
|
#if (flash || js)
|
||||||
|
|
||||||
/*if (path.exists (id)) {
|
//if (path.exists (id)) {
|
||||||
|
|
||||||
var loader = new Loader ();
|
// var loader = new Loader ();
|
||||||
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, function (event) {
|
// loader.contentLoaderInfo.addEventListener (Event.COMPLETE, function (event) {
|
||||||
|
|
||||||
handler (cast (event.currentTarget.content, Bitmap).bitmapData);
|
// handler (cast (event.currentTarget.content, Bitmap).bitmapData);
|
||||||
|
|
||||||
});
|
// });
|
||||||
loader.load (new URLRequest (path.get (id)));
|
// loader.load (new URLRequest (path.get (id)));
|
||||||
|
|
||||||
} else {*/
|
//} else {
|
||||||
|
|
||||||
handler (getMusic (id));
|
handler (getMusic (id));
|
||||||
|
|
||||||
@@ -549,24 +553,24 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public override function loadSound (id:String, handler:Dynamic /*Sound*/ -> Void):Void {
|
/*public override function loadSound (id:String, handler:Dynamic -> Void):Void {
|
||||||
|
|
||||||
#if (flash || js)
|
#if (flash || js)
|
||||||
|
|
||||||
/*if (path.exists (id)) {
|
//if (path.exists (id)) {
|
||||||
|
|
||||||
var loader = new Loader ();
|
// var loader = new Loader ();
|
||||||
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, function (event) {
|
// loader.contentLoaderInfo.addEventListener (Event.COMPLETE, function (event) {
|
||||||
|
|
||||||
handler (cast (event.currentTarget.content, Bitmap).bitmapData);
|
// handler (cast (event.currentTarget.content, Bitmap).bitmapData);
|
||||||
|
|
||||||
});
|
// });
|
||||||
loader.load (new URLRequest (path.get (id)));
|
// loader.load (new URLRequest (path.get (id)));
|
||||||
|
|
||||||
} else {*/
|
//} else {
|
||||||
|
|
||||||
handler (getSound (id));
|
handler (getSound (id));
|
||||||
|
|
||||||
@@ -578,7 +582,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public override function loadText (id:String, handler:String -> Void):Void {
|
public override function loadText (id:String, handler:String -> Void):Void {
|
||||||
|
|||||||
Reference in New Issue
Block a user