add entity metadata.

This commit is contained in:
trans_soup 2023-10-25 20:08:10 +02:00
parent 1e23765533
commit b367c4b3a3
1 changed files with 18 additions and 0 deletions

View File

@ -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";
});