@woosh/meep-engine 2.109.18 → 2.109.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.109.18",
8
+ "version": "2.109.19",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -6,7 +6,7 @@
6
6
  * @param {boolean} [constructorNameFallback]
7
7
  */
8
8
  export function abstractJSONSerializer<T>(source: T, serializers: any, classNames: Map<any, string>, constructorNameFallback?: boolean): T | {
9
- type: string;
9
+ type: any;
10
10
  data: any;
11
11
  };
12
12
  //# sourceMappingURL=abstractJSONSerializer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"abstractJSONSerializer.d.ts","sourceRoot":"","sources":["../../../../src/core/json/abstractJSONSerializer.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,mFAHW,SAAM,MAAM,CAAC,4BACb,OAAO;;;EAiEjB"}
1
+ {"version":3,"file":"abstractJSONSerializer.d.ts","sourceRoot":"","sources":["../../../../src/core/json/abstractJSONSerializer.js"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,mFAHW,SAAM,MAAM,CAAC,4BACb,OAAO;;;EA4DjB"}
@@ -1,3 +1,34 @@
1
+ /**
2
+ *
3
+ * @param {Function} Klass
4
+ * @param {Map<Function, string>} classNames
5
+ * @param {number} [max_depth] prevents infinite recursion
6
+ * @returns {*}
7
+ */
8
+ function resolve_class_name(Klass, classNames, max_depth = 64) {
9
+ let typeName = classNames.get(Klass);
10
+
11
+ if (typeName === undefined && Klass.hasOwnProperty("typeName")) {
12
+ // try fallback to "typeName" field on constructor
13
+ typeName = Klass.typeName;
14
+ }
15
+
16
+ if (typeName === undefined && max_depth > 0) {
17
+ // try walking up prototype chain
18
+
19
+ const proto = Object.getPrototypeOf(Klass);
20
+
21
+ if (proto !== null && typeof proto === "object") {
22
+
23
+ return resolve_class_name(proto, classNames, max_depth - 1);
24
+
25
+ }
26
+
27
+ }
28
+
29
+ return typeName;
30
+ }
31
+
1
32
  /**
2
33
  * @template T
3
34
  * @param {T} source
@@ -17,12 +48,7 @@ export function abstractJSONSerializer(source, serializers, classNames, construc
17
48
 
18
49
  // extract type name
19
50
  const Klass = source.constructor;
20
- let typeName = classNames.get(Klass);
21
-
22
- if (typeName === undefined && Klass.hasOwnProperty("typeName")) {
23
- // try fallback to "typeName" field on constructor
24
- typeName = Klass.typeName;
25
- }
51
+ let typeName = resolve_class_name(Klass, classNames);
26
52
 
27
53
  if (typeName === undefined && constructorNameFallback) {
28
54
  typeName = Klass.name;