diff --git a/include/game/game_utils.hpp b/include/game/game_utils.hpp index 5237d924..e0f0ac74 100644 --- a/include/game/game_utils.hpp +++ b/include/game/game_utils.hpp @@ -23,5 +23,25 @@ inline bool isPreWotlk() { return isClassicLikeExpansion() || isActiveExpansion("tbc"); } +// Shared item link formatter used by inventory, quest, spell, and social handlers. +// Centralised here so quality color table changes propagate everywhere. +inline std::string buildItemLink(uint32_t itemId, uint32_t quality, const std::string& name) { + static const char* kQualHex[] = { + "9d9d9d", // 0 Poor + "ffffff", // 1 Common + "1eff00", // 2 Uncommon + "0070dd", // 3 Rare + "a335ee", // 4 Epic + "ff8000", // 5 Legendary + "e6cc80", // 6 Artifact + "e6cc80", // 7 Heirloom + }; + uint32_t qi = quality < 8 ? quality : 1u; + char buf[512]; + snprintf(buf, sizeof(buf), "|cff%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r", + kQualHex[qi], itemId, name.c_str()); + return buf; +} + } // namespace game } // namespace wowee diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index f9906c8d..ae88df3c 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -90,28 +90,6 @@ bool isAuthCharPipelineOpcode(LogicalOpcode op) { } // end anonymous namespace -// Build a WoW-format item link for use in system chat messages. -// The chat renderer in game_screen.cpp parses this format and draws the -// item name in its quality colour with a small icon and tooltip. -// Format: |cff|Hitem::0:0:0:0:0:0:0:0|h[]|h|r -std::string buildItemLink(uint32_t itemId, uint32_t quality, const std::string& name) { - static const char* kQualHex[] = { - "9d9d9d", // 0 Poor - "ffffff", // 1 Common - "1eff00", // 2 Uncommon - "0070dd", // 3 Rare - "a335ee", // 4 Epic - "ff8000", // 5 Legendary - "e6cc80", // 6 Artifact - "e6cc80", // 7 Heirloom - }; - uint32_t qi = quality < 8 ? quality : 1u; - char buf[512]; - snprintf(buf, sizeof(buf), "|cff%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r", - kQualHex[qi], itemId, name.c_str()); - return buf; -} - namespace { bool isActiveExpansion(const char* expansionId) { diff --git a/src/game/inventory_handler.cpp b/src/game/inventory_handler.cpp index bcba01e8..ae05c9f8 100644 --- a/src/game/inventory_handler.cpp +++ b/src/game/inventory_handler.cpp @@ -18,8 +18,6 @@ namespace wowee { namespace game { -// Free functions defined in game_handler.cpp -std::string buildItemLink(uint32_t itemId, uint32_t quality, const std::string& name); std::string formatCopperAmount(uint32_t amount); InventoryHandler::InventoryHandler(GameHandler& owner) diff --git a/src/game/social_handler.cpp b/src/game/social_handler.cpp index b8337b6b..956987d4 100644 --- a/src/game/social_handler.cpp +++ b/src/game/social_handler.cpp @@ -17,8 +17,6 @@ namespace wowee { namespace game { -// Free function defined in game_handler.cpp -std::string buildItemLink(uint32_t itemId, uint32_t quality, const std::string& name); static bool packetHasRemaining(const network::Packet& packet, size_t need) { const size_t size = packet.getSize(); diff --git a/src/game/spell_handler.cpp b/src/game/spell_handler.cpp index cf6511ee..fa6ab658 100644 --- a/src/game/spell_handler.cpp +++ b/src/game/spell_handler.cpp @@ -60,23 +60,6 @@ static audio::SpellSoundManager::MagicSchool schoolMaskToMagicSchool(uint32_t ma return audio::SpellSoundManager::MagicSchool::ARCANE; } -static std::string buildItemLink(uint32_t itemId, uint32_t quality, const std::string& name) { - static const char* kQualHex[] = { - "9d9d9d", // 0 Poor - "ffffff", // 1 Common - "1eff00", // 2 Uncommon - "0070dd", // 3 Rare - "a335ee", // 4 Epic - "ff8000", // 5 Legendary - "e6cc80", // 6 Artifact - "e6cc80", // 7 Heirloom - }; - uint32_t qi = quality < 8 ? quality : 1u; - char buf[512]; - snprintf(buf, sizeof(buf), "|cff%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r", - kQualHex[qi], itemId, name.c_str()); - return buf; -} static std::string displaySpellName(GameHandler& handler, uint32_t spellId) { if (spellId == 0) return {};