namespace NT { /** Represents an Json asset */ export class JsonAsset implements IAsset { /** The name of this asset. */ public readonly Name : string ; /** The data of this asset. */ public readonly Data : any ; param name param data public constructor ( name , data ) { this . Name = name ; this . Data = data ; } } /** Represents an Json asset loader. */ export class JsonAssetLoader implements IAssetLoader { /** The extensions supported by this asset loader. */ public get supportedExtensions ( ) : string [ ] { return [ "json" ] ; } param assetName public LoadAsset ( assetName ) { let request = new XMLHttpRequest ( ) ; request . open ( "GET" , assetName ) ; request . addEventListener ( "load" , this . onJsonLoaded . bind ( this , assetName , request ) ) ; request . send ( ) ; } private onJsonLoaded ( assetName , request ) { console . log ( "onJsonLoaded: assetName/request" , assetName , request ) ; if ( request . readyState === request . DONE ) { let json = JSON . parse ( request . responseText ) ; let asset = new JsonAsset ( assetName , json ) ; AssetManager . onAssetLoaded ( asset ) ; } } } }