mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
feat: add GetSpellLink Lua API for clickable spell links in chat
Returns WoW-format spell link string "|cff71d5ff|Hspell:ID|h[Name]|h|r" for a spell ID or name. Used by damage meters, chat addons, and WeakAuras to create clickable spell references in chat messages.
This commit is contained in:
parent
bc4ff501e2
commit
6d2a94a844
1 changed files with 29 additions and 0 deletions
|
|
@ -1222,6 +1222,34 @@ static int lua_UnitCreatureType(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSpellLink(spellIdOrName) → "|cFFxxxxxx|Hspell:ID|h[Name]|h|r"
|
||||||
|
static int lua_GetSpellLink(lua_State* L) {
|
||||||
|
auto* gh = getGameHandler(L);
|
||||||
|
if (!gh) { lua_pushnil(L); return 1; }
|
||||||
|
|
||||||
|
uint32_t spellId = 0;
|
||||||
|
if (lua_isnumber(L, 1)) {
|
||||||
|
spellId = static_cast<uint32_t>(lua_tonumber(L, 1));
|
||||||
|
} else if (lua_isstring(L, 1)) {
|
||||||
|
const char* name = lua_tostring(L, 1);
|
||||||
|
if (!name || !*name) { lua_pushnil(L); return 1; }
|
||||||
|
std::string nameLow(name);
|
||||||
|
for (char& c : nameLow) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||||
|
for (uint32_t sid : gh->getKnownSpells()) {
|
||||||
|
std::string sn = gh->getSpellName(sid);
|
||||||
|
for (char& c : sn) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||||
|
if (sn == nameLow) { spellId = sid; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (spellId == 0) { lua_pushnil(L); return 1; }
|
||||||
|
std::string name = gh->getSpellName(spellId);
|
||||||
|
if (name.empty()) { lua_pushnil(L); return 1; }
|
||||||
|
char link[256];
|
||||||
|
snprintf(link, sizeof(link), "|cff71d5ff|Hspell:%u|h[%s]|h|r", spellId, name.c_str());
|
||||||
|
lua_pushstring(L, link);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// IsUsableSpell(spellIdOrName) → usable, noMana
|
// IsUsableSpell(spellIdOrName) → usable, noMana
|
||||||
static int lua_IsUsableSpell(lua_State* L) {
|
static int lua_IsUsableSpell(lua_State* L) {
|
||||||
auto* gh = getGameHandler(L);
|
auto* gh = getGameHandler(L);
|
||||||
|
|
@ -1685,6 +1713,7 @@ void LuaEngine::registerCoreAPI() {
|
||||||
{"UnitIsEnemy", lua_UnitIsEnemy},
|
{"UnitIsEnemy", lua_UnitIsEnemy},
|
||||||
{"UnitCreatureType", lua_UnitCreatureType},
|
{"UnitCreatureType", lua_UnitCreatureType},
|
||||||
{"UnitClassification", lua_UnitClassification},
|
{"UnitClassification", lua_UnitClassification},
|
||||||
|
{"GetSpellLink", lua_GetSpellLink},
|
||||||
{"IsUsableSpell", lua_IsUsableSpell},
|
{"IsUsableSpell", lua_IsUsableSpell},
|
||||||
{"IsInInstance", lua_IsInInstance},
|
{"IsInInstance", lua_IsInInstance},
|
||||||
{"GetInstanceInfo", lua_GetInstanceInfo},
|
{"GetInstanceInfo", lua_GetInstanceInfo},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue