Files
pixelheros/assets/script/game/map/CardBgComp.ts
panw f114fca2ce refactor(map): 抽象卡牌背景颜色逻辑,简化代码
将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件,
减少重复代码,提高可维护性
2026-05-28 09:23:01 +08:00

19 lines
459 B
TypeScript

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);
}
}