Fixing a stupid bug where it would crash because a fact wasn't in the world.

This commit is contained in:
Zed A. Shaw 2024-12-19 20:46:47 -05:00
parent 93f53d1714
commit 5a6494acf5
7 changed files with 11 additions and 6 deletions

View file

@ -8,6 +8,7 @@
#include <tuple>
#include <queue>
#include "tser.hpp"
#include "dbc.hpp"
namespace DinkyECS {
@ -56,8 +57,11 @@ namespace DinkyECS {
template <typename Comp>
Comp &get_the() {
auto comp_id = std::type_index(typeid(Comp));
dbc::check($facts.contains(comp_id), "!!!! ATTEMPT to access world fact that hasn't been set yet.");
// use .at to get std::out_of_range if fact not set
std::any &res = $facts.at(std::type_index(typeid(Comp)));
std::any &res = $facts.at(comp_id);
return std::any_cast<Comp&>(res);
}