refactor(map): 移除 CardUseComp 并将逻辑内联至 CardComp
简化卡片使用逻辑,删除独立的 CardUseComp 组件,将其 onCardUsed 方法中的事件分发逻辑直接移至 CardComp 的 executeCardEffectEntry 方法中。这减少了组件间的依赖和查找开销,使卡片使用流程更内聚。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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) {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { CardType } from "../common/config/CardSet";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
interface CardUsePayload {
|
||||
uuid: number
|
||||
type: CardType
|
||||
cost: number
|
||||
slotName?: string
|
||||
}
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('CardUseComp')
|
||||
@ecs.register('CardUseComp', false)
|
||||
export class CardUseComp extends CCComp {
|
||||
private debugMode: boolean = true;
|
||||
private useCount: number = 0;
|
||||
|
||||
onLoad() {
|
||||
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
onCardUsed(payload: CardUsePayload) {
|
||||
this.useCount += 1;
|
||||
mLogger.log(this.debugMode, "CardUseComp", "onCardUsed", {
|
||||
useCount: this.useCount,
|
||||
...payload
|
||||
});
|
||||
this.executeCardEffectEntry(payload);
|
||||
}
|
||||
|
||||
private executeCardEffectEntry(payload: CardUsePayload) {
|
||||
const effectTag = this.getEffectEntryTag(payload);
|
||||
mLogger.log(this.debugMode, "CardUseComp", "executeCardEffectEntry", payload);
|
||||
mLogger.log(this.debugMode, "CardUseComp", "effect entry tag", effectTag);
|
||||
}
|
||||
|
||||
private getEffectEntryTag(used:CardUsePayload): string {
|
||||
switch (used.type) {
|
||||
case CardType.Hero:
|
||||
oops.message.dispatchEvent(GameEvent.CallHero, used);
|
||||
return "hero";
|
||||
case CardType.Skill:
|
||||
oops.message.dispatchEvent(GameEvent.UseSkillCard, used);
|
||||
return "skill";
|
||||
case CardType.SpecialUpgrade:
|
||||
case CardType.SpecialRefresh:
|
||||
oops.message.dispatchEvent(GameEvent.UseSpecialCard, used);
|
||||
return "special";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8edfc7ca-1cda-4725-9a0c-ded8f5f95531",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user