fix: 修复 onCoinAdd 方法参数处理逻辑

调整事件参数处理方式,确保 payload 正确提取自 args 或 event 参数,以兼容不同调用场景。避免因参数结构不一致导致的硬币数量更新错误。
This commit is contained in:
panw
2026-03-27 10:59:07 +08:00
parent 8c3a142d9f
commit 09531f7ba2

View File

@@ -161,13 +161,14 @@ export class MissionCardComp extends CCComp {
this.cards_up?.on(NodeEventType.TOUCH_END, this.onUpgradeTouchEnd, this); this.cards_up?.on(NodeEventType.TOUCH_END, this.onUpgradeTouchEnd, this);
this.cards_up?.on(NodeEventType.TOUCH_CANCEL, this.onUpgradeTouchCancel, this); this.cards_up?.on(NodeEventType.TOUCH_CANCEL, this.onUpgradeTouchCancel, this);
} }
private onCoinAdd(args:any){ private onCoinAdd(event: string, args: any){
if (args?.syncOnly) { const payload = args ?? event;
if (payload?.syncOnly) {
this.updateCoinAndCostUI(); this.updateCoinAndCostUI();
this.playCoinChangeAnim((args?.delta ?? 0) > 0); this.playCoinChangeAnim((payload?.delta ?? 0) > 0);
return; return;
} }
const v = typeof args === 'number' ? args : (args?.delta ?? args?.value ?? 0); const v = typeof payload === 'number' ? payload : (payload?.delta ?? payload?.value ?? 0);
if (v === 0) return; if (v === 0) return;
this.setMissionCoin(this.getMissionCoin() + v); this.setMissionCoin(this.getMissionCoin() + v);
this.updateCoinAndCostUI(); this.updateCoinAndCostUI();