// import { MovieClip } from './../../libs/svga/MovieClip';
// import { Parser } from './../../libs/svga/parser';
export default class SVGACtrl {

    static _instance: SVGACtrl;

    public SVGAPool: any[] = [];

    public static get instance() { return SVGACtrl._instance || (SVGACtrl._instance = new SVGACtrl()) }

    public load(name, path) {
        return new Promise((resolve, reject) => {
            let parser = new window['SVGA'].Parser();
            parser.load(path, (videoItem) => {
                var mv = new window['SVGA'].EgretMovieClip(videoItem)

                this.SVGAPool[name] = videoItem;
                console.log(`${name}加载完成`)
                resolve();
                let fun
                mv.addEventListener(egret.Event.COMPLETE, fun = function () {
                    // console.log("svga加载完成"
                    mv.removeEventListener(egret.Event.COMPLETE, fun, this)
                    mv.stop()
                    mv.startAniRange(30, 60);
                }, this)
            }, function (error) {
                reject(error.message)
            })
        })
    }

    getSVGAByName(name) {
        this.SVGAPool.forEach(svga => {
            if (svga[`${name}`]) {
                return svga[`${name}`];
            }
        })
    }

    public play() {

    }
}
