@nanoforge-dev/schematics 2.2.1-beta.88f48da → 2.3.0
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 +472 -0
- package/README.md +12 -15
- package/dist/collection.json +8 -23
- package/dist/index.cjs +21 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/dist/libs/component/component.factory.d.ts +1 -3
- package/dist/libs/component/component.factory.d.ts.map +1 -1
- package/dist/libs/component/component.factory.js +2 -1
- package/dist/libs/component/component.factory.js.map +1 -1
- package/dist/libs/project/files/js/.dockerignore +5 -0
- package/dist/libs/project/files/js/Dockerfile +36 -0
- package/dist/libs/project/files/js/README.md +53 -0
- package/dist/libs/project/files/js/assets/__dot__gitkeep +0 -0
- package/dist/libs/project/files/js/jsconfig.json +36 -0
- package/dist/libs/project/files/js/nanoforge.config.js +10 -0
- package/dist/libs/project/files/js/package.json.template +24 -0
- package/dist/libs/project/files/js/pnpm-workspace.yaml.template +3 -0
- package/dist/libs/project/files/js/src/components/drawable-circle-2d.component.js +404 -0
- package/dist/libs/project/files/js/src/components/position-2d.component.js +42 -0
- package/dist/libs/project/files/js/src/main.js +43 -0
- package/dist/libs/project/files/js/src/systems/draw-2d.system.js +33 -0
- package/dist/libs/project/files/js/src/systems/move-2d.system.js +34 -0
- package/dist/libs/project/files/js/src/systems/position-sync.system.js +35 -0
- package/dist/libs/project/files/ts/.dockerignore +5 -0
- package/dist/libs/project/files/ts/Dockerfile +36 -0
- package/dist/libs/project/files/ts/README.md +53 -0
- package/dist/libs/project/files/ts/assets/__dot__gitkeep +0 -0
- package/dist/libs/project/files/ts/nanoforge.config.ts +5 -0
- package/dist/libs/project/files/ts/package.json.template +24 -0
- package/dist/libs/project/files/ts/pnpm-workspace.yaml.template +3 -0
- package/dist/libs/project/files/ts/src/components/drawable-circle-2d.component.ts +367 -0
- package/dist/libs/project/files/ts/src/components/position-2d.component.ts +35 -0
- package/dist/libs/project/files/ts/src/main.ts +39 -0
- package/dist/libs/project/files/ts/src/systems/draw-2d.system.ts +25 -0
- package/dist/libs/project/files/ts/src/systems/move-2d.system.ts +26 -0
- package/dist/libs/project/files/ts/src/systems/position-sync.system.ts +27 -0
- package/dist/libs/project/files/ts/tsconfig.json +42 -0
- package/dist/libs/project/project.factory.d.ts +64 -0
- package/dist/libs/project/project.factory.d.ts.map +1 -0
- package/dist/libs/project/project.factory.js +122 -0
- package/dist/libs/project/project.factory.js.map +1 -0
- package/dist/libs/project/schema.json +83 -0
- package/dist/libs/system/system.factory.d.ts +1 -3
- package/dist/libs/system/system.factory.d.ts.map +1 -1
- package/dist/libs/system/system.factory.js +2 -1
- package/dist/libs/system/system.factory.js.map +1 -1
- package/dist/libs/workspace/files/js/.dockerignore +5 -0
- package/dist/libs/workspace/files/js/Dockerfile +36 -0
- package/dist/libs/workspace/files/js/README.md +51 -0
- package/dist/libs/workspace/files/js/__dot__gitignore +137 -0
- package/dist/libs/{application → workspace}/files/js/jsconfig.json +1 -2
- package/dist/libs/workspace/files/js/nanoforge.config.js +6 -0
- package/dist/libs/workspace/files/js/package.json.template +19 -0
- package/dist/libs/workspace/files/js/pnpm-workspace.yaml.template +6 -0
- package/dist/libs/workspace/files/ts/.dockerignore +5 -0
- package/dist/libs/workspace/files/ts/Dockerfile +36 -0
- package/dist/libs/workspace/files/ts/README.md +51 -0
- package/dist/libs/workspace/files/ts/__dot__gitignore +134 -0
- package/dist/libs/workspace/files/ts/nanoforge.config.ts +6 -0
- package/dist/libs/workspace/files/ts/package.json.template +20 -0
- package/dist/libs/workspace/files/ts/pnpm-workspace.yaml.template +6 -0
- package/dist/libs/{application → workspace}/files/ts/tsconfig.json +1 -2
- package/dist/libs/workspace/schema.json +45 -0
- package/dist/libs/workspace/workspace.factory.d.ts +42 -0
- package/dist/libs/workspace/workspace.factory.d.ts.map +1 -0
- package/dist/libs/workspace/workspace.factory.js +116 -0
- package/dist/libs/workspace/workspace.factory.js.map +1 -0
- package/package.json +23 -21
- package/dist/libs/application/application.factory.d.ts +0 -59
- package/dist/libs/application/application.factory.d.ts.map +0 -1
- package/dist/libs/application/application.factory.js +0 -57
- package/dist/libs/application/application.factory.js.map +0 -1
- package/dist/libs/application/files/js/.prettierignore +0 -8
- package/dist/libs/application/files/js/README.md +0 -166
- package/dist/libs/application/files/js/eslint.config.js +0 -11
- package/dist/libs/application/files/js/package.json.template +0 -48
- package/dist/libs/application/files/js/pnpm-workspace.yaml.template +0 -3
- package/dist/libs/application/files/js/prettier.config.js +0 -6
- package/dist/libs/application/files/ts/.prettierignore +0 -8
- package/dist/libs/application/files/ts/README.md +0 -166
- package/dist/libs/application/files/ts/eslint.config.js +0 -15
- package/dist/libs/application/files/ts/package.json.template +0 -52
- package/dist/libs/application/files/ts/pnpm-workspace.yaml.template +0 -3
- package/dist/libs/application/files/ts/prettier.config.js +0 -6
- package/dist/libs/application/schema.json +0 -70
- package/dist/libs/configuration/configuration.factory.d.ts +0 -31
- package/dist/libs/configuration/configuration.factory.d.ts.map +0 -1
- package/dist/libs/configuration/configuration.factory.js +0 -97
- package/dist/libs/configuration/configuration.factory.js.map +0 -1
- package/dist/libs/configuration/files/nanoforge.config.json +0 -1
- package/dist/libs/configuration/schema.json +0 -34
- package/dist/libs/docker/docker.factory.d.ts +0 -19
- package/dist/libs/docker/docker.factory.d.ts.map +0 -1
- package/dist/libs/docker/docker.factory.js +0 -20
- package/dist/libs/docker/docker.factory.js.map +0 -1
- package/dist/libs/docker/files/.dockerignore +0 -1
- package/dist/libs/docker/files/Dockerfile +0 -25
- package/dist/libs/docker/schema.json +0 -19
- package/dist/libs/part-base/files/js/__nanoforgeFolder__/client.save.json +0 -77
- package/dist/libs/part-base/files/js/__nanoforgeFolder__/server.save.json +0 -49
- package/dist/libs/part-base/files/js/__part__/components/example.component.js +0 -72
- package/dist/libs/part-base/files/js/__part__/init/after-init.js +0 -12
- package/dist/libs/part-base/files/js/__part__/init/after-registry-init.js +0 -14
- package/dist/libs/part-base/files/js/__part__/init/after-run.js +0 -12
- package/dist/libs/part-base/files/js/__part__/init/before-init.js +0 -13
- package/dist/libs/part-base/files/js/__part__/init/before-registry-init.js +0 -14
- package/dist/libs/part-base/files/js/__part__/init/before-run.js +0 -12
- package/dist/libs/part-base/files/js/__part__/systems/example.system.js +0 -44
- package/dist/libs/part-base/files/ts/__nanoforgeFolder__/client.save.json +0 -77
- package/dist/libs/part-base/files/ts/__nanoforgeFolder__/server.save.json +0 -49
- package/dist/libs/part-base/files/ts/__part__/components/example.component.ts +0 -55
- package/dist/libs/part-base/files/ts/__part__/init/after-init.ts +0 -5
- package/dist/libs/part-base/files/ts/__part__/init/after-registry-init.ts +0 -6
- package/dist/libs/part-base/files/ts/__part__/init/after-run.ts +0 -5
- package/dist/libs/part-base/files/ts/__part__/init/before-init.ts +0 -5
- package/dist/libs/part-base/files/ts/__part__/init/before-registry-init.ts +0 -6
- package/dist/libs/part-base/files/ts/__part__/init/before-run.ts +0 -5
- package/dist/libs/part-base/files/ts/__part__/systems/example.system.ts +0 -31
- package/dist/libs/part-base/part-base.factory.d.ts +0 -31
- package/dist/libs/part-base/part-base.factory.d.ts.map +0 -1
- package/dist/libs/part-base/part-base.factory.js +0 -33
- package/dist/libs/part-base/part-base.factory.js.map +0 -1
- package/dist/libs/part-base/schema.json +0 -35
- package/dist/libs/part-main/part-main.factory.d.ts +0 -39
- package/dist/libs/part-main/part-main.factory.d.ts.map +0 -1
- package/dist/libs/part-main/part-main.factory.js +0 -252
- package/dist/libs/part-main/part-main.factory.js.map +0 -1
- package/dist/libs/part-main/schema.json +0 -43
- /package/dist/libs/{application → project}/files/js/__dot__gitignore +0 -0
- /package/dist/libs/{application → project}/files/ts/__dot__gitignore +0 -0
- /package/dist/libs/{application → workspace}/files/js/__dot__env +0 -0
- /package/dist/libs/{application → workspace}/files/ts/__dot__env +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"libraries": [
|
|
3
|
-
{
|
|
4
|
-
"id": "assetManagerLibrary",
|
|
5
|
-
"type": "asset-manager",
|
|
6
|
-
"name": "AssetManagerLibrary",
|
|
7
|
-
"path": "@nanoforge-dev/asset-manager",
|
|
8
|
-
"params": []
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"id": "ecsLibrary",
|
|
12
|
-
"type": "component-system",
|
|
13
|
-
"name": "ECSServerLibrary",
|
|
14
|
-
"path": "@nanoforge-dev/ecs-server",
|
|
15
|
-
"params": []
|
|
16
|
-
}<% if (server) { %>,
|
|
17
|
-
{
|
|
18
|
-
"id": "networkLibrary",
|
|
19
|
-
"type": "network",
|
|
20
|
-
"name": "NetworkServerLibrary",
|
|
21
|
-
"path": "@nanoforge-dev/network-server",
|
|
22
|
-
"params": []
|
|
23
|
-
}<% } %>
|
|
24
|
-
],
|
|
25
|
-
"components": [
|
|
26
|
-
{
|
|
27
|
-
"name": "ExampleComponent",
|
|
28
|
-
"path": "./components/example.component.ts",
|
|
29
|
-
"paramsNames": ["paramA", "paramB", "paramC"]
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
"systems": [
|
|
33
|
-
{
|
|
34
|
-
"name": "exampleSystem",
|
|
35
|
-
"path": "./systems/example.system.ts"
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"entities": [
|
|
39
|
-
{
|
|
40
|
-
"id": "exampleEntity",
|
|
41
|
-
"components": {
|
|
42
|
-
"ExampleComponent": {
|
|
43
|
-
"paramA": "example",
|
|
44
|
-
"paramB": 10
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { type EditorComponentManifest } from "@nanoforge-dev/ecs-<%= part %>";
|
|
2
|
-
|
|
3
|
-
export class ExampleComponent {
|
|
4
|
-
name = this.constructor.name;
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
public paramA: string,
|
|
8
|
-
public paramB: number,
|
|
9
|
-
public paramC: boolean = false,
|
|
10
|
-
) {}
|
|
11
|
-
|
|
12
|
-
get foo() {
|
|
13
|
-
return "bar";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get paramAOrDefault() {
|
|
17
|
-
return this.paramC ? this.paramA : "default";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
addOne() {
|
|
21
|
-
this.paramB += 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// * Required to generate code
|
|
26
|
-
export default ExampleComponent.name;
|
|
27
|
-
|
|
28
|
-
// * Required for the editor to display the component and generate code
|
|
29
|
-
export const EDITOR_COMPONENT_MANIFEST: EditorComponentManifest = {
|
|
30
|
-
name: "Example",
|
|
31
|
-
description: "Example component description",
|
|
32
|
-
params: [
|
|
33
|
-
{
|
|
34
|
-
type: "string",
|
|
35
|
-
name: "paramA",
|
|
36
|
-
description: "Param A description",
|
|
37
|
-
example: "Example value",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: "number",
|
|
41
|
-
name: "paramB",
|
|
42
|
-
description: "Param B description",
|
|
43
|
-
example: 3,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: "boolean",
|
|
47
|
-
name: "paramC",
|
|
48
|
-
description: "Param C description",
|
|
49
|
-
example: true,
|
|
50
|
-
default: false,
|
|
51
|
-
// Not required because it has a default value
|
|
52
|
-
optional: true,
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type <%= appClass %> } from "@nanoforge-dev/core";
|
|
2
|
-
import { type Registry } from "@nanoforge-dev/ecs";
|
|
3
|
-
|
|
4
|
-
export async function afterRegistryInit(app: <%= appClass %>, registry: Registry) {
|
|
5
|
-
// Actions after registry components, entities and systems initialization
|
|
6
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type <%= appClass %> } from "@nanoforge-dev/core";
|
|
2
|
-
import { type Registry } from "@nanoforge-dev/ecs";
|
|
3
|
-
|
|
4
|
-
export async function beforeRegistryInit(app: <%= appClass %>, registry: Registry) {
|
|
5
|
-
// Actions before registry components, entities and systems initialization
|
|
6
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type Context } from "@nanoforge-dev/common";
|
|
2
|
-
import { type EditorSystemManifest, type Registry } from "@nanoforge-dev/ecs-<%= part %>";
|
|
3
|
-
|
|
4
|
-
import { ExampleComponent } from "../components/example.component";
|
|
5
|
-
|
|
6
|
-
export const exampleSystem = (registry: Registry, ctx: Context) => {
|
|
7
|
-
const entities = registry.getZipper([ExampleComponent]);
|
|
8
|
-
|
|
9
|
-
entities.forEach((entity) => {
|
|
10
|
-
if (entity.ExampleComponent.paramA === "end") {
|
|
11
|
-
ctx.app.setIsRunning(false);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (entity.ExampleComponent.paramB === 0) entity.ExampleComponent.paramA = "end";
|
|
16
|
-
|
|
17
|
-
if (entity.ExampleComponent.paramB >= 0)
|
|
18
|
-
entity.ExampleComponent.paramB = entity.ExampleComponent.paramB - 1;
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// * Required to generate code
|
|
23
|
-
export default exampleSystem.name;
|
|
24
|
-
|
|
25
|
-
// * Required for the editor to display the system and generate code
|
|
26
|
-
export const EDITOR_SYSTEM_MANIFEST: EditorSystemManifest = {
|
|
27
|
-
name: "Example",
|
|
28
|
-
description:
|
|
29
|
-
"This system end the game when paramB reaches 0 for any entity with ExampleComponent",
|
|
30
|
-
dependencies: ["ExampleComponent"],
|
|
31
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Rule } from "@angular-devkit/schematics";
|
|
2
|
-
|
|
3
|
-
//#region src/libs/part-base/part-base.schema.d.ts
|
|
4
|
-
interface PartBaseSchema {
|
|
5
|
-
/**
|
|
6
|
-
* NanoForge application destination directory
|
|
7
|
-
*/
|
|
8
|
-
directory: string;
|
|
9
|
-
/**
|
|
10
|
-
* The part of the application to generate
|
|
11
|
-
*/
|
|
12
|
-
part: "client" | "server";
|
|
13
|
-
/**
|
|
14
|
-
* NanoForge Application language
|
|
15
|
-
*/
|
|
16
|
-
language: "js" | "ts";
|
|
17
|
-
/**
|
|
18
|
-
* Add init functions to the application
|
|
19
|
-
*/
|
|
20
|
-
initFunctions: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Configure a server for the application
|
|
23
|
-
*/
|
|
24
|
-
server: boolean;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/libs/part-base/part-base.factory.d.ts
|
|
28
|
-
declare const main: (schema: PartBaseSchema) => Rule;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { main };
|
|
31
|
-
//# sourceMappingURL=part-base.factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"part-base.factory.d.ts","names":["directory","part","language","initFunctions","server"],"sources":["../../../src/libs/part-base/part-base.schema.d.ts","../../../src/libs/part-base/part-base.factory.ts"],"mappings":";;;UAAiB,cAAA;;;AAAjB;EAIEA,SAAAA;EAJ6B;;;EAS7BC,IAAAA;EAeAG;;AAAM;EAVNF,QAAAA;;ACgCF;;ED3BEC,aAAAA;EC2B2B;;;EDtB3BC,MAAAA;AAAAA;;;cCsBW,IAAA,GAAQ,MAAA,EAAQ,cAAA,KAAiB,IAI7C"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { join, normalize, strings } from "@angular-devkit/core";
|
|
2
|
-
import { apply, filter, mergeWith, move, template, url } from "@angular-devkit/schematics";
|
|
3
|
-
//#region src/libs/part-base/part-base.factory.ts
|
|
4
|
-
const transform = (schema) => {
|
|
5
|
-
return {
|
|
6
|
-
part: schema.part,
|
|
7
|
-
server: schema.server,
|
|
8
|
-
appClass: schema.part === "client" ? "NanoforgeClient" : "NanoforgeServer",
|
|
9
|
-
nanoforgeFolder: ".nanoforge"
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
const generate = (options, path, initFunctions, language) => {
|
|
13
|
-
const rules = [
|
|
14
|
-
template({
|
|
15
|
-
...strings,
|
|
16
|
-
...options
|
|
17
|
-
}),
|
|
18
|
-
move(normalize(path)),
|
|
19
|
-
filter((path) => {
|
|
20
|
-
const splited = path.split("/");
|
|
21
|
-
return splited.at(-2) !== ".nanoforge" || splited.at(-1) === `${options.part}.save.json`;
|
|
22
|
-
})
|
|
23
|
-
];
|
|
24
|
-
if (!initFunctions) rules.push(filter((path) => path.split("/").at(-2) !== "init"));
|
|
25
|
-
return apply(url(join("./files", language)), rules);
|
|
26
|
-
};
|
|
27
|
-
const main = (schema) => {
|
|
28
|
-
return mergeWith(generate(transform(schema), schema.directory, schema.initFunctions, schema.language));
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
export { main };
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=part-base.factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"part-base.factory.js","names":[],"sources":["../../../src/libs/part-base/part-base.factory.ts"],"sourcesContent":["import { type Path, join, normalize, strings } from \"@angular-devkit/core\";\nimport {\n type Rule,\n type Source,\n apply,\n filter,\n mergeWith,\n move,\n template,\n url,\n} from \"@angular-devkit/schematics\";\n\nimport { type PartBaseOptions } from \"./part-base.options\";\nimport { type PartBaseSchema } from \"./part-base.schema\";\n\nconst transform = (schema: PartBaseSchema): PartBaseOptions => {\n return {\n part: schema.part,\n server: schema.server,\n appClass: schema.part === \"client\" ? \"NanoforgeClient\" : \"NanoforgeServer\",\n nanoforgeFolder: \".nanoforge\",\n };\n};\n\nconst generate = (\n options: PartBaseOptions,\n path: string,\n initFunctions: boolean,\n language: \"ts\" | \"js\",\n): Source => {\n const rules = [\n template({\n ...strings,\n ...options,\n }),\n move(normalize(path)),\n filter((path) => {\n const splited = path.split(\"/\");\n return splited.at(-2) !== \".nanoforge\" || splited.at(-1) === `${options.part}.save.json`;\n }),\n ];\n if (!initFunctions) rules.push(filter((path) => path.split(\"/\").at(-2) !== \"init\"));\n\n return apply(url(join(\"./files\" as Path, language)), rules);\n};\n\nexport const main = (schema: PartBaseSchema): Rule => {\n const options = transform(schema);\n\n return mergeWith(generate(options, schema.directory, schema.initFunctions, schema.language));\n};\n"],"mappings":";;;AAeA,MAAM,aAAa,WAA4C;CAC7D,OAAO;EACL,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,UAAU,OAAO,SAAS,WAAW,oBAAoB;EACzD,iBAAiB;CACnB;AACF;AAEA,MAAM,YACJ,SACA,MACA,eACA,aACW;CACX,MAAM,QAAQ;EACZ,SAAS;GACP,GAAG;GACH,GAAG;EACL,CAAC;EACD,KAAK,UAAU,IAAI,CAAC;EACpB,QAAQ,SAAS;GACf,MAAM,UAAU,KAAK,MAAM,GAAG;GAC9B,OAAO,QAAQ,GAAG,EAAE,MAAM,gBAAgB,QAAQ,GAAG,EAAE,MAAM,GAAG,QAAQ,KAAK;EAC/E,CAAC;CACH;CACA,IAAI,CAAC,eAAe,MAAM,KAAK,QAAQ,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;CAElF,OAAO,MAAM,IAAI,KAAK,WAAmB,QAAQ,CAAC,GAAG,KAAK;AAC5D;AAEA,MAAa,QAAQ,WAAiC;CAGpD,OAAO,UAAU,SAFD,UAAU,MAEA,GAAS,OAAO,WAAW,OAAO,eAAe,OAAO,QAAQ,CAAC;AAC7F"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$id": "SchematicsNanoForgePartBase",
|
|
4
|
-
"title": "NanoForge Part Base Options Schema",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
"directory": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "NanoForge application destination directory",
|
|
10
|
-
"default": "."
|
|
11
|
-
},
|
|
12
|
-
"part": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"enum": ["client", "server"],
|
|
15
|
-
"description": "The part of the application to generate"
|
|
16
|
-
},
|
|
17
|
-
"language": {
|
|
18
|
-
"type": "string",
|
|
19
|
-
"enum": ["ts", "js"],
|
|
20
|
-
"description": "NanoForge application language",
|
|
21
|
-
"default": "ts"
|
|
22
|
-
},
|
|
23
|
-
"initFunctions": {
|
|
24
|
-
"type": "boolean",
|
|
25
|
-
"description": "Add init functions to the application",
|
|
26
|
-
"default": false
|
|
27
|
-
},
|
|
28
|
-
"server": {
|
|
29
|
-
"type": "boolean",
|
|
30
|
-
"description": "There is a Server in app",
|
|
31
|
-
"default": false
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"required": ["part"]
|
|
35
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Rule } from "@angular-devkit/schematics";
|
|
2
|
-
|
|
3
|
-
//#region src/libs/part-main/part-main.schema.d.ts
|
|
4
|
-
interface PartMainSchema {
|
|
5
|
-
/**
|
|
6
|
-
* NanoForge application destination directory
|
|
7
|
-
*/
|
|
8
|
-
directory: string;
|
|
9
|
-
/**
|
|
10
|
-
* The part of the application to generate
|
|
11
|
-
*/
|
|
12
|
-
part: "client" | "server";
|
|
13
|
-
/**
|
|
14
|
-
* NanoForge Application language
|
|
15
|
-
*/
|
|
16
|
-
language: "js" | "ts";
|
|
17
|
-
/**
|
|
18
|
-
* Add init functions to the application
|
|
19
|
-
*/
|
|
20
|
-
initFunctions: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Save file path with components and systems in JSON format
|
|
23
|
-
*/
|
|
24
|
-
saveFile?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Path of the out file
|
|
27
|
-
*/
|
|
28
|
-
outFile?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Build main editor
|
|
31
|
-
*/
|
|
32
|
-
editor: boolean;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/libs/part-main/part-main.factory.d.ts
|
|
36
|
-
declare const main: (schema: PartMainSchema) => Rule;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { main };
|
|
39
|
-
//# sourceMappingURL=part-main.factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"part-main.factory.d.ts","names":["directory","part","language","initFunctions","saveFile","outFile","editor"],"sources":["../../../src/libs/part-main/part-main.schema.d.ts","../../../src/libs/part-main/part-main.factory.ts"],"mappings":";;;UAAiB,cAAA;;;AAAjB;EAIEA,SAAAA;EAJ6B;;;EAS7BC,IAAAA;EAeAG;;;EAVAF,QAAAA;;;;EAKAC,aAAAA;;;;EAKAC,QAAAA;EC2DD;AAAA;;EDtDCC,OAAAA;;;;EAKAC,MAAAA;AAAAA;;;cC6CW,IAAA,GAAQ,MAAA,EAAQ,cAAA,KAAiB,IAI7C"}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { join, normalize, strings } from "@angular-devkit/core";
|
|
2
|
-
import { apply, asSource, mergeWith, move, template } from "@angular-devkit/schematics";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { join as join$1 } from "path";
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/utils/path.ts
|
|
7
|
-
const joinRelative = (...paths) => {
|
|
8
|
-
const path = join$1(...paths);
|
|
9
|
-
return path.startsWith("./") || path.startsWith("../") ? path : `./${path}`;
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/utils/main/const.ts
|
|
13
|
-
const LIBS_FUNCTIONS_NAME = {
|
|
14
|
-
["asset-manager"]: "useAssetManager",
|
|
15
|
-
["component-system"]: "useComponentSystem",
|
|
16
|
-
["graphics"]: "useGraphics",
|
|
17
|
-
["input"]: "useInput",
|
|
18
|
-
["network"]: "useNetwork",
|
|
19
|
-
["sound"]: "useSound"
|
|
20
|
-
};
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/utils/main/main-utils.ts
|
|
23
|
-
const getStringParam = (value) => {
|
|
24
|
-
if (typeof value === "string") return `"${value}"`;
|
|
25
|
-
if (typeof value === "number") return value.toString();
|
|
26
|
-
if (typeof value === "boolean") return value ? "true" : "false";
|
|
27
|
-
if (typeof value === "object") return JSON.stringify(value);
|
|
28
|
-
return "undefined";
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/utils/main/main.generator.ts
|
|
32
|
-
var MainGenerator = class {
|
|
33
|
-
buffer = "";
|
|
34
|
-
indentation = 0;
|
|
35
|
-
editor;
|
|
36
|
-
pathToRoot;
|
|
37
|
-
constructor(editor = false, pathToRoot = "") {
|
|
38
|
-
this.editor = editor;
|
|
39
|
-
this.pathToRoot = pathToRoot;
|
|
40
|
-
}
|
|
41
|
-
toString() {
|
|
42
|
-
return this.buffer;
|
|
43
|
-
}
|
|
44
|
-
generateBaseImports(hasTypes) {
|
|
45
|
-
if (this.editor) if (hasTypes) this.writeLine(`import { type IEditorRunOptions, NanoforgeFactory } from "@nanoforge-dev/core-editor";`);
|
|
46
|
-
else this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core-editor";`);
|
|
47
|
-
else {
|
|
48
|
-
if (hasTypes) this.writeLine(`import { type IRunOptions } from "@nanoforge-dev/common";`);
|
|
49
|
-
this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core";`);
|
|
50
|
-
}
|
|
51
|
-
this.endSection();
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
generateLibsImports(libs) {
|
|
55
|
-
return this.generateImports(libs, false);
|
|
56
|
-
}
|
|
57
|
-
generateComponentsImports(libs) {
|
|
58
|
-
return this.generateImports(libs, true);
|
|
59
|
-
}
|
|
60
|
-
generateSystemsImports(libs) {
|
|
61
|
-
return this.generateImports(libs, true);
|
|
62
|
-
}
|
|
63
|
-
generateMainFunction(hasTypes, cb) {
|
|
64
|
-
if (this.editor) this.writeLine(`export async function main(options${hasTypes ? ": IEditorRunOptions" : ""}) {`);
|
|
65
|
-
else this.writeLine(`export async function main(options${hasTypes ? ": IRunOptions" : ""}) {`);
|
|
66
|
-
this.indentation += 1;
|
|
67
|
-
cb(this);
|
|
68
|
-
this.indentation -= 1;
|
|
69
|
-
this.writeLine("}");
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
generateApp(isServer) {
|
|
73
|
-
this.writeLine(`const app = NanoforgeFactory.create${isServer ? "Server" : "Client"}();`);
|
|
74
|
-
this.endSection();
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
generateAppInit() {
|
|
78
|
-
this.writeLine(`await app.init(options);`);
|
|
79
|
-
this.endSection();
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
generateAppRun(hasInitFunctions) {
|
|
83
|
-
this.writeLine(`await app.run();`);
|
|
84
|
-
if (hasInitFunctions) this.endSection();
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
generateLibsInstances(libs) {
|
|
88
|
-
libs.forEach(({ id, name }) => this.writeLine(`const ${id} = new ${name}();`));
|
|
89
|
-
this.endSection();
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
generateLibsInit(libs) {
|
|
93
|
-
libs.forEach(({ id, type }) => this.writeLine(this.getInitFunction(id, type)));
|
|
94
|
-
this.endSection();
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
generateRegistry(libs) {
|
|
98
|
-
const libName = libs.find((lib) => lib.type === "component-system")?.id ?? "ecsLibrary";
|
|
99
|
-
this.writeLine(`const registry = ${libName}.registry;`);
|
|
100
|
-
this.endSection();
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
generateEntities(libs, components, entities) {
|
|
104
|
-
entities.forEach((entity, index) => this.generateEntity(libs, components, entity, index));
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
generateSystems(systems) {
|
|
108
|
-
systems.forEach(({ name }) => this.writeLine(`registry.addSystem(${name});`));
|
|
109
|
-
this.endSection();
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
generateInitFunctionIfNeeded(needed, func) {
|
|
113
|
-
if (needed) return this.generateInitFunction(func);
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
generateInitFunctionsImportsIfNeeded(needed) {
|
|
117
|
-
if (!needed) return this;
|
|
118
|
-
return this.generateImports([
|
|
119
|
-
{
|
|
120
|
-
name: "afterInit",
|
|
121
|
-
path: "./init/after-init"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: "afterRegistryInit",
|
|
125
|
-
path: "./init/after-registry-init"
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: "afterRun",
|
|
129
|
-
path: "./init/after-run"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: "beforeInit",
|
|
133
|
-
path: "./init/before-init"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: "beforeRegistryInit",
|
|
137
|
-
path: "./init/before-registry-init"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: "beforeRun",
|
|
141
|
-
path: "./init/before-run"
|
|
142
|
-
}
|
|
143
|
-
], true);
|
|
144
|
-
}
|
|
145
|
-
generateInitFunction(func) {
|
|
146
|
-
const params = ["app"];
|
|
147
|
-
if (["beforeRegistryInit", "afterRegistryInit"].includes(func)) params.push("registry");
|
|
148
|
-
this.writeLine(`await ${func}(${params.join(", ")});`);
|
|
149
|
-
if (func !== "afterRun") this.endSection();
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
generateImports(els, relative) {
|
|
153
|
-
[...els].sort((a, b) => a.path.localeCompare(b.path)).forEach(({ name, path }) => {
|
|
154
|
-
path = path.replace(/\.(?:ts|js)$/, "");
|
|
155
|
-
this.writeLine(`import { ${name} } from "${relative ? joinRelative(this.pathToRoot, path) : path}";`);
|
|
156
|
-
});
|
|
157
|
-
this.endSection();
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
generateEntity(libs, components, entity, entityIndex) {
|
|
161
|
-
this.writeLine(`const ${entity.id} = registry.spawnEntity();`);
|
|
162
|
-
Object.entries(entity.components).forEach(([componentName, rawParams]) => {
|
|
163
|
-
const originalsParams = components.find(({ name }) => name === componentName)?.paramsNames;
|
|
164
|
-
if (!originalsParams) throw new Error("Missing component in entity or inexistent saved component");
|
|
165
|
-
const params = originalsParams.map((ogParam) => {
|
|
166
|
-
let isAsset = false;
|
|
167
|
-
if (ogParam.startsWith("__RESERVED_ASSET_")) {
|
|
168
|
-
isAsset = true;
|
|
169
|
-
ogParam = ogParam.replace("__RESERVED_ASSET_", "");
|
|
170
|
-
}
|
|
171
|
-
const param = this.editor ? `options.editor.save.entities[${entityIndex}].components["${componentName}"]["${ogParam}"]` : getStringParam(rawParams[ogParam]);
|
|
172
|
-
if (isAsset) return this.getAssetParam(param, libs);
|
|
173
|
-
return param;
|
|
174
|
-
});
|
|
175
|
-
this.writeLine(`registry.addComponent(${entity.id}, new ${componentName}(${params.join(", ")}));`);
|
|
176
|
-
});
|
|
177
|
-
if (this.editor) this.writeLine(`registry.addComponent(${entity.id}, { name: "__RESERVED_entityId", entityId: "${entity.id}" });`);
|
|
178
|
-
this.endSection();
|
|
179
|
-
}
|
|
180
|
-
getAssetParam(param, libs) {
|
|
181
|
-
return `${libs.find((lib) => lib.type === "asset-manager")?.id ?? "assetManagerLibrary"}.getAsset(${param})`;
|
|
182
|
-
}
|
|
183
|
-
getInitFunction(name, type) {
|
|
184
|
-
const baseName = LIBS_FUNCTIONS_NAME[type];
|
|
185
|
-
if (baseName) return `app.${baseName}(${name});`;
|
|
186
|
-
return `app.use(Symbol("${type}"), ${name});`;
|
|
187
|
-
}
|
|
188
|
-
writeLine(text, indentation = true) {
|
|
189
|
-
const line = `${" ".repeat(indentation ? this.indentation * 2 : 0)}${text}\n`;
|
|
190
|
-
this.buffer += line;
|
|
191
|
-
}
|
|
192
|
-
endSection() {
|
|
193
|
-
this.writeLine("");
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/utils/main/main-functions.ts
|
|
198
|
-
const generateMain = (options, save) => {
|
|
199
|
-
const isServer = options.part === "server";
|
|
200
|
-
const hasTypes = options.language === "ts";
|
|
201
|
-
const initFunctions = options.initFunctions;
|
|
202
|
-
return (!options.editor ? new MainGenerator() : new MainGenerator(true, join$1("../".repeat(options.outFile ? options.outFile.split("/").length - 1 : 3), options.part))).generateBaseImports(hasTypes).generateLibsImports(save.libraries).generateInitFunctionsImportsIfNeeded(initFunctions).generateComponentsImports(save.components).generateSystemsImports(save.systems).generateMainFunction(hasTypes, (generator) => {
|
|
203
|
-
generator.generateApp(isServer).generateLibsInstances(save.libraries).generateLibsInit(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeInit").generateAppInit().generateInitFunctionIfNeeded(initFunctions, "afterInit").generateRegistry(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeRegistryInit").generateEntities(save.libraries, save.components, save.entities).generateSystems(save.systems).generateInitFunctionIfNeeded(initFunctions, "afterRegistryInit").generateInitFunctionIfNeeded(initFunctions, "beforeRun").generateAppRun(initFunctions).generateInitFunctionIfNeeded(initFunctions, "afterRun");
|
|
204
|
-
}).toString();
|
|
205
|
-
};
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/libs/part-main/part-main.factory.ts
|
|
208
|
-
const transform = (schema) => {
|
|
209
|
-
return {};
|
|
210
|
-
};
|
|
211
|
-
const generate = (options, path, schema) => {
|
|
212
|
-
const rules = [template({
|
|
213
|
-
...strings,
|
|
214
|
-
...options
|
|
215
|
-
}), move(normalize(path))];
|
|
216
|
-
return apply(asSource(writeMain(schema, path)), rules);
|
|
217
|
-
};
|
|
218
|
-
const getMainPath = (schema) => {
|
|
219
|
-
if (schema.outFile) return schema.outFile;
|
|
220
|
-
if (schema.editor) return join(".nanoforge/editor", schema.part, `main.${schema.language}`);
|
|
221
|
-
return join(schema.part, `main.${schema.language}`);
|
|
222
|
-
};
|
|
223
|
-
const writeMain = (schema, path) => {
|
|
224
|
-
return (tree) => {
|
|
225
|
-
let save = getSave(path, schema.part, schema.saveFile);
|
|
226
|
-
const resPath = getMainPath(schema);
|
|
227
|
-
if (schema.editor) save = getEditorSave(save);
|
|
228
|
-
const content = generateMain(schema, save);
|
|
229
|
-
fs.rmSync(join(path, resPath), { force: true });
|
|
230
|
-
tree.create(resPath, content);
|
|
231
|
-
return tree;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
const getSave = (path, part, saveFile) => {
|
|
235
|
-
return JSON.parse(fs.readFileSync(saveFile ?? join(path, `.nanoforge/${part}.save.json`), "utf-8"));
|
|
236
|
-
};
|
|
237
|
-
const getEditorSave = (save) => {
|
|
238
|
-
if (save.libraries.some((lib) => lib.type === "graphics")) save.libraries.push({
|
|
239
|
-
id: "graphicsEditorLibrary",
|
|
240
|
-
type: "graphics-editor",
|
|
241
|
-
name: "Graphics2DEditorLibrary",
|
|
242
|
-
path: "@nanoforge-dev/graphics-2d-editor"
|
|
243
|
-
});
|
|
244
|
-
return save;
|
|
245
|
-
};
|
|
246
|
-
const main = (schema) => {
|
|
247
|
-
return mergeWith(generate(transform(schema), schema.directory, schema));
|
|
248
|
-
};
|
|
249
|
-
//#endregion
|
|
250
|
-
export { main };
|
|
251
|
-
|
|
252
|
-
//# sourceMappingURL=part-main.factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"part-main.factory.js","names":["join","join"],"sources":["../../../src/utils/main/enums.ts","../../../src/utils/path.ts","../../../src/utils/main/save.type.ts","../../../src/utils/main/const.ts","../../../src/utils/main/main-utils.ts","../../../src/utils/main/main.generator.ts","../../../src/utils/main/main-functions.ts","../../../src/libs/part-main/part-main.factory.ts"],"sourcesContent":["export enum InitFunctionEnum {\n BEFORE_INIT = \"beforeInit\",\n AFTER_INIT = \"afterInit\",\n BEFORE_REGISTRY_INIT = \"beforeRegistryInit\",\n AFTER_REGISTRY_INIT = \"afterRegistryInit\",\n BEFORE_RUN = \"beforeRun\",\n AFTER_RUN = \"afterRun\",\n}\n","import { join } from \"path\";\n\nexport const joinRelative = (...paths: [string, ...string[]]): string => {\n const path = join(...paths);\n return path.startsWith(\"./\") || path.startsWith(\"../\") ? path : `./${path}`;\n};\n","export enum SaveLibraryTypeEnum {\n COMPONENT_SYSTEM = \"component-system\",\n GRAPHICS = \"graphics\",\n ASSET_MANAGER = \"asset-manager\",\n NETWORK = \"network\",\n INPUT = \"input\",\n SOUND = \"sound\",\n}\n\nexport interface SaveLibrary {\n id: string;\n type: SaveLibraryTypeEnum | string;\n name: string;\n path: string;\n}\n\nexport interface SaveComponent {\n name: string;\n path: string;\n paramsNames: string[];\n}\n\nexport interface SaveSystem {\n name: string;\n path: string;\n}\n\nexport interface SaveEntity {\n id: string;\n components: Record<string, Record<string, any>>;\n}\n\nexport interface Save {\n libraries: SaveLibrary[];\n components: SaveComponent[];\n systems: SaveSystem[];\n entities: SaveEntity[];\n}\n","import { SaveLibraryTypeEnum } from \"@utils/main/save.type\";\n\nexport const LIBS_FUNCTIONS_NAME: Record<SaveLibraryTypeEnum | string, string> = {\n [SaveLibraryTypeEnum.ASSET_MANAGER]: \"useAssetManager\",\n [SaveLibraryTypeEnum.COMPONENT_SYSTEM]: \"useComponentSystem\",\n [SaveLibraryTypeEnum.GRAPHICS]: \"useGraphics\",\n [SaveLibraryTypeEnum.INPUT]: \"useInput\",\n [SaveLibraryTypeEnum.NETWORK]: \"useNetwork\",\n [SaveLibraryTypeEnum.SOUND]: \"useSound\",\n};\n","export const getStringParam = (value: any): string => {\n if (typeof value === \"string\") return `\"${value}\"`;\n if (typeof value === \"number\") return value.toString();\n if (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n if (typeof value === \"object\") return JSON.stringify(value);\n return \"undefined\";\n};\n","import { joinRelative } from \"@utils/path\";\n\nimport { LIBS_FUNCTIONS_NAME } from \"./const\";\nimport { InitFunctionEnum } from \"./enums\";\nimport { getStringParam } from \"./main-utils\";\nimport {\n type SaveComponent,\n type SaveEntity,\n type SaveLibrary,\n SaveLibraryTypeEnum,\n type SaveSystem,\n} from \"./save.type\";\n\nexport class MainGenerator {\n private buffer = \"\";\n private indentation = 0;\n private readonly editor: boolean;\n private readonly pathToRoot: string;\n\n constructor(editor: boolean = false, pathToRoot: string = \"\") {\n this.editor = editor;\n this.pathToRoot = pathToRoot;\n }\n\n toString(): string {\n return this.buffer;\n }\n\n generateBaseImports(hasTypes: boolean): MainGenerator {\n if (this.editor) {\n if (hasTypes)\n this.writeLine(\n `import { type IEditorRunOptions, NanoforgeFactory } from \"@nanoforge-dev/core-editor\";`,\n );\n else this.writeLine(`import { NanoforgeFactory } from \"@nanoforge-dev/core-editor\";`);\n } else {\n if (hasTypes) this.writeLine(`import { type IRunOptions } from \"@nanoforge-dev/common\";`);\n this.writeLine(`import { NanoforgeFactory } from \"@nanoforge-dev/core\";`);\n }\n\n this.endSection();\n return this;\n }\n\n generateLibsImports(libs: SaveLibrary[]): MainGenerator {\n return this.generateImports(libs, false);\n }\n\n generateComponentsImports(libs: SaveComponent[]): MainGenerator {\n return this.generateImports(libs, true);\n }\n\n generateSystemsImports(libs: SaveSystem[]): MainGenerator {\n return this.generateImports(libs, true);\n }\n\n generateMainFunction(hasTypes: boolean, cb: (generator: MainGenerator) => void): MainGenerator {\n if (this.editor)\n this.writeLine(\n `export async function main(options${hasTypes ? \": IEditorRunOptions\" : \"\"}) {`,\n );\n else this.writeLine(`export async function main(options${hasTypes ? \": IRunOptions\" : \"\"}) {`);\n this.indentation += 1;\n cb(this);\n this.indentation -= 1;\n this.writeLine(\"}\");\n return this;\n }\n\n generateApp(isServer: boolean): MainGenerator {\n this.writeLine(`const app = NanoforgeFactory.create${isServer ? \"Server\" : \"Client\"}();`);\n this.endSection();\n return this;\n }\n\n generateAppInit(): MainGenerator {\n this.writeLine(`await app.init(options);`);\n this.endSection();\n return this;\n }\n\n generateAppRun(hasInitFunctions: boolean): MainGenerator {\n this.writeLine(`await app.run();`);\n if (hasInitFunctions) this.endSection();\n return this;\n }\n\n generateLibsInstances(libs: SaveLibrary[]): MainGenerator {\n libs.forEach(({ id, name }) => this.writeLine(`const ${id} = new ${name}();`));\n this.endSection();\n return this;\n }\n\n generateLibsInit(libs: SaveLibrary[]): MainGenerator {\n libs.forEach(({ id, type }) => this.writeLine(this.getInitFunction(id, type)));\n this.endSection();\n return this;\n }\n\n generateRegistry(libs: SaveLibrary[]): MainGenerator {\n const libName =\n libs.find((lib) => lib.type === SaveLibraryTypeEnum.COMPONENT_SYSTEM)?.id ?? \"ecsLibrary\";\n this.writeLine(`const registry = ${libName}.registry;`);\n this.endSection();\n return this;\n }\n\n generateEntities(\n libs: SaveLibrary[],\n components: SaveComponent[],\n entities: SaveEntity[],\n ): MainGenerator {\n entities.forEach((entity, index) => this.generateEntity(libs, components, entity, index));\n return this;\n }\n\n generateSystems(systems: SaveSystem[]): MainGenerator {\n systems.forEach(({ name }) => this.writeLine(`registry.addSystem(${name});`));\n this.endSection();\n return this;\n }\n\n generateInitFunctionIfNeeded(needed: boolean, func: InitFunctionEnum): MainGenerator {\n if (needed) return this.generateInitFunction(func);\n return this;\n }\n\n generateInitFunctionsImportsIfNeeded(needed: boolean): MainGenerator {\n if (!needed) return this;\n return this.generateImports(\n [\n { name: \"afterInit\", path: \"./init/after-init\" },\n { name: \"afterRegistryInit\", path: \"./init/after-registry-init\" },\n { name: \"afterRun\", path: \"./init/after-run\" },\n { name: \"beforeInit\", path: \"./init/before-init\" },\n { name: \"beforeRegistryInit\", path: \"./init/before-registry-init\" },\n { name: \"beforeRun\", path: \"./init/before-run\" },\n ],\n true,\n );\n }\n\n private generateInitFunction(func: InitFunctionEnum): MainGenerator {\n const params = [\"app\"];\n if (\n [InitFunctionEnum.BEFORE_REGISTRY_INIT, InitFunctionEnum.AFTER_REGISTRY_INIT].includes(func)\n )\n params.push(\"registry\");\n this.writeLine(`await ${func}(${params.join(\", \")});`);\n if (func !== InitFunctionEnum.AFTER_RUN) this.endSection();\n return this;\n }\n\n private generateImports(els: { name: string; path: string }[], relative: boolean): MainGenerator {\n [...els]\n .sort((a, b) => a.path.localeCompare(b.path))\n .forEach(({ name, path }) => {\n path = path.replace(/\\.(?:ts|js)$/, \"\");\n this.writeLine(\n `import { ${name} } from \"${relative ? joinRelative(this.pathToRoot, path) : path}\";`,\n );\n });\n this.endSection();\n return this;\n }\n\n private generateEntity(\n libs: SaveLibrary[],\n components: SaveComponent[],\n entity: SaveEntity,\n entityIndex: number,\n ): void {\n this.writeLine(`const ${entity.id} = registry.spawnEntity();`);\n Object.entries(entity.components).forEach(([componentName, rawParams]) => {\n const originalsParams = components.find(({ name }) => name === componentName)?.paramsNames;\n if (!originalsParams)\n throw new Error(\"Missing component in entity or inexistent saved component\");\n const params: string[] = originalsParams.map((ogParam) => {\n let isAsset = false;\n if (ogParam.startsWith(\"__RESERVED_ASSET_\")) {\n isAsset = true;\n ogParam = ogParam.replace(\"__RESERVED_ASSET_\", \"\");\n }\n\n const param = this.editor\n ? `options.editor.save.entities[${entityIndex}].components[\"${componentName}\"][\"${ogParam}\"]`\n : getStringParam(rawParams[ogParam]);\n if (isAsset) return this.getAssetParam(param, libs);\n return param;\n });\n this.writeLine(\n `registry.addComponent(${entity.id}, new ${componentName}(${params.join(\", \")}));`,\n );\n });\n if (this.editor) {\n this.writeLine(\n `registry.addComponent(${entity.id}, { name: \"__RESERVED_entityId\", entityId: \"${entity.id}\" });`,\n );\n }\n this.endSection();\n }\n\n private getAssetParam(param: string, libs: SaveLibrary[]): string {\n const libName =\n libs.find((lib) => lib.type === SaveLibraryTypeEnum.ASSET_MANAGER)?.id ??\n \"assetManagerLibrary\";\n return `${libName}.getAsset(${param})`;\n }\n\n private getInitFunction(name: string, type: SaveLibraryTypeEnum | string): string {\n const baseName = LIBS_FUNCTIONS_NAME[type];\n if (baseName) return `app.${baseName}(${name});`;\n return `app.use(Symbol(\"${type}\"), ${name});`;\n }\n\n private writeLine(text: string, indentation = true): void {\n const line = `${\" \".repeat(indentation ? this.indentation * 2 : 0)}${text}\\n`;\n this.buffer += line;\n }\n\n private endSection(): void {\n this.writeLine(\"\");\n }\n}\n","import { join } from \"path\";\n\nimport { InitFunctionEnum } from \"@utils/main/enums\";\n\nimport { MainGenerator } from \"./main.generator\";\nimport { type Save } from \"./save.type\";\n\nexport interface MainOptions {\n part: \"client\" | \"server\";\n language: \"js\" | \"ts\";\n initFunctions: boolean;\n editor: boolean;\n outFile?: string;\n}\n\nexport const generateMain = (options: MainOptions, save: Save) => {\n const isServer = options.part === \"server\";\n const hasTypes = options.language === \"ts\";\n const initFunctions = options.initFunctions;\n\n return (\n !options.editor\n ? new MainGenerator()\n : new MainGenerator(\n true,\n join(\n \"../\".repeat(options.outFile ? options.outFile.split(\"/\").length - 1 : 3),\n options.part,\n ),\n )\n )\n .generateBaseImports(hasTypes)\n .generateLibsImports(save.libraries)\n .generateInitFunctionsImportsIfNeeded(initFunctions)\n .generateComponentsImports(save.components)\n .generateSystemsImports(save.systems)\n\n .generateMainFunction(hasTypes, (generator) => {\n generator\n .generateApp(isServer)\n\n .generateLibsInstances(save.libraries)\n .generateLibsInit(save.libraries)\n\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.BEFORE_INIT)\n .generateAppInit()\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.AFTER_INIT)\n\n .generateRegistry(save.libraries)\n\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.BEFORE_REGISTRY_INIT)\n .generateEntities(save.libraries, save.components, save.entities)\n .generateSystems(save.systems)\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.AFTER_REGISTRY_INIT)\n\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.BEFORE_RUN)\n .generateAppRun(initFunctions)\n .generateInitFunctionIfNeeded(initFunctions, InitFunctionEnum.AFTER_RUN);\n })\n .toString();\n};\n","import { type Path, join, normalize, strings } from \"@angular-devkit/core\";\nimport {\n type Rule,\n type Source,\n type Tree,\n apply,\n asSource,\n mergeWith,\n move,\n template,\n} from \"@angular-devkit/schematics\";\nimport * as fs from \"fs\";\n\nimport { generateMain } from \"@utils/main/main-functions\";\nimport { type Save, SaveLibraryTypeEnum } from \"@utils/main/save.type\";\n\nimport { type PartMainOptions } from \"./part-main.options\";\nimport { type PartMainSchema } from \"./part-main.schema\";\n\nconst transform = (schema: PartMainSchema): PartMainOptions => {\n void schema;\n\n return {};\n};\n\nconst generate = (options: PartMainOptions, path: string, schema: PartMainSchema): Source => {\n const rules = [\n template({\n ...strings,\n ...options,\n }),\n move(normalize(path)),\n ];\n\n return apply(asSource(writeMain(schema, path)), rules);\n};\n\nconst getMainPath = (schema: PartMainSchema): string => {\n if (schema.outFile) return schema.outFile;\n if (schema.editor)\n return join(\".nanoforge/editor\" as Path, schema.part, `main.${schema.language}`);\n return join(schema.part as Path, `main.${schema.language}`);\n};\n\nconst writeMain = (schema: PartMainSchema, path: string) => {\n return (tree: Tree) => {\n let save = getSave(path, schema.part, schema.saveFile);\n\n const resPath = getMainPath(schema);\n\n if (schema.editor) {\n save = getEditorSave(save);\n }\n\n const content = generateMain(schema, save);\n fs.rmSync(join(path as Path, resPath), { force: true });\n tree.create(resPath, content);\n return tree;\n };\n};\n\nconst getSave = (path: string, part: \"client\" | \"server\", saveFile?: string): Save => {\n return JSON.parse(\n fs.readFileSync(saveFile ?? join(path as Path, `.nanoforge/${part}.save.json`), \"utf-8\"),\n ) as Save;\n};\n\nconst getEditorSave = (save: Save): Save => {\n if (save.libraries.some((lib) => lib.type === SaveLibraryTypeEnum.GRAPHICS))\n save.libraries.push({\n id: \"graphicsEditorLibrary\",\n type: \"graphics-editor\",\n name: \"Graphics2DEditorLibrary\",\n path: \"@nanoforge-dev/graphics-2d-editor\",\n });\n\n return save;\n};\n\nexport const main = (schema: PartMainSchema): Rule => {\n const options = transform(schema);\n\n return mergeWith(generate(options, schema.directory, schema));\n};\n"],"mappings":";;;;;;ACEA,MAAa,gBAAgB,GAAG,UAAyC;CACvE,MAAM,OAAOA,OAAK,GAAG,KAAK;CAC1B,OAAO,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK,IAAI,OAAO,KAAK;AACvE;;;AEHA,MAAa,sBAAoE;oBAC1C;uBACG;eACR;YACH;cACE;YACF;AAC/B;;;ACTA,MAAa,kBAAkB,UAAuB;CACpD,IAAI,OAAO,UAAU,UAAU,OAAO,IAAI,MAAM;CAChD,IAAI,OAAO,UAAU,UAAU,OAAO,MAAM,SAAS;CACrD,IAAI,OAAO,UAAU,WAAW,OAAO,QAAQ,SAAS;CACxD,IAAI,OAAO,UAAU,UAAU,OAAO,KAAK,UAAU,KAAK;CAC1D,OAAO;AACT;;;ACOA,IAAa,gBAAb,MAA2B;CACzB,SAAiB;CACjB,cAAsB;CACtB;CACA;CAEA,YAAY,SAAkB,OAAO,aAAqB,IAAI;EAC5D,KAAK,SAAS;EACd,KAAK,aAAa;CACpB;CAEA,WAAmB;EACjB,OAAO,KAAK;CACd;CAEA,oBAAoB,UAAkC;EACpD,IAAI,KAAK,QACP,IAAI,UACF,KAAK,UACH,wFACF;OACG,KAAK,UAAU,gEAAgE;OAC/E;GACL,IAAI,UAAU,KAAK,UAAU,2DAA2D;GACxF,KAAK,UAAU,yDAAyD;EAC1E;EAEA,KAAK,WAAW;EAChB,OAAO;CACT;CAEA,oBAAoB,MAAoC;EACtD,OAAO,KAAK,gBAAgB,MAAM,KAAK;CACzC;CAEA,0BAA0B,MAAsC;EAC9D,OAAO,KAAK,gBAAgB,MAAM,IAAI;CACxC;CAEA,uBAAuB,MAAmC;EACxD,OAAO,KAAK,gBAAgB,MAAM,IAAI;CACxC;CAEA,qBAAqB,UAAmB,IAAuD;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