refactor(map): 抽象卡牌背景颜色逻辑,简化代码
将多个文件中重复的卡池颜色切换逻辑提取为CardBgComp组件, 减少重复代码,提高可维护性
This commit is contained in:
18
assets/script/game/map/CardBgComp.ts
Normal file
18
assets/script/game/map/CardBgComp.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user