@needle-tools/needle-component-compiler 2.4.1-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.
- package/dist/BaseWriter.d.ts +23 -0
- package/dist/BaseWriter.js +90 -0
- package/dist/Compiler.d.ts +20 -0
- package/{src/base-compiler.js → dist/Compiler.js} +99 -194
- package/dist/base-compiler.d.ts +54 -0
- package/dist/base-compiler.js +168 -0
- package/dist/commands.d.ts +3 -0
- package/dist/component-compiler.d.ts +3 -0
- package/{src → dist}/component-compiler.js +5 -0
- package/dist/impl/blender-compiler.d.ts +14 -0
- package/{src → dist/impl}/blender-compiler.js +69 -80
- package/dist/impl/csharp-compiler.d.ts +16 -0
- package/dist/impl/csharp-compiler.js +306 -0
- package/dist/impl/react-three-fiber-compiler.d.ts +20 -0
- package/{src → dist/impl}/react-three-fiber-compiler.js +3 -1
- package/dist/register-types.d.ts +8 -0
- package/dist/watcher.d.ts +6 -0
- package/{src → dist}/watcher.js +3 -2
- package/package.json +13 -7
- package/src/csharp-compiler.js +0 -58
- package/src/test.js +0 -194
- package/src/types.js +0 -51
- package/test/component.basic.test.js +0 -26
- package/test/component.methods.test.js +0 -82
- package/test/component.nonserialized.test.js +0 -20
- package/test/component.primitives.test.js +0 -47
- package/test/helpers.js +0 -54
- /package/{src → dist}/commands.js +0 -0
- /package/{src → dist}/register-types.js +0 -0
|
@@ -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.
|
|
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;
|
package/{src → dist}/watcher.js
RENAMED
|
@@ -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
|
|
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
|
|
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": "
|
|
4
|
-
"description": "Compile
|
|
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
|
|
8
|
+
"dev": "npm-watch compile",
|
|
9
9
|
"compile": "tsc",
|
|
10
|
-
"test"
|
|
11
|
-
"test:csharp": "mocha -r ts-node/register test/csharp
|
|
12
|
-
"test:blender": "mocha -r ts-node/register test/blender
|
|
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"
|
package/src/csharp-compiler.js
DELETED
|
@@ -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;
|
package/src/test.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
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
|
-
// }
|