Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of custom texture formats #872

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions starling/src/starling/utils/AssetManager.as
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ package starling.utils
private var _xmls:Dictionary;
private var _objects:Dictionary;
private var _byteArrays:Dictionary;
private var _textureProcessors:Dictionary;

/** helper objects */
private static var sNames:Vector.<String> = new <String>[];
Expand All @@ -156,6 +157,7 @@ package starling.utils
_xmls = new Dictionary();
_objects = new Dictionary();
_byteArrays = new Dictionary();
_textureProcessors = new Dictionary();
_numConnections = 3;
_verbose = true;
_queue = [];
Expand All @@ -180,6 +182,8 @@ package starling.utils

for each (var byteArray:ByteArray in _byteArrays)
byteArray.clear();

_textureProcessors = null;
}

// retrieving
Expand All @@ -200,6 +204,10 @@ package starling.utils
return null;
}
}
public function addTextureProcessor(extension:String, decodeFunction:Function):void
{
_textureProcessors[extension] = decodeFunction;
}

/** Returns all textures that start with a certain string, sorted alphabetically
* (especially useful for "MovieClip"). */
Expand Down Expand Up @@ -773,7 +781,7 @@ package starling.utils
var canceled:Boolean = false;

addEventListener(Event.CANCEL, cancel);
loadRawAsset(rawAsset, progress, process);
var extension:String = loadRawAsset(rawAsset, progress, process);

function process(asset:Object):void
{
Expand Down Expand Up @@ -914,8 +922,24 @@ package starling.utils
}
else
{
addByteArray(name, bytes);
onComplete();
if (extension){

var processor:Function = _textureProcessors[extension];

if (processor != null){
var bmp:Bitmap = new Bitmap(processor(bytes));
process(bmp);
bytes.clear();
}else{
addByteArray(name, bytes);
onComplete();
}


}else{
addByteArray(name, bytes);
onComplete();
}
}
}
else
Expand Down Expand Up @@ -957,7 +981,7 @@ package starling.utils
* <p>When overriding this method, you can call 'onProgress' with a number between 0 and 1
* to update the total queue loading progress.</p>
*/
protected function loadRawAsset(rawAsset:Object, onProgress:Function, onComplete:Function):void
protected function loadRawAsset(rawAsset:Object, onProgress:Function, onComplete:Function):String
{
var extension:String = null;
var loaderInfo:LoaderInfo = null;
Expand Down Expand Up @@ -1091,6 +1115,7 @@ package starling.utils
else
SystemUtil.executeWhenApplicationIsActive(onComplete, asset);
}
return extension;
}

// helpers
Expand Down