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

const playgood = (image: engine.Image) => {
    engine.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 530.5 }, 100).wait(500).to({ alpha: 0 }, 200)
}
const playgreat = (image: engine.Image) => {
    engine.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, engine.Ease.getBackOut(2)).wait(500).to({ alpha: 0 }, 200)
}
const playcool = (image: engine.Image) => {
    engine.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, engine.Ease.getBackOut(7)).wait(500).to({ alpha: 0 }, 200)
}
const playperfect = (image: engine.Image) => {
    engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, }).to({ scaleX: 1, scaleY: 1 }, 200, engine.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: engine.Image) => {
    engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -20 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.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: engine.Image) => {
    // egret.Tween.get(image).set({ x: 750, alpha: 1 }).to({ x: 482.5 }, 100).wait(500).to({ alpha: 0 }, 200)
    engine.Tween.get(image).set({ scaleX: 0, scaleY: 0, alpha: 1, rotation: -60 }).to({ scaleX: 1, scaleY: 1, rotation: 0 }, 200, engine.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;
// 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.gameHint[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']