const ArtistManager = require('../utils/ArtistManager');
cc.Class({
    extends: cc.Component,

    properties: {
        levelBgBefor: cc.Sprite,
        levelBgAfter: cc.Sprite,
        levelBefor: cc.RichText,
        levelAfter: cc.RichText,
        nameBefor: cc.RichText,
        nameAfter: cc.RichText,
        role: sp.Skeleton,
        salaryLabel: cc.Label,
        progressbar: cc.ProgressBar,
        blessings: cc.RichText,

        levelSpriteFrame: [cc.SpriteFrame],
    },


    bind(userInfo, upgradeInfo, wish) {
        this.levelBgBefor.spriteFrame = this.levelSpriteFrame[userInfo.jobLevel - 1];
        this.levelBgAfter.spriteFrame = this.levelSpriteFrame[userInfo.jobLevel];

        // this.levelBefor.string = this.numberString(userInfo.jobLevel);
        this.nameBefor.string = this.nameString(userInfo.jobLevelName);

        // this.levelAfter.string = this.numberString(upgradeInfo.level);
        this.nameAfter.string = this.nameString(upgradeInfo.name);

        this.salaryLabel.string = upgradeInfo.salary;
        this.blessings.string = this.nameString('祝福值：' + wish);
        this.progressbar.progress = wish * this.progressbar.totalLength / 100;

        //现在只有舞者有骨骼动画，默认jodId为2
        ArtistManager.loadArtist(true, userInfo.gender, 2)
            .then((skeletonData) => {
                this.role.skeletonData = skeletonData;
                this.role.animation = "stand";
            }).catch((err) => {
                console.log(err);
            });
    },

    numberString(level) {
        return '<outline color=#000000 width=1><b>' + level + '</b></outline>'
    },

    nameString(name) {
        return '<outline color=#000000 width=1><b>' + name + '</b></outline>'
    },

});
