refactor(map): 抽象卡牌背景颜色逻辑,简化代码
将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件, 减少重复代码,提高可维护性
This commit is contained in:
@@ -37,6 +37,7 @@ import { MissionHeroComp } from "./MissionHeroComp";
|
||||
import { MoveComp } from "../hero/MoveComp";
|
||||
import { FacSet, getLvColor } from "../common/config/GameSet";
|
||||
import { CKind } from "../common/config/CardSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { MissionEconomy } from "./MissionEconomy";
|
||||
|
||||
const {property, ccclass } = _decorator;
|
||||
@@ -158,22 +159,12 @@ export class HInfoComp extends CCComp {
|
||||
this.lv_node.color = getLvColor(heroLv);
|
||||
}
|
||||
|
||||
const poolColorNames = ["green", "blue", "purple", "yellow", "red"];
|
||||
const poolColorIdx = Math.min(this.previewPoolLv, 5) - 1;
|
||||
const activeColor = poolColorNames[poolColorIdx];
|
||||
const kindName = CKind[CKind.Hero];
|
||||
if (this.BG_node) {
|
||||
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(this.previewPoolLv) : bg.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -279,22 +270,12 @@ export class HInfoComp extends CCComp {
|
||||
}
|
||||
|
||||
// ---- 卡池等级标识 ----
|
||||
const poolColorNames = ["green", "blue", "purple", "yellow", "red"];
|
||||
const poolColorIdx = Math.min(this.model.pool_lv ?? 1, 5) - 1;
|
||||
const activeColor = poolColorNames[poolColorIdx];
|
||||
const kindName = CKind[CKind.Hero];
|
||||
if (this.BG_node) {
|
||||
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(this.model.pool_lv ?? 1) : bg.clear();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user