Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix skeleton's setTrackXXXListener doesn't work on web platform #16512

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

bofeng-song
Copy link
Contributor

@bofeng-song bofeng-song commented Nov 16, 2023

Re: # #16493

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

(cherry picked from commit 9b90131d968185bd3d73c30f1a11960a9786fbde)
instance->onAnimationStateEvent(entry, type, event);
}

void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the function static.

void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) {
(static_cast<SpineSkeletonInstance *>(state->getRendererObject()))->onTrackEntryEvent(entry, type, event);
if (type == EventType_Dispose) {
if (entry->getRendererObject()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the renderobject be nullptr? If so, the above line

(static_cast<SpineSkeletonInstance *>(state->getRendererObject()))->onTrackEntryEvent(entry, type, event);

should also consider the situation of nullptr.

_trackListenerID = trackId;
entry->setRendererObject(this);
entry->setListener(trackEntryCallback);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we output an error if render object is invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render object only used to prevent setTrackListener multi times

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So setTrackListener could not be invoked multiple times for the same trackId?
If I want to replace entry for the same trackId, how to achieve that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trackId is generated by engine internal, one trackEntry only has one trackListener. While dispose_event called, trackEntry's listener will be reset to null.

Copy link

github-actions bot commented Nov 16, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -51741,8 +51741,9 @@
                 dtRate: number;
                 isCache: boolean;
                 isDelete: boolean;
                 enable: boolean;
+                setTrackEntryListener: any;
                 initSkeleton(data: SkeletonData);
                 getAnimationState();
                 setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null;
                 setSkin(name: string);
@@ -67139,10 +67140,11 @@
             end?: ((entry: sp.spine.TrackEntry) => void);
             dispose?: ((entry: sp.spine.TrackEntry) => void);
             complete?: ((entry: sp.spine.TrackEntry) => void);
             event?: ((entry: sp.spine.TrackEntry, event: sp.spine.Event) => void);
-            static getListeners(entry: sp.spine.TrackEntry): sp.spine.AnimationStateListener;
+            static getListeners(entry: sp.spine.TrackEntry, instance: sp.spine.SkeletonInstance): sp.spine.AnimationStateListener;
             static emitListener(id: number, entry: sp.spine.TrackEntry, event: sp.spine.Event): void;
+            static emitTrackEntryListener(id: number, entry: sp.spine.TrackEntry, event: sp.spine.Event, eventType: sp.spine.EventType): void;
             static addListener(listener: _cocos_spine_track_entry_listeners__CommonTrackEntryListener): number;
         }
         export class _cocos_spine_skeleton_cache__SpineDrawItem {
             iCount: number;

cocos/spine/track-entry-listeners.ts Outdated Show resolved Hide resolved
curTrack.listener.event(entry, event);
}
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to handle default case and print an error/warning log.

cocos/spine/track-entry-listeners.ts Show resolved Hide resolved
@minggo minggo merged commit 60627e2 into cocos:v3.8.2 Nov 16, 2023
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants