refactor(map): 抽象卡牌背景颜色逻辑,简化代码

将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件,
减少重复代码,提高可维护性
This commit is contained in:
panw
2026-05-28 09:23:01 +08:00
parent 83e9188cd4
commit f114fca2ce
7 changed files with 67 additions and 69 deletions

View File

@@ -0,0 +1,18 @@
import { _decorator, Component } from "cc";
const { ccclass } = _decorator;
const POOL_COLORS = ["green", "blue", "purple", "yellow", "red"];
@ccclass('CardBgComp')
export class CardBgComp extends Component {
apply(poolLv: number) {
const color = POOL_COLORS[Math.min(poolLv, 5) - 1];
this.node.children.forEach(c => c.active = c.name === color);
}
clear() {
this.node.children.forEach(c => c.active = false);
}
}