Solve a problem where if you give a name for cell and the name doesn't exist you get a crash during world query in GUECS.
This commit is contained in:
parent
0e2f213871
commit
5a3b567fd1
2 changed files with 14 additions and 12 deletions
25
guecs.cpp
25
guecs.cpp
|
@ -80,23 +80,24 @@ namespace guecs {
|
|||
dbc::check(good, "LEL parsing failed.");
|
||||
|
||||
for(auto& [name, cell] : $parser.cells) {
|
||||
auto ent = entity(name);
|
||||
auto ent = init_entity(name);
|
||||
$world.set<lel::Cell>(ent, cell);
|
||||
}
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::init_entity(std::string name) {
|
||||
auto entity = $world.entity();
|
||||
// this lets you look up an entity by name
|
||||
$name_ents.insert_or_assign(name, entity);
|
||||
// this makes it easier to get the name during querying
|
||||
$world.set<CellName>(entity, {name});
|
||||
return entity;
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::entity(std::string name) {
|
||||
if($name_ents.contains(name)) {
|
||||
// already exists so just return it
|
||||
return $name_ents.at(name);
|
||||
} else {
|
||||
auto entity = $world.entity();
|
||||
// this lets you look up an entity by name
|
||||
$name_ents.insert_or_assign(name, entity);
|
||||
// this makes it easier to get the name during querying
|
||||
$world.set<CellName>(entity, {name});
|
||||
return entity;
|
||||
}
|
||||
dbc::check($name_ents.contains(name),
|
||||
fmt::format("GUECS entity {} does not exist. Forgot to init_entity?", name));
|
||||
return $name_ents.at(name);
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue