ArtistManager.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. static getSpineByPath(path, res) {
  31. let filePath = `spines/precedence/${path}`;
  32. let uuid = cc.loader._getResUuid(filePath, sp.SkeletonData, true);
  33. let result = res.filter((item) => {
  34. return item._uuid === uuid
  35. });
  36. if (result != null && result.length != undefined) {
  37. let spine = result[0];
  38. if (spine) {
  39. return spine;
  40. } else {
  41. return null;
  42. }
  43. }
  44. return null;
  45. }
  46. //prefab预制资源
  47. static loadStarSpine(starId) {
  48. let name = 60000 + parseInt(starId);
  49. if (Global.starSpineRes) {
  50. let p = new Promise((resolve, reject) => {
  51. let spine = this.getSpineByPath(name,Global.starSpineRes);
  52. if (spine) {
  53. resolve(spine)
  54. } else {
  55. cc.loader.loadRes(`./spines/star/${name}`, sp.SkeletonData, (err, skeletonData,) => {
  56. if (err) {
  57. reject(err);
  58. } else {
  59. resolve(skeletonData);
  60. }
  61. });
  62. }
  63. });
  64. return p;
  65. } else {
  66. let p = new Promise((resolve, reject) => {
  67. cc.loader.loadRes(`./spines/star/${name}`, sp.SkeletonData, (err, skeletonData,) => {
  68. if (err) {
  69. reject(err);
  70. } else {
  71. resolve(skeletonData);
  72. }
  73. });
  74. });
  75. return p;
  76. }
  77. }
  78. //明星黑色头像
  79. static loadStarBlackAvatarSpriteFrame(starId, sprite) {
  80. if (Global.starAvatarRes) {
  81. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,Global.starAvatarRes);
  82. if (spriteFrame) {
  83. sprite.spriteFrame = spriteFrame;
  84. } else {
  85. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  86. .then((spriteFrame) => {
  87. sprite.spriteFrame = spriteFrame;
  88. }).catch((err) => {
  89. console.log(err);
  90. });
  91. }
  92. } else {
  93. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  94. .then((spriteFrame) => {
  95. sprite.spriteFrame = spriteFrame;
  96. }).catch((err) => {
  97. console.log(err);
  98. });
  99. }
  100. }
  101. //明星普通头像
  102. static loadStarAvatarSpriteFrame(starId, sprite) {
  103. if (Global.starAvatarRes) {
  104. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,Global.starAvatarRes);
  105. if (spriteFrame) {
  106. sprite.spriteFrame = spriteFrame;
  107. } else {
  108. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  109. .then((spriteFrame) => {
  110. sprite.spriteFrame = spriteFrame;
  111. }).catch((err) => {
  112. console.log(err);
  113. });
  114. }
  115. } else {
  116. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  117. .then((spriteFrame) => {
  118. sprite.spriteFrame = spriteFrame;
  119. }).catch((err) => {
  120. console.log(err);
  121. });
  122. }
  123. }
  124. }
  125. module.exports = ThemeManager;