@needle-tools/needle-component-compiler 1.11.0 → 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 CHANGED
@@ -4,6 +4,10 @@ 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
+
7
11
  ## [1.11.0] - 2023-11-18
8
12
  - Add: support to wrap fields with `#if UNITY_EDITOR` if their namespace contains UnityEditor
9
13
  - Add: more threejs types to generate Unity Material fields for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "Compile mock unity components from typescript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- paramsStr += type + " @" + param.name.getText();
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) {
@@ -610,8 +620,30 @@ function run(program, outputDir, sourceFile) {
610
620
  typeName = varDec.type.getText();
611
621
  }
612
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];
613
642
  // console.log("Unknown type: " + typeName);
614
643
  switch (node.kind) {
644
+ case ts.SyntaxKind.ObjectBindingPattern:
645
+ res = "object";
646
+ break;
615
647
  // case ts.SyntaxKind.SyntaxList:
616
648
  // const list = node as ts.SyntaxList;
617
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
- paramsStr += type + " @" + param.name.getText();
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) {
@@ -639,11 +649,33 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
639
649
 
640
650
  let res: string | undefined = undefined;
641
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
+ }
642
668
 
669
+ return "object";
670
+ }
643
671
 
672
+ // const kindName = ts.SyntaxKind[node.kind];
644
673
  // console.log("Unknown type: " + typeName);
645
674
 
646
675
  switch (node.kind) {
676
+ case ts.SyntaxKind.ObjectBindingPattern:
677
+ res = "object";
678
+ break;
647
679
  // case ts.SyntaxKind.SyntaxList:
648
680
  // const list = node as ts.SyntaxList;
649
681
  // for (const ch of list._children) {
package/src/types.js CHANGED
@@ -37,6 +37,7 @@ 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",