refactor: tidy

This commit is contained in:
cha0s 2024-07-20 02:59:40 -05:00
parent 13b457210e
commit 767f014107
2 changed files with 7 additions and 80 deletions

View File

@ -252,6 +252,10 @@ export default class Engine {
);
}
createEcs() {
return createEcs(this.Ecs);
}
async disconnectPlayer(connection) {
const connectedPlayer = this.connectedPlayers.get(connection);
if (!connectedPlayer) {
@ -270,7 +274,7 @@ export default class Engine {
async loadEcs(path) {
this.ecses[path] = await this.Ecs.deserialize(
createEcs(this.Ecs),
this.createEcs(),
await this.server.readData(path),
);
}
@ -284,7 +288,7 @@ export default class Engine {
if ('ENOENT' !== error.code) {
throw error;
}
const homestead = createEcs(this.Ecs);
const homestead = this.createEcs();
for (const entity of await createHomestead(id)) {
await homestead.create(entity);
}
@ -297,7 +301,7 @@ export default class Engine {
['houses', `${id}`].join('/'),
house,
);
const forest = createEcs(this.Ecs);
const forest = this.createEcs();
for (const entity of await createForest()) {
await forest.create(entity);
}

View File

@ -1,77 +0,0 @@
import {expect, test} from 'vitest';
import {RESOLUTION} from '@/constants.js'
import Server from '@/net/server/server.js';
import Engine from './engine.js';
class TestServer extends Server {
constructor() {
super();
this.data = {};
}
async readAsset() {
return new ArrayBuffer(0);
}
async readData(path) {
if (path in this.data) {
return this.data[path];
}
const error = new Error();
error.code = 'ENOENT';
throw error;
}
async writeData(path, view) {
this.data[path] = view;
}
}
test('visibility-based updates', async () => {
// const engine = new Engine(TestServer);
// // Connect an entity.
// await engine.connectPlayer(0, 0);
// const ecs = engine.ecses['homesteads/0'];
// // Create an entity.
// const entity = ecs.get(await ecs.create({
// Forces: {forceX: 1},
// Position: {x: (RESOLUTION.x * 1.5) + 32 - 3, y: 20},
// Sprite: {
// anchor: {x: 0.5, y: 0.8},
// animation: 'moving:down',
// frame: 0,
// frames: 8,
// source: '/assets/dude/dude.json',
// speed: 0.115,
// },
// VisibleAabb: {},
// }));
// const {entity: mainEntity} = engine.connectedPlayers.get(0);
// // Tick and get update. Should be a full update.
// engine.tick(1);
// expect(engine.updateFor(0))
// .to.deep.include({[mainEntity.id]: {MainEntity: {}, ...ecs.get(mainEntity.id).toJSON()}, [entity.id]: ecs.get(entity.id).toJSON()});
// engine.setClean();
// // Tick and get update. Should be a partial update.
// engine.tick(1);
// expect(engine.updateFor(0))
// .to.deep.include({
// [entity.id]: {
// Position: {x: (RESOLUTION.x * 1.5) + 32 - 1},
// VisibleAabb: {
// x0: 1199,
// x1: 1263,
// },
// },
// });
// engine.setClean();
// // Tick and get update. Should remove the entity.
// engine.tick(1);
// expect(engine.updateFor(0))
// .to.deep.include({[entity.id]: false});
// // Aim back toward visible area and tick. Should be a full update for that entity.
// engine.setClean();
// entity.Forces.forceX = -1;
// engine.tick(1);
// expect(engine.updateFor(0))
// .to.deep.include({[entity.id]: ecs.get(entity.id).toJSON()});
});