Implement a way to map entities to their names, which comes up often enough.

This commit is contained in:
Zed A. Shaw 2025-07-07 10:54:23 -04:00
parent e1d61dc2c1
commit ad78c186c6
3 changed files with 12 additions and 0 deletions

View file

@ -38,11 +38,19 @@ namespace guecs {
auto ent = entity();
// this lets you look up an entity by name
$name_ents.insert_or_assign(name, ent);
// this lets you get a name by entity
$ents_name.insert_or_assign(ent, name);
// this makes it easier to get the name during querying
set<CellName>(ent, {name});
return ent;
}
const std::string& UI::name_for(Entity gui_id) {
assert($ents_name.contains(gui_id) &&
"Attempt to get name_for an Entity but that's not a valid ID.");
return $ents_name.at(gui_id);
}
Entity UI::entity(const string& name) {
assert($name_ents.contains(name) &&
"GUECS entity does not exist. Mispelled cell name?");