ArtistManager.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const DWTool = require("./DWTool");
  2. class ThemeManager {
  3. static getSpriteFrameByPath(path, res) {
  4. let filePath = `resources/textures/${path}`;
  5. let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true);
  6. let result = res.filter((item) => { return item._uuid === uuid });
  7. if (result != null && result.length != undefined) {
  8. let texture = result[0];
  9. if (texture) {
  10. return new cc.SpriteFrame(texture);
  11. } else {
  12. return null;
  13. }
  14. }
  15. return null;
  16. }
  17. static loadStar(starId) {
  18. let p = new Promise((resolve, reject) => {
  19. let name = 60000 + parseInt(starId);
  20. cc.loader.loadRes(`./spines/star/${name}`, sp.SkeletonData, (err, skeletonData,) => {
  21. if (err) {
  22. reject(err);
  23. } else {
  24. resolve(skeletonData);
  25. }
  26. });
  27. });
  28. return p;
  29. }
  30. //明星黑色头像
  31. static loadStarBlackAvatarSpriteFrame(starId, sprite) {
  32. if (Global.starAvatarRes) {
  33. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,Global.starAvatarRes);
  34. if (spriteFrame) {
  35. sprite.spriteFrame = spriteFrame;
  36. } else {
  37. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  38. .then((spriteFrame) => {
  39. sprite.spriteFrame = spriteFrame;
  40. }).catch((err) => {
  41. console.log(err);
  42. });
  43. }
  44. } else {
  45. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  46. .then((spriteFrame) => {
  47. sprite.spriteFrame = spriteFrame;
  48. }).catch((err) => {
  49. console.log(err);
  50. });
  51. }
  52. }
  53. //明星普通头像
  54. static loadStarAvatarSpriteFrame(starId, sprite) {
  55. if (Global.starAvatarRes) {
  56. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,Global.starAvatarRes);
  57. if (spriteFrame) {
  58. sprite.spriteFrame = spriteFrame;
  59. } else {
  60. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  61. .then((spriteFrame) => {
  62. sprite.spriteFrame = spriteFrame;
  63. }).catch((err) => {
  64. console.log(err);
  65. });
  66. }
  67. } else {
  68. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  69. .then((spriteFrame) => {
  70. sprite.spriteFrame = spriteFrame;
  71. }).catch((err) => {
  72. console.log(err);
  73. });
  74. }
  75. }
  76. }
  77. module.exports = ThemeManager;