ThemeManger.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const DWTool = require("./DWTool");
  2. class ThemeManager {
  3. static getSpriteFrameByPath(path) {
  4. let uuid = cc.loader._getResUuid(path.slice(10), cc.Texture2D, true);
  5. let result = Global.buildRes.filter((item) => { return item._uuid === uuid });
  6. if (result != null && result.length != undefined) {
  7. let texture = result[0];
  8. return new cc.SpriteFrame(texture);
  9. }
  10. return null;
  11. }
  12. // LevelHomeItem 样式变化
  13. static setItemBuildSpriteFrame(cityId, buildSprite, index) {
  14. cityId = cityId >= 3 ? 1 : cityId
  15. if (Global.buildRes) {
  16. buildSprite.spriteFrame = this.getSpriteFrameByPath(`resources/building/${cityId}_${index}`);
  17. } else {
  18. DWTool.loadResSpriteFrame(`./building/${cityId}_${index}`)
  19. .then((spriteFrame) => {
  20. buildSprite.spriteFrame = spriteFrame;
  21. }).catch((err) => {
  22. console.log(err);
  23. });
  24. }
  25. }
  26. static setItemPillarSpriteFrame(cityId, pillars) {
  27. cityId = cityId >= 3 ? 1 : cityId
  28. if (Global.buildRes) {
  29. let spriteFrame = this.getSpriteFrameByPath(`resources/building/${cityId}_pillar`);
  30. for (let i = 0; i < pillars.length; i++) {
  31. let sprite = pillars[i];
  32. sprite.spriteFrame = spriteFrame;
  33. }
  34. } else {
  35. DWTool.loadResSpriteFrame(`./building/${cityId}_pillar`)
  36. .then((spriteFrame) => {
  37. for (let i = 0; i < pillars.length; i++) {
  38. let sprite = pillars[i];
  39. sprite.spriteFrame = spriteFrame;
  40. }
  41. }).catch((err) => {
  42. console.log(err);
  43. });
  44. }
  45. }
  46. static setItemDownSpriteFrame(cityId, bottomBg) {
  47. cityId = cityId >= 3 ? 1 : cityId
  48. if (Global.buildRes) {
  49. bottomBg.spriteFrame = this.getSpriteFrameByPath(`resources/building/${cityId}_down`);
  50. } else {
  51. DWTool.loadResSpriteFrame(`./building/${cityId}_down`)
  52. .then((spriteFrame) => {
  53. bottomBg.spriteFrame = spriteFrame;
  54. }).catch((err) => {
  55. console.log(err);
  56. });
  57. }
  58. }
  59. static setItemLockDownSpriteFrame(cityId, lockBottomBg) {
  60. cityId = cityId >= 3 ? 1 : cityId
  61. if (Global.buildRes) {
  62. lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`resources/building/${cityId}_down_lock`);
  63. } else {
  64. DWTool.loadResSpriteFrame(`./building/${cityId}_down_lock`)
  65. .then((spriteFrame) => {
  66. lockBottomBg.spriteFrame = spriteFrame;
  67. }).catch((err) => {
  68. console.log(err);
  69. });
  70. }
  71. }
  72. // LevelHomeBottom 样式变化
  73. static setBottomBuildSpriteFrame(cityId, buildSprite) {
  74. cityId = cityId >= 3 ? 1 : cityId
  75. if (Global.buildRes) {
  76. buildSprite.spriteFrame = this.getSpriteFrameByPath(`resources/building/${cityId}_bottom`);
  77. } else {
  78. DWTool.loadResSpriteFrame(`./building/${cityId}_bottom`)
  79. .then((spriteFrame) => {
  80. buildSprite.spriteFrame = spriteFrame;
  81. }).catch((err) => {
  82. console.log(err);
  83. });
  84. }
  85. }
  86. // LevelHomeTop 样式变化
  87. }
  88. module.exports = ThemeManager;