Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Fix bug with animation step adding duplicate event listeners

Scott Petrovic8d35f70943e6
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index f9cbbc4..eee4b06 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -24,6 +24,8 @@ export class StepAnimationsListing extends EventTarget
private current_playing_index: number = 0
private skeleton_type: string = SkeletonType.BipedalSimple;
+ private has_added_event_listeners: boolean = false
+
constructor()
{
super();
@@ -211,6 +213,11 @@ export class StepAnimationsListing extends EventTarget
private addEventListeners(): void
{
+ if(this.has_added_event_listeners)
+ {
+ return
+ }
+
// event listener for animation clip list with changing the current animation
if (this.ui.dom_animation_clip_list) {
this.ui.dom_animation_clip_list.addEventListener('click', (event) => {
@@ -257,6 +264,9 @@ export class StepAnimationsListing extends EventTarget
this.play_animation(this.current_playing_index)
})
+
+ // helps ensure we don't add event listeners multiple times
+ this.has_added_event_listeners = true
}
private load_fbx_animation_clips(fbx_file, file_name: string): void
@@ -346,11 +356,6 @@ export class StepAnimationsListing extends EventTarget
}
- private removeEventListeners()
- {
- this.ui.dom_animation_clip_list.removeEventListener('click', () => {});
- }
-
private append_animation_clips(animation_clips)
{
// loop through each animation_clip and change name if the animaton name already exists
diff --git a/src/script.js b/src/script.js
index 9596125..8c99b41 100644
--- a/src/script.js
+++ b/src/script.js
@@ -203,7 +203,6 @@ function process_step_changed(process_step)
// clean up any event listeners from the previous steps
edit_skeleton_step.removeEventListeners()
- animations_listing_step.removeEventListeners()
switch(process_step)
{