refactor query into yielding api
This commit is contained in:
parent
6bf8f60a45
commit
976a99baa1
5 changed files with 70 additions and 54 deletions
|
@ -1,7 +1,7 @@
|
|||
import { mts } from "../../common/mod.ts";
|
||||
import { log_from, range, v2, Vec2 } from "../../common/utils.ts";
|
||||
import { CompDisplay } from "../components/display.ts";
|
||||
import { CompPos, query_in_rect, sys_find_free_pos } from "../components/world.ts";
|
||||
import { log_from, v2, Vec2 } from "../../common/utils.ts";
|
||||
import { CompDisplay, sys_render_world } from "../components/display.ts";
|
||||
import { CompPos, 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);
|
||||
|
@ -58,20 +58,6 @@ export class Session {
|
|||
}
|
||||
}
|
||||
|
||||
export function sys_render_world(center: Vec2, size: Vec2) {
|
||||
return (engine: Engine) => {
|
||||
const radius = size.scale(0.5);
|
||||
const result = Array.from(range(0, size.y())).map(() => Array.from(range(0, size.x())).map(() => " "));
|
||||
const min = center.sub(radius);
|
||||
const max = center.add(radius);
|
||||
for (const entity of engine.query_all(query_in_rect(min, max).with(CompDisplay))) {
|
||||
const local_pos = entity.get_force(CompPos).position.sub(min);
|
||||
result[local_pos.y()][local_pos.x()] = entity.get_force(CompDisplay).display;
|
||||
}
|
||||
return result.map((line) => line.join("")).toReversed().join("\n");
|
||||
};
|
||||
}
|
||||
|
||||
export function sys_spawn_player(position: Vec2) {
|
||||
return (engine: Engine) => {
|
||||
return engine.spawn((entity) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue