refactor
This commit is contained in:
parent
a633cb7252
commit
6bf8f60a45
5 changed files with 15 additions and 63 deletions
|
@ -1,5 +1,5 @@
|
|||
import { spiral } from "../../common/utils.ts";
|
||||
import { chunks, enumerate, log_from, Vec2 } from "../../common/utils.ts";
|
||||
import { assertEquals } from "https://deno.land/std@0.221.0/assert/mod.ts";
|
||||
import { chunks, enumerate, log_from, spiral, Vec2 } from "../../common/utils.ts";
|
||||
import { Engine, Entity, Query } from "../engine.ts";
|
||||
import { CompDisplay } from "./display.ts";
|
||||
const log = log_from(import.meta);
|
||||
|
@ -53,6 +53,13 @@ function* displacement_steps(position: Vec2, displacement: Vec2) {
|
|||
}
|
||||
}
|
||||
|
||||
Deno.test("test_displacement", () => {
|
||||
assertEquals(
|
||||
[...displacement_steps(new Vec2(1, 1), new Vec2(4, 6))],
|
||||
[new Vec2(2, 2), new Vec2(3, 3), new Vec2(4, 4), new Vec2(5, 5), new Vec2(5, 6), new Vec2(5, 7)],
|
||||
);
|
||||
});
|
||||
|
||||
export function query_at(pos: Vec2) {
|
||||
return Query.filter(CompPos, (c) => c.position.overlaps(pos));
|
||||
}
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
import { assertEquals } from "https://deno.land/std@0.221.0/assert/mod.ts";
|
||||
import { Awaitable, log_from, Prototyped, Vec2 } from "../common/utils.ts";
|
||||
import { ClassMap } from "../common/utils.ts";
|
||||
import { wait } from "../common/utils.ts";
|
||||
import { Constructible } from "../common/utils.ts";
|
||||
import { first } from "../common/utils.ts";
|
||||
import { Awaitable, ClassMap, Constructible, first, log_from, Prototyped, wait } from "../common/utils.ts";
|
||||
const log = log_from(import.meta);
|
||||
|
||||
export class Entity {
|
||||
|
@ -90,37 +85,6 @@ export class Engine {
|
|||
}
|
||||
}
|
||||
|
||||
function* displacement_steps(position: Vec2, displacement: Vec2) {
|
||||
let pos = position;
|
||||
let left = displacement;
|
||||
while (left.len() >= 1) {
|
||||
if (left.x() >= 1) {
|
||||
pos = pos.add(new Vec2(1, 0));
|
||||
left = left.sub(new Vec2(1, 0));
|
||||
}
|
||||
if (left.x() <= -1) {
|
||||
pos = pos.add(new Vec2(-1, 0));
|
||||
left = left.sub(new Vec2(-1, 0));
|
||||
}
|
||||
if (left.y() >= 1) {
|
||||
pos = pos.add(new Vec2(0, 1));
|
||||
left = left.sub(new Vec2(0, 1));
|
||||
}
|
||||
if (left.y() <= -1) {
|
||||
pos = pos.add(new Vec2(0, -1));
|
||||
left = left.sub(new Vec2(0, -1));
|
||||
}
|
||||
yield pos;
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test("test_displacement", () => {
|
||||
assertEquals(
|
||||
[...displacement_steps(new Vec2(1, 1), new Vec2(4, 6))],
|
||||
[new Vec2(2, 2), new Vec2(3, 3), new Vec2(4, 4), new Vec2(5, 5), new Vec2(5, 6), new Vec2(5, 7)],
|
||||
);
|
||||
});
|
||||
|
||||
export class Query {
|
||||
private test;
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import { mts } from "../../common/mod.ts";
|
||||
import { range } from "../../common/utils.ts";
|
||||
import { log_from, v2, Vec2 } from "../../common/utils.ts";
|
||||
import { log_from, range, v2, Vec2 } from "../../common/utils.ts";
|
||||
import { CompDisplay } from "../components/display.ts";
|
||||
import { sys_find_free_pos } from "../components/world.ts";
|
||||
import { CompPos, query_in_rect } from "../components/world.ts";
|
||||
import { CompPos, query_in_rect, sys_find_free_pos } from "../components/world.ts";
|
||||
import { Engine, Entity } from "../engine.ts";
|
||||
import { ClientInterface } from "../network.ts";
|
||||
const log = log_from(import.meta);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#!/bin/env -S deno run --allow-net --allow-read
|
||||
|
||||
import { log_from, v2, wait } from "../common/utils.ts";
|
||||
import { log_from, v2 } 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 { 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() {
|
||||
|
@ -16,14 +15,6 @@ async function main() {
|
|||
engine.run(await sys_spawn_structure("../data/structures/houses.txt", v2(2, 2)));
|
||||
engine.run(sys_spawn_enemy(v2(1, 1)));
|
||||
|
||||
(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.");
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
#!/bin/env -S deno run --allow-net
|
||||
|
||||
import { MsgToClient, MsgToServer, mts } from "../common/mod.ts";
|
||||
import {
|
||||
channel,
|
||||
launch_caught,
|
||||
log_from,
|
||||
parsed_stream,
|
||||
Receiver,
|
||||
Sender,
|
||||
serialized_stream,
|
||||
} from "../common/utils.ts";
|
||||
import { channel, log_from, parsed_stream, Receiver, Sender, serialized_stream } from "../common/utils.ts";
|
||||
const log = log_from(import.meta);
|
||||
|
||||
export class Gateway {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue