1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const DWTool = require("./DWTool");
- 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 loadStarBlackAvatarSpriteFrame(starId, sprite) {
- if (Global.starAvatarRes) {
- let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,Global.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 (Global.starAvatarRes) {
- let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,Global.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;
|