export default class SVGAClip {
    private static _parser: any = null;
    public static get parser(): any {
        if (SVGAClip._parser == null) {
            SVGAClip._parser = new window["SVGA"].Parser();
        }
        return SVGAClip._parser;
    }
    init() {
        this.svga.visible = false;
    }

    public svga: any = null;
    public offset: egret.Point = new egret.Point();
    public gameStage: egret.DisplayObjectContainer = null;
    constructor(svga: any, gameStage: egret.DisplayObjectContainer) {
        this.svga = svga;
        this.gameStage = gameStage;
    }

    play(pos: number = 1, loop: boolean = false) {
        this.svga.addEventListener(egret.Event.COMPLETE, () => {
            this.onComplete();
        }, this);
        this.svga.gotoAndPlay(pos, true);
        this.svga.visible = true;
    }

    stop(pos: number) {
        this.svga.gotoAndStop(pos);
    }

    setPosition(x: number = 0, y: number = 0) {
        this.gameStage.addChild(this.svga);
        this.svga.x = x + this.offset.x;
        this.svga.y = y + this.offset.y;
    }

    public onComplete = () => { }
}