fix: to each their own

This commit is contained in:
cha0s 2024-07-24 01:50:33 -05:00
parent 3d7b0fc14e
commit 52f19b1d89
3 changed files with 27 additions and 20 deletions

View File

@ -168,6 +168,7 @@ export default async function createHomestead(id) {
},
],
collisionStartScript: `
if (other.Player) {
ecs.switchEcs(
other,
'town',
@ -178,6 +179,7 @@ export default async function createHomestead(id) {
},
},
);
}
`,
},

View File

@ -38,9 +38,10 @@ export default async function createTown() {
},
],
collisionStartScript: `
if (other.Player) {
ecs.switchEcs(
other,
['homesteads', '0'].join('/'),
['homesteads', other.Player.id].join('/'),
{
Position: {
x: 20,
@ -48,6 +49,7 @@ export default async function createTown() {
},
},
);
}
`,
},
Position: {x: 952, y: 480},

View File

@ -63,6 +63,7 @@ export default class Engine {
if (entity !== connectedPlayer.entity) {
continue;
}
const {id} = entity.Player;
// remove entity link to connection to start queueing actions and pause updates
delete connectedPlayer.entity;
// forget previous state
@ -93,6 +94,7 @@ export default class Engine {
}
// recreate the entity in the new ECS and again associate it with the connection
connectedPlayer.entity = engine.ecses[path].get(await engine.ecses[path].create(dumped));
connectedPlayer.entity.Player.id = id
}
}
}
@ -226,11 +228,12 @@ export default class Engine {
await this.loadEcs(entityJson.Ecs.path);
}
const ecs = this.ecses[entityJson.Ecs.path];
const entity = await ecs.create(entityJson);
const entity = ecs.get(await ecs.create(entityJson));
entity.Player.id = id
this.connectedPlayers.set(
connection,
{
entity: ecs.get(entity),
entity,
id,
memory: {
chunks: new Map(),