GUECS now doesn't have the facts feature from DinkyECS and instead you refer to the whole area with gui.MAIN. This is an entity that's at 0 and represents the whole grid. Background is placed there.
This commit is contained in:
parent
abea6da2e0
commit
7c90eb6da1
5 changed files with 7 additions and 39 deletions
|
@ -54,7 +54,7 @@ namespace gui {
|
|||
|
||||
$boss_background = textures::get(boss.background);
|
||||
$boss_background.sprite->setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
|
||||
$status.set_the<Background>({$status.$parser});
|
||||
$status.set<Background>($status.MAIN, {$status.$parser});
|
||||
|
||||
if(boss.stage) {
|
||||
$boss_has_stage = true;
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void CombatUI::init() {
|
||||
$gui.set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID});
|
||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||
|
||||
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
||||
|
|
10
guecs.cpp
10
guecs.cpp
|
@ -182,11 +182,6 @@ namespace guecs {
|
|||
}
|
||||
|
||||
void UI::init() {
|
||||
if(has_the<Background>()) {
|
||||
auto& bg = get_the<Background>();
|
||||
bg.init();
|
||||
}
|
||||
|
||||
query<Background>([](auto, auto& bg) {
|
||||
bg.init();
|
||||
});
|
||||
|
@ -232,9 +227,8 @@ namespace guecs {
|
|||
}
|
||||
|
||||
void UI::render(sf::RenderWindow& window) {
|
||||
if(has_the<Background>()) {
|
||||
auto& bg = get_the<Background>();
|
||||
window.draw(*bg.shape);
|
||||
if(auto bg = get_if<Background>(MAIN)) {
|
||||
window.draw(*(bg->shape));
|
||||
}
|
||||
|
||||
query<Effect>([&](auto, auto& shader) {
|
||||
|
|
30
guecs.hpp
30
guecs.hpp
|
@ -150,11 +150,10 @@ namespace guecs {
|
|||
|
||||
class UI {
|
||||
public:
|
||||
unsigned long entity_count = 0;
|
||||
Entity MAIN = 0;
|
||||
unsigned long entity_count = 1;
|
||||
std::unordered_map<std::type_index, EntityMap> $components;
|
||||
std::unordered_map<std::type_index, std::any> $facts;
|
||||
std::unordered_map<std::type_index, std::any> $component_storages;
|
||||
|
||||
std::unordered_map<string, Entity> $name_ents;
|
||||
shared_ptr<sf::Font> $font = nullptr;
|
||||
lel::Parser $parser;
|
||||
|
@ -212,31 +211,6 @@ namespace guecs {
|
|||
return $components[std::type_index(typeid(Comp))];
|
||||
}
|
||||
|
||||
|
||||
template <typename Comp>
|
||||
bool has_the() {
|
||||
auto comp_id = std::type_index(typeid(Comp));
|
||||
return $facts.contains(comp_id);
|
||||
}
|
||||
|
||||
template <typename Comp>
|
||||
void set_the(Comp val) {
|
||||
$facts.insert_or_assign(std::type_index(typeid(Comp)), val);
|
||||
}
|
||||
|
||||
template <typename Comp>
|
||||
Comp &get_the() {
|
||||
auto comp_id = std::type_index(typeid(Comp));
|
||||
dbc::check($facts.contains(comp_id),
|
||||
fmt::format("!!!! ATTEMPT to access world fact that hasn't "
|
||||
"been set yet: {}",
|
||||
typeid(Comp).name()));
|
||||
|
||||
// use .at to get std::out_of_range if fact not set
|
||||
std::any &res = $facts.at(comp_id);
|
||||
return std::any_cast<Comp &>(res);
|
||||
}
|
||||
|
||||
template <typename Comp>
|
||||
void set(Entity ent, Comp val) {
|
||||
EntityMap &map = entity_map_for<Comp>();
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void StatusUI::init() {
|
||||
$gui.set_the<Background>({$gui.$parser});
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser});
|
||||
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
if(name == "log_view") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue