ArtistManager.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const DWTool = require("./DWTool");
  2. var Promise = require('../lib/es6-promise').Promise;
  3. class ThemeManager {
  4. static getSpriteFrameByPath(path, res) {
  5. let filePath = `resources/textures/${path}`;
  6. let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true);
  7. let result = res.filter((item) => { return item._uuid === uuid });
  8. if (result != null && result.length != undefined) {
  9. let texture = result[0];
  10. if (texture) {
  11. return new cc.SpriteFrame(texture);
  12. } else {
  13. return null;
  14. }
  15. }
  16. return null;
  17. }
  18. static loadStar(starId) {
  19. let p = new Promise((resolve, reject) => {
  20. let name = 60000 + parseInt(starId);
  21. cc.loader.loadRes(`./spines/star/${name}`, sp.SkeletonData, (err, skeletonData,) => {
  22. if (err) {
  23. reject(err);
  24. } else {
  25. resolve(skeletonData);
  26. }
  27. });
  28. });
  29. return p;
  30. }
  31. static getSpineByPath(path, res) {
  32. let filePath = `spines/precedence/${path}`;
  33. let uuid = cc.loader._getResUuid(filePath, sp.SkeletonData, true);
  34. let result = res.filter((item) => {
  35. return item._uuid === uuid
  36. });
  37. if (result != null && result.length != undefined) {
  38. let spine = result[0];
  39. if (spine) {
  40. return spine;
  41. } else {
  42. return null;
  43. }
  44. }
  45. return null;
  46. }
  47. //骨骼预制资源
  48. static loadStarSpine(starId) {
  49. let name = 60000 + parseInt(starId);
  50. if (GameGlobal.starSpineRes) {
  51. let p = new Promise((resolve, reject) => {
  52. let spine = this.getSpineByPath(name,GameGlobal.starSpineRes);
  53. if (spine) {
  54. resolve(spine)
  55. } else {
  56. var path = `./spines/star/${name}`;
  57. if (starId >= 20 && starId <= 24) {
  58. path = `./spines/precedence/${name}`;
  59. }
  60. cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => {
  61. if (err) {
  62. reject(err);
  63. } else {
  64. resolve(skeletonData);
  65. }
  66. });
  67. }
  68. });
  69. return p;
  70. } else {
  71. let p = new Promise((resolve, reject) => {
  72. var path = `./spines/star/${name}`;
  73. if (starId >= 20 && starId <= 24) {
  74. path = `./spines/precedence/${name}`;
  75. }
  76. cc.loader.loadRes(path, sp.SkeletonData, (err, skeletonData,) => {
  77. if (err) {
  78. reject(err);
  79. } else {
  80. resolve(skeletonData);
  81. }
  82. });
  83. });
  84. return p;
  85. }
  86. }
  87. //明星黑色头像
  88. static loadStarBlackAvatarSpriteFrame(starId, sprite) {
  89. if (GameGlobal.starAvatarRes) {
  90. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/dark_${starId}`,GameGlobal.starAvatarRes);
  91. if (spriteFrame) {
  92. sprite.spriteFrame = spriteFrame;
  93. } else {
  94. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  95. .then((spriteFrame) => {
  96. sprite.spriteFrame = spriteFrame;
  97. }).catch((err) => {
  98. console.log(err);
  99. });
  100. }
  101. } else {
  102. DWTool.loadResSpriteFrame(`./textures/star_handbook/dark_${starId}`)
  103. .then((spriteFrame) => {
  104. sprite.spriteFrame = spriteFrame;
  105. }).catch((err) => {
  106. console.log(err);
  107. });
  108. }
  109. }
  110. //明星普通头像
  111. static loadStarAvatarSpriteFrame(starId, sprite) {
  112. if (GameGlobal.starAvatarRes) {
  113. let spriteFrame = this.getSpriteFrameByPath(`star_handbook/${starId}`,GameGlobal.starAvatarRes);
  114. if (spriteFrame) {
  115. sprite.spriteFrame = spriteFrame;
  116. } else {
  117. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  118. .then((spriteFrame) => {
  119. sprite.spriteFrame = spriteFrame;
  120. }).catch((err) => {
  121. console.log(err);
  122. });
  123. }
  124. } else {
  125. DWTool.loadResSpriteFrame(`./textures/star_handbook/${starId}`)
  126. .then((spriteFrame) => {
  127. sprite.spriteFrame = spriteFrame;
  128. }).catch((err) => {
  129. console.log(err);
  130. });
  131. }
  132. }
  133. }
  134. module.exports = ThemeManager;