refactor: creators manage teleport id

This commit is contained in:
cha0s 2024-07-09 15:05:23 -05:00
parent af571e25af
commit 3f580c47c1
4 changed files with 11 additions and 9 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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();