refactor: consolidate buildItemLink into game_utils.hpp

Three identical copies (game_handler.cpp, spell_handler.cpp,
quest_handler.cpp) plus two forward declarations (inventory_handler.cpp,
social_handler.cpp) replaced with a single inline definition in
game_utils.hpp. All affected files already include this header, so
quality color table changes now propagate from one source of truth.
This commit is contained in:
Kelsi 2026-03-29 17:57:05 -07:00
parent 0aff4b155c
commit dc500fede9
5 changed files with 20 additions and 43 deletions

View file

@ -23,5 +23,25 @@ inline bool isPreWotlk() {
return isClassicLikeExpansion() || isActiveExpansion("tbc"); 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 game
} // namespace wowee } // namespace wowee

View file

@ -90,28 +90,6 @@ bool isAuthCharPipelineOpcode(LogicalOpcode op) {
} // end anonymous namespace } // 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<rrggbb>|Hitem:<id>:0:0:0:0:0:0:0:0|h[<name>]|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 { namespace {
bool isActiveExpansion(const char* expansionId) { bool isActiveExpansion(const char* expansionId) {

View file

@ -18,8 +18,6 @@
namespace wowee { namespace wowee {
namespace game { 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); std::string formatCopperAmount(uint32_t amount);
InventoryHandler::InventoryHandler(GameHandler& owner) InventoryHandler::InventoryHandler(GameHandler& owner)

View file

@ -17,8 +17,6 @@
namespace wowee { namespace wowee {
namespace game { 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) { static bool packetHasRemaining(const network::Packet& packet, size_t need) {
const size_t size = packet.getSize(); const size_t size = packet.getSize();

View file

@ -60,23 +60,6 @@ static audio::SpellSoundManager::MagicSchool schoolMaskToMagicSchool(uint32_t ma
return audio::SpellSoundManager::MagicSchool::ARCANE; 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) { static std::string displaySpellName(GameHandler& handler, uint32_t spellId) {
if (spellId == 0) return {}; if (spellId == 0) return {};