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
27struct AchievementEntry;
35struct GarrAbilityEntry;
37struct GarrMissionEntry;
41enum ItemQualities : uint8;
42struct ItemTemplate;
43struct LocalizedString;
44struct MapEntry;
46struct MawPowerEntry;
48struct PvpTalentEntry;
49class Quest;
50struct SkillLineEntry;
52class SpellInfo;
54struct TalentEntry;
55struct TransmogSetEntry;
56struct UiMapEntry;
57
59{
60
62 {
63 AchievementEntry const* Achievement = nullptr;
65 bool IsFinished = false;
69 std::array<uint32, 4> Criteria = { };
70 };
71
73 {
74 std::string_view Type;
75 std::string_view Name;
76 std::string_view Parent;
77 };
78
85
87 {
88 AzeriteEssenceEntry const* Essence = nullptr;
90 };
91
103
111
113 {
114 CurrencyTypesEntry const* Currency = nullptr;
116
118 };
119
141
143 {
144 GarrFollowerEntry const* Follower = nullptr;
148 std::array<uint32, 4> Abilities = { };
149 uint32 Traits[4] = { };
151 };
152
154 {
155 GarrMissionEntry const* Mission = nullptr;
157 };
158
166
168 {
169 ItemTemplate const* Item = nullptr;
171 std::array<uint32, 3> GemItemId = { };
175 std::vector<int32> ItemBonusListIDs;
176
177 struct Modifier
178 {
181 };
182
183 std::vector<Modifier> Modifiers;
184 std::vector<int32> GemItemBonusListIDs[3];
187
190 };
191
193 {
194 enum class Types : uint8
195 {
196 Instance = 0,
197 Encounter = 1,
199 Tier = 3
200 };
201
205 };
206
208 {
210 MapChallengeModeEntry const* Map = nullptr;
212 std::array<uint32, 4> Affix = { };
213 };
214
216 {
217 SpellInfo const* Spell = nullptr;
219 std::string_view Customizations;
220 };
221
223 {
224 ::Quest const* Quest = nullptr;
226 };
227
229 {
230 SpellInfo const* Spell = nullptr;
231 GlyphPropertiesEntry const* Glyph = nullptr;
232 };
233
235 {
236 ChrSpecializationEntry const* Spec = nullptr;
238 std::string_view ImportString;
239 };
240
242 {
244 SpellInfo const* Spell = nullptr;
245 SkillLineEntry const* Skill = nullptr;
246 };
247
249 {
250 UiMapEntry const* UiMap = nullptr;
254 };
255
256 namespace LinkTags {
257
258 /************************** LINK TAGS ***************************************************\
259 |* Link tags must abide by the following: *|
260 |* - MUST expose ::value_type typedef *|
261 |* - storage type is remove_cvref_t<value_type> *|
262 |* - MUST expose static ::tag method, void -> std::string_view *|
263 |* - this method SHOULD be constexpr *|
264 |* - returns identifier string for the link ("creature", "creature_entry", "item") *|
265 |* - MUST expose static ::StoreTo method, (storage&, std::string_view) *|
266 |* - assign storage& based on content of std::string_view *|
267 |* - return value indicates success/failure *|
268 |* - for integral/string types this can be achieved by extending base_tag *|
269 \****************************************************************************************/
270 struct base_tag
271 {
272 static bool StoreTo(std::string_view& val, std::string_view data)
273 {
274 val = data;
275 return true;
276 }
277
278 static bool StoreTo(std::string& val, std::string_view data)
279 {
280 val.assign(data);
281 return true;
282 }
283
284 template <typename T>
285 static std::enable_if_t<std::is_integral_v<T>, bool> StoreTo(T& val, std::string_view data)
286 {
287 if (Optional<T> res = Trinity::StringTo<T>(data))
288 {
289 val = *res;
290 return true;
291 }
292 else
293 return false;
294 }
295
296 static bool StoreTo(ObjectGuid& val, std::string_view data)
297 {
298 ObjectGuid parsed = ObjectGuid::FromString(std::string(data));
299 if (parsed != ObjectGuid::FromStringFailed)
300 {
301 val = parsed;
302 return true;
303 }
304 else
305 return false;
306 }
307 };
308
309 #define make_base_tag(ltag, type) struct ltag : public base_tag { using value_type = type; static constexpr std::string_view tag() { return #ltag; } }
310 // custom formats
312 make_base_tag(areatrigger, uint32);
314 make_base_tag(creature_entry, uint32);
317 make_base_tag(gameobject_entry, uint32);
319 make_base_tag(player, std::string_view);
324
325 // client format
327 make_base_tag(clubTicket, std::string_view);
328 make_base_tag(outfit, std::string_view); // some sort of weird base91 derived encoding
329 #undef make_base_tag
330
332 {
334 static constexpr std::string_view tag() { return "achievement"; }
335 static bool StoreTo(AchievementLinkData& val, std::string_view text);
336 };
337
339 {
340 using value_type = ApiLinkData const&;
341 static constexpr std::string_view tag() { return "api"; }
342 static bool StoreTo(ApiLinkData& val, std::string_view text);
343 };
344
346 {
348 static constexpr std::string_view tag() { return "apower"; }
349 static bool StoreTo(ArtifactPowerLinkData& val, std::string_view text);
350 };
351
353 {
355 static constexpr std::string_view tag() { return "azessence"; }
356 static bool StoreTo(AzeriteEssenceLinkData& val, std::string_view text);
357 };
358
360 {
362 static constexpr std::string_view tag() { return "battlepet"; }
363 static bool StoreTo(BattlePetLinkData& val, std::string_view text);
364 };
365
367 {
369 static constexpr std::string_view tag() { return "battlePetAbil"; }
370 static bool StoreTo(BattlePetAbilLinkData& val, std::string_view text);
371 };
372
374 {
376 static constexpr std::string_view tag() { return "conduit"; }
377 static bool StoreTo(SoulbindConduitRankEntry const*& val, std::string_view text);
378 };
379
381 {
382 using value_type = SpellInfo const*;
383 static constexpr std::string_view tag() { return "curio"; }
384 static bool StoreTo(SpellInfo const*& val, std::string_view text);
385 };
386
388 {
390 static constexpr std::string_view tag() { return "currency"; }
391 static bool StoreTo(CurrencyLinkData& val, std::string_view text);
392 };
393
395 {
397 static constexpr std::string_view tag() { return "dungeonScore"; }
398 static bool StoreTo(DungeonScoreLinkData& val, std::string_view text);
399 };
400
402 {
403 using value_type = SpellInfo const*;
404 static constexpr std::string_view tag() { return "enchant"; }
405 static bool StoreTo(SpellInfo const*& val, std::string_view text);
406 };
407
409 {
411 static constexpr std::string_view tag() { return "garrfollower"; }
412 static bool StoreTo(GarrisonFollowerLinkData& val, std::string_view text);
413 };
414
416 {
418 static constexpr std::string_view tag() { return "garrfollowerability"; }
419 static bool StoreTo(GarrAbilityEntry const*& val, std::string_view text);
420 };
421
423 {
425 static constexpr std::string_view tag() { return "garrmission"; }
426 static bool StoreTo(GarrisonMissionLinkData& val, std::string_view text);
427 };
428
430 {
432 static constexpr std::string_view tag() { return "instancelock"; }
433 static bool StoreTo(InstanceLockLinkData& val, std::string_view text);
434 };
435
437 {
438 using value_type = ItemLinkData const&;
439 static constexpr std::string_view tag() { return "item"; }
440 static bool StoreTo(ItemLinkData& val, std::string_view text);
441 };
442
444 {
446 static constexpr std::string_view tag() { return "journal"; }
447 static bool StoreTo(JournalLinkData& val, std::string_view text);
448 };
449
451 {
453 static constexpr std::string_view tag() { return "keystone"; }
454 static bool StoreTo(KeystoneLinkData& val, std::string_view text);
455 };
456
458 {
459 using value_type = MawPowerEntry const*;
460 static constexpr std::string_view tag() { return "mawpower"; }
461 static bool StoreTo(MawPowerEntry const*& val, std::string_view text);
462 };
463
465 {
466 using value_type = MountLinkData const&;
467 static constexpr std::string_view tag() { return "mount"; }
468 static bool StoreTo(MountLinkData& val, std::string_view text);
469 };
470
472 {
474 static constexpr std::string_view tag() { return "perksactivity"; }
475 static bool StoreTo(PerksActivityEntry const*& val, std::string_view text);
476 };
477
479 {
481 static constexpr std::string_view tag() { return "pvptal"; }
482 static bool StoreTo(PvpTalentEntry const*& val, std::string_view text);
483 };
484
486 {
487 using value_type = QuestLinkData const&;
488 static constexpr std::string_view tag() { return "quest"; }
489 static bool StoreTo(QuestLinkData& val, std::string_view text);
490 };
491
493 {
494 using value_type = SpellLinkData const&;
495 static constexpr std::string_view tag() { return "spell"; }
496 static bool StoreTo(SpellLinkData& val, std::string_view text);
497 };
498
500 {
501 using value_type = TalentEntry const*;
502 static constexpr std::string_view tag() { return "talent"; }
503 static bool StoreTo(TalentEntry const*& val, std::string_view text);
504 };
505
507 {
509 static constexpr std::string_view tag() { return "talentbuild"; }
510 static bool StoreTo(TalentBuildLinkData& val, std::string_view text);
511 };
512
514 {
516 static constexpr std::string_view tag() { return "trade"; }
517 static bool StoreTo(TradeskillLinkData& val, std::string_view text);
518 };
519
521 {
523 static constexpr std::string_view tag() { return "transmogappearance"; }
524 static bool StoreTo(ItemModifiedAppearanceEntry const*& val, std::string_view text);
525 };
526
528 {
530 static constexpr std::string_view tag() { return "transmogillusion"; }
531 static bool StoreTo(SpellItemEnchantmentEntry const*& val, std::string_view text);
532 };
533
535 {
537 static constexpr std::string_view tag() { return "transmogset"; }
538 static bool StoreTo(TransmogSetEntry const*& val, std::string_view text);
539 };
540
542 {
544 static constexpr std::string_view tag() { return "worldmap"; }
545 static bool StoreTo(WorldMapLinkData& val, std::string_view text);
546 };
547 }
548
550 {
551 HyperlinkColor() = default;
552 HyperlinkColor(std::string_view c) : data(c) {}
553 std::string_view data;
554 bool operator==(uint32 c) const
555 {
556 return Trinity::StringTo<uint32>(data, 16) == c;
557 }
558
559 bool operator==(ItemQualities q) const;
560 };
561
563 {
564 HyperlinkInfo() : ok(false) {}
565 HyperlinkInfo(std::string_view t, std::string_view c, std::string_view ta, std::string_view d, std::string_view te) :
566 ok(true), tail(t), color(c), tag(ta), data(d), text(te) {}
567
568 explicit operator bool() const { return ok; }
569 bool const ok;
570 std::string_view const tail;
572 std::string_view const tag;
573 std::string_view const data;
574 std::string_view const text;
575 };
576 HyperlinkInfo TC_GAME_API ParseSingleHyperlink(std::string_view str);
577 bool TC_GAME_API CheckAllLinks(std::string_view str);
578
579}
580
581#endif
Difficulty
Definition DBCEnums.h:932
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
ItemQualities
Achievement
Definition Item.h:179
Definition Map.h:225
static ObjectGuid const FromStringFailed
Definition ObjectGuid.h:316
static ObjectGuid FromString(std::string_view guidString)
uint64 LowType
Definition ObjectGuid.h:321
Definition Spell.h:277