@needle-tools/needle-component-compiler 1.10.3 → 1.11.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 +8 -0
- package/package.json +1 -1
- package/src/component-compiler.js +40 -1
- package/src/component-compiler.ts +40 -1
- package/src/types.js +7 -0
package/Changelog.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [1.11.1] - 2023-12-02
|
|
8
|
+
- Fix: Use Unity AnimatorController type
|
|
9
|
+
- Fix: method inline anonymous type declaration (e.g. `myMethod(arg: {x:number})`)
|
|
10
|
+
|
|
11
|
+
## [1.11.0] - 2023-11-18
|
|
12
|
+
- Add: support to wrap fields with `#if UNITY_EDITOR` if their namespace contains UnityEditor
|
|
13
|
+
- Add: more threejs types to generate Unity Material fields for
|
|
14
|
+
|
|
7
15
|
## [1.10.3] - 2023-09-08
|
|
8
16
|
- Add: Needle Engine type `RGBAColor` is now automatically emitted as `UnityEngine.Color`
|
|
9
17
|
|
package/package.json
CHANGED
|
@@ -270,7 +270,17 @@ function run(program, outputDir, sourceFile) {
|
|
|
270
270
|
var type = tryResolveTypeRecursive(param);
|
|
271
271
|
if (type === undefined)
|
|
272
272
|
type = "object";
|
|
273
|
-
|
|
273
|
+
var paramName = "";
|
|
274
|
+
var paramNameKind = param.name.kind;
|
|
275
|
+
switch (paramNameKind) {
|
|
276
|
+
case ts.SyntaxKind.ObjectBindingPattern:
|
|
277
|
+
paramName = "obj";
|
|
278
|
+
break;
|
|
279
|
+
default:
|
|
280
|
+
paramName = param.name.getText();
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
paramsStr += type + " @" + paramName;
|
|
274
284
|
}
|
|
275
285
|
var methodName = meth.name.getText();
|
|
276
286
|
switch (methodName) {
|
|
@@ -377,7 +387,14 @@ function run(program, outputDir, sourceFile) {
|
|
|
377
387
|
if (allowDebugLogs)
|
|
378
388
|
console.log("EMIT member: \"" + typeString + "\" " + varName, assignment, "Last type found:", lastTypeFound);
|
|
379
389
|
var prefix = shouldCommentTheLine ? "// " : "";
|
|
390
|
+
var isUnityEditorType = typeString === null || typeString === void 0 ? void 0 : typeString.includes("UnityEditor");
|
|
391
|
+
if (isUnityEditorType) {
|
|
392
|
+
context.appendLine("#if UNITY_EDITOR");
|
|
393
|
+
}
|
|
380
394
|
context.append(prefix + visibility + " " + typeString + " " + varName + assignment + ";" + postFix + "\n");
|
|
395
|
+
if (isUnityEditorType) {
|
|
396
|
+
context.appendLine("#endif");
|
|
397
|
+
}
|
|
381
398
|
lastTypeFound = null;
|
|
382
399
|
if (requireEndIf) {
|
|
383
400
|
context.appendLine("#endif");
|
|
@@ -603,8 +620,30 @@ function run(program, outputDir, sourceFile) {
|
|
|
603
620
|
typeName = varDec.type.getText();
|
|
604
621
|
}
|
|
605
622
|
var res = undefined;
|
|
623
|
+
// if it's a { x: number } inline object type:
|
|
624
|
+
if (typeName.startsWith("{")) {
|
|
625
|
+
// check if it has XYZW we assume it's a vector
|
|
626
|
+
var hasX = typeName.includes("x");
|
|
627
|
+
var hasY = typeName.includes("y");
|
|
628
|
+
var hasZ = typeName.includes("z");
|
|
629
|
+
var hasW = typeName.includes("w");
|
|
630
|
+
if (hasX && hasY && hasZ && hasW) {
|
|
631
|
+
return tryGetTypeFromText("Vector4");
|
|
632
|
+
}
|
|
633
|
+
else if (hasX && hasY && hasZ) {
|
|
634
|
+
return tryGetTypeFromText("Vector3");
|
|
635
|
+
}
|
|
636
|
+
else if (hasX && hasY) {
|
|
637
|
+
return tryGetTypeFromText("Vector2");
|
|
638
|
+
}
|
|
639
|
+
return "object";
|
|
640
|
+
}
|
|
641
|
+
// const kindName = ts.SyntaxKind[node.kind];
|
|
606
642
|
// console.log("Unknown type: " + typeName);
|
|
607
643
|
switch (node.kind) {
|
|
644
|
+
case ts.SyntaxKind.ObjectBindingPattern:
|
|
645
|
+
res = "object";
|
|
646
|
+
break;
|
|
608
647
|
// case ts.SyntaxKind.SyntaxList:
|
|
609
648
|
// const list = node as ts.SyntaxList;
|
|
610
649
|
// for (const ch of list._children) {
|
|
@@ -305,7 +305,17 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
305
305
|
if (paramsStr.length > 0) paramsStr += ", ";
|
|
306
306
|
let type = tryResolveTypeRecursive(param);
|
|
307
307
|
if (type === undefined) type = "object";
|
|
308
|
-
|
|
308
|
+
let paramName = "";
|
|
309
|
+
const paramNameKind = param.name.kind;
|
|
310
|
+
switch (paramNameKind) {
|
|
311
|
+
case ts.SyntaxKind.ObjectBindingPattern:
|
|
312
|
+
paramName = "obj"
|
|
313
|
+
break;
|
|
314
|
+
default:
|
|
315
|
+
paramName = param.name.getText();
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
paramsStr += type + " @" + paramName;
|
|
309
319
|
}
|
|
310
320
|
let methodName = meth.name.getText();
|
|
311
321
|
switch (methodName) {
|
|
@@ -409,7 +419,14 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
409
419
|
if (allowDebugLogs)
|
|
410
420
|
console.log("EMIT member: \"" + typeString + "\" " + varName, assignment, "Last type found:", lastTypeFound);
|
|
411
421
|
const prefix = shouldCommentTheLine ? "// " : "";
|
|
422
|
+
const isUnityEditorType = typeString?.includes("UnityEditor");
|
|
423
|
+
if (isUnityEditorType) {
|
|
424
|
+
context.appendLine("#if UNITY_EDITOR");
|
|
425
|
+
}
|
|
412
426
|
context.append(prefix + visibility + " " + typeString + " " + varName + assignment + ";" + postFix + "\n");
|
|
427
|
+
if (isUnityEditorType) {
|
|
428
|
+
context.appendLine("#endif");
|
|
429
|
+
}
|
|
413
430
|
lastTypeFound = null;
|
|
414
431
|
if (requireEndIf) {
|
|
415
432
|
context.appendLine("#endif");
|
|
@@ -632,11 +649,33 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
632
649
|
|
|
633
650
|
let res: string | undefined = undefined;
|
|
634
651
|
|
|
652
|
+
// if it's a { x: number } inline object type:
|
|
653
|
+
if (typeName.startsWith("{")) {
|
|
654
|
+
// check if it has XYZW we assume it's a vector
|
|
655
|
+
const hasX = typeName.includes("x");
|
|
656
|
+
const hasY = typeName.includes("y");
|
|
657
|
+
const hasZ = typeName.includes("z");
|
|
658
|
+
const hasW = typeName.includes("w");
|
|
659
|
+
if (hasX && hasY && hasZ && hasW) {
|
|
660
|
+
return tryGetTypeFromText("Vector4");
|
|
661
|
+
}
|
|
662
|
+
else if (hasX && hasY && hasZ) {
|
|
663
|
+
return tryGetTypeFromText("Vector3");
|
|
664
|
+
}
|
|
665
|
+
else if (hasX && hasY) {
|
|
666
|
+
return tryGetTypeFromText("Vector2");
|
|
667
|
+
}
|
|
635
668
|
|
|
669
|
+
return "object";
|
|
670
|
+
}
|
|
636
671
|
|
|
672
|
+
// const kindName = ts.SyntaxKind[node.kind];
|
|
637
673
|
// console.log("Unknown type: " + typeName);
|
|
638
674
|
|
|
639
675
|
switch (node.kind) {
|
|
676
|
+
case ts.SyntaxKind.ObjectBindingPattern:
|
|
677
|
+
res = "object";
|
|
678
|
+
break;
|
|
640
679
|
// case ts.SyntaxKind.SyntaxList:
|
|
641
680
|
// const list = node as ts.SyntaxList;
|
|
642
681
|
// for (const ch of list._children) {
|
package/src/types.js
CHANGED
|
@@ -37,10 +37,17 @@ const dict = {
|
|
|
37
37
|
"AnimationClip" : "UnityEngine.AnimationClip",
|
|
38
38
|
"SignalAsset" : "UnityEngine.Timeline.SignalAsset",
|
|
39
39
|
"PlayableDirector" : "UnityEngine.Playables.PlayableDirector",
|
|
40
|
+
"AnimatorController": "UnityEditor.Animations.AnimatorController",
|
|
40
41
|
// Rendering
|
|
41
42
|
"Renderer" : "UnityEngine.Renderer",
|
|
42
43
|
"Material" : "UnityEngine.Material",
|
|
44
|
+
"MeshBasicMaterial": "UnityEngine.Material",
|
|
45
|
+
"MeshPhysicalMaterial": "UnityEngine.Material",
|
|
46
|
+
"MeshStandardMaterial": "UnityEngine.Material",
|
|
47
|
+
"ShaderMaterial": "UnityEngine.Material",
|
|
48
|
+
"RawShaderMaterial": "UnityEngine.Material",
|
|
43
49
|
"Mesh" : "UnityEngine.Mesh",
|
|
50
|
+
"SkinnedMesh" : "UnityEngine.Mesh",
|
|
44
51
|
"Texture" : "UnityEngine.Texture",
|
|
45
52
|
// UI
|
|
46
53
|
"Text" : "UnityEngine.UI.Text",
|