diff --git a/js/entity.mjs b/js/entity.mjs index ad09b79..88f4d4c 100644 --- a/js/entity.mjs +++ b/js/entity.mjs @@ -52,6 +52,17 @@ export function is_visible (entity) { +const metadata = new Map(); + +export function get_meta (entity) { + if (!metadata.has(entity.id)) { + metadata.set(entity.id, new Map()); + } + return metadata.get(entity.id); +} + + + // TESTS assert("entity creation works.", _ => { @@ -123,3 +134,10 @@ assert("creating entities with preset visibility works.", _ => { }); return e2.visible; }); + +assert("entity `get_meta` works.", _ => { + const e = create(); + const meta = get_meta(e); + meta.set("test", "gay"); + return get_meta(e).get("test") === "gay"; +});