@needle-tools/needle-component-compiler 2.4.0-pre → 3.0.0-alpha

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.
@@ -0,0 +1,306 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CSharpWriter = void 0;
19
+ var base_compiler_1 = require("../base-compiler");
20
+ var BaseWriter_1 = require("../BaseWriter");
21
+ var allowDebugLogs = false;
22
+ /** Inline type dictionary: TypeScript type name → fully-qualified C# type name */
23
+ var TYPE_MAP = {
24
+ // Primitives
25
+ "number": "float",
26
+ "boolean": "bool",
27
+ "string": "string",
28
+ "any": "object",
29
+ "object": "UnityEngine.Object",
30
+ "void": "void",
31
+ // Unity base types
32
+ "Behaviour": "UnityEngine.MonoBehaviour",
33
+ "MonoBehaviour": "UnityEngine.MonoBehaviour",
34
+ "Component": "UnityEngine.Component",
35
+ "ScriptableObject": "UnityEngine.ScriptableObject",
36
+ // GameObjects / Transforms
37
+ "GameObject": "UnityEngine.GameObject",
38
+ "Object3D": "UnityEngine.Transform",
39
+ "Transform": "UnityEngine.Transform",
40
+ "AssetReference": "UnityEngine.Transform",
41
+ "THREE.Object3D": "UnityEngine.Transform",
42
+ // Math types
43
+ "Vector2": "UnityEngine.Vector2",
44
+ "Vector3": "UnityEngine.Vector3",
45
+ "Vector4": "UnityEngine.Vector4",
46
+ "Quaternion": "UnityEngine.Quaternion",
47
+ "Color": "UnityEngine.Color",
48
+ "RGBAColor": "UnityEngine.Color",
49
+ "THREE.Color": "UnityEngine.Color",
50
+ "THREE.Vector2": "UnityEngine.Vector2",
51
+ "THREE.Vector3": "UnityEngine.Vector3",
52
+ "THREE.Vector4": "UnityEngine.Vector4",
53
+ "Matrix4": "UnityEngine.Matrix4x4",
54
+ "Box3": "UnityEngine.Bounds",
55
+ // Rendering
56
+ "Renderer": "UnityEngine.Renderer",
57
+ "Material": "UnityEngine.Material",
58
+ "Mesh": "UnityEngine.Mesh",
59
+ "Texture": "UnityEngine.Texture",
60
+ "Texture2D": "UnityEngine.Texture2D",
61
+ "RenderTexture": "UnityEngine.RenderTexture",
62
+ // Audio
63
+ "AudioClip": "UnityEngine.AudioClip",
64
+ "AudioSource": "UnityEngine.AudioSource",
65
+ // Animation
66
+ "Animator": "UnityEngine.Animator",
67
+ "Animation": "UnityEngine.Animation",
68
+ "AnimationClip": "UnityEngine.AnimationClip",
69
+ // Events
70
+ "EventList": "UnityEngine.Events.UnityEvent",
71
+ "UnityEvent": "UnityEngine.Events.UnityEvent",
72
+ // Physics / Colliders
73
+ "ICollider": "UnityEngine.Collider",
74
+ // UI
75
+ "Text": "UnityEngine.UI.Text",
76
+ "Image": "UnityEngine.UI.Image",
77
+ "RawImage": "UnityEngine.UI.RawImage",
78
+ // Camera / Light
79
+ "Camera": "UnityEngine.Camera",
80
+ "Light": "UnityEngine.Light",
81
+ // Timeline / Playables
82
+ "SignalAsset": "UnityEngine.Timeline.SignalAsset",
83
+ "PlayableDirector": "UnityEngine.Playables.PlayableDirector",
84
+ // Miscellaneous
85
+ "Rigidbody": "UnityEngine.Rigidbody",
86
+ "Map": "System.Collections.Generic.Dictionary",
87
+ };
88
+ /** Lifecycle method name mappings: camelCase TS → PascalCase C# */
89
+ var LIFECYCLE_METHODS = {
90
+ "awake": "Awake",
91
+ "start": "Start",
92
+ "onEnable": "OnEnable",
93
+ "onDisable": "OnDisable",
94
+ "update": "Update",
95
+ "lateUpdate": "LateUpdate",
96
+ "fixedUpdate": "FixedUpdate",
97
+ "onDestroy": "OnDestroy",
98
+ "onCollisionEnter": "OnCollisionEnter",
99
+ "onCollisionExit": "OnCollisionExit",
100
+ "onCollisionStay": "OnCollisionStay",
101
+ "onTriggerEnter": "OnTriggerEnter",
102
+ "onTriggerExit": "OnTriggerExit",
103
+ "onTriggerStay": "OnTriggerStay",
104
+ "onApplicationQuit": "OnApplicationQuit",
105
+ "onBecameVisible": "OnBecameVisible",
106
+ "onBecameInvisible": "OnBecameInvisible",
107
+ "onGUI": "OnGUI",
108
+ "onValidate": "OnValidate",
109
+ "reset": "Reset",
110
+ };
111
+ /** UnityEditor types that need #if UNITY_EDITOR wrapping */
112
+ var EDITOR_TYPES = new Set([
113
+ "UnityEditor", "AnimatorController", "EditorApplication",
114
+ "EditorUtility", "SerializedObject", "SerializedProperty",
115
+ ]);
116
+ function isEditorType(typeName) {
117
+ return EDITOR_TYPES.has(typeName) || typeName.startsWith("UnityEditor.");
118
+ }
119
+ var CSharpWriter = /** @class */ (function (_super) {
120
+ __extends(CSharpWriter, _super);
121
+ function CSharpWriter() {
122
+ return _super !== null && _super.apply(this, arguments) || this;
123
+ }
124
+ CSharpWriter.prototype.resolveCSharpTypeName = function (typescriptTypeName) {
125
+ var _a, _b;
126
+ if (!typescriptTypeName)
127
+ return undefined;
128
+ // Strip THREE. prefix for lookup fallback
129
+ var stripped = typescriptTypeName.startsWith("THREE.") ? typescriptTypeName.substring(6) : typescriptTypeName;
130
+ return (_b = (_a = TYPE_MAP[typescriptTypeName]) !== null && _a !== void 0 ? _a : TYPE_MAP[stripped]) !== null && _b !== void 0 ? _b : typescriptTypeName;
131
+ };
132
+ CSharpWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
133
+ var _a;
134
+ if (comments === null || comments === void 0 ? void 0 : comments.includes("@dont-generate-component"))
135
+ return false;
136
+ // @type override: first comment matching "@type <T>" overrides base class
137
+ var resolvedBase = "UnityEngine.MonoBehaviour";
138
+ var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
139
+ if (typeOverride) {
140
+ resolvedBase = typeOverride.substring("@type ".length).trim();
141
+ }
142
+ else if (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) {
143
+ var first = baseTypes[0];
144
+ resolvedBase = (_a = this.resolveCSharpTypeName(first)) !== null && _a !== void 0 ? _a : "UnityEngine.MonoBehaviour";
145
+ }
146
+ // Abstract modifier
147
+ var isAbstract = comments === null || comments === void 0 ? void 0 : comments.includes("@abstract");
148
+ var modifiers = isAbstract ? "abstract partial" : "partial";
149
+ this.writer.writeLine("// NEEDLE_CODEGEN_START");
150
+ this.writer.writeLine("// auto generated code - do not edit directly");
151
+ this.writer.writeLine("");
152
+ this.writer.writeLine("#pragma warning disable");
153
+ this.writer.writeLine("");
154
+ this.writer.beginBlock("namespace Needle.Typescript.GeneratedComponents\n{");
155
+ this.writer.beginBlock("public ".concat(modifiers, " class ").concat(typeName, " : ").concat(resolvedBase, "\n{"));
156
+ };
157
+ CSharpWriter.prototype.endNewType = function (filePath, typeName) {
158
+ this.writer.endBlock("}");
159
+ this.writer.endBlock("}");
160
+ this.writer.writeLine("");
161
+ this.writer.writeLine("// NEEDLE_CODEGEN_END");
162
+ this.writeCSharpScheme(filePath, typeName);
163
+ };
164
+ CSharpWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
165
+ var _a;
166
+ if (allowDebugLogs)
167
+ console.log("[CSharp] writeMember", name, type, comments);
168
+ // @nonSerialized → skip entirely
169
+ if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
170
+ return;
171
+ // @type override
172
+ var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
173
+ var csharpType = typeOverride
174
+ ? typeOverride.substring("@type ".length).trim()
175
+ : ((_a = this.resolveCSharpTypeName(type)) !== null && _a !== void 0 ? _a : type);
176
+ // Determine visibility string
177
+ var vis = "public";
178
+ if (visibility === base_compiler_1.Visibility.Private || visibility === base_compiler_1.Visibility.Protected) {
179
+ vis = visibility === base_compiler_1.Visibility.Protected ? "protected" : "private";
180
+ }
181
+ // @serializeField → add attribute + force private becomes serialized
182
+ var serializeField = comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@serializeField") || c.startsWith("@serializable"); });
183
+ // @tooltip
184
+ var tooltipComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@tooltip "); });
185
+ var tooltip = tooltipComment ? tooltipComment.substring("@tooltip ".length).trim().replace(/^["']|["']$/g, "") : null;
186
+ // @contextmenu
187
+ var contextMenuComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@contextmenu "); });
188
+ var contextMenu = contextMenuComment ? contextMenuComment.substring("@contextmenu ".length).trim() : null;
189
+ // @ifdef
190
+ var ifdefComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@ifdef "); });
191
+ var ifdef = ifdefComment ? ifdefComment.substring("@ifdef ".length).trim() : null;
192
+ // Skip private/protected fields unless @serializeField
193
+ if (visibility !== base_compiler_1.Visibility.Public && !serializeField)
194
+ return;
195
+ // Resolve assignment
196
+ var assignment = "";
197
+ if (initialValue !== undefined && initialValue !== null) {
198
+ if (initialValue === "null") {
199
+ // keep null for reference types, skip for value types
200
+ }
201
+ else if (csharpType === "float") {
202
+ assignment = " = ".concat(initialValue, "f");
203
+ }
204
+ else if (csharpType === "bool") {
205
+ assignment = " = ".concat(initialValue.toLowerCase());
206
+ }
207
+ else if (csharpType === "string") {
208
+ assignment = " = \"".concat(initialValue, "\"");
209
+ }
210
+ else if (initialValue.startsWith("new ")) {
211
+ // constructor expression already prefixed with new
212
+ var resolved = this.resolveNewExpression(initialValue);
213
+ assignment = " = ".concat(resolved);
214
+ }
215
+ else {
216
+ assignment = " = ".concat(initialValue);
217
+ }
218
+ }
219
+ // Array suffix
220
+ if (isArray)
221
+ csharpType += "[]";
222
+ // Editor type wrapping
223
+ var needsEditorWrap = isEditorType(csharpType.split("[")[0].split("<")[0]);
224
+ if (ifdef)
225
+ this.writer.writeLine("#ifdef ".concat(ifdef));
226
+ if (needsEditorWrap)
227
+ this.writer.writeLine("#if UNITY_EDITOR");
228
+ // Emit attributes
229
+ if (tooltip)
230
+ this.writer.writeLine("[UnityEngine.Tooltip(\"".concat(tooltip, "\")]"));
231
+ if (contextMenu)
232
+ this.writer.writeLine("[UnityEngine.ContextMenu(\"".concat(contextMenu, "\")]"));
233
+ if (serializeField && visibility !== base_compiler_1.Visibility.Public) {
234
+ this.writer.writeLine("[UnityEngine.SerializeField]");
235
+ }
236
+ // Emit field
237
+ var varName = "@".concat(name);
238
+ this.writer.writeLine("".concat(vis, " ").concat(csharpType, " ").concat(varName).concat(assignment, ";"));
239
+ if (needsEditorWrap)
240
+ this.writer.writeLine("#endif");
241
+ if (ifdef)
242
+ this.writer.writeLine("#endif");
243
+ };
244
+ CSharpWriter.prototype.writeMethod = function (visibility, name, returnType, args, comments) {
245
+ var _this = this;
246
+ var _a, _b;
247
+ if (allowDebugLogs)
248
+ console.log("[CSharp] writeMethod", name, returnType);
249
+ // @contextmenu on method → add attribute
250
+ var contextMenuComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@contextmenu "); });
251
+ var contextMenu = contextMenuComment ? contextMenuComment.substring("@contextmenu ".length).trim() : null;
252
+ // Only emit public methods and lifecycle methods (which are always public)
253
+ var lifecycleName = LIFECYCLE_METHODS[name];
254
+ if (visibility !== base_compiler_1.Visibility.Public && !lifecycleName)
255
+ return;
256
+ // Lifecycle methods get PascalCase; regular public methods keep their name as-is
257
+ var methodName = lifecycleName !== null && lifecycleName !== void 0 ? lifecycleName : name;
258
+ // Build parameter list — inline object types (e.g. { x: number }) resolve to "object"
259
+ var paramList = (_a = args === null || args === void 0 ? void 0 : args.map(function (arg) {
260
+ var _a, _b;
261
+ var csharpType;
262
+ if (!arg.type || arg.type.includes("{")) {
263
+ csharpType = "object";
264
+ }
265
+ else {
266
+ csharpType = (_b = (_a = _this.resolveCSharpTypeName(arg.type)) !== null && _a !== void 0 ? _a : arg.type) !== null && _b !== void 0 ? _b : "object";
267
+ }
268
+ return "".concat(csharpType, " @").concat(arg.name);
269
+ }).join(", ")) !== null && _a !== void 0 ? _a : "";
270
+ var csReturnType = returnType
271
+ ? ((_b = this.resolveCSharpTypeName(returnType)) !== null && _b !== void 0 ? _b : returnType)
272
+ : "void";
273
+ if (contextMenu)
274
+ this.writer.writeLine("[UnityEngine.ContextMenu(\"".concat(contextMenu, "\")]"));
275
+ this.writer.writeLine("public void ".concat(methodName, "(").concat(paramList, ") {}"));
276
+ };
277
+ CSharpWriter.prototype.writeNewTypeExpression = function (typeName, args) {
278
+ // no-op for C# output
279
+ };
280
+ // ── Helpers ────────────────────────────────────────────────────────────
281
+ /** Converts camelCase to PascalCase for method names */
282
+ CSharpWriter.prototype.toPascalCase = function (name) {
283
+ return name.charAt(0).toUpperCase() + name.slice(1);
284
+ };
285
+ /** Resolve a "new Type(args)" expression: map TS types to C# qualified types */
286
+ CSharpWriter.prototype.resolveNewExpression = function (expr) {
287
+ var _a;
288
+ // expr is already resolved: "new UnityEngine.Vector2(1, 0.5)" → "new UnityEngine.Vector2(1f, 0.5f)"
289
+ var match = expr.match(/^new\s+([\w.]+)\s*\((.*)\)$/s);
290
+ if (!match)
291
+ return expr;
292
+ var typeName = match[1], argsStr = match[2];
293
+ var csharpType = (_a = this.resolveCSharpTypeName(typeName)) !== null && _a !== void 0 ? _a : typeName;
294
+ // Convert numeric literals to float
295
+ var csharpArgs = argsStr.replace(/(\d+\.?\d*)/g, function (n) {
296
+ return n.includes(".") ? "".concat(n, "f") : "".concat(n, "f");
297
+ });
298
+ return "new ".concat(csharpType, "(").concat(csharpArgs, ")");
299
+ };
300
+ /** Override writeScheme to use .cs extension instead of .component.json */
301
+ CSharpWriter.prototype.writeCSharpScheme = function (processingFilePath, component) {
302
+ var res = this.sink.flush(component + ".cs", this.writer.flush());
303
+ };
304
+ return CSharpWriter;
305
+ }(BaseWriter_1.BaseWriter));
306
+ exports.CSharpWriter = CSharpWriter;
@@ -0,0 +1,20 @@
1
+ import { IWriter, Visibility } from "../base-compiler";
2
+ import { TypeSourceInformation } from "../register-types";
3
+ export declare class ReactThreeFiberCompiler implements IWriter {
4
+ get outputInfo(): TypeSourceInformation;
5
+ private readonly _typeSourceInformation;
6
+ constructor();
7
+ resolveCSharpTypeName(typescriptTypeName: string): string | void;
8
+ begin(filePath: string): void;
9
+ end(filePath: string): void;
10
+ startNewType(filePath: string, typeName: string, baseType: string[], comments?: string[]): boolean | void;
11
+ endNewType(filePath: string, typeName: string): void;
12
+ writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
13
+ writeMethod(visibility: Visibility, name: string, returnType: string, args: {
14
+ name: string;
15
+ type: string;
16
+ defaultValue?: string;
17
+ }[], comments: string[]): void;
18
+ writeNewTypeExpression(typeName: string, args?: string[]): void;
19
+ registerEnum(name: string, members: import("../base-compiler").EnumMember[]): void;
20
+ }
@@ -12,7 +12,7 @@ var ReactThreeFiberCompiler = /** @class */ (function () {
12
12
  enumerable: false,
13
13
  configurable: true
14
14
  });
15
- ReactThreeFiberCompiler.prototype.resolveTypeName = function (typescriptTypeName) {
15
+ ReactThreeFiberCompiler.prototype.resolveCSharpTypeName = function (typescriptTypeName) {
16
16
  return typescriptTypeName;
17
17
  };
18
18
  ReactThreeFiberCompiler.prototype.begin = function (filePath) {
@@ -29,6 +29,8 @@ var ReactThreeFiberCompiler = /** @class */ (function () {
29
29
  };
30
30
  ReactThreeFiberCompiler.prototype.writeNewTypeExpression = function (typeName, args) {
31
31
  };
32
+ ReactThreeFiberCompiler.prototype.registerEnum = function (name, members) {
33
+ };
32
34
  return ReactThreeFiberCompiler;
33
35
  }());
34
36
  exports.ReactThreeFiberCompiler = ReactThreeFiberCompiler;
@@ -0,0 +1,8 @@
1
+ /**@key is the typescript source file */
2
+ export declare type TypeSourceInformation = {
3
+ [key: string]: {
4
+ componentName: string;
5
+ filePath: string;
6
+ }[];
7
+ };
8
+ export declare function writeTypeRegistry(types: TypeSourceInformation, registerTypesPath: string): void;
@@ -0,0 +1,6 @@
1
+ import { IWriter } from "./base-compiler";
2
+ export declare class DirectoryWatcher {
3
+ private readonly compiler;
4
+ private _typesChanged;
5
+ startWatching(dir: string, writer: IWriter, registerTypesPath: string): void;
6
+ }
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DirectoryWatcher = void 0;
4
4
  var fs = require("fs");
5
5
  var base_compiler_1 = require("./base-compiler");
6
- var blender_compiler_1 = require("./blender-compiler");
6
+ var Compiler_1 = require("./Compiler");
7
+ var blender_compiler_1 = require("./impl/blender-compiler");
7
8
  var chokidar = require("chokidar");
8
9
  var commands_1 = require("./commands");
9
10
  var register_types_1 = require("./register-types");
10
11
  // https://github.com/paulmillr/chokidar
11
12
  var DirectoryWatcher = /** @class */ (function () {
12
13
  function DirectoryWatcher() {
13
- this.compiler = new base_compiler_1.Compiler();
14
+ this.compiler = new Compiler_1.Compiler();
14
15
  this._typesChanged = false;
15
16
  }
16
17
  DirectoryWatcher.prototype.startWatching = function (dir, writer, registerTypesPath) {
package/package.json CHANGED
@@ -1,17 +1,23 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "2.4.0-pre",
4
- "description": "Compile mock unity components from typescript",
5
- "main": "index.js",
3
+ "version": "3.0.0-alpha",
4
+ "description": "Compile Editor components for Needle Engine for C# and Blender",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "tsc": "tsc",
8
- "dev": "npm-watch compile || exit 1",
8
+ "dev": "npm-watch compile",
9
9
  "compile": "tsc",
10
- "test" : "npm run test:csharp & npm run test:blender",
11
- "test:csharp": "mocha -r ts-node/register test/csharp/**.test.ts",
12
- "test:blender": "mocha -r ts-node/register test/blender/**.test.ts",
10
+ "test": "npm run test:csharp && npm run test:blender",
11
+ "test:csharp": "mocha -r ts-node/register 'test/csharp/**/*.test.ts'",
12
+ "test:blender": "mocha -r ts-node/register 'test/blender/**/*.test.ts'",
13
13
  "test:single": "mocha"
14
14
  },
15
+ "files": [
16
+ "Readme.md",
17
+ "Changelog.md",
18
+ "package.json",
19
+ "dist/**/*"
20
+ ],
15
21
  "dependencies": {
16
22
  "chokidar": "^3.5.3",
17
23
  "typescript": "^4.5.5"
@@ -1,180 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlenderWriter = void 0;
4
- var fs_1 = require("fs");
5
- var base_compiler_1 = require("./base-compiler");
6
- var commands_1 = require("./commands");
7
- var supportedTypes = ["string", "float", "int", "bool", "col", "obj", "evt", "fn", "vec2", "vec3", "comp"];
8
- var knownBaseTypes = ["Behaviour", "IComponent"];
9
- var BlenderWriter = /** @class */ (function () {
10
- function BlenderWriter(_sink) {
11
- this._sink = _sink;
12
- this.writer = new base_compiler_1.CodeTextWriter();
13
- this._createdSchemesPerFile = {};
14
- this._currentlyProcessingFiles = {};
15
- }
16
- Object.defineProperty(BlenderWriter.prototype, "outputInfo", {
17
- get: function () {
18
- return this._createdSchemesPerFile;
19
- },
20
- enumerable: false,
21
- configurable: true
22
- });
23
- Object.defineProperty(BlenderWriter.prototype, "sink", {
24
- get: function () {
25
- return this._sink;
26
- },
27
- enumerable: false,
28
- configurable: true
29
- });
30
- BlenderWriter.prototype.resolveTypeName = function (typeName, comments) {
31
- typeName = typeName.toLocaleLowerCase();
32
- if (typeName.startsWith("three."))
33
- typeName = typeName.substring("three.".length);
34
- switch (typeName) {
35
- case "number":
36
- return "float";
37
- case "int":
38
- return "int";
39
- case "boolean":
40
- return "bool";
41
- case "string":
42
- return "string";
43
- case "void":
44
- return "void";
45
- case "vector2":
46
- return "vec2";
47
- case "vector3":
48
- return "vec3";
49
- case "vector4":
50
- return "vec4";
51
- case "quaternion":
52
- return "quat";
53
- case "euler":
54
- return "vec3";
55
- case "color":
56
- return "col";
57
- case "eventlist":
58
- return "evt";
59
- case "behaviour":
60
- return "comp";
61
- }
62
- return typeName;
63
- };
64
- BlenderWriter.prototype.begin = function (filePath) {
65
- if (!this._currentlyProcessingFiles[filePath]) {
66
- this._currentlyProcessingFiles[filePath] = [];
67
- }
68
- };
69
- BlenderWriter.prototype.end = function (filePath) {
70
- var results = this._currentlyProcessingFiles[filePath];
71
- console.log("Writing schemes for", filePath, results);
72
- if (results) {
73
- var previousResultsFromThisFile = this._createdSchemesPerFile[filePath];
74
- if (previousResultsFromThisFile) {
75
- for (var _i = 0, previousResultsFromThisFile_1 = previousResultsFromThisFile; _i < previousResultsFromThisFile_1.length; _i++) {
76
- var previouslyCreated = previousResultsFromThisFile_1[_i];
77
- var foundInAny = false;
78
- for (var _a = 0, results_1 = results; _a < results_1.length; _a++) {
79
- var res = results_1[_a];
80
- if (res.filePath === previouslyCreated.filePath) {
81
- foundInAny = true;
82
- break;
83
- }
84
- }
85
- if (!foundInAny) {
86
- for (var sourcePath in this._createdSchemesPerFile) {
87
- if (foundInAny)
88
- break;
89
- if (sourcePath === filePath)
90
- continue;
91
- var otherSourceSchemes = this._createdSchemesPerFile[sourcePath];
92
- if (otherSourceSchemes.includes(previouslyCreated)) {
93
- // the file was moved to another source file
94
- foundInAny = true;
95
- }
96
- }
97
- }
98
- if (!foundInAny && (0, fs_1.existsSync)(previouslyCreated.filePath)) {
99
- (0, fs_1.unlinkSync)(previouslyCreated.filePath);
100
- (0, commands_1.sendFileDeletedCommand)(previouslyCreated.filePath);
101
- }
102
- }
103
- }
104
- this._createdSchemesPerFile[filePath] = results;
105
- }
106
- delete this._currentlyProcessingFiles[filePath];
107
- };
108
- BlenderWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
109
- var isSupportedType = false;
110
- for (var i = 0; i < knownBaseTypes.length; i++) {
111
- if (baseTypes.includes(knownBaseTypes[i])) {
112
- isSupportedType = true;
113
- break;
114
- }
115
- }
116
- // console.log(baseTypes, knownBaseTypes, isSupportedType)
117
- if (!isSupportedType)
118
- return false;
119
- this.writer.beginBlock("{");
120
- if (comments)
121
- console.log(comments);
122
- this.writer.beginBlock("\"" + typeName + "\": {");
123
- };
124
- BlenderWriter.prototype.endNewType = function (filePath, typeName) {
125
- this.writer.endBlock("},");
126
- this.writer.endBlock("}");
127
- this.writeScheme(filePath, typeName);
128
- };
129
- BlenderWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
130
- if (visibility !== base_compiler_1.Visibility.Public)
131
- return;
132
- // if (!supportedTypes.includes(type)) {
133
- // console.log("-- unsupported type:", type);
134
- // return;
135
- // }
136
- this.writer.beginBlock("\"" + name + "\": {");
137
- this.writer.writeLine("\"type\": \"" + type + "\",");
138
- if (initialValue && !isArray) {
139
- if (initialValue.startsWith("new "))
140
- initialValue = undefined;
141
- switch (type) {
142
- case "bool":
143
- initialValue = initialValue.toLowerCase();
144
- break;
145
- case "string":
146
- initialValue = "\"" + initialValue + "\"";
147
- }
148
- if (initialValue)
149
- this.writer.writeLine("\"value\": " + initialValue);
150
- }
151
- if (isArray) {
152
- this.writer.writeLine("\"value\": []");
153
- }
154
- this.writer.endBlock("},");
155
- };
156
- BlenderWriter.prototype.writeMethod = function (visibility, name, returnType, args, comments) {
157
- if (visibility !== base_compiler_1.Visibility.Public)
158
- return;
159
- this.writer.beginBlock("\"" + name + "\": {");
160
- this.writer.writeLine("\"type\": \"fn\",");
161
- this.writer.endBlock("},");
162
- };
163
- BlenderWriter.prototype.writeNewTypeExpression = function (typeName, args) {
164
- console.log("new type:", typeName);
165
- };
166
- BlenderWriter.prototype.writeScheme = function (processingFilePath, component) {
167
- var res = this.sink.flush(component + ".component.json", this.writer.flush());
168
- // if an output path is returned it means a file has been written to that path
169
- if (res && (0, fs_1.existsSync)(res)) {
170
- (0, commands_1.sendFileWrittenCommand)(res);
171
- // add the scheme to the list of created schemes
172
- if (processingFilePath && this._currentlyProcessingFiles[processingFilePath]) {
173
- this._currentlyProcessingFiles[processingFilePath].push({ componentName: component, filePath: res });
174
- }
175
- }
176
- };
177
- return BlenderWriter;
178
- }());
179
- exports.BlenderWriter = BlenderWriter;
180
- // runFromFile(new BlenderWriter("dist"), "src\\test.ts");
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CSharpWriter = void 0;
4
- var fs_1 = require("fs");
5
- var path = require("path");
6
- var allowDebugLogs = false;
7
- var CSharpWriter = /** @class */ (function () {
8
- function CSharpWriter(_outputDir) {
9
- this._outputDir = _outputDir;
10
- }
11
- Object.defineProperty(CSharpWriter.prototype, "outputInfo", {
12
- get: function () {
13
- return this._outputInfo;
14
- },
15
- enumerable: false,
16
- configurable: true
17
- });
18
- CSharpWriter.prototype.resolveTypeName = function (typescriptTypeName) {
19
- if (this._typesFileContent === undefined) {
20
- this._typesFileContent = null;
21
- var filePath = path.dirname(__dirname) + "/src/types.json";
22
- if ((0, fs_1.existsSync)(filePath)) {
23
- if (allowDebugLogs)
24
- console.log("Reading types file");
25
- var content = (0, fs_1.readFileSync)(filePath, "utf8");
26
- this._typesFileContent = JSON.parse(content);
27
- }
28
- }
29
- if (this._typesFileContent) {
30
- var fullType = this._typesFileContent[typescriptTypeName];
31
- if (fullType && allowDebugLogs)
32
- console.log(fullType);
33
- return fullType;
34
- }
35
- return null;
36
- };
37
- CSharpWriter.prototype.begin = function (filePath) {
38
- };
39
- CSharpWriter.prototype.end = function (filePath) {
40
- };
41
- CSharpWriter.prototype.startNewType = function (filePath, typeName, baseType, comments) {
42
- throw new Error("Method not implemented.");
43
- };
44
- CSharpWriter.prototype.endNewType = function (filePath, typeName) {
45
- throw new Error("Method not implemented.");
46
- };
47
- CSharpWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
48
- throw new Error("Method not implemented.");
49
- };
50
- CSharpWriter.prototype.writeMethod = function (visibility, name, returnType, args, comments) {
51
- throw new Error("Method not implemented.");
52
- };
53
- CSharpWriter.prototype.writeNewTypeExpression = function (typeName, args) {
54
- throw new Error("Method not implemented.");
55
- };
56
- return CSharpWriter;
57
- }());
58
- exports.CSharpWriter = CSharpWriter;