Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames #1881

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Renames #1881

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ do
end
function API.SetSpellRename(spellId, text)
if type(spellId) ~= "number" then error("Invalid spell ID for spell rename.") end
if type(text) ~= "string" or #text < 3 then error("Invalid spell text for spell rename.") end
if text and type(text) ~= "string" then error("Invalid spell text for spell rename.") end
tbl[spellId] = text
end
end
Expand Down
107 changes: 70 additions & 37 deletions Core/BossPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,18 @@ function boss:GetAllowWin()
return self.allowWin and true or false
end

--- Register private auras.
-- @param opts the options table
function boss:SetPrivateAuraSounds(opts)
for i = 1, #opts do
if type(opts[i]) ~= "table" then
opts[i] = { opts[i] }
local o = opts[i]
if type(o) ~= "table" then
opts[i] = { o }
elseif o.extra then -- XXX compat
for j, v in ipairs(o.extra) do
o[j + 1] = v
end
o.extra = nil
end
end
self.privateAuraSoundOptions = opts
Expand Down Expand Up @@ -581,7 +589,11 @@ boss.NewLocale = boss.GetLocale
do
local SetSpellRename = BigWigsAPI.SetSpellRename
function boss:SetSpellRename(spellId, text)
SetSpellRename(spellId, text)
rawset(spells, spellId, text)
-- External API is ment for SPELL_CAST_START/SPELL_CAST_SUCCESS? so need a way to translate locale and ej keys to the cast id
if type(spellId) == "number" and spellId > 0 then
SetSpellRename(spellId, text)
end
end
end

Expand Down Expand Up @@ -733,7 +745,7 @@ do
args.sourceGUID, args.sourceName, args.sourceFlags, args.sourceRaidFlags = sourceGUID, sourceName, sourceFlags, sourceRaidFlags
args.destGUID, args.destName, args.destFlags, args.destRaidFlags = destGUID, destName, destFlags, destRaidFlags
args.spellId, args.spellName, args.spellSchool = spellId, spellName, spellSchool
args.time, args.extraSpellId, args.extraSpellName, args.amount = time, extraSpellId, amount, amount
args.time, args.extraSpellId, args.extraSpellName, args.amount = time, extraSpellId, rawget(spells, extraSpellId) or amount, nil
self[func](self, args)
end
end
Expand All @@ -746,7 +758,7 @@ do
-- DEVS! Please ask if you need args attached to the table that we've missed out!
args.sourceGUID, args.sourceName, args.sourceFlags, args.sourceRaidFlags = sourceGUID, sourceName, sourceFlags, sourceRaidFlags
args.destGUID, args.destName, args.destFlags, args.destRaidFlags = destGUID, destName, destFlags, destRaidFlags
args.spellId, args.spellName, args.spellSchool = spellId, spellName, spellSchool
args.spellId, args.spellName, args.spellSchool = spellId, rawget(spells, spellId) or spellName, spellSchool
args.time, args.extraSpellId, args.extraSpellName, args.amount = time, extraSpellId, amount, amount
self[func](self, args)
end
Expand Down Expand Up @@ -1293,44 +1305,43 @@ do
self.privateAuraSounds = {}
local soundModule = plugins.Sounds
if soundModule then
for _, option in next, self.privateAuraSoundOptions do
local spellId = option[1]
local default = soundModule:GetDefaultSound("privateaura")

local key = ("pa_%d"):format(spellId)
local default = soundModule:GetDefaultSound("privateaura")
for _, opt in next, self.privateAuraSoundOptions do
local key = ("pa_%d"):format(opt[1])
local sound = soundModule:GetSoundFile(nil, nil, self.db.profile[key] or default)
if sound then
local privateAuraSoundId = C_UnitAuras.AddPrivateAuraAppliedSound({
spellID = spellId,
unitToken = "player",
soundFileName = sound,
outputChannel = "master",
})
if type(privateAuraSoundId) == "number" then
self.privateAuraSounds[#self.privateAuraSounds + 1] = privateAuraSoundId
else
self:Error("Failed to register Private Aura %q with return: %s", spellId, tostring(privateAuraSoundId))
end
if option.extra then
for _, id in next, option.extra do
local extrasSoundId = C_UnitAuras.AddPrivateAuraAppliedSound({
spellID = id,
unitToken = "player",
soundFileName = sound,
outputChannel = "master",
})
if type(extrasSoundId) == "number" then
self.privateAuraSounds[#self.privateAuraSounds + 1] = extrasSoundId
else
self:Error("Failed to register Private Aura %q with return: %s", id, tostring(extrasSoundId))
end
for i = 1, #opt do
local privateAuraSoundId = C_UnitAuras.AddPrivateAuraAppliedSound({
spellID = opt[i],
unitToken = "player",
soundFileName = sound,
outputChannel = "master",
})
if privateAuraSoundId then
self.privateAuraSounds[#self.privateAuraSounds + 1] = privateAuraSoundId
end
end
end
end
end
end

-- rename updates
local renameModule = plugins.Rename
if renameModule then
-- update cleu spells
for spellId, key in next, self.renameSpells do
self:SetSpellRename(spellId, renameModule:GetName(self, key))
end
-- update locale string overrides
if self.renameStringDefaults then
local ML = self:GetLocale()
for key, value in next, self.renameStringDefaults do
ML[key] = renameModule:GetName(self, key) or value
end
end
end

if not noEngage or noEngage ~= "NoEngage" then
updateData(self)

Expand Down Expand Up @@ -1606,8 +1617,16 @@ end

--- Get a localized spell name from an id. Positive ids for spells (C_Spell.GetSpellName) and negative ids for journal-based section entries (C_EncounterJournal.GetSectionInfo).
-- @number spellIdOrSectionId The spell id or the journal-based section id (as a negative number)
-- @bool[opt] noAltName Set to force an API lookup for the name
-- @return spell name
function boss:SpellName(spellIdOrSectionId)
function boss:SpellName(spellIdOrSectionId, noAltName)
if noAltName then
if spellIdOrSectionId < 0 then
local info = C_EncounterJournal_GetSectionInfo(-spellIdOrSectionId)
return info and info.title
end
return GetSpellName(spellIdOrSectionId)
end
return spells[spellIdOrSectionId]
end

Expand Down Expand Up @@ -3369,7 +3388,14 @@ do
if englishSayMessages and englishText then
SendChatMessage(format(on, englishText, myName), "SAY")
else
SendChatMessage(format(L.on, msg and (type(msg) == "number" and spells[msg] or msg) or spells[key], myName), "SAY")
-- never use renames for chat messages
local text = msg
if not text then
text = self:SpellName(key, true)
elseif type(text) == "number" then
text = self:SpellName(text, true)
end
SendChatMessage(format(L.on, text, myName), "SAY")
end
end
self:Debug(":Say", key, msg, directPrint, englishText)
Expand All @@ -3388,7 +3414,14 @@ do
if englishSayMessages and englishText then
SendChatMessage(format(on, englishText, myName), "YELL")
else
SendChatMessage(format(L.on, msg and (type(msg) == "number" and spells[msg] or msg) or spells[key], myName), "YELL")
-- never use renames for chat messages
local text = msg
if not text then
text = self:SpellName(key, true)
elseif type(text) == "number" then
text = self:SpellName(text, true)
end
SendChatMessage(format(L.on, text, myName), "YELL")
end
end
self:Debug(":Yell", key, msg, directPrint, englishText)
Expand Down
44 changes: 2 additions & 42 deletions Core/BossPrototype_Classic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ function boss:GetAllowWin()
return self.allowWin and true or false
end

--- Register private auras.
-- @param opts the options table
function boss:SetPrivateAuraSounds(opts)
for i = 1, #opts do
if type(opts[i]) ~= "table" then
Expand Down Expand Up @@ -1362,48 +1364,6 @@ do

self:Debug(":Engage", "noEngage:", noEngage, self:GetEncounterID(), self.moduleName)

if self.privateAuraSoundOptions and not self.privateAuraSounds then
self.privateAuraSounds = {}
local soundModule = plugins.Sounds
if soundModule then
for _, option in next, self.privateAuraSoundOptions do
local spellId = option[1]
local default = soundModule:GetDefaultSound("privateaura")

local key = ("pa_%d"):format(spellId)
local sound = soundModule:GetSoundFile(nil, nil, self.db.profile[key] or default)
if sound then
local privateAuraSoundId = C_UnitAuras.AddPrivateAuraAppliedSound({
spellID = spellId,
unitToken = "player",
soundFileName = sound,
outputChannel = "master",
})
if type(privateAuraSoundId) == "number" then
self.privateAuraSounds[#self.privateAuraSounds + 1] = privateAuraSoundId
else
self:Error("Failed to register Private Aura %q with return: %s", spellId, tostring(privateAuraSoundId))
end
if option.extra then
for _, id in next, option.extra do
local extrasSoundId = C_UnitAuras.AddPrivateAuraAppliedSound({
spellID = id,
unitToken = "player",
soundFileName = sound,
outputChannel = "master",
})
if type(extrasSoundId) == "number" then
self.privateAuraSounds[#self.privateAuraSounds + 1] = extrasSoundId
else
self:Error("Failed to register Private Aura %q with return: %s", id, tostring(extrasSoundId))
end
end
end
end
end
end
end

if not noEngage or noEngage ~= "NoEngage" then
updateData(self)

Expand Down
8 changes: 7 additions & 1 deletion Core/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ function BigWigs:GetBossOptionDetails(module, option)
optionType = type(option)
end

local alternativeName = module.altNames and module.altNames[option]
local alternativeName
local renameModule = self:GetPlugin("Rename", true)
if renameModule then
alternativeName = renameModule:GetName(module, option)
else
alternativeName = module.altNames and module.altNames[option]
end
local moduleLocale = module:GetLocale(true)

if optionType == "string" then
Expand Down
40 changes: 40 additions & 0 deletions Core/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,46 @@ do
end
setupOptions(self)
self.SetupOptions = nil

local renameModule = plugins.Rename
if renameModule then
self.renameSpells = {} -- spellId -> option key
if self.altNames then
local ML = self:GetLocale()
for key, value in next, self.altNames do
if type(value) == "table" then
self.altNames[key] = value[1] -- reduce back to a simple lookup table
for i = 2, #value do
local v = value[i]
if type(v) == "number" then -- set rename for additional spell ids
self.renameSpells[v] = key
self:SetSpellRename(v, renameModule:GetName(self, key))
elseif type(v) == "string" then -- locale string key
if not self.renameStrings then
self.renameStrings = {} -- option key -> locale string keys
self.renameStringDefaults = {} -- locale string key -> default value
end
if not self.renameStrings[key] then
self.renameStrings[key] = {}
end
table.insert(self.renameStrings[key], v)
self.renameStringDefaults[v] = ML[v]
end
end
end
end
end
-- set current renames
for _, key in next, self.toggleOptions do
if type(key) == "table" then
key = key[1]
end
if type(key) == "number" then
self.renameSpells[key] = key
self:SetSpellRename(key, renameModule:GetName(self, key))
end
end
end
end

function core:RegisterBossModule(module)
Expand Down
Loading
Loading