30 lines
920 B
TypeScript
30 lines
920 B
TypeScript
import { v2 } from "../../common/utils.ts";
|
|
import { range, Vec2 } from "../../common/utils.ts";
|
|
import { Engine } from "../engine.ts";
|
|
import { query_in_rect } from "./world.ts";
|
|
|
|
export class CompDisplay {
|
|
display;
|
|
|
|
constructor(display: string) {
|
|
this.display = display;
|
|
}
|
|
|
|
update(display: string) {
|
|
this.display = display;
|
|
}
|
|
}
|
|
|
|
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).sub(v2(1, 1));
|
|
for (const [pos, display] of engine.all(query_in_rect(min, max).with(CompDisplay))) {
|
|
const local_pos = pos.pos.sub(min);
|
|
result[local_pos.y()][local_pos.x()] = display.display;
|
|
}
|
|
return result.map((line) => line.join("")).toReversed().join("\n");
|
|
};
|
|
}
|