Now have a do_if on GUECS for many of the 'if this exists do this' patterns.

This commit is contained in:
Zed A. Shaw 2025-04-15 12:02:24 -04:00
parent 2ecef8d9f9
commit 57e042e786
5 changed files with 17 additions and 14 deletions

View file

@ -99,7 +99,6 @@ namespace guecs {
struct Sound {
std::string on_click{""};
std::string on_hover{""};
void play(bool hover);
};
@ -166,6 +165,13 @@ namespace guecs {
$world.set<Comp>(ent, val);
}
template <typename Comp>
void do_if(DinkyECS::Entity ent, std::function<void(Comp &)> cb) {
if($world.has<Comp>(ent)) {
cb($world.get<Comp>(ent));
}
}
lel::Cell& cell_for(DinkyECS::Entity ent) {
return $world.get<lel::Cell>(ent);
}