[oden][game] Multiple screens, logging, pre/post, bluescreen
Better blue screens and also logging and whatnot
This commit is contained in:
parent
95d626c15f
commit
93d4e3eb91
8 changed files with 1201 additions and 244 deletions
|
|
@ -2,8 +2,9 @@
|
|||
// javascript. Dealing with the level code is really nice in javascript
|
||||
// but there's a bunch of weird stuff that really feels lower level.
|
||||
import { load_texture } from "./assets";
|
||||
import { Texture, print, spr, use_texture } from "./graphics";
|
||||
import { Texture, spr, use_texture } from "./graphics";
|
||||
import { load_string } from "./io";
|
||||
import { log } from "./log";
|
||||
|
||||
// TODO: Use io-ts? YIKES.
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ export interface EntityLayer {
|
|||
}
|
||||
|
||||
export interface Level {
|
||||
iid: string;
|
||||
world_x: number;
|
||||
world_y: number;
|
||||
width: number;
|
||||
|
|
@ -52,11 +54,19 @@ export interface Level {
|
|||
tile_layers: TileLayer[];
|
||||
entities: Entity[];
|
||||
values: { [key: string]: number[] };
|
||||
neighbors: {
|
||||
n: string | null;
|
||||
s: string | null;
|
||||
e: string | null;
|
||||
w: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface World {
|
||||
levels: Level[];
|
||||
level_map: Map<string, Level>;
|
||||
tilesets: Map<number, TileSet>;
|
||||
current_level: Level;
|
||||
}
|
||||
|
||||
interface LDTKTilesetDef {
|
||||
|
|
@ -78,7 +88,15 @@ async function load_tileset(def: LDTKTilesetDef): Promise<TileSet> {
|
|||
tags.set(et.enumValueId, et.tileIds);
|
||||
}
|
||||
|
||||
print("Loaded tileset", def.uid, "from", relPath, "as ID", texture.id());
|
||||
log(
|
||||
"map_load",
|
||||
"Loaded tileset",
|
||||
def.uid,
|
||||
"from",
|
||||
relPath,
|
||||
"as ID",
|
||||
texture.id()
|
||||
);
|
||||
return { id: def.uid, texture, tags };
|
||||
}
|
||||
|
||||
|
|
@ -179,15 +197,18 @@ function is_intgrid_layer_instance(
|
|||
}
|
||||
|
||||
type LDTKLevel = {
|
||||
iid: string;
|
||||
worldX: number;
|
||||
worldY: number;
|
||||
pxWid: number;
|
||||
pxHei: number;
|
||||
layerInstances: LDTKLayerInstance[];
|
||||
__neighbours: { levelIid: string; dir: "n" | "s" | "e" | "w" }[];
|
||||
};
|
||||
|
||||
function load_level(tile_sets: Map<number, TileSet>, def: LDTKLevel): Level {
|
||||
const result: Level = {
|
||||
iid: def.iid,
|
||||
world_x: def.worldX,
|
||||
world_y: def.worldY,
|
||||
width: def.pxWid,
|
||||
|
|
@ -197,6 +218,7 @@ function load_level(tile_sets: Map<number, TileSet>, def: LDTKLevel): Level {
|
|||
tile_layers: [],
|
||||
entities: [],
|
||||
values: {},
|
||||
neighbors: { n: null, s: null, e: null, w: null },
|
||||
};
|
||||
|
||||
for (const li of def.layerInstances) {
|
||||
|
|
@ -220,6 +242,18 @@ function load_level(tile_sets: Map<number, TileSet>, def: LDTKLevel): Level {
|
|||
}
|
||||
|
||||
result.tile_layers = result.tile_layers.reverse();
|
||||
const neighbors = result.neighbors;
|
||||
for (const n of def.__neighbours) {
|
||||
if (n.dir == "n") {
|
||||
neighbors.n = n.levelIid;
|
||||
} else if (n.dir == "s") {
|
||||
neighbors.s = n.levelIid;
|
||||
} else if (n.dir == "e") {
|
||||
neighbors.e = n.levelIid;
|
||||
} else if (n.dir == "w") {
|
||||
neighbors.w = n.levelIid;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -255,7 +289,7 @@ function is_ldtk_map(map: unknown): map is LDTKMap {
|
|||
}
|
||||
|
||||
export async function load_world(path: string): Promise<World> {
|
||||
print("Loading map:", path);
|
||||
log("map_load", "Loading map:", path);
|
||||
const blob = await load_string(path);
|
||||
const map = JSON.parse(blob);
|
||||
|
||||
|
|
@ -274,7 +308,17 @@ export async function load_world(path: string): Promise<World> {
|
|||
}
|
||||
|
||||
const levels = map.levels.map((l: any) => load_level(tilesets, l));
|
||||
return { levels, tilesets };
|
||||
const level_map = new Map();
|
||||
for (const level of levels) {
|
||||
level_map.set(level.iid, level);
|
||||
}
|
||||
|
||||
const current_level = levels.find((l) => l.world_x == 0 && l.world_y == 0);
|
||||
if (!current_level) {
|
||||
throw new Error("UNABLE TO FIND LEVEL AT 0,0: CANNOT START");
|
||||
}
|
||||
|
||||
return { levels, level_map, tilesets, current_level };
|
||||
}
|
||||
|
||||
export function has_collision(level: Level, cx: number, cy: number): boolean {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue