TrinityCore
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
27struct AchievementEntry;
35struct GarrAbilityEntry;
37struct GarrMissionEntry;
41struct ItemTemplate;
42struct LocalizedString;
43struct MapEntry;
45struct MawPowerEntry;
46struct PvpTalentEntry;
47class Quest;
48struct SkillLineEntry;
50class SpellInfo;
52struct TalentEntry;
53struct TransmogSetEntry;
54struct UiMapEntry;
55
57{
58
60 {
61 AchievementEntry const* Achievement = nullptr;
63 bool IsFinished = false;
67 std::array<uint32, 4> Criteria = { };
68 };
69
71 {
72 std::string_view Type;
73 std::string_view Name;
74 std::string_view Parent;
75 };
76
78 {
82 };
83
85 {
86 AzeriteEssenceEntry const* Essence = nullptr;
88 };
89
91 {
100 };
101
103 {
108 };
109
111 {
112 CurrencyTypesEntry const* Currency = nullptr;
114
116 };
117
119 {
122 std::string_view PlayerName;
129
130 struct Dungeon
131 {
133 bool CompletedInTime = false;
135 };
136
137 std::vector<Dungeon> Dungeons;
138 };
139
141 {
142 GarrFollowerEntry const* Follower = nullptr;
146 std::array<uint32, 4> Abilities = { };
147 uint32 Traits[4] = { };
149 };
150
152 {
153 GarrMissionEntry const* Mission = nullptr;
155 };
156
158 {
160 MapEntry const* Map = nullptr;
163 };
164
166 {
167 ItemTemplate const* Item = nullptr;
169 std::array<uint32, 3> GemItemId = { };
173 std::vector<int32> ItemBonusListIDs;
174
175 struct Modifier
176 {
179 };
180
181 std::vector<Modifier> Modifiers;
182 std::vector<int32> GemItemBonusListIDs[3];
185
188 };
189
191 {
192 enum class Types : uint8
193 {
194 Instance = 0,
195 Encounter = 1,
196 EncounterSection = 2,
197 Tier = 3
198 };
199
203 };
204
206 {
208 MapChallengeModeEntry const* Map = nullptr;
210 std::array<uint32, 4> Affix = { };
211 };
212
214 {
215 SpellInfo const* Spell = nullptr;
217 std::string_view Customizations;
218 };
219
221 {
222 ::Quest const* Quest = nullptr;
224 };
225
227 {
228 SpellInfo const* Spell = nullptr;
229 GlyphPropertiesEntry const* Glyph = nullptr;
230 };
231
233 {
234 ChrSpecializationEntry const* Spec = nullptr;
236 std::string_view ImportString;
237 };
238
240 {
242 SpellInfo const* Spell = nullptr;
243 SkillLineEntry const* Skill = nullptr;
244 };
245
247 {
248 UiMapEntry const* UiMap = nullptr;
252 };
253
254 namespace LinkTags {
255
256 /************************** LINK TAGS ***************************************************\
257 |* Link tags must abide by the following: *|
258 |* - MUST expose ::value_type typedef *|
259 |* - storage type is remove_cvref_t<value_type> *|
260 |* - MUST expose static ::tag method, void -> std::string_view *|
261 |* - this method SHOULD be constexpr *|
262 |* - returns identifier string for the link ("creature", "creature_entry", "item") *|
263 |* - MUST expose static ::StoreTo method, (storage&, std::string_view) *|
264 |* - assign storage& based on content of std::string_view *|
265 |* - return value indicates success/failure *|
266 |* - for integral/string types this can be achieved by extending base_tag *|
267 \****************************************************************************************/
268 struct base_tag
269 {
270 static bool StoreTo(std::string_view& val, std::string_view data)
271 {
272 val = data;
273 return true;
274 }
275
276 static bool StoreTo(std::string& val, std::string_view data)
277 {
278 val.assign(data);
279 return true;
280 }
281
282 template <typename T>
283 static std::enable_if_t<std::is_integral_v<T>, bool> StoreTo(T& val, std::string_view data)
284 {
285 if (Optional<T> res = Trinity::StringTo<T>(data))
286 {
287 val = *res;
288 return true;
289 }
290 else
291 return false;
292 }
293
294 static bool StoreTo(ObjectGuid& val, std::string_view data)
295 {
296 ObjectGuid parsed = ObjectGuid::FromString(std::string(data));
297 if (parsed != ObjectGuid::FromStringFailed)
298 {
299 val = parsed;
300 return true;
301 }
302 else
303 return false;
304 }
305 };
306
307 #define make_base_tag(ltag, type) struct ltag : public base_tag { using value_type = type; static constexpr std::string_view tag() { return #ltag; } }
308 // custom formats
310 make_base_tag(areatrigger, uint32);
312 make_base_tag(creature_entry, uint32);
315 make_base_tag(gameobject_entry, uint32);
317 make_base_tag(player, std::string_view);
322
323 // client format
325 make_base_tag(clubTicket, std::string_view);
326 make_base_tag(outfit, std::string_view); // some sort of weird base91 derived encoding
327 #undef make_base_tag
328
330 {
332 static constexpr std::string_view tag() { return "achievement"; }
333 static bool StoreTo(AchievementLinkData& val, std::string_view text);
334 };
335
337 {
338 using value_type = ApiLinkData const&;
339 static constexpr std::string_view tag() { return "api"; }
340 static bool StoreTo(ApiLinkData& val, std::string_view text);
341 };
342
344 {
346 static constexpr std::string_view tag() { return "apower"; }
347 static bool StoreTo(ArtifactPowerLinkData& val, std::string_view text);
348 };
349
351 {
353 static constexpr std::string_view tag() { return "azessence"; }
354 static bool StoreTo(AzeriteEssenceLinkData& val, std::string_view text);
355 };
356
358 {
360 static constexpr std::string_view tag() { return "battlepet"; }
361 static bool StoreTo(BattlePetLinkData& val, std::string_view text);
362 };
363
365 {
367 static constexpr std::string_view tag() { return "battlePetAbil"; }
368 static bool StoreTo(BattlePetAbilLinkData& val, std::string_view text);
369 };
370
372 {
374 static constexpr std::string_view tag() { return "conduit"; }
375 static bool StoreTo(SoulbindConduitRankEntry const*& val, std::string_view text);
376 };
377
379 {
381 static constexpr std::string_view tag() { return "currency"; }
382 static bool StoreTo(CurrencyLinkData& val, std::string_view text);
383 };
384
386 {
388 static constexpr std::string_view tag() { return "dungeonScore"; }
389 static bool StoreTo(DungeonScoreLinkData& val, std::string_view text);
390 };
391
393 {
394 using value_type = SpellInfo const*;
395 static constexpr std::string_view tag() { return "enchant"; }
396 static bool StoreTo(SpellInfo const*& val, std::string_view text);
397 };
398
400 {
402 static constexpr std::string_view tag() { return "garrfollower"; }
403 static bool StoreTo(GarrisonFollowerLinkData& val, std::string_view text);
404 };
405
407 {
409 static constexpr std::string_view tag() { return "garrfollowerability"; }
410 static bool StoreTo(GarrAbilityEntry const*& val, std::string_view text);
411 };
412
414 {
416 static constexpr std::string_view tag() { return "garrmission"; }
417 static bool StoreTo(GarrisonMissionLinkData& val, std::string_view text);
418 };
419
421 {
423 static constexpr std::string_view tag() { return "instancelock"; }
424 static bool StoreTo(InstanceLockLinkData& val, std::string_view text);
425 };
426
428 {
429 using value_type = ItemLinkData const&;
430 static constexpr std::string_view tag() { return "item"; }
431 static bool StoreTo(ItemLinkData& val, std::string_view text);
432 };
433
435 {
437 static constexpr std::string_view tag() { return "journal"; }
438 static bool StoreTo(JournalLinkData& val, std::string_view text);
439 };
440
442 {
444 static constexpr std::string_view tag() { return "keystone"; }
445 static bool StoreTo(KeystoneLinkData& val, std::string_view text);
446 };
447
449 {
450 using value_type = MawPowerEntry const*;
451 static constexpr std::string_view tag() { return "mawpower"; }
452 static bool StoreTo(MawPowerEntry const*& val, std::string_view text);
453 };
454
456 {
457 using value_type = MountLinkData const&;
458 static constexpr std::string_view tag() { return "mount"; }
459 static bool StoreTo(MountLinkData& val, std::string_view text);
460 };
461
463 {
465 static constexpr std::string_view tag() { return "pvptal"; }
466 static bool StoreTo(PvpTalentEntry const*& val, std::string_view text);
467 };
468
470 {
471 using value_type = QuestLinkData const&;
472 static constexpr std::string_view tag() { return "quest"; }
473 static bool StoreTo(QuestLinkData& val, std::string_view text);
474 };
475
477 {
478 using value_type = SpellLinkData const&;
479 static constexpr std::string_view tag() { return "spell"; }
480 static bool StoreTo(SpellLinkData& val, std::string_view text);
481 };
482
484 {
485 using value_type = TalentEntry const*;
486 static constexpr std::string_view tag() { return "talent"; }
487 static bool StoreTo(TalentEntry const*& val, std::string_view text);
488 };
489
491 {
493 static constexpr std::string_view tag() { return "talentbuild"; }
494 static bool StoreTo(TalentBuildLinkData& val, std::string_view text);
495 };
496
498 {
500 static constexpr std::string_view tag() { return "trade"; }
501 static bool StoreTo(TradeskillLinkData& val, std::string_view text);
502 };
503
505 {
507 static constexpr std::string_view tag() { return "transmogappearance"; }
508 static bool StoreTo(ItemModifiedAppearanceEntry const*& val, std::string_view text);
509 };
510
512 {
514 static constexpr std::string_view tag() { return "transmogillusion"; }
515 static bool StoreTo(SpellItemEnchantmentEntry const*& val, std::string_view text);
516 };
517
519 {
521 static constexpr std::string_view tag() { return "transmogset"; }
522 static bool StoreTo(TransmogSetEntry const*& val, std::string_view text);
523 };
524
526 {
528 static constexpr std::string_view tag() { return "worldmap"; }
529 static bool StoreTo(WorldMapLinkData& val, std::string_view text);
530 };
531 }
532
534 {
535 HyperlinkColor(uint32 c) : r(c >> 16), g(c >> 8), b(c), a(c >> 24) {}
536 uint8 const r, g, b, a;
537 bool operator==(uint32 c) const
538 {
539 if ((c & 0xff) ^ b)
540 return false;
541 if (((c >>= 8) & 0xff) ^ g)
542 return false;
543 if (((c >>= 8) & 0xff) ^ r)
544 return false;
545 if ((c >>= 8) ^ a)
546 return false;
547 return true;
548 }
549 };
550
552 {
553 HyperlinkInfo() : ok(false), color(0) {}
554 HyperlinkInfo(std::string_view t, uint32 c, std::string_view ta, std::string_view d, std::string_view te) :
555 ok(true), tail(t), color(c), tag(ta), data(d), text(te) {}
556
557 explicit operator bool() { return ok; }
558 bool const ok;
559 std::string_view const tail;
561 std::string_view const tag;
562 std::string_view const data;
563 std::string_view const text;
564 };
565 HyperlinkInfo TC_GAME_API ParseSingleHyperlink(std::string_view str);
566 bool TC_GAME_API CheckAllLinks(std::string_view str);
567
568}
569
570#endif
Difficulty
Definition: DBCEnums.h:873
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Achievement
Definition: Item.h:170
Definition: Map.h:189
static ObjectGuid FromString(std::string const &guidString)
Definition: ObjectGuid.cpp:564
static ObjectGuid const FromStringFailed
Definition: ObjectGuid.h:275
uint64 LowType
Definition: ObjectGuid.h:278
Definition: Spell.h:255