| 40 | class Stage; |
| 41 | |
| 42 | class GameObject { |
| 43 | public: |
| 44 | GameObject(); |
| 45 | |
| 46 | void set_stage(Stage& stage); |
| 47 | |
| 48 | [[nodiscard]] std::optional<std::reference_wrapper<Stage>> |
| 49 | get_stage() const; |
| 50 | |
| 51 | template <typename T> |
| 52 | [[nodiscard]] std::optional<std::reference_wrapper<T>> |
| 53 | get_component(const std::string& tag) { |
| 54 | if (!all_components_.contains(tag)) { |
| 55 | return std::nullopt; |
| 56 | } |
| 57 | auto* ptr = dynamic_cast<T*>(all_components_[tag].get()); |
| 58 | if (ptr == nullptr) { |
| 59 | return std::nullopt; |
| 60 | } |
| 61 | return std::ref(*ptr); |
| 62 | } |
| 63 | |
| 64 | [[nodiscard]] bool initialize() const; |
| 65 | |
| 66 | [[nodiscard]] bool post_initialize() const; |
| 67 | |
| 68 | void update() const; |
| 69 | |
| 70 | void add_component(const std::string& component_name, |
| 71 | const std::shared_ptr<Component>& component); |
| 72 | |
| 73 | mat4 get_pose(); |
| 74 | |
| 75 | void set_pose(const mat4& pose); |
| 76 | |
| 77 | void request_render_update() const; |
| 78 | |
| 79 | void mouse_drag_event(int mouse_x, int mouse_y) const; |
| 80 | |
| 81 | void mouse_move_event(int mouse_x, int mouse_y) const; |
| 82 | |
| 83 | [[nodiscard]] EventProcessCode key_press_event(int key_code) const; |
| 84 | |
| 85 | const std::map<std::string, std::shared_ptr<Component>, std::less<>>& |
| 86 | get_components() const; |
| 87 | |
| 88 | private: |
| 89 | std::optional<std::reference_wrapper<Stage>> |
| 90 | stage_{}; // Set via set_stage() before use |
| 91 | |
| 92 | [[nodiscard]] Stage& stage() const { |
| 93 | assert(stage_.has_value() && |
| 94 | "stage_ must be set via set_stage() before use"); |
| 95 | return stage_->get(); |
| 96 | } |
| 97 | |
| 98 | std::map<std::string, std::shared_ptr<Component>, std::less<>> |
| 99 | all_components_{}; |
nothing calls this directly
no outgoing calls
no test coverage detected