@needle-tools/needle-component-compiler 2.4.0-pre → 3.0.0-68ab237
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 +183 -84
- package/Readme.md +134 -19
- package/dist/BaseWriter.d.ts +23 -0
- package/dist/BaseWriter.js +91 -0
- package/dist/Compiler.d.ts +22 -0
- package/{src/base-compiler.js → dist/Compiler.js} +461 -507
- package/dist/base-compiler.d.ts +56 -0
- package/dist/base-compiler.js +182 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +63 -0
- package/dist/commands.d.ts +3 -0
- package/{src → dist}/commands.js +15 -15
- package/dist/impl/blender-compiler.d.ts +14 -0
- package/dist/impl/blender-compiler.js +195 -0
- package/dist/impl/csharp-compiler.d.ts +16 -0
- package/dist/impl/csharp-compiler.js +307 -0
- package/dist/impl/react-three-fiber-compiler.d.ts +20 -0
- package/{src → dist/impl}/react-three-fiber-compiler.js +36 -34
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -0
- package/dist/register-types.d.ts +8 -0
- package/{src → dist}/register-types.js +34 -34
- package/dist/watcher.d.ts +6 -0
- package/{src → dist}/watcher.js +79 -78
- package/package.json +63 -49
- package/src/blender-compiler.js +0 -180
- package/src/component-compiler.js +0 -699
- 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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TypeSourceInformation } from "./register-types";
|
|
2
|
+
import { Compiler } from "./Compiler";
|
|
3
|
+
export declare enum Visibility {
|
|
4
|
+
Public = 0,
|
|
5
|
+
Protected = 1,
|
|
6
|
+
Private = 2
|
|
7
|
+
}
|
|
8
|
+
export declare type Argument = {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
};
|
|
13
|
+
export interface ISink {
|
|
14
|
+
flush(id: string, str: string): string;
|
|
15
|
+
}
|
|
16
|
+
export declare class FileSink implements ISink {
|
|
17
|
+
private directory;
|
|
18
|
+
private static readonly CODEGEN_START;
|
|
19
|
+
private static readonly CODEGEN_END;
|
|
20
|
+
constructor(directory: string);
|
|
21
|
+
flush(id: string, str: string): string;
|
|
22
|
+
}
|
|
23
|
+
export declare class MemorySink implements ISink {
|
|
24
|
+
results: string[];
|
|
25
|
+
clear(): void;
|
|
26
|
+
flush(id: string, str: string): string;
|
|
27
|
+
}
|
|
28
|
+
export declare class CodeTextWriter {
|
|
29
|
+
private indent;
|
|
30
|
+
private lines;
|
|
31
|
+
beginBlock(line: string): void;
|
|
32
|
+
endBlock(line: string): void;
|
|
33
|
+
writeLine(line: string): void;
|
|
34
|
+
write(text: string): void;
|
|
35
|
+
flush(): string;
|
|
36
|
+
clear(): void;
|
|
37
|
+
toString(): string;
|
|
38
|
+
}
|
|
39
|
+
export declare function handleDeletedFile(filePath: string, types: TypeSourceInformation): void;
|
|
40
|
+
export declare type EnumMember = {
|
|
41
|
+
name: string;
|
|
42
|
+
value: number | string;
|
|
43
|
+
};
|
|
44
|
+
export interface IWriter {
|
|
45
|
+
get outputInfo(): TypeSourceInformation;
|
|
46
|
+
begin(filePath: string | null): void;
|
|
47
|
+
resolveCSharpTypeName(typescriptTypeName: string, baseTypes?: string[]): string | void;
|
|
48
|
+
end(filePath: string | null): void;
|
|
49
|
+
startNewType(filePath: string | null, typeName: string, baseType: string[], comments?: string[]): void | boolean;
|
|
50
|
+
endNewType(filePath: string | null, typeName: string): void;
|
|
51
|
+
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
52
|
+
writeMethod(visibility: Visibility, name: string, returnType: string | undefined, args: Argument[], comments: string[]): void;
|
|
53
|
+
writeNewTypeExpression(typeName: string, args?: string[]): void;
|
|
54
|
+
registerEnum(name: string, members: EnumMember[]): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function runFromFile(writer: IWriter, path: string): Compiler;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runFromFile = exports.handleDeletedFile = exports.CodeTextWriter = exports.MemorySink = exports.FileSink = exports.Visibility = void 0;
|
|
4
|
+
var fs_1 = require("fs");
|
|
5
|
+
var fs = require("fs");
|
|
6
|
+
var commands_1 = require("./commands");
|
|
7
|
+
var Compiler_1 = require("./Compiler");
|
|
8
|
+
var Visibility;
|
|
9
|
+
(function (Visibility) {
|
|
10
|
+
Visibility[Visibility["Public"] = 0] = "Public";
|
|
11
|
+
Visibility[Visibility["Protected"] = 1] = "Protected";
|
|
12
|
+
Visibility[Visibility["Private"] = 2] = "Private";
|
|
13
|
+
})(Visibility = exports.Visibility || (exports.Visibility = {}));
|
|
14
|
+
var FileSink = /** @class */ (function () {
|
|
15
|
+
function FileSink(directory) {
|
|
16
|
+
this.directory = directory;
|
|
17
|
+
}
|
|
18
|
+
FileSink.prototype.flush = function (id, str) {
|
|
19
|
+
if (!fs.existsSync(this.directory)) {
|
|
20
|
+
fs.mkdirSync(this.directory, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
console.log("Writing " + id + " to " + this.directory);
|
|
23
|
+
var fullPath = this.directory + "/" + id;
|
|
24
|
+
// If the file already exists and contains codegen fences,
|
|
25
|
+
// preserve content outside the fences
|
|
26
|
+
if (fs.existsSync(fullPath)) {
|
|
27
|
+
var existing = fs.readFileSync(fullPath, "utf-8");
|
|
28
|
+
var startIdx = existing.indexOf(FileSink.CODEGEN_START);
|
|
29
|
+
var endIdx = existing.indexOf(FileSink.CODEGEN_END);
|
|
30
|
+
if (startIdx !== -1 && endIdx !== -1) {
|
|
31
|
+
var before_1 = existing.substring(0, startIdx);
|
|
32
|
+
var after_1 = existing.substring(endIdx + FileSink.CODEGEN_END.length);
|
|
33
|
+
str = before_1 + str + after_1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
fs.writeFileSync(fullPath, str);
|
|
37
|
+
return fs.realpathSync(fullPath);
|
|
38
|
+
};
|
|
39
|
+
FileSink.CODEGEN_START = "// NEEDLE_CODEGEN_START";
|
|
40
|
+
FileSink.CODEGEN_END = "// NEEDLE_CODEGEN_END";
|
|
41
|
+
return FileSink;
|
|
42
|
+
}());
|
|
43
|
+
exports.FileSink = FileSink;
|
|
44
|
+
var MemorySink = /** @class */ (function () {
|
|
45
|
+
function MemorySink() {
|
|
46
|
+
this.results = [];
|
|
47
|
+
}
|
|
48
|
+
MemorySink.prototype.clear = function () {
|
|
49
|
+
this.results.length = 0;
|
|
50
|
+
};
|
|
51
|
+
MemorySink.prototype.flush = function (id, str) {
|
|
52
|
+
this.results.push(str);
|
|
53
|
+
return "";
|
|
54
|
+
};
|
|
55
|
+
return MemorySink;
|
|
56
|
+
}());
|
|
57
|
+
exports.MemorySink = MemorySink;
|
|
58
|
+
var CodeTextWriter = /** @class */ (function () {
|
|
59
|
+
function CodeTextWriter() {
|
|
60
|
+
this.indent = 0;
|
|
61
|
+
this.lines = [];
|
|
62
|
+
}
|
|
63
|
+
CodeTextWriter.prototype.beginBlock = function (line) {
|
|
64
|
+
this.writeLine(line);
|
|
65
|
+
this.indent++;
|
|
66
|
+
};
|
|
67
|
+
CodeTextWriter.prototype.endBlock = function (line) {
|
|
68
|
+
// remove the comma from the last line
|
|
69
|
+
if (this.lines.length > 0) {
|
|
70
|
+
var prevLine = this.lines[this.lines.length - 1];
|
|
71
|
+
if (prevLine.endsWith(",")) {
|
|
72
|
+
this.lines[this.lines.length - 1] = prevLine.substring(0, prevLine.length - 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this.indent--;
|
|
76
|
+
this.writeLine(line);
|
|
77
|
+
};
|
|
78
|
+
CodeTextWriter.prototype.writeLine = function (line) {
|
|
79
|
+
var indent = "";
|
|
80
|
+
for (var i = 0; i < this.indent; i++) {
|
|
81
|
+
indent += "\t";
|
|
82
|
+
}
|
|
83
|
+
var lines = line.split(/\r?\n/);
|
|
84
|
+
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
|
|
85
|
+
var line_1 = lines_1[_i];
|
|
86
|
+
// remove whitespace so we can ensure we correctly end with a comma
|
|
87
|
+
this.lines.push(indent + (line_1 === null || line_1 === void 0 ? void 0 : line_1.trim()));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
CodeTextWriter.prototype.write = function (text) {
|
|
91
|
+
var lines = text.split(/\r?\n/);
|
|
92
|
+
if (lines.length > 1) {
|
|
93
|
+
for (var i = 0; i < lines.length; i++) {
|
|
94
|
+
this.writeLine(lines[i]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (this.lines.length == 0) {
|
|
99
|
+
this.writeLine(text);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
var lastLine = this.lines[this.lines.length - 1];
|
|
103
|
+
this.lines[this.lines.length - 1] = lastLine + text;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
// beginArray() {
|
|
108
|
+
// this.writeLine("[");
|
|
109
|
+
// this.indent++;
|
|
110
|
+
// }
|
|
111
|
+
// insertArrayItem(item: string) {
|
|
112
|
+
// this.writeLine(item + ",");
|
|
113
|
+
// }
|
|
114
|
+
// endArray() {
|
|
115
|
+
// }
|
|
116
|
+
CodeTextWriter.prototype.flush = function () {
|
|
117
|
+
var str = this.toString();
|
|
118
|
+
this.lines.length = 0;
|
|
119
|
+
return str;
|
|
120
|
+
// if (this.lines.length === 0) return;
|
|
121
|
+
// if (!fs.existsSync(directory)) {
|
|
122
|
+
// fs.mkdirSync(directory, { recursive: true });
|
|
123
|
+
// }
|
|
124
|
+
// console.log("Writing " + filename + " to " + directory);
|
|
125
|
+
// const content = this.toString();
|
|
126
|
+
// this.lines.length = 0;
|
|
127
|
+
// const fullPath = directory + "/" + filename;
|
|
128
|
+
// fs.writeFileSync(fullPath, content);
|
|
129
|
+
// return fs.realpathSync(fullPath);
|
|
130
|
+
};
|
|
131
|
+
CodeTextWriter.prototype.clear = function () {
|
|
132
|
+
this.lines.length = 0;
|
|
133
|
+
};
|
|
134
|
+
CodeTextWriter.prototype.toString = function () {
|
|
135
|
+
return this.lines.join("\n");
|
|
136
|
+
};
|
|
137
|
+
return CodeTextWriter;
|
|
138
|
+
}());
|
|
139
|
+
exports.CodeTextWriter = CodeTextWriter;
|
|
140
|
+
function handleDeletedFile(filePath, types) {
|
|
141
|
+
if (!fs.existsSync(filePath)) {
|
|
142
|
+
var infos = types[filePath];
|
|
143
|
+
if (!infos)
|
|
144
|
+
return;
|
|
145
|
+
for (var i = 0; i < infos.length; i++) {
|
|
146
|
+
var info = infos[i];
|
|
147
|
+
// check if the source file is in any other file
|
|
148
|
+
var found = false;
|
|
149
|
+
for (var otherSourceFile in types) {
|
|
150
|
+
if (otherSourceFile == filePath)
|
|
151
|
+
continue;
|
|
152
|
+
for (var _i = 0, _a = types[otherSourceFile]; _i < _a.length; _i++) {
|
|
153
|
+
var otherInfo = _a[_i];
|
|
154
|
+
if (otherInfo.filePath == info.filePath) {
|
|
155
|
+
found = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (found)
|
|
160
|
+
break;
|
|
161
|
+
if (fs.existsSync(info.filePath)) {
|
|
162
|
+
fs.rmSync(info.filePath);
|
|
163
|
+
(0, commands_1.sendFileDeletedCommand)(info.filePath);
|
|
164
|
+
infos.splice(i, 1);
|
|
165
|
+
i--;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.handleDeletedFile = handleDeletedFile;
|
|
172
|
+
function runFromFile(writer, path) {
|
|
173
|
+
if (!fs.existsSync(path)) {
|
|
174
|
+
console.error("File not found", path);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
var code = (0, fs_1.readFileSync)(path).toString();
|
|
178
|
+
var compiler = new Compiler_1.Compiler();
|
|
179
|
+
compiler.compile(writer, code, path);
|
|
180
|
+
return compiler;
|
|
181
|
+
}
|
|
182
|
+
exports.runFromFile = runFromFile;
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
var fs = require("fs");
|
|
5
|
+
var path = require("path");
|
|
6
|
+
var Compiler_1 = require("./Compiler");
|
|
7
|
+
var base_compiler_1 = require("./base-compiler");
|
|
8
|
+
var csharp_compiler_1 = require("./impl/csharp-compiler");
|
|
9
|
+
var blender_compiler_1 = require("./impl/blender-compiler");
|
|
10
|
+
var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf-8"));
|
|
11
|
+
var args = process.argv.slice(2);
|
|
12
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
13
|
+
console.log("needle-component-compiler v".concat(pkg.version));
|
|
14
|
+
process.exit(0);
|
|
15
|
+
}
|
|
16
|
+
if (args.includes("--help") || args.includes("-h") || args.length < 3) {
|
|
17
|
+
console.log("needle-component-compiler v".concat(pkg.version));
|
|
18
|
+
console.log("");
|
|
19
|
+
console.log("Usage: needle-component-compiler <target> <output_dir> <input_files...>");
|
|
20
|
+
console.log("");
|
|
21
|
+
console.log(" target csharp or blender");
|
|
22
|
+
console.log(" output_dir directory for generated files");
|
|
23
|
+
console.log(" input_files one or more .ts source files");
|
|
24
|
+
console.log("");
|
|
25
|
+
console.log("Flags:");
|
|
26
|
+
console.log(" --version, -v print version");
|
|
27
|
+
console.log(" --help, -h print this help");
|
|
28
|
+
if (args.length < 3 && !args.includes("--help") && !args.includes("-h")) {
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
var target = args[0];
|
|
34
|
+
var outputDir = args[1];
|
|
35
|
+
var inputFiles = args.slice(2);
|
|
36
|
+
if (target !== "csharp" && target !== "blender") {
|
|
37
|
+
console.error("Error: unknown target \"".concat(target, "\". Use \"csharp\" or \"blender\"."));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
console.log("needle-component-compiler v".concat(pkg.version));
|
|
41
|
+
var sink = new base_compiler_1.FileSink(outputDir);
|
|
42
|
+
var writer = target === "csharp" ? new csharp_compiler_1.CSharpWriter(sink) : new blender_compiler_1.BlenderWriter(sink);
|
|
43
|
+
var compiler = new Compiler_1.Compiler();
|
|
44
|
+
var hasErrors = false;
|
|
45
|
+
for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
|
|
46
|
+
var filePath = inputFiles_1[_i];
|
|
47
|
+
try {
|
|
48
|
+
if (!fs.existsSync(filePath)) {
|
|
49
|
+
console.error("Error: file not found: ".concat(filePath));
|
|
50
|
+
hasErrors = true;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
var code = fs.readFileSync(filePath, "utf-8");
|
|
54
|
+
compiler.compile(writer, code, filePath);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error("Error processing ".concat(filePath, ": ").concat(e));
|
|
58
|
+
hasErrors = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (hasErrors) {
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
package/{src → dist}/commands.js
RENAMED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendFileDeletedCommand = exports.sendFileWrittenCommand = exports.sendReloadCommand = void 0;
|
|
4
|
-
function sendReloadCommand() {
|
|
5
|
-
process.stdout.write("CMD:reload\r");
|
|
6
|
-
}
|
|
7
|
-
exports.sendReloadCommand = sendReloadCommand;
|
|
8
|
-
function sendFileWrittenCommand(path) {
|
|
9
|
-
process.stdout.write("CMD:writefile " + path + "\r");
|
|
10
|
-
}
|
|
11
|
-
exports.sendFileWrittenCommand = sendFileWrittenCommand;
|
|
12
|
-
function sendFileDeletedCommand(path) {
|
|
13
|
-
process.stdout.write("CMD:deletedfile " + path + "\r");
|
|
14
|
-
}
|
|
15
|
-
exports.sendFileDeletedCommand = sendFileDeletedCommand;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendFileDeletedCommand = exports.sendFileWrittenCommand = exports.sendReloadCommand = void 0;
|
|
4
|
+
function sendReloadCommand() {
|
|
5
|
+
process.stdout.write("CMD:reload\r");
|
|
6
|
+
}
|
|
7
|
+
exports.sendReloadCommand = sendReloadCommand;
|
|
8
|
+
function sendFileWrittenCommand(path) {
|
|
9
|
+
process.stdout.write("CMD:writefile " + path + "\r");
|
|
10
|
+
}
|
|
11
|
+
exports.sendFileWrittenCommand = sendFileWrittenCommand;
|
|
12
|
+
function sendFileDeletedCommand(path) {
|
|
13
|
+
process.stdout.write("CMD:deletedfile " + path + "\r");
|
|
14
|
+
}
|
|
15
|
+
exports.sendFileDeletedCommand = sendFileDeletedCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Visibility } from "../base-compiler";
|
|
2
|
+
import { BaseWriter } from "../BaseWriter";
|
|
3
|
+
export declare class BlenderWriter extends BaseWriter {
|
|
4
|
+
resolveCSharpTypeName(typeName: string, comments?: string[]): string | void;
|
|
5
|
+
startNewType(filePath: string | null, typeName: string, baseTypes: string[], comments?: string[]): void | boolean;
|
|
6
|
+
endNewType(filePath: string | null, typeName: string): void;
|
|
7
|
+
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
8
|
+
writeMethod(visibility: Visibility, name: string, returnType: string | undefined, args: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
}[], comments?: string[]): void;
|
|
13
|
+
writeNewTypeExpression(typeName: string, args?: string[]): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
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.BlenderWriter = void 0;
|
|
19
|
+
var base_compiler_1 = require("../base-compiler");
|
|
20
|
+
var BaseWriter_1 = require("../BaseWriter");
|
|
21
|
+
var supportedTypes = ["string", "float", "int", "bool", "col", "obj", "evt", "fn", "vec2", "vec3", "comp"];
|
|
22
|
+
var knownBaseTypes = ["Behaviour", "IComponent"];
|
|
23
|
+
var BlenderWriter = /** @class */ (function (_super) {
|
|
24
|
+
__extends(BlenderWriter, _super);
|
|
25
|
+
function BlenderWriter() {
|
|
26
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
}
|
|
28
|
+
BlenderWriter.prototype.resolveCSharpTypeName = function (typeName, comments) {
|
|
29
|
+
typeName = typeName.toLocaleLowerCase();
|
|
30
|
+
if (typeName.startsWith("three."))
|
|
31
|
+
typeName = typeName.substring("three.".length);
|
|
32
|
+
// If the type is a registered enum, return as-is so writeMember handles it
|
|
33
|
+
if (this._enumRegistry.has(typeName))
|
|
34
|
+
return typeName;
|
|
35
|
+
switch (typeName) {
|
|
36
|
+
case "number":
|
|
37
|
+
return "float";
|
|
38
|
+
case "int":
|
|
39
|
+
return "int";
|
|
40
|
+
case "boolean":
|
|
41
|
+
return "bool";
|
|
42
|
+
case "string":
|
|
43
|
+
return "string";
|
|
44
|
+
case "void":
|
|
45
|
+
return "void";
|
|
46
|
+
case "vector2":
|
|
47
|
+
return "vec2";
|
|
48
|
+
case "vector3":
|
|
49
|
+
return "vec3";
|
|
50
|
+
case "vector4":
|
|
51
|
+
return "vec4";
|
|
52
|
+
case "quaternion":
|
|
53
|
+
return "quat";
|
|
54
|
+
case "euler":
|
|
55
|
+
return "vec3";
|
|
56
|
+
case "color":
|
|
57
|
+
return "col";
|
|
58
|
+
case "eventlist":
|
|
59
|
+
return "evt";
|
|
60
|
+
case "behaviour":
|
|
61
|
+
case "animation": // Animation component ref
|
|
62
|
+
case "animator": // Animator component ref
|
|
63
|
+
case "camera":
|
|
64
|
+
case "light":
|
|
65
|
+
case "rigidbody":
|
|
66
|
+
case "renderer": // Renderer component ref
|
|
67
|
+
case "canvas": // Canvas component ref
|
|
68
|
+
case "charactercontroller": // CharacterController component ref
|
|
69
|
+
case "videoplayer": // VideoPlayer component ref
|
|
70
|
+
case "lookatconstraint": // LookAtConstraint component ref
|
|
71
|
+
return "comp";
|
|
72
|
+
case "texture":
|
|
73
|
+
return "tex";
|
|
74
|
+
case "image":
|
|
75
|
+
return "img";
|
|
76
|
+
case "object3d":
|
|
77
|
+
case "gameobject": // GameObject = scene object reference
|
|
78
|
+
return "obj";
|
|
79
|
+
case "vec2":
|
|
80
|
+
return "vec2";
|
|
81
|
+
case "material":
|
|
82
|
+
return "mat";
|
|
83
|
+
case "animationclip":
|
|
84
|
+
return "anim";
|
|
85
|
+
case "animatorcontroller":
|
|
86
|
+
return "animatorcontroller";
|
|
87
|
+
case "audioclip":
|
|
88
|
+
return "audioclip";
|
|
89
|
+
case "videoclip":
|
|
90
|
+
case "video":
|
|
91
|
+
return "videoclip";
|
|
92
|
+
case "assetreference":
|
|
93
|
+
case "asset":
|
|
94
|
+
return "assetreference";
|
|
95
|
+
case "mesh":
|
|
96
|
+
return "mesh";
|
|
97
|
+
case "timelineasset":
|
|
98
|
+
return "timeline";
|
|
99
|
+
}
|
|
100
|
+
return typeName;
|
|
101
|
+
};
|
|
102
|
+
BlenderWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
|
|
103
|
+
if (comments === null || comments === void 0 ? void 0 : comments.includes("@dont-generate-component"))
|
|
104
|
+
return false;
|
|
105
|
+
var isSupportedType = false;
|
|
106
|
+
for (var i = 0; i < knownBaseTypes.length; i++) {
|
|
107
|
+
if (baseTypes.includes(knownBaseTypes[i])) {
|
|
108
|
+
isSupportedType = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!isSupportedType)
|
|
113
|
+
return false;
|
|
114
|
+
this.writer.beginBlock("{");
|
|
115
|
+
this.writer.beginBlock("\"" + typeName + "\": {");
|
|
116
|
+
};
|
|
117
|
+
BlenderWriter.prototype.endNewType = function (filePath, typeName) {
|
|
118
|
+
this.writer.endBlock("},");
|
|
119
|
+
this.writer.endBlock("}");
|
|
120
|
+
this.writeScheme(filePath, typeName);
|
|
121
|
+
};
|
|
122
|
+
BlenderWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
|
|
123
|
+
if (visibility !== base_compiler_1.Visibility.Public)
|
|
124
|
+
return;
|
|
125
|
+
// @nonSerialized → skip entirely
|
|
126
|
+
if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
|
|
127
|
+
return;
|
|
128
|
+
// @type override
|
|
129
|
+
var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
|
|
130
|
+
if (typeOverride) {
|
|
131
|
+
type = typeOverride.substring("@type ".length).trim();
|
|
132
|
+
}
|
|
133
|
+
// Check if type is a registered TypeScript enum
|
|
134
|
+
var enumMembers = this._enumRegistry.get(type);
|
|
135
|
+
if (enumMembers && enumMembers.length > 0) {
|
|
136
|
+
this.writer.beginBlock("\"" + name + "\": {");
|
|
137
|
+
this.writer.writeLine("\"type\": \"enum\",");
|
|
138
|
+
// Resolve default value: try to match explicit initializer (e.g. "lighttype.spot")
|
|
139
|
+
var enumValue = enumMembers[0].value;
|
|
140
|
+
if (initialValue && initialValue.includes(".")) {
|
|
141
|
+
var memberKey_1 = initialValue.split(".").pop();
|
|
142
|
+
var found = enumMembers.find(function (m) { return m.name.toLowerCase() === memberKey_1; });
|
|
143
|
+
if (found !== undefined)
|
|
144
|
+
enumValue = found.value;
|
|
145
|
+
}
|
|
146
|
+
this.writer.writeLine("\"value\": " + JSON.stringify(enumValue) + ",");
|
|
147
|
+
var options = enumMembers.map(function (m) { return m.name; });
|
|
148
|
+
this.writer.writeLine("\"options\": " + JSON.stringify(options));
|
|
149
|
+
this.writer.endBlock("},");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// if (!supportedTypes.includes(type)) {
|
|
153
|
+
// console.log("-- unsupported type:", type);
|
|
154
|
+
// return;
|
|
155
|
+
// }
|
|
156
|
+
// @tooltip → description
|
|
157
|
+
var tooltipComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@tooltip "); });
|
|
158
|
+
var tooltip = tooltipComment ? tooltipComment.substring("@tooltip ".length).trim() : null;
|
|
159
|
+
this.writer.beginBlock("\"" + name + "\": {");
|
|
160
|
+
this.writer.writeLine("\"type\": \"" + type + "\",");
|
|
161
|
+
if (initialValue && !isArray) {
|
|
162
|
+
if (initialValue.startsWith("new "))
|
|
163
|
+
initialValue = undefined;
|
|
164
|
+
switch (type) {
|
|
165
|
+
case "bool":
|
|
166
|
+
initialValue = initialValue.toLowerCase();
|
|
167
|
+
break;
|
|
168
|
+
case "string":
|
|
169
|
+
initialValue = "\"" + initialValue + "\"";
|
|
170
|
+
}
|
|
171
|
+
if (initialValue)
|
|
172
|
+
this.writer.writeLine("\"value\": " + initialValue + ",");
|
|
173
|
+
}
|
|
174
|
+
if (isArray) {
|
|
175
|
+
this.writer.writeLine("\"value\": [],");
|
|
176
|
+
}
|
|
177
|
+
if (tooltip) {
|
|
178
|
+
this.writer.writeLine("\"description\": \"" + tooltip.replace(/"/g, "'") + "\"");
|
|
179
|
+
}
|
|
180
|
+
this.writer.endBlock("},");
|
|
181
|
+
};
|
|
182
|
+
BlenderWriter.prototype.writeMethod = function (visibility, name, returnType, args, comments) {
|
|
183
|
+
if (visibility !== base_compiler_1.Visibility.Public)
|
|
184
|
+
return;
|
|
185
|
+
this.writer.beginBlock("\"" + name + "\": {");
|
|
186
|
+
this.writer.writeLine("\"type\": \"fn\",");
|
|
187
|
+
this.writer.endBlock("},");
|
|
188
|
+
};
|
|
189
|
+
BlenderWriter.prototype.writeNewTypeExpression = function (typeName, args) {
|
|
190
|
+
console.log("new type:", typeName);
|
|
191
|
+
};
|
|
192
|
+
return BlenderWriter;
|
|
193
|
+
}(BaseWriter_1.BaseWriter));
|
|
194
|
+
exports.BlenderWriter = BlenderWriter;
|
|
195
|
+
// runFromFile(new BlenderWriter("dist"), "src\\test.ts");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Argument, Visibility } from "../base-compiler";
|
|
2
|
+
import { BaseWriter } from "../BaseWriter";
|
|
3
|
+
export declare class CSharpWriter extends BaseWriter {
|
|
4
|
+
resolveCSharpTypeName(typescriptTypeName: string): string | void;
|
|
5
|
+
startNewType(filePath: string, typeName: string, baseTypes: string[], comments?: string[]): boolean | void;
|
|
6
|
+
endNewType(filePath: string, typeName: string): void;
|
|
7
|
+
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
8
|
+
writeMethod(visibility: Visibility, name: string, returnType: string, args: Argument[], comments: string[]): void;
|
|
9
|
+
writeNewTypeExpression(typeName: string, args?: string[]): void;
|
|
10
|
+
/** Converts camelCase to PascalCase for method names */
|
|
11
|
+
private toPascalCase;
|
|
12
|
+
/** Resolve a "new Type(args)" expression: map TS types to C# qualified types */
|
|
13
|
+
private resolveNewExpression;
|
|
14
|
+
/** Override writeScheme to use .cs extension instead of .component.json */
|
|
15
|
+
protected writeCSharpScheme(processingFilePath: string | null, component: string): void;
|
|
16
|
+
}
|