refactor(game/map): 使用事件队列管理卡片显示逻辑

将直接显示卡片的逻辑改为事件队列处理,避免多个卡片显示请求冲突
This commit is contained in:
panw
2026-01-05 15:05:29 +08:00
parent 45508abca4
commit d1409770d6

View File

@@ -89,28 +89,38 @@ export class MissionCardComp extends CCComp {
// 是否已经选择了天赋
private hasSelected: boolean = false;
// 事件队列
private eventQueue: CardType[] = [];
private onShopOpen(event: string, args: any) {
this.node.active = true;
this.hasSelected = false;
this.curCardType = CardType.Potion;
this.resetCardStates();
this.refCards();
this.playShowAnimation();
this.eventQueue.push(CardType.Potion);
this.checkQueue();
}
private onTalentSelect(event: string, args: any) {
this.node.active = true;
this.hasSelected = false; // 重置选择状态
this.curCardType = CardType.Talent; // 记录当前类型为天赋
this.resetCardStates(); // 每次刷新前重置卡片状态
this.refCards();
this.playShowAnimation();
this.eventQueue.push(CardType.Talent);
this.checkQueue();
}
private onHeroSkillSelect(event: string, args: any) {
this.eventQueue.push(CardType.Skill);
this.checkQueue();
}
private checkQueue() {
if (this.node.active) return;
if (this.eventQueue.length === 0) return;
const type = this.eventQueue.shift();
if (type) {
this.showCardType(type);
}
}
private showCardType(type: CardType) {
this.node.active = true;
this.hasSelected = false;
this.curCardType = CardType.Skill;
this.curCardType = type;
this.resetCardStates();
this.refCards();
this.playShowAnimation();
@@ -336,6 +346,7 @@ export class MissionCardComp extends CCComp {
*/
close() {
this.node.active = false;
this.checkQueue();
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */