mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
C_Spell.GetSpellName(spellID) and C_Spell.GetSpellTexture(spellID)
This commit is contained in:
@@ -17,7 +17,7 @@ Quick index:
|
||||
|
||||
| Namespace | Calls |
|
||||
|-----------|-------|
|
||||
| Spell | `GetSpellInfo` (with `(slot, bookType)` overload), `C_Spell.GetSpellInfo`, `GameTooltip:SetSpellByID`, `C_Spell.GetSpellDescription` |
|
||||
| Spell | `GetSpellInfo` (with `(slot, bookType)` overload), `C_Spell.GetSpellInfo`, `C_Spell.GetSpellName`, `C_Spell.GetSpellTexture`, `GameTooltip:SetSpellByID`, `C_Spell.GetSpellDescription` |
|
||||
| Quest | `GetQuestIDFromLogIndex`, `C_QuestLog.RequestLoadQuestByID` (+ `QUEST_DATA_LOAD_RESULT` event), `C_QuestLog.GetTitleForQuestID` |
|
||||
| Faction | `GetFactionIDByIndex`, `GetFactionInfoByID` |
|
||||
| Item | `C_Item.IsBound`, `C_Item.GetItemID`, `C_Item.GetItemInfoInstant`, `C_Item.IsItemDataCached(ByID)`, `C_Item.RequestLoadItemData(ByID)` (+ `ITEM_DATA_LOAD_RESULT` event) |
|
||||
|
||||
+34
@@ -9,6 +9,8 @@ build instructions.
|
||||
- [Spell](#spell)
|
||||
- [`GetSpellInfo(spellID)` / `GetSpellInfo(slot, bookType)`](#getspellinfospellid--getspellinfoslot-booktype)
|
||||
- [`C_Spell.GetSpellInfo(spellID)`](#c_spellgetspellinfospellid)
|
||||
- [`C_Spell.GetSpellName(spellID)`](#c_spellgetspellnamespellid)
|
||||
- [`C_Spell.GetSpellTexture(spellID)`](#c_spellgetspelltexturespellid)
|
||||
- [`GameTooltip:SetSpellByID(spellID)`](#gametooltipsetspellbyidspellid)
|
||||
- [`C_Spell.GetSpellDescription(spellID)`](#c_spellgetspelldescriptionspellid)
|
||||
- [Quest](#quest)
|
||||
@@ -115,6 +117,38 @@ local info = C_Spell.GetSpellInfo(133)
|
||||
|
||||
Equivalent to the function of the same name introduced in 4.0.
|
||||
|
||||
### `C_Spell.GetSpellName(spellID)`
|
||||
|
||||
Returns the localized name of `spellID`, or `nil` if the spell ID is out
|
||||
of range or has no name in the current locale. Convenience accessor for
|
||||
the `name` field of [`C_Spell.GetSpellInfo`](#c_spellgetspellinfospellid)
|
||||
when that's all you need — single field read, no DBC indirection beyond
|
||||
the locale lookup.
|
||||
|
||||
```lua
|
||||
local name = C_Spell.GetSpellName(133) -- "Fireball"
|
||||
```
|
||||
|
||||
Equivalent to the function of the same name introduced in 10.0.
|
||||
|
||||
### `C_Spell.GetSpellTexture(spellID)`
|
||||
|
||||
Returns the icon path string for `spellID` (read from `SpellIcon.dbc`
|
||||
via the spell's `SpellIconID` field), or `nil` if the spell ID is out
|
||||
of range or the icon record is empty.
|
||||
|
||||
> **Path string, not fileID.** Modern WoW returns this as a
|
||||
> `fileID:number`. Vanilla 1.12 has no fileID system — see the same
|
||||
> note on [`C_Spell.GetSpellInfo`](#c_spellgetspellinfospellid)'s
|
||||
> `iconID` field. Pass directly to `texture:SetTexture(...)`.
|
||||
|
||||
```lua
|
||||
local path = C_Spell.GetSpellTexture(133)
|
||||
-- path = "Interface\\Icons\\Spell_Fire_FlameBolt"
|
||||
```
|
||||
|
||||
Equivalent to the function of the same name introduced in 10.0.
|
||||
|
||||
### `GameTooltip:SetSpellByID(spellID)`
|
||||
|
||||
Renders a spell tooltip for any `spellID`, including spells the player has
|
||||
|
||||
@@ -218,9 +218,51 @@ static int __fastcall Script_C_GetSpellInfo(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __fastcall Script_C_GetSpellName(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_Spell.GetSpellName(spellID)");
|
||||
return 0;
|
||||
}
|
||||
const int spellID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
|
||||
if (record == nullptr)
|
||||
return 0; // nil for unknown spellID
|
||||
|
||||
const int locale = ReadGlobal<int>(Offsets::VAR_LOCALE_INDEX);
|
||||
const char *name = *reinterpret_cast<const char *const *>(record + OFF_NAME + locale * 4);
|
||||
if (name == nullptr || *name == '\0')
|
||||
return 0; // empty / no name in current locale → nil
|
||||
Game::Lua::PushString(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __fastcall Script_C_GetSpellTexture(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_Spell.GetSpellTexture(spellID)");
|
||||
return 0;
|
||||
}
|
||||
const int spellID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
|
||||
if (record == nullptr)
|
||||
return 0;
|
||||
|
||||
const int iconID = *reinterpret_cast<const int *>(record + OFF_ICON_ID);
|
||||
auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS,
|
||||
Offsets::VAR_SPELL_ICON_COUNT, iconID);
|
||||
if (iconRec == nullptr)
|
||||
return 0;
|
||||
const char *path = *reinterpret_cast<const char *const *>(iconRec + 4);
|
||||
if (path == nullptr || *path == '\0')
|
||||
return 0;
|
||||
Game::Lua::PushString(L, path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterGlobalFunction("GetSpellInfo", &Script_GetSpellInfo);
|
||||
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellInfo", &Script_C_GetSpellInfo);
|
||||
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellName", &Script_C_GetSpellName);
|
||||
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellTexture", &Script_C_GetSpellTexture);
|
||||
}
|
||||
|
||||
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
Reference in New Issue
Block a user