refactor(map): 抽象卡牌背景颜色逻辑,简化代码
将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件, 减少重复代码,提高可维护性
This commit is contained in:
@@ -25,6 +25,7 @@ import { mLogger } from "../common/Logger";
|
||||
import { HeroInfo, HeroList } from "../common/config/heroSet";
|
||||
import { buildSkillDesc } from "../common/config/HeroSkillDesc";
|
||||
import { CKind } from "../common/config/CardSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { CardLiteComp } from "./CardLiteComp";
|
||||
|
||||
const { property, ccclass } = _decorator;
|
||||
@@ -212,21 +213,11 @@ export class HerosListComp extends CCComp {
|
||||
|
||||
private updatePoolLvBg(poolLv: number) {
|
||||
if (!this.BG_node) return
|
||||
const poolColorNames = ["green", "blue", "purple", "yellow", "red"];
|
||||
const poolColorIdx = Math.min(poolLv, 5) - 1;
|
||||
const activeColor = poolColorNames[poolColorIdx];
|
||||
const kindName = CKind[CKind.Hero];
|
||||
this.BG_node.children.forEach(child => {
|
||||
child.active = (child.name === kindName);
|
||||
if (child.active) {
|
||||
child.children.forEach(colorChild => {
|
||||
colorChild.active = (colorChild.name === activeColor);
|
||||
});
|
||||
} else {
|
||||
child.children.forEach(colorChild => {
|
||||
colorChild.active = false;
|
||||
});
|
||||
}
|
||||
const bg = child.getComponent(CardBgComp);
|
||||
if (bg) child.active ? bg.apply(poolLv) : bg.clear();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user