/**
 * 工具类
 */


export class Utils extends cc.Component {

    /**
     * 格式化数字长度
     * @param num 整数
     * @param len 格式化后的长度
     */
    static formatLen(num, len): string {
        let result = num.toString();

        if (result.length >= len) {
            return result;
        }

        while (result.length < len) {
            result = '0' + result;
        }

        return result;
    }

    /**按钮动画 */
    public static btnTween(node: cc.Node) {
        cc.tween(node)
            .to(0.5, { scale: 1.1 }, { easing: 'quadOut' })
            .delay(0.3)
            .to(0.5, { scale: 1 }, { easing: 'quadIn' })
            .union()
            .repeatForever()
            .start();
    }

    /**打开面板 */
    public static openPanel(node: cc.Node) {
        node.scale = 0.7;
        cc.tween(node)
            .to(0.2, { scale: 1 }, { easing: "backOut" })
            .start();
    }

    /**摇晃 */
    public static shake(node: cc.Node) {
        cc.tween(node)
            .to(0.3, { scale: 1.3 }, { easing: 'sineOut' })
            .delay(0.2)
            .to(0.1, { angle: -30 })
            .to(0.2, { angle: 30 })
            .to(0.1, { angle: 0 })
            .delay(0.2)
            .to(0.3, { scale: 1 }, { easing: 'sineIn' })
            .delay(1)
            .union()
            .repeatForever()
            .start();
    }
}
