Skip to content
6 changes: 4 additions & 2 deletions e2e/part-main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const clientSave: Save = {
],
components: [{ name: "ExampleComponent", path: "./components/example.component" }],
systems: [{ name: "exampleSystem", path: "./systems/example.system" }],
entities: [{ id: "player", components: [{ name: "ExampleComponent", params: ['"test"', "5"] }] }],
entities: [
{ id: "player", components: [{ name: "ExampleComponent", paramsValues: ['"test"', "5"] }] },
],
};

const serverSave: Save = {
Expand Down Expand Up @@ -202,7 +204,7 @@ describe("part-main schematic", () => {

it("should use entity params from editor save", () => {
const content = tree.readContent("/my-app/.nanoforge/editor/client/main.ts");
expect(content).toContain("options.editor.save.entities[0].components[0].params[0]");
expect(content).toContain("options.editor.save.entities[0].components[0].paramsValues[0]");
});

it("should import components and systems with relative path to root", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/main/main-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("generateMain", () => {
entities: [
{
id: "player",
components: [{ name: "Position", params: ["0", "0"] }],
components: [{ name: "Position", paramsValues: ["0", "0"] }],
},
],
};
Expand Down
4 changes: 2 additions & 2 deletions src/utils/main/main.generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ describe("MainGenerator", () => {
{
id: "player",
components: [
{ name: "Position", params: ["0", "0"] },
{ name: "Velocity", params: ["1"] },
{ name: "Position", paramsValues: ["0", "0"] },
{ name: "Velocity", paramsValues: ["1"] },
],
},
];
Expand Down
8 changes: 4 additions & 4 deletions src/utils/main/main.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export class MainGenerator {

private generateEntity(entity: SaveEntity, entityIndex: number): void {
this.writeLine(`const ${entity.id} = registry.spawnEntity();`);
entity.components.forEach(({ name, params: rawParams }, componentIndex) => {
entity.components.forEach(({ name, paramsValues }, componentIndex) => {
const params = !this.editor
? rawParams
: rawParams.map(
? paramsValues
: paramsValues.map(
(_param, index) =>
`options.editor.save.entities[${entityIndex}].components[${componentIndex}].params[${index}]`,
`options.editor.save.entities[${entityIndex}].components[${componentIndex}].paramsValues[${index}]`,
);
this.writeLine(`registry.addComponent(${entity.id}, new ${name}(${params.join(", ")}));`);
});
Expand Down
3 changes: 2 additions & 1 deletion src/utils/main/save.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SaveLibrary {
export interface SaveComponent {
name: string;
path: string;
paramsNames: string[];
}

export interface SaveSystem {
Expand All @@ -28,7 +29,7 @@ export interface SaveEntity {
id: string;
components: {
name: string;
params: string[];
paramsValues: string[];
}[];
}

Expand Down
Loading