[oden] Text is mildly functional

This commit is contained in:
John Doty 2023-08-31 17:18:37 -07:00
parent 8914b1795f
commit ecce7b64eb
5 changed files with 204 additions and 114 deletions

View file

@ -1,4 +1,4 @@
import { cls, print } from "./graphics";
import { cls } from "./graphics";
import { since_start } from "./time";
import { new_v2 } from "./vector";
import { load_world, World, Level, draw_level } from "./level";
@ -10,6 +10,7 @@ import {
is_actor_type,
spawn_actor,
} from "./actor";
import { log, draw_log } from "./log";
/// A nice looping frame counter.
let clock = 0;
@ -25,7 +26,7 @@ let actors: Actor[] = [];
function start_load_assets() {
// Start this load, but then...
load_world("./overworld.ldtk").then((w) => {
print("World loaded at", since_start());
log("World loaded at", since_start());
world = w;
// Assume we start at 0,0
@ -43,7 +44,7 @@ function start_load_assets() {
const props = new_actor_props(entity.id, new_v2(x, y), w);
actors.push(spawn_actor(entity.type, props));
} else {
print("WARNING: Ignoring entity of type", entity.type);
log("WARNING: Ignoring entity of type", entity.type);
}
}
});
@ -52,7 +53,7 @@ function start_load_assets() {
// TODO: Build a system whereby the signatures of the fundamental functions can be checked.
export function init() {
print("Hello world!");
log("Hello world!");
start_load_assets();
}
@ -62,7 +63,7 @@ interface Snapshot {
}
export function suspend(): Snapshot {
print("Suspend! ", actors.length, "actors");
log("Suspend! ", actors.length, "actors");
return {
clock,
actors: actors.map((a) => {
@ -75,7 +76,7 @@ export function resume(snapshot: Snapshot | undefined) {
if (snapshot) {
clock = snapshot.clock || 0;
actors = snapshot.actors.map((s) => spawn_actor(s.type, s.props));
print("Resume! ", actors.length, "actors");
log("Resume! ", actors.length, "actors");
}
}
@ -109,5 +110,6 @@ export function draw() {
actor.draw(clock);
}
// print("FRAME TIME:", since_last_frame());
// log("FRAME TIME:", since_last_frame());
draw_log();
}