| 45 | } |
| 46 | |
| 47 | auto Sorcery::ComponentStore::get(std::string_view combined_key) |
| 48 | -> Component & { |
| 49 | |
| 50 | // swap into _load instead and check if refresh needed is called unnecessary |
| 51 | try { |
| 52 | |
| 53 | // First check if we need to reload if anything has changed! |
| 54 | if (need_refresh()) |
| 55 | load(_file); |
| 56 | |
| 57 | } catch (std::exception &e) { |
| 58 | |
| 59 | Error error{Enums::System::Error::JSON_PARSE_ERROR, e, |
| 60 | "layout.json is not valid JSON!"}; |
| 61 | std::cerr << error; |
| 62 | exit(EXIT_FAILURE); |
| 63 | } |
| 64 | |
| 65 | try { |
| 66 | |
| 67 | // Else return the requested component |
| 68 | if (_loaded) |
| 69 | if (_components.contains(std::string{combined_key})) |
| 70 | return _components.at(std::string{combined_key}); |
| 71 | else |
| 72 | return _components.begin()->second; |
| 73 | else |
| 74 | return _components.begin()->second; |
| 75 | |
| 76 | } catch (std::exception &e) { |
| 77 | Error error{Enums::System::Error::UNKNOWN_COMPONENT, e, |
| 78 | std::format("Unable to find Component '{}' in layout.json!", |
| 79 | combined_key)}; |
| 80 | std::cerr << error; |
| 81 | exit(EXIT_FAILURE); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Overload () Operator |
| 86 | auto Sorcery::ComponentStore::operator()(std::string_view screen) |