Editing Module:AbilityHintsGive feedback
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
-- | -- Ability interaction hints: small item icons on ability cards showing how an | ||
-- | -- ability interacts with items (dispellable, reduced, blocked, etc.). | ||
-- Membership is decided by Module:AbilityTable.is_member so these icons always | |||
-- agree with the dynamic ability-interaction tables. | |||
-- | |||
local AbilityTable = require("Module:AbilityTable") | local AbilityTable = require("Module:AbilityTable") | ||
local | local icon_module = require("Module:Icon") | ||
local | local ability_data = mw.loadJsonData("Data:AbilityData.json") | ||
local p = {} | local p = {} | ||
-- Display order: item | -- Display order. Each entry is either: | ||
-- { list = "...", item = "...", tip = "..." } a single icon shown when the ability is in `list` | |||
-- { group = "..." } a grouped relationship (see GROUPS) | |||
local CONFIG = { | |||
{ list = "melee", item = "Melee Lifesteal", tip = "Benefits from melee items" }, | |||
{ list = "movementbased", item = "Slowing Hex", tip = "Disabled by Slowing Hex" }, | |||
{ list = "debuffresist", item = "Debuff Reducer", tip = "Duration reduced by Debuff Resist" }, | |||
{ list = "heal", item = "Healing Booster", tip = "Healing amplified by Healing Booster and affected by healing reduction" }, | |||
{ group = "reactive_indomitable" }, | |||
{ list = "dispelmagic", item = "Dispel Magic", tip = "Effect can be dispelled" }, | |||
{ list = "unstoppable", item = "Unstoppable", tip = "Disable prevented by Unstoppable" }, | |||
{ list = "platedarmor", item = "Plated Armor", tip = "On-shot effect prevented by Plated Armor" }, | |||
} | |||
-- Grouped relationships: two related lists collapse into ONE full-size icon | |||
-- whose item and tooltip depend on which of the two the ability matches. | |||
local GROUPS = { | |||
reactive_indomitable = { | |||
a = "reactivebarrier", | |||
b = "indomitable", | |||
a_only = { item = "Reactive Barrier", tip = "Triggers Reactive Barrier<br>does <b>not</b> trigger Indomitable" }, | |||
-- | b_only = { item = "Indomitable", tip = "Blocked by Indomitable<br>does <b>not</b> trigger Reactive Barrier" }, | ||
-- | both = { item = "Reactive Barrier", tip = "Triggers Reactive Barrier<br>Blocked by Indomitable" }, | ||
local | }, | ||
} | |||
local function | -- Renders one item icon as a title-less external link (so Page Previews / Popups | ||
-- ignores it) wrapping just the image. | |||
local function icon_img(item) | |||
local url = tostring(mw.uri.canonicalUrl(item)) | |||
return icon_module._render(item, { size = '24px', ['icon-only'] = 'true', link = url }) | |||
end | end | ||
-- One full-size hint icon with a tooltip. | |||
local function hint_icon(item, tip) | |||
return '<span class="ability-hint">' .. icon_img(item) | |||
return '<span class=" | |||
.. '<span class="ability-hint-tip">' .. tip .. '</span></span>' | .. '<span class="ability-hint-tip">' .. tip .. '</span></span>' | ||
end | end | ||
function p.get_icons(ability_key, ability_num | -- Renders the interaction icon rail for one ability. | ||
-- ability_key the ability's internal key (AbilityCards .Key) | |||
-- ability_num the ability's slot (1-4); coerced to number | |||
-- Returns rail HTML, or '' when the ability has no interactions. | |||
function p.get_icons(ability_key, ability_num) | |||
local record = ability_data[ability_key] | |||
if record == nil then return '' end | |||
local num = tonumber(ability_num) | |||
local | -- Membership for every list referenced by CONFIG or GROUPS. | ||
local member = {} | |||
local function check(list) | |||
if list ~= nil and member[list] == nil then | |||
member[list] = AbilityTable.is_member(list, record, num) | |||
end | |||
end | end | ||
for _, def in ipairs(CONFIG) do | for _, def in ipairs(CONFIG) do | ||
if | if def.list then | ||
check(def.list) | |||
local | elseif def.group then | ||
local g = GROUPS[def.group] | |||
check(g.a) | |||
check(g.b) | |||
end | end | ||
end | end | ||
for _, | local icons = {} | ||
if | for _, def in ipairs(CONFIG) do | ||
table.insert( | if def.group then | ||
local g = GROUPS[def.group] | |||
local ma, mb = member[g.a], member[g.b] | |||
local case | |||
if ma and mb then | |||
case = g.both | |||
elseif ma then | |||
case = g.a_only | |||
elseif mb then | |||
case = g.b_only | |||
end | |||
if case then | |||
table.insert(icons, hint_icon(case.item, case.tip)) | |||
end | |||
elseif def.list and member[def.list] then | |||
table.insert(icons, hint_icon(def.item, def.tip)) | |||
end | end | ||
end | end | ||
if # | if #icons == 0 then return '' end | ||
return '<div class="ability-section-hints">' .. table.concat(icons) .. '</div>' | return '<div class="ability-section-hints">' .. table.concat(icons) .. '</div>' | ||
end | end | ||
return p | return p | ||