@needle-tools/needle-component-compiler 1.8.0 → 1.9.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.
@@ -4,7 +4,6 @@ import * as fs from "fs";
4
4
  import * as path from 'path';
5
5
 
6
6
  import * as types from "./types";
7
- import { type } from "os";
8
7
  const dict = types.dict;
9
8
 
10
9
  // add either of these two comments above a class to enforce code gen or disable it for the next class
@@ -20,24 +19,46 @@ const ifdefPattern = new RegExp("@ifdef ?(?<ifdef>.+)")
20
19
  const CODEGEN_MARKER_START = "// NEEDLE_CODEGEN_START";
21
20
  const CODEGEN_MARKER_END = "// NEEDLE_CODEGEN_END";
22
21
 
22
+ let allowDebugLogs = true;
23
+
23
24
  // will be set to true when e.g. a comment for export is found
24
25
  let exportNextClass: boolean = false;
25
26
  let dontExportNextClass: boolean = false;
26
27
  let serializeField: boolean = false;
27
28
  let dontSerialize: boolean = false;
29
+ let typesFileContent: object | undefined | null = undefined;
30
+
31
+ // const exportDir = "../dist";
32
+ const commentStarts: Array<number> = [];
33
+ const contexts: ExportContext[] = [];
34
+ let lastTypeFound: string | null = null;
35
+ let ifdefSections: string[] = [];
36
+
37
+ function resetAllState() {
38
+ exportNextClass = false;
39
+ dontExportNextClass = false;
40
+ serializeField = false;
41
+ dontSerialize = false;
42
+ typesFileContent = undefined;
43
+
44
+ commentStarts.length = 0;
45
+ contexts.length = 0;
46
+ lastTypeFound = null;
47
+ ifdefSections.length = 0;
48
+ }
49
+
28
50
  function resetExportNextClass() {
29
51
  dontExportNextClass = false;
30
52
  exportNextClass = false;
31
53
  }
32
54
 
33
-
34
- let typesFileContent: object | undefined | null = undefined;
35
55
  function tryGetKnownType(str: string): string | null {
36
56
  if (typesFileContent === undefined) {
37
57
  typesFileContent = null;
38
58
  const filePath = path.dirname(__dirname) + "/src/types.json";
39
59
  if (fs.existsSync(filePath)) {
40
- console.log("Reading types file");
60
+ if (allowDebugLogs)
61
+ console.log("Reading types file");
41
62
  const content = fs.readFileSync(filePath, "utf8");
42
63
  typesFileContent = JSON.parse(content);
43
64
  }
@@ -45,7 +66,7 @@ function tryGetKnownType(str: string): string | null {
45
66
 
46
67
  if (typesFileContent) {
47
68
  const fullType = typesFileContent[str];
48
- if (fullType)
69
+ if (fullType && allowDebugLogs)
49
70
  console.log(fullType);
50
71
  return fullType;
51
72
  }
@@ -54,17 +75,15 @@ function tryGetKnownType(str: string): string | null {
54
75
 
55
76
  // https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API
56
77
 
57
- // const exportDir = "../dist";
58
- const commentStarts: Array<number> = [];
59
78
 
60
79
  class ExportContext {
61
- outputDir: string;
80
+ outputDir: string | null;
62
81
  fileName: string;
63
82
  textBuffer: string;
64
83
  classEnd: number = -1;
65
84
  indentLevel: number = 0;
66
85
 
67
- constructor(outputDir: string, fileName: string) {
86
+ constructor(outputDir: string | null, fileName: string) {
68
87
  this.outputDir = outputDir;
69
88
  this.fileName = fileName;
70
89
  this.reset();
@@ -90,14 +109,20 @@ class ExportContext {
90
109
  this.append(text + "\n");
91
110
  }
92
111
 
93
- flush() {
112
+ flush(): string {
94
113
  if (this.textBuffer.length <= 0) return;
95
- const dir = this.outputDir + "/";
96
- const path = dir + this.fileName;
97
- this.replaceGeneratedCodeSection(path);
98
- console.log("Write to " + path);
99
- fs.writeFileSync(path, this.textBuffer);
114
+ this.textBuffer = CODEGEN_MARKER_START + "\n" + this.textBuffer + "\n" + CODEGEN_MARKER_END;
115
+ const code = this.textBuffer;
116
+ if (this.outputDir !== null) {
117
+ const dir = this.outputDir + "/";
118
+ const path = dir + this.fileName;
119
+ this.replaceGeneratedCodeSection(path);
120
+ if (allowDebugLogs)
121
+ console.log("Write to " + path);
122
+ fs.writeFileSync(path, code);
123
+ }
100
124
  this.reset();
125
+ return code;
101
126
  }
102
127
 
103
128
  reset() {
@@ -106,13 +131,13 @@ class ExportContext {
106
131
  }
107
132
 
108
133
  private replaceGeneratedCodeSection(path: string) {
109
- this.textBuffer = CODEGEN_MARKER_START + "\n" + this.textBuffer + "\n" + CODEGEN_MARKER_END;
110
134
  if (fs.existsSync(path)) {
111
135
  const existing = fs.readFileSync(path, "utf8");
112
136
  const regex = new RegExp("(?<before>.*?)\/\/ ?NEEDLE_CODEGEN_START.+\/\/ ?NEEDLE_CODEGEN_END(?<after>.*)", "s");
113
137
  const matches = regex.exec(existing);
114
138
  if (matches?.groups) {
115
- console.log("Found codegen sections")
139
+ if (allowDebugLogs)
140
+ console.log("Found codegen sections")
116
141
  const before = matches.groups.before;
117
142
  const after = matches.groups.after;
118
143
  this.textBuffer = before + this.textBuffer + after;
@@ -121,18 +146,34 @@ class ExportContext {
121
146
  }
122
147
  }
123
148
 
124
- const contexts: ExportContext[] = [];
149
+ export function compile(code: string, fileName: string, outputDir: string | null, debugLogs: boolean = true): string[] {
125
150
 
126
- let lastTypeFound: string | null = null;
127
- let ifdefSections: string[] = [];
151
+ resetAllState();
152
+ allowDebugLogs = debugLogs;
153
+
154
+ // Parse a file
155
+ const sourceFile = ts.createSourceFile(
156
+ fileName,
157
+ code,
158
+ ts.ScriptTarget.ES2015,
159
+ true, /*setParentNodes */
160
+ );
161
+
162
+ const prog = ts.createProgram([fileName], {});
163
+
164
+ // delint it
165
+ return run(prog, outputDir, sourceFile);
166
+ }
128
167
 
129
- export function run(program: ts.Program, outputDir: string, sourceFile: ts.SourceFile) {
168
+ export function run(program: ts.Program, outputDir: string | null, sourceFile: ts.SourceFile): string[] {
130
169
 
131
- if (!fs.existsSync(outputDir)) {
170
+ if (outputDir !== null && !fs.existsSync(outputDir)) {
132
171
  console.error("Output directory does not exist: \"" + outputDir + "\"");
133
172
  return;
134
173
  }
135
174
 
175
+ const results: string[] = [];
176
+
136
177
  traverseFile(sourceFile);
137
178
  function traverseFile(node: ts.Node) {
138
179
 
@@ -140,6 +181,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
140
181
  ts.forEachChild(node, traverseFile);
141
182
  }
142
183
 
184
+ return results;
185
+
143
186
  function visit(node: ts.Node) {
144
187
  let context: ExportContext | null = contexts.length > 0 ? contexts[contexts.length - 1] : null;
145
188
 
@@ -149,12 +192,14 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
149
192
  context.indentLevel -= 1;
150
193
  context.append("}\n");
151
194
  }
152
- context.flush();
195
+ const code = context.flush();
196
+ results.push(code);
153
197
  context = null;
154
198
  contexts.pop();
155
199
  }
156
200
  }
157
- console.log("\t", ts.SyntaxKind[node.kind]);
201
+ if (allowDebugLogs)
202
+ console.log("\t", ts.SyntaxKind[node.kind]);
158
203
 
159
204
  const commentRanges = ts.getLeadingCommentRanges(
160
205
  sourceFile.getFullText(),
@@ -186,7 +231,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
186
231
  // so we remove them
187
232
  let type = typeMatch.groups["type"];
188
233
  type = type.replace(/\(/, "").replace(/\)/, "");
189
- console.log("Found type: ", type);
234
+ if (allowDebugLogs)
235
+ console.log("Found type: ", type);
190
236
  lastTypeFound = type;
191
237
  }
192
238
 
@@ -226,6 +272,9 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
226
272
  const meth = node as ts.MethodDeclaration;
227
273
  // const isCoroutine = func.asteriskToken;
228
274
  if (!skip && meth.name) {
275
+ const pub = isPublic(meth);
276
+ if (!pub) return;
277
+
229
278
  let paramsStr = "";
230
279
  for (let param of meth.parameters) {
231
280
  if (!param || !param.name) continue;
@@ -234,8 +283,13 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
234
283
  if (type === undefined) type = "object";
235
284
  paramsStr += type + " @" + param.name.getText();
236
285
  }
237
- const methodName = meth.name.getText();
286
+ let methodName = meth.name.getText();
287
+ switch (methodName) {
288
+ case "onEnable": methodName = "OnEnable"; break;
289
+ case "onDisable": methodName = "OnDisable"; break;
290
+ }
238
291
  context.onBeforeMethod(methodName);
292
+ // let visibility = pub ? "public" : "private";
239
293
  context.append("public void " + methodName + "(" + paramsStr + "){}\n");
240
294
  }
241
295
  break;
@@ -245,7 +299,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
245
299
  case ts.SyntaxKind.PropertyDeclaration:
246
300
  resetExportNextClass();
247
301
  if (!context) break;
248
- console.log("Found variable", node.getText());
302
+ if (allowDebugLogs)
303
+ console.log("Found variable", node.getText());
249
304
  const vardec = node as ts.VariableDeclaration;
250
305
 
251
306
  const varName = "@" + vardec.name.getText();
@@ -254,20 +309,23 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
254
309
  let isAccessible = pub;
255
310
  dontSerialize = false;
256
311
  if (serializeField) {
257
- console.log("[SerializeField]");
312
+ if (allowDebugLogs)
313
+ console.log("[SerializeField]");
258
314
  context.appendLine("[UnityEngine.SerializeField]");
259
315
  isAccessible = true;
260
316
  }
261
- else if(skip)
317
+ else if (skip)
262
318
  isAccessible = false;
263
-
319
+
264
320
  if (!isAccessible) {
265
- console.log("Skip because not public or serializeable")
321
+ if (allowDebugLogs)
322
+ console.log("Skip because not public or serializeable")
266
323
  break;
267
324
  }
268
325
 
269
326
  const name = vardec.name.getText();
270
- console.log("Variable:", name);
327
+ if (allowDebugLogs)
328
+ console.log("Variable:", name);
271
329
  if (name.startsWith("\"@") || name.startsWith("\"$") || name.startsWith("$")) break;
272
330
  let typeString = lastTypeFound ?? tryResolveTypeRecursive(node);
273
331
  let postFix = "";
@@ -317,12 +375,14 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
317
375
  }
318
376
  if (typeString === undefined) typeString = typeName;
319
377
  if (typeString === "[]") {
320
- console.log("Unknown array type for \"" + varName + " " + typeName + "\" - your type is probably not known (did you just create it this session?) and you might need to regenerate the Typemap in Unity. Go to \"Needle Engine/Internal/Generate Type Map for component compiler")
378
+ if (allowDebugLogs)
379
+ console.log("Unknown array type for \"" + varName + " " + typeName + "\" - your type is probably not known (did you just create it this session?) and you might need to regenerate the Typemap in Unity. Go to \"Needle Engine/Internal/Generate Type Map for component compiler")
321
380
  // typeString = "object[]";
322
381
  // assignment = " = new object[0]";
323
382
  shouldCommentTheLine = true;
324
383
  }
325
- console.log("EMIT member: \"" + typeString + "\" " + varName, assignment, "Last type found:", lastTypeFound);
384
+ if (allowDebugLogs)
385
+ console.log("EMIT member: \"" + typeString + "\" " + varName, assignment, "Last type found:", lastTypeFound);
326
386
  const prefix = shouldCommentTheLine ? "// " : "";
327
387
  context.append(prefix + visibility + " " + typeString + " " + varName + assignment + ";" + postFix + "\n");
328
388
  lastTypeFound = null;
@@ -339,9 +399,11 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
339
399
  if (!dontExportNextClass && (lastTypeFound || exportNextClass || inheritsComponent)) {
340
400
  resetExportNextClass();
341
401
  const name = dec.name?.escapedText;
342
- console.log("Found class: ", name);
402
+ if (allowDebugLogs)
403
+ console.log("Found class: ", name);
343
404
  const namespace = tryParseNamespace(node) ?? "Needle.Typescript.GeneratedComponents";
344
- console.log("NAMESPACE", namespace);
405
+ if (allowDebugLogs)
406
+ console.log("NAMESPACE", namespace);
345
407
  const newContext = new ExportContext(outputDir, name + ".cs");
346
408
  newContext.appendLine("// auto generated code - do not edit directly");
347
409
  newContext.appendLine("");
@@ -354,14 +416,16 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
354
416
  let typeName = "UnityEngine.MonoBehaviour";
355
417
  if (typeof inheritsComponent === "string") typeName = inheritsComponent;
356
418
  if (lastTypeFound) typeName = lastTypeFound;
357
- console.log(name + " inherits " + typeName);
419
+ if (allowDebugLogs)
420
+ console.log(name + " inherits " + typeName);
358
421
  let modifiers = "";
359
422
  if (dec.modifiers) {
360
423
  for (const mod of dec.modifiers) {
361
424
  switch (mod.getText()) {
362
425
  case "abstract":
363
426
  modifiers += " abstract";
364
- console.log(name + " is abstract");
427
+ if (allowDebugLogs)
428
+ console.log(name + " is abstract");
365
429
  break;
366
430
  }
367
431
  }
@@ -374,7 +438,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
374
438
  contexts.push(newContext);
375
439
  }
376
440
  else {
377
- console.log("Class type is unknown and will not generate a component: ", dec.name?.escapedText);
441
+ if (allowDebugLogs)
442
+ console.log("Class type is unknown and will not generate a component: ", dec.name?.escapedText);
378
443
  }
379
444
  lastTypeFound = null;
380
445
  break;
@@ -420,18 +485,32 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
420
485
  type = tryGetTypeFromText(text);
421
486
  break;
422
487
  case ts.SyntaxKind.SyntaxList:
423
- args = text;
488
+ for (const arg of ch.getChildren()) {
489
+ if (args === undefined) args = "";
490
+ const res = getTypeForAssignment(arg);
491
+ // handle floats being assigned with "f" suffix
492
+ if (Number.parseFloat(res) >= 0) {
493
+ args += res + "f";
494
+ }
495
+ else {
496
+ args += res;
497
+ if (res === ",") args += " ";
498
+ }
499
+ }
424
500
  break;
425
501
  }
426
502
  }
427
503
  if (!args) args = "";
428
- if (type)
504
+ if (type) {
505
+ console.log(type, args)
429
506
  return "new " + type + "(" + args + ")";
507
+ }
430
508
  // const expType = node.getChildren().find(c => c.kind === ts.SyntaxKind.Identifier);
431
509
  break;
432
510
  }
433
511
  const str = node.getText();
434
- console.log("Unknown assignment:", str, ts.SyntaxKind[node.kind]);
512
+ if (allowDebugLogs)
513
+ console.log("Unknown assignment:", str, ts.SyntaxKind[node.kind]);
435
514
  return str;
436
515
  }
437
516
 
@@ -439,7 +518,7 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
439
518
  if (node.kind === ts.SyntaxKind.PublicKeyword) {
440
519
  return true;
441
520
  }
442
- else if (node.kind === ts.SyntaxKind.PrivateKeyword) {
521
+ else if (node.kind === ts.SyntaxKind.PrivateKeyword || node.kind === ts.SyntaxKind.ProtectedKeyword) {
443
522
  return false;
444
523
  }
445
524
 
@@ -480,7 +559,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
480
559
  const separatorIndex = typeName.lastIndexOf(".");
481
560
  if (separatorIndex > 0) {
482
561
  let newName = typeName.substring(separatorIndex + 1);
483
- console.log("Remove import name from type: \"" + typeName + "\" → \"" + newName + "\"");
562
+ if (allowDebugLogs)
563
+ console.log("Remove import name from type: \"" + typeName + "\" → \"" + newName + "\"");
484
564
  typeName = newName;
485
565
  }
486
566
 
@@ -541,7 +621,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
541
621
  case ts.SyntaxKind.TypeReference:
542
622
  const typeRef = node as ts.TypeReferenceNode;
543
623
  const typeName = typeRef.typeName.getText();
544
- console.log("TypeReference:", typeName);
624
+ if (allowDebugLogs)
625
+ console.log("TypeReference:", typeName);
545
626
  switch (typeName) {
546
627
  case "Array":
547
628
  break;
@@ -600,7 +681,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
600
681
  const childResult = tryResolveTypeRecursive(child);
601
682
  if (childResult !== undefined) {
602
683
  if (res === undefined) res = "";
603
- console.log("Child: " + ts.SyntaxKind[child.kind] + " → " + childResult);
684
+ if (allowDebugLogs)
685
+ console.log("Child: " + ts.SyntaxKind[child.kind] + " → " + childResult);
604
686
  // if the thing is a generic return as generic result
605
687
  if (isInGenericDeclaration && !res.includes("[]")) {
606
688
  res = "<" + childResult + ">";
@@ -630,24 +712,23 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
630
712
  }
631
713
  }
632
714
 
633
- if (process.argv.length < 4) {
634
- console.error("Missing args, call with: <output_dir> <input_files>");
635
- }
636
- else {
637
- const outputDir = process.argv[2];
638
- const fileNames = process.argv.slice(3);
639
- fileNames.forEach(fileName => {
640
- // Parse a file
641
- const sourceFile = ts.createSourceFile(
642
- fileName,
643
- readFileSync(fileName).toString(),
644
- ts.ScriptTarget.ES2015,
645
- /*setParentNodes */ true
646
- );
647
-
648
- const prog = ts.createProgram([fileName], {});
649
-
650
- // delint it
651
- run(prog, outputDir, sourceFile);
652
- });
715
+
716
+ if (process) {
717
+
718
+ if (process.argv.length < 4) {
719
+ console.error("Missing args, call with: <output_dir> <input_files>");
720
+ }
721
+ else {
722
+ const outputDir = process.argv[2];
723
+ const fileNames = process.argv.slice(3);
724
+ fileNames.forEach(fileName => {
725
+ if (!fs.existsSync(fileName)) {
726
+
727
+ }
728
+ else {
729
+ const code = readFileSync(fileName).toString();
730
+ compile(code, fileName, outputDir);
731
+ }
732
+ });
733
+ }
653
734
  }
package/src/test.js ADDED
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ exports.__esModule = true;
18
+ exports.MyTestComponent = void 0;
19
+ var MyTestComponent = /** @class */ (function (_super) {
20
+ __extends(MyTestComponent, _super);
21
+ function MyTestComponent() {
22
+ var _this = _super !== null && _super.apply(this, arguments) || this;
23
+ _this.myVector2 = new Vector2(1, .5);
24
+ return _this;
25
+ }
26
+ MyTestComponent.prototype.myMethod = function () {
27
+ };
28
+ return MyTestComponent;
29
+ }(Behaviour));
30
+ exports.MyTestComponent = MyTestComponent;
31
+ // export class SkipFieldAndMethod extends Behaviour {
32
+ // //@nonSerialized
33
+ // myMethod() {
34
+ // }
35
+ // // @nonSerialized
36
+ // myField : string;
37
+ // }
38
+ // export class ComponentWithUnknownType extends Behaviour {
39
+ // views: SomeUnknownType;
40
+ // }
41
+ // export class ComponentWithAnimationClip extends Behaviour implements IPointerClickHandler {
42
+ // @serializeable(AnimationClip)
43
+ // animation?: THREE.AnimationClip;
44
+ // }
45
+ // export abstract class MyAbstractComponent extends Behaviour {
46
+ // abstract myMethod();
47
+ // }
48
+ // export class CameraView extends Behaviour {
49
+ // static views: CameraView[] = [];
50
+ // }
51
+ // export class EventComponent extends Behaviour {
52
+ // @serializeable(EventList)
53
+ // roomChanged: EventList = new EventList();
54
+ // }
55
+ // export class SocLoader extends Behaviour {
56
+ // @serializeable(AssetReference)
57
+ // scenes: Array<AssetReference> = [];
58
+ // }
59
+ // // class Test123 {}
60
+ // export class Bla extends Behaviour
61
+ // {
62
+ // myNumber:number = 42;
63
+ // myBool:boolean = true;
64
+ // myString:string = "test";
65
+ // numberArr: number[] = [1,2,3];
66
+ // myColor : THREE.Color = new THREE.Color(255, 0, 0);
67
+ // renderers = new Array<Renderer>();
68
+ // renderers2 : Renderer[] = [];
69
+ // objArr : object[];
70
+ // colArr: THREE.Color[] = [new THREE.Color(1,2,3)];
71
+ // map : Map<string> = new Map<string>();
72
+ // map2 : Map<object> = new Map<object>();
73
+ // private myThing : Test123;
74
+ // }
75
+ // //@type UnityEngine.MonoBehaviour
76
+ // export class ButtonObject extends Interactable implements IPointerClickHandler, ISerializable {
77
+ // //@type UnityEngine.Transform[]
78
+ // myType?: SceneFXWindow;
79
+ // }
80
+ // import { Behaviour } from "needle.tiny.engine/engine-components/Component";
81
+ // import { RoomEntity } from "./Room";
82
+ // import { Behaviour } from "needle.tiny.engine/engine-components/Component";
83
+ // export class MyNewScript extends DriveClient
84
+ // {
85
+ // //@type test
86
+ // texture : RenderTexture;
87
+ // }
88
+ // namespace Hello.World
89
+ // {
90
+ // namespace Deep {
91
+ // export class MyClass extends Behaviour {
92
+ // //@ifdef TEST
93
+ // public myFloat :number;
94
+ // }
95
+ // }
96
+ // }
97
+ // class OtherClass extends Behaviour {
98
+ // }
99
+ //@type (RoomEntity)
100
+ // export class NavigationManager extends RoomEntity {
101
+ // fl:number = 1;
102
+ // nav_forward() {
103
+ // }
104
+ // nav_backward() {
105
+ // }
106
+ // }
107
+ // export abstract class NavComponent extends Behaviour {
108
+ // abstract next();
109
+ // abstract prev();
110
+ // abstract isAtEnd():boolean;
111
+ // }
112
+ // export class PointOfInterest extends Behaviour {
113
+ // myVal:number = 12;
114
+ // // @type(HELLO)
115
+ // myFunction(){
116
+ // }
117
+ // // @type(UnityEngine.Camera)
118
+ // view?:Camera;
119
+ // test:string = "123";
120
+ // // test
121
+ // }
122
+ // export class MaterialColorHandler extends Behaviour {
123
+ // @serializeable(Renderer)
124
+ // renderer?: Renderer[];
125
+ // }
126
+ // export class MyArray extends Behaviour {
127
+ // arr? : Array<number> = [1,2,3];
128
+ // }
129
+ // export class PrivateSerializedField extends Behaviour {
130
+ // //@serializeField
131
+ // private color? : THREE.Color;
132
+ // }
133
+ // export class MyPropertyClass extends Behaviour {
134
+ // set color(col: THREE.Color) {
135
+ // }
136
+ // }
137
+ // export class MyClassWithAFloat extends Behaviour {
138
+ // myfloat:number = .5;
139
+ // private myString : string;
140
+ // }
141
+ // export class GltfExport extends Behaviour {
142
+ // binary: boolean = true;
143
+ // "$serializedTypes" = {
144
+ // url:null
145
+ // }
146
+ // // @contextmenu enable this
147
+ // test(){
148
+ // }
149
+ // }
150
+ // export class SetColor extends Behaviour {
151
+ // "@serializedTypes" = {
152
+ // col: Number,
153
+ // }
154
+ // }
155
+ // class Behaviour {
156
+ // }
157
+ // export class PlatformerMusic extends Behaviour implements IPlaymodeChangeListener {
158
+ // source?: AudioSource;
159
+ // editMode?: string;
160
+ // playMode?: string;
161
+ // onPlaymodeChange(playmode: PlayMode): void {
162
+ // console.log(this);
163
+ // if(!this.source) return;
164
+ // const clip = playmode.isInPlayMode ? this.playMode : this.editMode;
165
+ // console.log("PLAY", clip);
166
+ // this.source.play(clip);
167
+ // }
168
+ // }
169
+ // // TODO: export UnityEvent like this
170
+ // // disable codegen
171
+ // class UnityEvent {
172
+ // methods: Function[] = [];
173
+ // invoke() {
174
+ // for (const m of this.methods) {
175
+ // m();
176
+ // }
177
+ // }
178
+ // }
179
+ // export class MyClass extends Behaviour {
180
+ // myFloat: number = 15;
181
+ // myBool: boolean;
182
+ // // just some default values
183
+ // myArray: number[] = [1, 2, 3];
184
+ // // comment for myString
185
+ // myString: string = "this is a string1";
186
+ // myObject: THREE.Object3D;
187
+ // myBool2: boolean;
188
+ // myFunction() { }
189
+ // myFunctionWithStringParameter(string: string) { }
190
+ // myFunctionWithSomeObjectAndArray(obj: THREE.Object3D, arr: number[]) { }
191
+ // myFunctionWithoutParamTypes(test) { }
192
+ // someOtherStuff: THREE.Object3D[] | null = null;
193
+ // myEvent: UnityEvent;
194
+ // }
package/src/test.ts CHANGED
@@ -1,17 +1,24 @@
1
1
  import { ThisExpression } from "typescript";
2
2
 
3
+ export class MyTestComponent extends Behaviour {
4
+ public myVector2: Vector2 = new Vector2(1, .5);
5
+ private myMethod(){
6
+
7
+ }
8
+ }
3
9
 
4
- export class SkipFieldAndMethod extends Behaviour {
10
+
11
+ // export class SkipFieldAndMethod extends Behaviour {
5
12
 
6
- //@nonSerialized
7
- myMethod() {
13
+ // //@nonSerialized
14
+ // myMethod() {
8
15
 
9
- }
16
+ // }
10
17
 
11
- // @nonSerialized
12
- myField : string;
18
+ // // @nonSerialized
19
+ // myField : string;
13
20
 
14
- }
21
+ // }
15
22
 
16
23
 
17
24
  // export class ComponentWithUnknownType extends Behaviour {