diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index ffb93567fef..8e20f58c144 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1189,7 +1189,7 @@ declare namespace spine { isCache: boolean; isDelete: boolean; enable: boolean; - setTrackListener: any; + setTrackEntryListener: any; initSkeleton(data: SkeletonData); getAnimationState(); setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null; diff --git a/cocos/spine/track-entry-listeners.ts b/cocos/spine/track-entry-listeners.ts index 39f7beb1385..c51b0b38844 100644 --- a/cocos/spine/track-entry-listeners.ts +++ b/cocos/spine/track-entry-listeners.ts @@ -23,6 +23,7 @@ */ import spine from './lib/spine-core.js'; +import { warn } from '../core'; let _listener_ID = 0; let _track_ID = 0; @@ -43,7 +44,7 @@ export class TrackEntryListeners { if (!entry.listener) { entry.listener = new TrackEntryListeners() as any; const id = ++_track_ID; - instance.setTrackListener(id, entry); + instance.setTrackEntryListener(id, entry); TrackEntryListeners._trackSet.set(id, entry); } return entry.listener; @@ -58,11 +59,10 @@ export class TrackEntryListeners { } } - static emitTrackListener (id: number, entry: spine.TrackEntry, event: spine.Event, eventType: spine.EventType): void { + static emitTrackEntryListener (id: number, entry: spine.TrackEntry, event: spine.Event, eventType: spine.EventType): void { const curTrack = this._trackSet.get(id); if (!curTrack) return; - // eslint-disable-next-line default-case - switch (eventType as number) { + switch (eventType) { case spine.EventType.start: if (curTrack.listener.start) { curTrack.listener.start(entry); @@ -83,6 +83,7 @@ export class TrackEntryListeners { curTrack.listener.dispose(entry); } this._trackSet.delete(id); + curTrack.listener = null as any; break; case spine.EventType.complete: if (curTrack.listener.complete) { @@ -94,6 +95,9 @@ export class TrackEntryListeners { curTrack.listener.event(entry, event); } break; + default: + warn('TrackEntry doesn\'t handled', eventType); + break; } } diff --git a/native/cocos/editor-support/spine-wasm/library_spine.js b/native/cocos/editor-support/spine-wasm/library_spine.js index 3e0d2829b37..ee6dc3b98f7 100644 --- a/native/cocos/editor-support/spine-wasm/library_spine.js +++ b/native/cocos/editor-support/spine-wasm/library_spine.js @@ -13,6 +13,6 @@ mergeInto(LibraryManager.library, { var eventType = wasmUtil.getCurrentEventType(); var trackEntry = wasmUtil.getCurrentTrackEntry(); var event = wasmUtil.getCurrentEvent(); - globalThis.TrackEntryListeners.emitTrackListener(listenerID, trackEntry, event, eventType.value); + globalThis.TrackEntryListeners.emitTrackEntryListener(listenerID, trackEntry, event, eventType.value); } }); diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 281d47c7eed..08192bf0aea 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -433,9 +433,9 @@ void SpineSkeletonInstance::setListener(uint32_t listenerID, uint32_t type) { } } -void SpineSkeletonInstance::setTrackListener(uint32_t trackId, TrackEntry *entry) { +void SpineSkeletonInstance::setTrackEntryListener(uint32_t trackId, TrackEntry *entry) { if (!entry->getRendererObject()) { - _trackListenerID = trackId; + _trackEntryListenerID = trackId; entry->setRendererObject(this); entry->setListener(trackEntryCallback); } @@ -451,7 +451,7 @@ void SpineSkeletonInstance::setDebugMode(bool debug) { void SpineSkeletonInstance::onTrackEntryEvent(TrackEntry *entry, EventType type, Event *event) { if (!entry->getRendererObject()) return; - SpineWasmUtil::s_listenerID = _trackListenerID; + SpineWasmUtil::s_listenerID = _trackEntryListenerID; SpineWasmUtil::s_currentType = type; SpineWasmUtil::s_currentEntry = entry; SpineWasmUtil::s_currentEvent = event; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 0911638004c..c34a18fbd64 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -52,7 +52,7 @@ class SpineSkeletonInstance { AnimationState *getAnimationState(); void setMix(const std::string &from, const std::string &to, float duration); void setListener(uint32_t listenerID, uint32_t type); - void setTrackListener(uint32_t trackId, TrackEntry *entry); + void setTrackEntryListener(uint32_t trackId, TrackEntry *entry); void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event); void onTrackEntryEvent(TrackEntry *entry, EventType type, Event *event); std::vector &getDebugShapes(); @@ -79,7 +79,7 @@ class SpineSkeletonInstance { uint32_t _disposeListenerID = 0; uint32_t _completeListenerID = 0; uint32_t _eventListenerID = 0; - uint32_t _trackListenerID = 0; + uint32_t _trackEntryListenerID = 0; UserData _userData; std::vector _debugShapes{}; std::map slotTextureSet{}; diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 20515d014c1..cb4a910276e 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1604,7 +1604,7 @@ EMSCRIPTEN_BINDINGS(spine) { .function("getAnimationState", &SpineSkeletonInstance::getAnimationState, allow_raw_pointer()) .function("setMix", &SpineSkeletonInstance::setMix) .function("setListener", &SpineSkeletonInstance::setListener) - .function("setTrackListener", &SpineSkeletonInstance::setTrackListener, allow_raw_pointer()) + .function("setTrackEntryListener", &SpineSkeletonInstance::setTrackEntryListener, allow_raw_pointer()) .function("setDebugMode", &SpineSkeletonInstance::setDebugMode) .function("getDebugShapes", &SpineSkeletonInstance::getDebugShapes) .function("resizeSlotRegion", &SpineSkeletonInstance::resizeSlotRegion)