TrinityCore
Loading...
Searching...
No Matches
Hyperlinks.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_HYPERLINKS_H
19#define TRINITY_HYPERLINKS_H
20
21#include "ObjectGuid.h"
22#include "StringConvert.h"
23#include <array>
24#include <string>
25#include <string_view>
26#include <type_traits>
27#include <utility>
28
29struct AchievementEntry;
31struct GlyphSlotEntry;
34struct ItemTemplate;
35class SpellInfo;
36class Quest;
37struct TalentEntry;
38
40{
41
52
58
60 {
63 std::array<uint32, 3> GemEnchantId;
66 uint32 RandomSuffixBaseAmount; /* ITEM_FIELD_PROPERTY_SEED - only nonzero for RandomSuffix items, AllocationPct from DBC are multiplied with this, then floored, to get stat value */
69 };
70
72 {
73 ::Quest const* Quest;
75 };
76
83
92
93 namespace LinkTags {
94
95 /************************** LINK TAGS ***************************************************\
96 |* Link tags must abide by the following: *|
97 |* - MUST expose ::value_type typedef *|
98 |* - storage type is remove_cvref_t<value_type> *|
99 |* - MUST expose static ::tag method, void -> std::string_view *|
100 |* - this method SHOULD be constexpr *|
101 |* - returns identifier string for the link ("creature", "creature_entry", "item") *|
102 |* - MUST expose static ::StoreTo method, (storage&, std::string_view) *|
103 |* - assign storage& based on content of std::string_view *|
104 |* - return value indicates success/failure *|
105 |* - for integral/string types this can be achieved by extending base_tag *|
106 \****************************************************************************************/
107 struct base_tag
108 {
109 static bool StoreTo(std::string_view& val, std::string_view data)
110 {
111 val = data;
112 return true;
113 }
114
115 static bool StoreTo(std::string& val, std::string_view data)
116 {
117 val.assign(data);
118 return true;
119 }
120
121 template <typename T>
122 static std::enable_if_t<std::is_integral_v<T>, bool> StoreTo(T& val, std::string_view data)
123 {
124 if (Optional<T> res = Trinity::StringTo<T>(data))
125 {
126 val = *res;
127 return true;
128 }
129 else
130 return false;
131 }
132
133 static bool StoreTo(ObjectGuid& val, std::string_view data)
134 {
135 if (Optional<uint64> res = Trinity::StringTo<uint64>(data, 16))
136 {
137 val.SetRawValue(*res);
138 return true;
139 }
140 else
141 return false;
142 }
143 };
144
145 #define make_base_tag(ltag, type) struct ltag : public base_tag { using value_type = type; static constexpr std::string_view tag() { return #ltag; } }
147 make_base_tag(areatrigger, uint32);
149 make_base_tag(creature_entry, uint32);
152 make_base_tag(gameobject_entry, uint32);
154 make_base_tag(player, std::string_view);
159 #undef make_base_tag
160
162 {
164 static constexpr std::string_view tag() { return "achievement"; }
165 static bool StoreTo(AchievementLinkData& val, std::string_view data);
166 };
167
169 {
170 using value_type = SpellInfo const*;
171 static constexpr std::string_view tag() { return "enchant"; }
172 static bool StoreTo(SpellInfo const*& val, std::string_view data);
173 };
174
176 {
177 using value_type = GlyphLinkData const&;
178 static constexpr std::string_view tag() { return "glyph"; };
179 static bool StoreTo(GlyphLinkData& val, std::string_view data);
180 };
181
183 {
184 using value_type = ItemLinkData const&;
185 static constexpr std::string_view tag() { return "item"; }
186 static bool StoreTo(ItemLinkData& val, std::string_view data);
187 };
188
190 {
191 using value_type = QuestLinkData const&;
192 static constexpr std::string_view tag() { return "quest"; }
193 static bool StoreTo(QuestLinkData& val, std::string_view data);
194 };
195
197 {
198 using value_type = SpellInfo const*;
199 static constexpr std::string_view tag() { return "spell"; }
200 static bool StoreTo(SpellInfo const*& val, std::string_view data);
201 };
202
204 {
206 static constexpr std::string_view tag() { return "talent"; }
207 static bool StoreTo(TalentLinkData& val, std::string_view data);
208 };
209
211 {
213 static constexpr std::string_view tag() { return "trade"; }
214 static bool StoreTo(TradeskillLinkData& val, std::string_view data);
215 };
216 }
217
219 {
220 HyperlinkColor(uint32 c) : r(c >> 16), g(c >> 8), b(c), a(c >> 24) {}
221 uint8 const r, g, b, a;
222 bool operator==(uint32 c) const
223 {
224 if ((c & 0xff) ^ b)
225 return false;
226 if (((c >>= 8) & 0xff) ^ g)
227 return false;
228 if (((c >>= 8) & 0xff) ^ r)
229 return false;
230 if ((c >>= 8) ^ a)
231 return false;
232 return true;
233 }
234 };
235
237 {
238 HyperlinkInfo() : ok(false), color(0) {}
239 HyperlinkInfo(std::string_view t, uint32 c, std::string_view ta, std::string_view d, std::string_view te) :
240 ok(true), tail(t), color(c), tag(ta), data(d), text(te) {}
241
242 explicit operator bool() { return ok; }
243 bool const ok;
244 std::string_view const tail;
246 std::string_view const tag;
247 std::string_view const data;
248 std::string_view const text;
249 };
250 HyperlinkInfo TC_GAME_API ParseSingleHyperlink(std::string_view str);
251 bool TC_GAME_API CheckAllLinks(std::string_view str);
252
253}
254
255#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int16_t int16
Definition Define.h:130
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
void SetRawValue(uint64 guid)
Definition ObjectGuid.h:149
uint32 LowType
Definition ObjectGuid.h:142