ecs refactor

This commit is contained in:
Matthieu Jolimaitre 2024-04-09 04:25:34 +02:00
parent 28b026a614
commit f2e5d13000
8 changed files with 410 additions and 170 deletions

View file

@ -1,24 +1,35 @@
#!/bin/env -S deno run --allow-net --allow-read
import { log_from, Vec2 } from "../common/utils.ts";
import { Engine, World } from "./engine.ts";
import { Enemy } from "./entities/enemy.ts";
import { log_from, v2, wait } from "../common/utils.ts";
import { Engine } from "./engine.ts";
import { Session } from "./entities/player.ts";
import { sys_spawn_obstacle, sys_spawn_structure } from "./components/world.ts";
import { Gateway } from "./network.ts";
import { sys_spawn_enemy } from "./entities/enemy.ts";
import { spiral } from "../common/utils.ts";
const log = log_from(import.meta);
async function main() {
log("Starting.");
const world = new World();
await world.spawn_structure("../data/structures/houses.txt", new Vec2(2, 2));
const engine = new Engine(world);
const engine = new Engine();
engine.start();
engine.run(await sys_spawn_structure("../data/structures/houses.txt", v2(2, 2)));
engine.run(sys_spawn_enemy(v2(1, 1)));
Enemy.spawn(world, new Vec2(-3, -3));
(async () => {
await wait(5_000);
for (const pos of spiral(v2(-8, -8))) {
await wait(500);
engine.run(sys_spawn_obstacle(pos, "@@"));
}
})();
const port = 9999;
const gateway = new Gateway(port);
log("Awaiting connection.");
for await (const session of gateway.accept()) engine.add_session(session);
for await (const client of gateway.accept()) {
Session.init(client, engine).start();
}
}
if (import.meta.main) await main();