refactor(map): 抽象卡牌背景颜色逻辑,简化代码
将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件, 减少重复代码,提高可维护性
This commit is contained in:
@@ -23,6 +23,7 @@ import { _decorator, Animation, AnimationClip, EventTouch, Label, Node, NodeEven
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { CardConfig, CardType, SpecialRefreshCardList, SpecialUpgradeCardList, CKind, CardPoolList } from "../common/config/CardSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { getLvColor } from "../common/config/GameSet";
|
||||
@@ -218,22 +219,11 @@ export class CardLiteComp extends CCComp {
|
||||
|
||||
const kindName = CKind[this.cardData.kind];
|
||||
|
||||
const poolColorNames = ["green", "blue", "purple", "yellow", "red"];
|
||||
const poolColorIdx = Math.min(this.cardData.pool_lv, 5) - 1;
|
||||
const activeColor = poolColorNames[poolColorIdx];
|
||||
|
||||
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.cardData.pool_lv) : bg.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -307,9 +297,8 @@ export class CardLiteComp extends CCComp {
|
||||
if (this.BG_node) {
|
||||
this.BG_node.children.forEach(child => {
|
||||
child.active = false;
|
||||
child.children.forEach(colorChild => {
|
||||
colorChild.active = false;
|
||||
});
|
||||
const bg = child.getComponent(CardBgComp);
|
||||
if (bg) bg.clear();
|
||||
});
|
||||
}
|
||||
if (this.icon_node) {
|
||||
|
||||
Reference in New Issue
Block a user