@needle-tools/engine 2.67.10-pre → 3.0.0-alpha.1
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/CHANGELOG.md +7 -0
- package/dist/needle-engine.js +11190 -11279
- package/dist/needle-engine.umd.cjs +232 -232
- package/lib/engine/api.d.ts +2 -0
- package/lib/engine/api.js +2 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_assetdatabase.js +24 -17
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_components.js +3 -3
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_components_internal.d.ts +6 -3
- package/lib/engine/engine_components_internal.js +34 -21
- package/lib/engine/engine_components_internal.js.map +1 -1
- package/lib/engine/engine_constants.d.ts +1 -1
- package/lib/engine/engine_constants.js +2 -1
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_gameobject.js +5 -5
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +2 -2
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_patcher.d.ts +4 -3
- package/lib/engine/engine_patcher.js +61 -44
- package/lib/engine/engine_patcher.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -6
- package/plugins/vite/alias.js +45 -0
- package/plugins/vite/index.js +2 -0
- package/src/engine/api.ts +3 -2
- package/src/engine/engine_assetdatabase.ts +29 -18
- package/src/engine/engine_components.ts +3 -3
- package/src/engine/engine_components_internal.ts +33 -20
- package/src/engine/engine_constants.ts +2 -3
- package/src/engine/engine_gameobject.ts +5 -5
- package/src/engine/engine_gltf_builtin_components.ts +2 -2
- package/src/engine/engine_patcher.ts +104 -47
- package/plugins/generate-font.js +0 -65
|
@@ -4,55 +4,53 @@ const _wrappedMethods = new WeakSet();
|
|
|
4
4
|
* Use patcher for patching properties insteadof calling Object.defineProperty individually
|
|
5
5
|
* since this will cause conflicts if multiple patches need to be applied to the same property
|
|
6
6
|
*/
|
|
7
|
-
export function addPatch(prototype, fieldName,
|
|
7
|
+
export function addPatch(prototype, fieldName, beforeCallback, afterCallback) {
|
|
8
|
+
// TODO
|
|
9
|
+
return;
|
|
8
10
|
// TODO: we probably want to turn this into a symbol to prevent anyone from overriding it
|
|
9
11
|
// But when we need to store the symbol per prototype to allow e.g. material disposing to iterate those and dispose all
|
|
10
|
-
const backingField = fieldName + "__needle"; // Symbol(fieldName);// + " (patched)";
|
|
11
|
-
internalAddPatch(prototype, fieldName,
|
|
12
|
+
const backingField = Symbol(fieldName + "__needle"); // Symbol(fieldName);// + " (patched)";
|
|
13
|
+
internalAddPatch(prototype, fieldName, afterCallback, beforeCallback);
|
|
12
14
|
const desc = Object.getOwnPropertyDescriptor(prototype, fieldName);
|
|
15
|
+
const existing = prototype[fieldName];
|
|
16
|
+
console.log(prototype);
|
|
13
17
|
if (desc) {
|
|
14
|
-
// TODO: check if the property is writable
|
|
15
|
-
// the property might be a method in which case we want to wrap it
|
|
16
|
-
if (typeof desc.value === "function") {
|
|
17
|
-
const method = desc.value;
|
|
18
|
-
if (method) {
|
|
19
|
-
if (_wrappedMethods.has(method)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
_wrappedMethods.add(method);
|
|
23
|
-
prototype[fieldName] = function (...args) {
|
|
24
|
-
// call the original method
|
|
25
|
-
const result = method.apply(this, args);
|
|
26
|
-
// call the patches
|
|
27
|
-
const patches = getPatches(prototype, fieldName);
|
|
28
|
-
if (patches) {
|
|
29
|
-
for (const patch of patches) {
|
|
30
|
-
patch(this, result, ...args);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// TODO: declare method?
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (prototype.hasOwnProperty(backingField)) {
|
|
42
18
|
}
|
|
43
19
|
else {
|
|
44
20
|
Object.defineProperty(prototype, fieldName, {
|
|
45
21
|
set: function (value) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
console.log("setting", fieldName, value);
|
|
23
|
+
if (typeof value === "function") {
|
|
24
|
+
this[backingField] = addWrapper(value, prototype, fieldName);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const prev = this[backingField];
|
|
28
|
+
executePrefixes(prototype, fieldName, this, prev, value);
|
|
29
|
+
this[backingField] = value;
|
|
30
|
+
executePostFixes(prototype, fieldName, this, prev, value);
|
|
31
|
+
}
|
|
49
32
|
},
|
|
50
33
|
get: function () {
|
|
51
|
-
|
|
34
|
+
console.log("GET", fieldName);
|
|
35
|
+
const value = this[backingField];
|
|
36
|
+
if (typeof value === "function") {
|
|
37
|
+
if (value[backingField]) {
|
|
38
|
+
return value[backingField];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
52
42
|
}
|
|
53
43
|
});
|
|
54
44
|
}
|
|
55
45
|
}
|
|
46
|
+
function addWrapper(originalFunction, prototype, fieldname) {
|
|
47
|
+
return function (...args) {
|
|
48
|
+
executePrefixes(prototype, fieldname, this, ...args);
|
|
49
|
+
const result = originalFunction.apply(this, args);
|
|
50
|
+
executePostFixes(prototype, fieldname, this, result, ...args);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
56
54
|
export function removePatch(prototype, fieldName, cb) {
|
|
57
55
|
const patches = getPatches(prototype, fieldName);
|
|
58
56
|
if (patches) {
|
|
@@ -63,35 +61,54 @@ export function removePatch(prototype, fieldName, cb) {
|
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
const
|
|
64
|
+
export const NeedlePatchesKey = "Needle:Patches";
|
|
65
|
+
function patches() {
|
|
66
|
+
if (!globalThis[NeedlePatchesKey]) {
|
|
67
|
+
globalThis[NeedlePatchesKey] = new WeakMap();
|
|
68
|
+
}
|
|
69
|
+
return globalThis[NeedlePatchesKey];
|
|
70
|
+
}
|
|
67
71
|
function getPatches(prototype, fieldName) {
|
|
68
|
-
let patchesMap = patches.get(prototype);
|
|
72
|
+
let patchesMap = patches().get(prototype);
|
|
69
73
|
if (!patchesMap) {
|
|
70
74
|
return null;
|
|
71
75
|
}
|
|
72
76
|
return patchesMap.get(fieldName);
|
|
73
77
|
;
|
|
74
78
|
}
|
|
75
|
-
function internalAddPatch(prototype, fieldName,
|
|
76
|
-
let patchesMap = patches.get(prototype);
|
|
79
|
+
function internalAddPatch(prototype, fieldName, postfix, prefix) {
|
|
80
|
+
let patchesMap = patches().get(prototype);
|
|
77
81
|
if (!patchesMap) {
|
|
78
82
|
patchesMap = new Map();
|
|
79
|
-
patches.set(prototype, patchesMap);
|
|
83
|
+
patches().set(prototype, patchesMap);
|
|
80
84
|
}
|
|
81
85
|
let patchList = patchesMap.get(fieldName);
|
|
82
86
|
if (!patchList) {
|
|
83
87
|
patchList = [];
|
|
84
88
|
patchesMap.set(fieldName, patchList);
|
|
85
89
|
}
|
|
86
|
-
patchList.push(
|
|
90
|
+
patchList.push({
|
|
91
|
+
prefix: prefix,
|
|
92
|
+
postfix: postfix
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function executePrefixes(prototype, fieldName, instance, ...args) {
|
|
96
|
+
if (!instance)
|
|
97
|
+
return;
|
|
98
|
+
const patches = getPatches(prototype, fieldName);
|
|
99
|
+
if (patches) {
|
|
100
|
+
for (const patchInfo of patches) {
|
|
101
|
+
patchInfo.prefix?.call(instance, ...args);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
87
104
|
}
|
|
88
|
-
function
|
|
105
|
+
function executePostFixes(prototype, fieldName, instance, result, ...args) {
|
|
89
106
|
if (!instance)
|
|
90
107
|
return;
|
|
91
108
|
const patches = getPatches(prototype, fieldName);
|
|
92
109
|
if (patches) {
|
|
93
|
-
for (const
|
|
94
|
-
|
|
110
|
+
for (const patchInfo of patches) {
|
|
111
|
+
patchInfo.postfix?.call(instance, result, ...args);
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine_patcher.js","sourceRoot":"","sources":["../../src/engine/engine_patcher.ts"],"names":[],"mappings":"AACA,iGAAiG;AAEjG,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"engine_patcher.js","sourceRoot":"","sources":["../../src/engine/engine_patcher.ts"],"names":[],"mappings":"AACA,iGAAiG;AAEjG,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;AAuCtC;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAmB,SAAY,EAAE,SAAiB,EAAE,cAAuB,EAAE,aAAuB;IAExH,OAAO;IACP,OAAO;IAEP,yFAAyF;IACzF,uHAAuH;IACvH,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,GAAG,UAAU,CAAC,CAAC,CAAA,uCAAuC;IAE3F,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;IAEtE,MAAM,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEnE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAEvB,IAAI,IAAI,EAAE;KACT;SACI;QACD,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE;YACxC,GAAG,EAAE,UAAwB,KAAU;gBACnC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACzC,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;oBAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;iBAChE;qBACI;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