refactor(map): 移除 CardUseComp 并将逻辑内联至 CardComp
简化卡片使用逻辑,删除独立的 CardUseComp 组件,将其 onCardUsed 方法中的事件分发逻辑直接移至 CardComp 的 executeCardEffectEntry 方法中。这减少了组件间的依赖和查找开销,使卡片使用流程更内聚。
This commit is contained in:
@@ -3,7 +3,6 @@ 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, SkillCardList } from "../common/config/CardSet";
|
||||
import { CardUseComp } from "./CardUseComp";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
@@ -62,7 +61,6 @@ export class CardComp extends CCComp {
|
||||
private fixedBaseY: number = 0;
|
||||
private fixedBaseZ: number = 0;
|
||||
private opacityComp: UIOpacity | null = null;
|
||||
private cardUseComp: CardUseComp | null = null;
|
||||
private iconVisualToken: number = 0;
|
||||
|
||||
onLoad() {
|
||||
@@ -70,7 +68,6 @@ export class CardComp extends CCComp {
|
||||
this.bindEvents();
|
||||
this.restPosition = this.node.position.clone();
|
||||
this.opacityComp = this.node.getComponent(UIOpacity) || this.node.addComponent(UIOpacity);
|
||||
this.cardUseComp = this.resolveCardUseComp();
|
||||
this.opacityComp.opacity = 255;
|
||||
this.updateLockUI();
|
||||
this.applyEmptyUI();
|
||||
@@ -217,10 +214,25 @@ export class CardComp extends CCComp {
|
||||
this.playUseDisappearAnim(() => {
|
||||
this.clearAfterUse();
|
||||
this.isUsing = false;
|
||||
this.cardUseComp?.onCardUsed(used);
|
||||
this.executeCardEffectEntry(used);
|
||||
});
|
||||
return used;
|
||||
}
|
||||
|
||||
private executeCardEffectEntry(payload: CardConfig) {
|
||||
switch (payload.type) {
|
||||
case CardType.Hero:
|
||||
oops.message.dispatchEvent(GameEvent.CallHero, payload);
|
||||
break;
|
||||
case CardType.Skill:
|
||||
oops.message.dispatchEvent(GameEvent.UseSkillCard, payload);
|
||||
break;
|
||||
case CardType.SpecialUpgrade:
|
||||
case CardType.SpecialRefresh:
|
||||
oops.message.dispatchEvent(GameEvent.UseSpecialCard, payload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询槽位是否有卡 */
|
||||
hasCard(): boolean {
|
||||
@@ -518,16 +530,6 @@ export class CardComp extends CCComp {
|
||||
if (label) label.string = value;
|
||||
}
|
||||
|
||||
private resolveCardUseComp(): CardUseComp | null {
|
||||
let current: Node | null = this.node.parent;
|
||||
while (current) {
|
||||
const comp = current.getComponent(CardUseComp);
|
||||
if (comp) return comp;
|
||||
current = current.parent;
|
||||
}
|
||||
mLogger.log(this.debugMode, "CardComp", "CardUseComp not found for", this.node.name);
|
||||
return null;
|
||||
}
|
||||
|
||||
private resolveCardIconId(type: CardType, uuid: number): string {
|
||||
if (type === CardType.Skill) {
|
||||
|
||||
Reference in New Issue
Block a user