ArtistManager.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. //骨骼预制资源
  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. var path = `./spines/star/${name}`;
  56. if (starId >= 20 && starId <= 24) {
  57. path = `./spines/precedence/${name}`;
  58. }
  59. cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => {
  60. if (err) {
  61. reject(err);
  62. } else {
  63. resolve(skeletonData);
  64. }
  65. });
  66. }
  67. });
  68. return p;
  69. } else {
  70. let p = new Promise((resolve, reject) => {
  71. var path = `./spines/star/${name}`;
  72. if (starId >= 20 && starId <= 24) {
  73. path = `./spines/precedence/${name}`;
  74. }
  75. cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => {
  76. if (err) {
  77. reject(err);
  78. } else {
  79. resolve(skeletonData);
  80. }
  81. });
  82. });
  83. return p;
  84. }
  85. }
  86. //明星黑色头像
  87. static loadStarBlackAvatarSpriteFrame(starId, sprite) {
  88. if (Global.starAvatarRes) {
  89. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,Global.starAvatarRes);
  90. if (spriteFrame) {
  91. sprite.spriteFrame = spriteFrame;
  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. } else {
  101. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  102. .then((spriteFrame) => {
  103. sprite.spriteFrame = spriteFrame;
  104. }).catch((err) => {
  105. console.log(err);
  106. });
  107. }
  108. }
  109. //明星普通头像
  110. static loadStarAvatarSpriteFrame(starId, sprite) {
  111. if (Global.starAvatarRes) {
  112. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,Global.starAvatarRes);
  113. if (spriteFrame) {
  114. sprite.spriteFrame = spriteFrame;
  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. } else {
  124. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  125. .then((spriteFrame) => {
  126. sprite.spriteFrame = spriteFrame;
  127. }).catch((err) => {
  128. console.log(err);
  129. });
  130. }
  131. }
  132. }
  133. module.exports = ThemeManager;