r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1///
2/// @file Systems.hpp
3/// @brief This file contains the TextSystem definitions
4/// @namespace cli
5///
6
7#pragma once
8
9#include "ECS/Component.hpp"
10#include "ECS/Registry.hpp"
12
13namespace cli
14{
15
16 ///
17 /// @class TextSystem
18 /// @brief Class for managing entities and their components
19 /// @namespace ecs
20 ///
21 class TextSystem final : public eng::ASystem
22 {
23 public:
24 explicit TextSystem(eng::IRenderer &renderer) : m_renderer(renderer) {}
25 ~TextSystem() override = default;
26
27 TextSystem(const TextSystem &) = delete;
28 TextSystem &operator=(const TextSystem &) = delete;
29 TextSystem(TextSystem &&) = delete;
31
32 void update(ecs::Registry &registry, float /* dt */) override
33 {
34
35 for (auto &[entity, text] : registry.getAll<ecs::Text>())
36 {
37 const auto *transform = registry.getComponent<ecs::Transform>(entity);
38 const auto *color = registry.getComponent<ecs::Color>(entity);
39
40 const float x = (transform != nullptr) ? transform->x : 0.F;
41 const float y = (transform != nullptr) ? transform->y : 0.F;
42
43 const std::uint8_t r = color ? color->r : 255u;
44 const std::uint8_t g = color ? color->g : 255u;
45 const std::uint8_t b = color ? color->b : 255u;
46 const std::uint8_t a = color ? color->a : 255u;
47
48 m_renderer.setTextContent(text.id, text.content);
49 m_renderer.setTextPosition(text.id, x, y);
50 m_renderer.setTextColor(text.id, {.r = r, .g = g, .b = b, .a = a});
51 m_renderer.drawText(text.id);
52 }
53 }
54
55 private:
57 }; // class TextSystem
58
59} // namespace cli
This file contains the component definitions.
This file contains the IRenderer class declaration.
This file contains the Registry class declaration.
Class for managing entities and their components.
Definition Text.hpp:22
TextSystem(TextSystem &&)=delete
TextSystem(const TextSystem &)=delete
void update(ecs::Registry &registry, float) override
Definition Text.hpp:32
~TextSystem() override=default
TextSystem(eng::IRenderer &renderer)
Definition Text.hpp:24
eng::IRenderer & m_renderer
Definition Text.hpp:56
TextSystem & operator=(const TextSystem &)=delete
TextSystem & operator=(TextSystem &&)=delete
Class for managing entities and their components.
Definition Registry.hpp:25
std::unordered_map< Entity, T > & getAll()
Definition Registry.hpp:77
T * getComponent(Entity e)
Definition Registry.hpp:71
Interface for the renderer.
virtual void setTextPosition(const std::string &name, float x, float y)=0
virtual void drawText(const std::string &name)=0
virtual void setTextContent(const std::string &name, const std::string &content)=0
virtual void setTextColor(const std::string &name, Color color)=0