Needle Engine

Changes between version 3.21.1-alpha.1 and 3.21.2
Files changed (3) hide show
  1. src/engine-components/ui/Button.ts +5 -3
  2. src/engine-components/EventList.ts +5 -1
  3. src/engine-components/ui/EventSystem.ts +1 -2
src/engine-components/ui/Button.ts CHANGED
@@ -125,9 +125,11 @@
125
125
  console.warn("Button Click", this.onClick);
126
126
  showBalloonMessage("CLICKED button " + this.name + " at " + this.context.time.frameCount);
127
127
  }
128
- this.onClick?.invoke();
129
-
130
- args.use();
128
+
129
+ if (this.onClick && this.onClick.listenerCount > 0) {
130
+ this.onClick.invoke();
131
+ args.use();
132
+ }
131
133
  }
132
134
 
133
135
  @serializable()
src/engine-components/EventList.ts CHANGED
@@ -53,6 +53,8 @@
53
53
  }
54
54
  }
55
55
 
56
+ get listenerCount() { return this.methods?.length ?? 0; }
57
+
56
58
  private _isInvoking: boolean = false;
57
59
 
58
60
  // TODO: can we make functions serializable?
@@ -65,9 +67,10 @@
65
67
  invoke(...args: any) {
66
68
  if (this._isInvoking) {
67
69
  console.warn("Circular event invocation detected. Please check your event listeners for circular references.", this);
68
- return;
70
+ return false;
69
71
  }
70
72
 
73
+ if (this.methods?.length <= 0) return false;
71
74
 
72
75
  this._isInvoking = true;
73
76
  try {
@@ -93,6 +96,7 @@
93
96
  finally {
94
97
  this._isInvoking = false;
95
98
  }
99
+ return true;
96
100
  }
97
101
 
98
102
  addEventListener(cb: Function): Function {
src/engine-components/ui/EventSystem.ts CHANGED
@@ -425,11 +425,10 @@
425
425
  /**
426
426
  * Propagate up in hiearchy and call the callback for each component that is possibly a handler
427
427
  */
428
- private propagate(object: THREE.Object3D, args: PointerEventData, onComponent: (behaviour: Behaviour) => void) {
428
+ private propagate(object: THREE.Object3D, _args: PointerEventData, onComponent: (behaviour: Behaviour) => void) {
429
429
 
430
430
  while (true) {
431
431
  // Propagate up the hierarchy
432
- if (args.used) break; // Use acts like stopPropagation
433
432
 
434
433
  GameObject.foreachComponent(object, comp => {
435
434
  onComponent(comp);