const DWTool = require("./DWTool"); var Promise = require('../lib/es6-promise').Promise; class ThemeManager { static getSpriteFrameByPath(path, res) { let filePath = `resources/textures/${path}`; let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true); let result = res.filter((item) => { return item._uuid === uuid }); if (result != null && result.length != undefined) { let texture = result[0]; if (texture) { return new cc.SpriteFrame(texture); } else { return null; } } return null; } static loadStar(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 getSpineByPath(path, res) { let filePath = `spines/precedence/${path}`; let uuid = cc.loader._getResUuid(filePath, sp.SkeletonData, true); let result = res.filter((item) => { return item._uuid === uuid }); if (result != null && result.length != undefined) { let spine = result[0]; if (spine) { return spine; } else { return null; } } return null; } //骨骼预制资源 static loadStarSpine(starId) { let name = 60000 + parseInt(starId); if (GameGlobal.starSpineRes) { let p = new Promise((resolve, reject) => { let spine = this.getSpineByPath(name,GameGlobal.starSpineRes); if (spine) { resolve(spine) } else { var path = `./spines/star/${name}`; if (starId >= 20 && starId <= 24) { path = `./spines/precedence/${name}`; } cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => { if (err) { reject(err); } else { resolve(skeletonData); } }); } }); return p; } else { let p = new Promise((resolve, reject) => { var path = `./spines/star/${name}`; if (starId >= 20 && starId <= 24) { path = `./spines/precedence/${name}`; } cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => { if (err) { reject(err); } else { resolve(skeletonData); } }); }); return p; } } //明星黑色头像 static loadStarBlackAvatarSpriteFrame(starId, sprite) { if (GameGlobal.starAvatarRes) { let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,GameGlobal.starAvatarRes); if (spriteFrame) { sprite.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`) .then((spriteFrame) => { sprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } else { DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`) .then((spriteFrame) => { sprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } //明星普通头像 static loadStarAvatarSpriteFrame(starId, sprite) { if (GameGlobal.starAvatarRes) { let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,GameGlobal.starAvatarRes); if (spriteFrame) { sprite.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`) .then((spriteFrame) => { sprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } else { DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`) .then((spriteFrame) => { sprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } } module.exports = ThemeManager;