
const DWTool = require("./DWTool");

class ThemeManager {

    /**
     * 从res中加载对应的艺人骨骼动画
     * @param {*} isBigMan 
     * @param {*} gender 
     * @param {*} jobId 1: 主持, 2: 舞者, 3: 歌手, 4: 演员, 5: 电竞明星
     */
    static loadArtist(isBigMan = false, gender = 1, jobId) {

        //处理性别为0时未知性别
        if (gender === 0) {
            gender = 1;
        }

        let p = new Promise((resolve, reject) => {
            let name = `4${isBigMan ? 1 : 2}${gender}0${jobId}`;
            cc.loader.loadRes(`./people_spines/${name}`, sp.SkeletonData, (err, skeletonData,) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(skeletonData);
                }
            });
        });
        return p;
    }

    static loadStar(starId) {
        // starId = starId > 3 ? (Math.ceil(Math.random()*3)) : starId;
        let p = new Promise((resolve, reject) => {
            let name = 60000 + parseInt(starId);
            cc.loader.loadRes(`./spines/star/${name}`, sp.SkeletonData, (err, skeletonData,) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(skeletonData);
                }
            });
        });
        return p;
    }

    //因骨骼动画未全部完成，顾加入静态职业人物
    static loadArtistImage(gender = 1, jobId) {

        //处理性别为0时未知性别
        if (gender === 0) {
            gender = 1;
        }

        let p = new Promise((resolve, reject) => {
            let name = `41${gender}0${jobId}`;
            cc.loader.loadRes(`people_figure/${name}`, cc.SpriteFrame, (err, spriteFrame) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(spriteFrame);
                }
            });
        });
        return p;
    }


}

module.exports = ThemeManager;