CardGame
Rogue-like card videogame
Loading...
Searching...
No Matches
cardRenderer.h
Go to the documentation of this file.
1#ifndef CARDRENDERER_H
2#define CARDRENDERER_H
3
4#include <memory>
5#include <optional>
6#include <string>
7#include <string_view>
8#include <vector>
9
10class CardInstance;
11struct CardParams;
12
16enum class SlotAlignment
17{
18 Left,
19 Center,
20 Right
21};
22
29struct Slot
30{
35};
36
43{
44 std::string firstName;
45 std::optional<std::string> secondName;
46};
47
58{
59 public:
60 CardRenderer() = default;
61
68 std::vector<std::string> renderCard(const CardInstance& cardToRender) const;
69
71 int getCardTemplateWidth() const { return m_width; }
72
73 private:
75 void drawTemplate(std::vector<std::string>& grid) const;
76
87 std::string fitText(Slot currentSlot, std::string_view text) const;
88
96 void writeSlot(std::vector<std::string>& grid, Slot slot, std::string_view formattedText) const;
97
101 static void appendWord(std::string& line, std::string_view word);
102
106 static void appendSeparator(std::string& line, std::string_view word);
107
117 NameLayout drawLayout(std::string_view cardName, Slot currentSlot) const;
118
119 std::string drawEffects(const CardParams& cardParams) const;
120
121 const int m_width{24};
122 const int m_height{12};
123
124 const int m_nameWidth{16};
125 const int m_nameColumn{m_width / 2 - m_nameWidth / 2};
126
127 const char m_padding{' '};
128 const char m_verticalBorder{'|'};
129 const char m_horizontalBorder{'-'};
130
131 Slot m_firstNameSlot{1, m_nameColumn, m_nameWidth, SlotAlignment::Center};
132 Slot m_secondNameSlot{2, m_nameColumn, m_nameWidth, SlotAlignment::Center};
133
134 Slot m_atkLabelSlot{5, 2, 6, SlotAlignment::Left};
135 Slot m_defLabelSlot{5, m_width - 10, 6, SlotAlignment::Left};
136
137 Slot m_damageValueSlot{5, 8, 2, SlotAlignment::Right};
138 Slot m_armorValueSlot{5, m_width - 4, 2, SlotAlignment::Right};
139 Slot m_effectsSumSlot{7, 3, 18, SlotAlignment::Center};
140 Slot m_firstDescrSlot{9, 2, m_width - 4, SlotAlignment::Left};
141 Slot m_secondDescrSlot{10, 2, m_width - 4, SlotAlignment::Left};
142};
143
144#endif // CARDRENDERER_H
SlotAlignment
Text alignment used when fitting content into a fixed-width slot.
Definition: cardRenderer.h:17
Represents a runtime instance of a card during combat.
Definition: cardInstance.h:21
Renders a CardInstance as a fixed-size ASCII grid.
Definition: cardRenderer.h:58
std::vector< std::string > renderCard(const CardInstance &cardToRender) const
Renders the given card into an ASCII grid.
Definition: cardRenderer.cpp:9
CardRenderer()=default
int getCardTemplateWidth() const
Returns the fixed width of the rendered card template.
Definition: cardRenderer.h:71
Numeric parameters used to resolve gameplay effects.
Definition: cardParams.h:16
Two-line text layout produced by splitting a string to fit a slot width.
Definition: cardRenderer.h:43
std::optional< std::string > secondName
Definition: cardRenderer.h:45
std::string firstName
Definition: cardRenderer.h:44
Defines a rectangular text slot within a rendered card grid.
Definition: cardRenderer.h:30
SlotAlignment alignment
Definition: cardRenderer.h:34
int maxWidth
Definition: cardRenderer.h:33
int rowIndex
Definition: cardRenderer.h:31
int columnIndex
Definition: cardRenderer.h:32