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
13
guecs.cpp
13
guecs.cpp
|
@ -80,16 +80,12 @@ 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::entity(std::string name) {
|
||||
if($name_ents.contains(name)) {
|
||||
// already exists so just return it
|
||||
return $name_ents.at(name);
|
||||
} else {
|
||||
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);
|
||||
|
@ -97,6 +93,11 @@ namespace guecs {
|
|||
$world.set<CellName>(entity, {name});
|
||||
return entity;
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::entity(std::string name) {
|
||||
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() {
|
||||
|
|
|
@ -114,6 +114,7 @@ namespace guecs {
|
|||
|
||||
void position(int x, int y, int width, int height);
|
||||
void layout(std::string grid);
|
||||
DinkyECS::Entity init_entity(std::string name);
|
||||
DinkyECS::Entity entity(std::string name);
|
||||
|
||||
inline lel::CellMap& cells() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue