const DWTool = require("./DWTool"); class ThemeManager { static setBuildItemColor(cityId, node) { var color; switch (cityId) { case 1: color = new cc.color('#41b3e9'); break; case 2: color = new cc.color('#81f9c8'); break; case 3: color = new cc.color('#ffffc0'); break; case 4: color = new cc.color('#360f5a'); break; default: color = new cc.color('#41b3e9'); break; } node.color = color; } static getSpriteFrameByPath(path) { let filePath = `resources/building/${path}`; let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true); let result = Global.buildRes.filter((item) => { return item._uuid === uuid }); if (result != null && result.length != undefined) { let texture = result[0]; return new cc.SpriteFrame(texture); } return null; } // LevelHomeItem 样式变化 static setItemBuildSpriteFrame(cityId, buildSprite, index) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}0${index}`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}0${index}`) .then((spriteFrame) => { buildSprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // 外墙顶部 static setItemPillarTopSpriteFrame(cityId, pillar) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { let spriteFrame = this.getSpriteFrameByPath(`30${cityId}08`); pillar.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./building/30${cityId}08`) .then((spriteFrame) => { pillar.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // 外墙底部 static setItemPillarBottomSpriteFrame(cityId, pillar) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { let spriteFrame = this.getSpriteFrameByPath(`30${cityId}09`); pillar.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./building/30${cityId}09`) .then((spriteFrame) => { pillar.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // 外墙右边 static setItemPillarRightSpriteFrame(cityId, pillar) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { let spriteFrame = this.getSpriteFrameByPath(`30${cityId}10`); pillar.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./building/30${cityId}10`) .then((spriteFrame) => { pillar.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // 外墙左边 static setItemPillarLeftSpriteFrame(cityId, pillar) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { let spriteFrame = this.getSpriteFrameByPath(`30${cityId}11`); pillar.spriteFrame = spriteFrame; } else { DWTool.loadResSpriteFrame(`./building/30${cityId}11`) .then((spriteFrame) => { pillar.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } static setItemPillarSpriteFrame(cityId, pillars) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { let spriteFrame = this.getSpriteFrameByPath(`${cityId}_pillar`); for (let i = 0; i < pillars.length; i++) { let sprite = pillars[i]; sprite.spriteFrame = spriteFrame; } } else { DWTool.loadResSpriteFrame(`./building/${cityId}_pillar`) .then((spriteFrame) => { for (let i = 0; i < pillars.length; i++) { let sprite = pillars[i]; sprite.spriteFrame = spriteFrame; } }).catch((err) => { console.log(err); }); } } static setItemDownSpriteFrame(cityId, lockBottomBg) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}16`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}16`) .then((spriteFrame) => { lockBottomBg.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } static setItemLockDownSpriteFrame(cityId, lockBottomBg) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}12`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}12`) .then((spriteFrame) => { lockBottomBg.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // LevelHomeBottom 样式变化 static setBottomBuildSpriteFrame(cityId, buildSprite) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}13`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}13`) .then((spriteFrame) => { buildSprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } // LevelHomeTop 样式变化 static setTopBgBuildSpriteFrame(cityId, buildSprite) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}06`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}06`) .then((spriteFrame) => { buildSprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } static setTopCoverSpriteFrame(cityId, coverSprite) { cityId = cityId >= 5 ? 1 : cityId if (Global.buildRes) { coverSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}07`); } else { DWTool.loadResSpriteFrame(`./building/30${cityId}07`) .then((spriteFrame) => { coverSprite.spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }); } } } module.exports = ThemeManager;