const clear = (that) => {
    TextList.forEach(i => {
        egret.Tween.removeTweens(that[i]);
        that[i].alpha = 0;
    })
}

const playgood = (image: eui.Image) => {
    egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 530.5 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playgreat = (image: eui.Image) => {
    egret.Tween.get(image).set({ x: 750, alpha: 1, scaleX: .9, scaleY: .9, rotation: 20 }).to({ x: 540.5, scaleX: 1, scaleY: 1, rotation: 0 }, 200, egret.Ease.getBackOut(2)).wait(500).to({ alpha: 0 }, 200)
}
const playcool = (image: eui.Image) => {
    egret.Tween.get(image).set({ x: 750, alpha: 1, scaleX: .9, scaleY: .9, rotation: 60 }).to({ x: 526.09, scaleX: 1, scaleY: 1, rotation: 0 }, 200, egret.Ease.getBackOut(7)).wait(500).to({ alpha: 0 }, 200)
}
const playperfect = (image: eui.Image) => {
    egret.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, }).to({ scaleX: 1, scaleY: 1 }, 200, egret.Ease.getBackOut(10)).wait(500).to({ alpha: 0 }, 200)
    // egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 530.5 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playawesome = (image: eui.Image) => {
    egret.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -20 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, egret.Ease.getBackOut(20)).wait(500).to({ alpha: 0 }, 200)
    // egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 527 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playunbelievable = (image: eui.Image) => {
    // egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 482.5 }, 100).wait(500).to({ alpha: 0 }, 200)
    egret.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -60 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, egret.Ease.getBackOut(40)).wait(500).to({ alpha: 0 }, 200)
}

const funcs = [playgreat, playcool, playperfect, playawesome, playunbelievable];
// const funcs = [playgood, playgreat, playcool, playperfect, playawesome, playunbelievable];

let cdtimer = 0
// let timer = 0;
let count = 0;

export const playTextAni = async (that) => {
    clear(that);
    count++;
    if (count >= TextList.length) count = TextList.length;
    console.log(count);
    const image = that[TextList[count - 1]];
    image.visible = true;
    funcs[count - 1](image);
    if (cdtimer > 0) clearTimeout(cdtimer);
    cdtimer = setTimeout(() => {
        count = 0;
        console.log('clear')
    }, 5000);
}

export const TextList = ['great', 'cool', 'perfect', 'awesome', 'unbelievable']
// export const TextList = ['good', 'great', 'cool', 'perfect', 'awesome', 'unbelievable']