Optimize GUECS a bit so that it automatically sets up the cell names and lel::Cell contents in the world, making it easier to work with.

master
Zed A. Shaw 2 weeks ago
parent 2261e6f418
commit 389690e5c3
  1. 2
      combat_ui.cpp
  2. 5
      guecs.cpp
  3. 5
      overlay_ui.cpp
  4. 2
      status_ui.cpp
  5. 4
      tests/sound.cpp

@ -23,14 +23,12 @@ namespace gui {
for(auto& [name, cell] : $gui.cells()) {
if(name.starts_with("button_")) {
auto button = $gui.entity(name);
world.set<lel::Cell>(button, cell);
world.set<Rectangle>(button, {});
world.set<Clickable>(button,
guecs::make_action(*$level.world, Events::GUI::ATTACK));
world.set<Label>(button, {"Attack"});
} else if(name.starts_with("bar_")) {
$meter = $gui.entity(name);
world.set<lel::Cell>($meter, cell);
world.set<Rectangle>($meter, {});
world.set<Meter>($meter, {});
} else {

@ -12,6 +12,11 @@ namespace guecs {
void UI::layout(std::string grid) {
$grid = grid;
$parser.parse($grid);
for(auto& [name, cell] : $parser.cells) {
auto ent = entity(name);
$world.set<lel::Cell>(ent, cell);
}
}
DinkyECS::Entity UI::entity(std::string name) {

@ -22,11 +22,6 @@ namespace gui {
}
void OverlayUI::render() {
auto &world = $gui.world();
for(auto &[name, cell] : $gui.cells()) {
auto region = $gui.entity(name);
world.set<lel::Cell>(region, cell);
}
$gui.init();
}

@ -30,7 +30,6 @@ namespace gui {
for(auto& [name, cell] : $gui.cells()) {
if(name == "log_view") {
$log_to = $gui.entity("log_view");
world.set<lel::Cell>($log_to, cell);
world.set<Rectangle>($log_to, {});
world.set<Textual>($log_to, {"Welcome to the Game!", 20});
} else {
@ -39,7 +38,6 @@ namespace gui {
auto& fake_item = fake_items[selected_item];
auto button = $gui.entity(name);
world.set<lel::Cell>(button, cell);
world.set<Rectangle>(button, {});
world.set<Sprite>(button, {fake_item});
world.set<Clickable>(button,

@ -9,7 +9,7 @@ using namespace fmt;
TEST_CASE("test sound manager", "[sound]") {
sound::init();
sound::play("sword_1");
sound::play("blank");
sound::play_at("sword_1", 0.1, 0.1, 0.1);
sound::play_at("blank", 0.1, 0.1, 0.1);
}

Loading…
Cancel
Save