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

@ -60,10 +60,7 @@ namespace guecs {
}
void Sound::play(bool hover) {
if(hover) {
// BUG: need to sort out how to make hover a one shot thing
// sound::play(on_hover);
} else {
if(!hover) {
sound::play(on_click);
}
}
@ -235,17 +232,14 @@ namespace guecs {
if((x >= cell.x && x <= cell.x + cell.w) &&
(y >= cell.y && y <= cell.y + cell.h))
{
if($world.has<Effect>(ent)) {
auto& effect = $world.get<Effect>(ent);
do_if<Effect>(ent, [hover](auto& effect) {
effect.$shader->setUniform("hover", hover);
effect.run();
}
if($world.has<Sound>(ent)) {
auto& sound = $world.get<Sound>(ent);
sound.play(hover);
}
});
do_if<Sound>(ent, [hover](auto& sound) {
sound.play(hover);
});
if(hover) return; // kinda gross