From 3f580c47c149a4f2ac321ed11a6bc72bf8229355 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 9 Jul 2024 15:05:23 -0500 Subject: [PATCH] refactor: creators manage teleport id --- app/create-homestead.js | 6 ++++-- app/create-house.js | 6 ++++-- app/engine.js | 6 ++---- app/net/server/worker.js | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/create-homestead.js b/app/create-homestead.js index 8598e52..e6a210f 100644 --- a/app/create-homestead.js +++ b/app/create-homestead.js @@ -1,6 +1,6 @@ import createEcs from './create-ecs.js'; -export default async function createHomestead(Ecs) { +export default async function createHomestead(Ecs, id) { const ecs = createEcs(Ecs); const area = {x: 100, y: 60}; await ecs.create({ @@ -49,7 +49,9 @@ export default async function createHomestead(Ecs) { ], collisionStartScript: '/assets/shit-shack/collision-start.js', }, - Ecs: {}, + Ecs: { + path: ['houses', `${id}`].join('/'), + }, Position: {x: 100, y: 100}, Sprite: { anchorX: 0.5, diff --git a/app/create-house.js b/app/create-house.js index b926113..020b716 100644 --- a/app/create-house.js +++ b/app/create-house.js @@ -1,6 +1,6 @@ import createEcs from './create-ecs.js'; -export default async function createHouse(Ecs) { +export default async function createHouse(Ecs, id) { const ecs = createEcs(Ecs); const area = {x: 20, y: 20}; await ecs.create({ @@ -31,7 +31,9 @@ export default async function createHouse(Ecs) { ], collisionStartScript: '/assets/house/collision-start.js', }, - Ecs: {}, + Ecs: { + path: ['homesteads', `${id}`].join('/'), + }, Position: { x: 72, y: 320, diff --git a/app/engine.js b/app/engine.js index 5f176a2..edd565d 100644 --- a/app/engine.js +++ b/app/engine.js @@ -215,14 +215,12 @@ export default class Engine { if ('ENOENT' !== error.code) { throw error; } - const homestead = await createHomestead(this.Ecs); - homestead.get(2).Ecs.path = ['houses', `${id}`].join('/'); + const homestead = await createHomestead(this.Ecs, id); await this.saveEcs( ['homesteads', `${id}`].join('/'), homestead, ); - const house = await createHouse(this.Ecs); - house.get(2).Ecs.path = ['homesteads', `${id}`].join('/'); + const house = await createHouse(this.Ecs, id); await this.saveEcs( ['houses', `${id}`].join('/'), house, diff --git a/app/net/server/worker.js b/app/net/server/worker.js index b5b166c..893a833 100644 --- a/app/net/server/worker.js +++ b/app/net/server/worker.js @@ -98,7 +98,7 @@ if (import.meta.hot) { await beforeResolver; // delete engine.ecses['homesteads/0']; // await engine.server.removeData('homesteads/0'); - // const homestead = await createHomestead(engine.Ecs); + // const homestead = await createHomestead(engine.Ecs, '0'); // homestead.get(2).Ecs.path = 'houses/0'; // await engine.saveEcs('homesteads/0', homestead); resolver.resolve();