// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { getLv, getMinLv } from "../util_PK_Game";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Cup extends cc.Component {

    @property(cc.SpriteFrame)
    iconList = [];
    @property(cc.SpriteFrame)
    lvIconList = [];

    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.Sprite)
    lvIcon: cc.Sprite = null;

    @property(cc.Label)
    lb_minlv: cc.Label = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    init(score, autoAni?) {

        let lv = getLv(score);
        let minlv = getMinLv(score);
        lv = Math.min(lv, 3);
        minlv = Math.min(minlv, 4);
        this.icon.spriteFrame = this.iconList[lv];
        this.lvIcon.spriteFrame = this.lvIconList[lv];
        this.lb_minlv.string = ["I", "II", "III", "IV", "V"][minlv];

        if (autoAni) {

            cc.tween(this.icon.node).by(1, { y: 20 }, { easing: "sineOut" }).delay(0.15).by(1, { y: -20 }, { easing: "sineOut" }).delay(0.15).union().repeatForever().start()

        }

    }

    // update (dt) {}
}
