123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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 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 (Global.starSpineRes) {
- let p = new Promise((resolve, reject) => {
- let spine = this.getSpineByPath(name,Global.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 (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;
|