@@ -72,6 +72,9 @@ class AssetManager extends MessageDispatcher {
7272 /** @private @type {Object.<string, BitmapFontData> } */
7373 this . mBitmapFonts = { } ;
7474
75+ /** @private @type {Object.<string, CustomAsset> } */
76+ this . mCustomAssets = { } ;
77+
7578 /** @private @type {AssetManagerState } */
7679 this . mState = AssetManagerState . NONE ;
7780
@@ -226,6 +229,16 @@ class AssetManager extends MessageDispatcher {
226229 this . mQueue . push ( new FontAsset ( name , '' , false ) ) ;
227230 }
228231
232+ /**
233+ * Adds custom asset to the loading queue.
234+ *
235+ * @param {Asset } asset
236+ */
237+ enqueueCustomAsset ( asset ) {
238+ this . __validateState ( ) ;
239+ this . mQueue . push ( asset ) ;
240+ }
241+
229242 /**
230243 * Starts loading all enqueued assets.
231244 *
@@ -287,11 +300,17 @@ class AssetManager extends MessageDispatcher {
287300 else if ( item . constructor === BVGAsset ) {
288301 this . mGraphicsData [ item . name ] = item . data ;
289302
290- const bakedTextures = item . bakeTextures ( ) ;
291- Object . keys ( bakedTextures ) . forEach ( name => name !== item . name && this . __validateName ( name ) ) ;
292- Object . assign ( this . mVectorTextures , bakedTextures ) ;
293- }
294- else {
303+ const bakedTextures = /** @type {BVGAsset } */ ( item ) . bakeTextures ( ) ;
304+
305+ for ( let name in bakedTextures ) {
306+ if ( ! bakedTextures . hasOwnProperty ( name ) ) continue ;
307+
308+ name !== item . name && this . __validateName ( name ) ;
309+ this . mVectorTextures [ name ] = bakedTextures [ name ] ;
310+ }
311+ } else if ( item instanceof CustomAsset ) {
312+ this . mCustomAssets [ item . name ] = item . data ;
313+ } else {
295314 Debug . error ( `[AssetManager] Unable to handle asset type ${ item } .` ) ;
296315 }
297316
@@ -423,24 +442,32 @@ class AssetManager extends MessageDispatcher {
423442 // collect single textures
424443 for ( let key in this . mTextures )
425444 if ( re . test ( key ) )
426- names . push ( { name : key , atlas : null } ) ;
445+ names . push ( { name : key , atlas : null , isBakedVector : false } ) ;
446+
447+ for ( let key in this . mVectorTextures )
448+ if ( re . test ( key ) )
449+ names . push ( { name : key , atlas : null , isBakedVector : true } ) ;
427450
428451 // collect textures from all atlases
429452 for ( let key in this . mAtlases ) {
430453 let atlas = this . mAtlases [ key ] ;
431454
432455 for ( let key2 in atlas . subTextures )
433456 if ( re . test ( key2 ) )
434- names . push ( { name : key2 , atlas : atlas } ) ;
457+ names . push ( { name : key2 , atlas : atlas , isBakedVector : false } ) ;
435458 }
436459
437460 AtlasTexture . naturalSort ( names , 'name' ) ;
438461
439462 for ( let i = 0 ; i < names . length ; i ++ ) {
440463 let ao = names [ i ] ;
441464
442- if ( ao . atlas == null )
443- out . push ( this . mTextures [ ao . name ] ) ;
465+ if ( ao . atlas === null ) {
466+ if ( ao . isBakedVector === true )
467+ out . push ( this . mVectorTextures [ ao . name ] ) ;
468+ else
469+ out . push ( this . mTextures [ ao . name ] ) ;
470+ }
444471 else
445472 out . push ( ao . atlas . mSubTextures [ ao . name ] ) ;
446473 }
@@ -508,6 +535,16 @@ class AssetManager extends MessageDispatcher {
508535 return this . mJsons [ name ] ;
509536 }
510537
538+ /**
539+ * Returns Object parsed from `CutsomAsset` by given name.
540+ *
541+ * @param {string } name The name of the asset.
542+ * @return {Object } Returns object or null.
543+ */
544+ getCustomAsset ( name ) {
545+ return this . mCustomAssets [ name ] ;
546+ }
547+
511548 __validateState ( ) {
512549 Debug . assert ( this . mState === AssetManagerState . NONE || this . mState === AssetManagerState . FINISHED , 'Illegal state.' ) ;
513550 }
0 commit comments