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 icon_module = require("Module:Icon") | ||
-- | local ability_data = mw.loadJsonData("Data:AbilityData.json") | ||
local p = {} | |||
-- Display order. Each entry: | |||
-- list AbilityTable list name (Module:AbilityTable/Lists) | |||
-- item item whose icon represents the interaction | |||
-- tip short hover text | |||
-- suppressed_by optional: hide this icon when the named list is also a member | |||
local CONFIG = { | local CONFIG = { | ||
{ list = "melee", | { list = "melee", item = "Melee Lifesteal", tip = "Benefits from melee items" }, | ||
{ list = "reactivebarrier", item = "Reactive Barrier", tip = "Triggers Reactive Barrier" }, | |||
{ list = "debuffresist", item = "Debuff Reducer", tip = "Duration reduced by Debuff Resist" }, | |||
{ list = " | { list = "movementbased", item = "Slowing Hex", tip = "Disabled by Slowing Hex" }, | ||
{ list = "heal", | { list = "heal", item = "Healing Booster", tip = "Healing amplified by Healing Booster and affected by healing reduction" }, | ||
{ list = "dispelmagic", item = "Dispel Magic", tip = "Effect can be dispelled" }, | |||
{ list = " | { list = "indomitable", item = "Indomitable", tip = "Effect blocked by Indomitable" }, | ||
{ list = "unstoppable", item = "Unstoppable", tip = "Disable prevented by Unstoppable" }, | |||
{ list = "indomitable", | { list = "platedarmor", item = "Plated Armor", tip = "Bullet effect prevented by Plated Armor" }, | ||
{ list = "unstoppable", | |||
{ list = "platedarmor", | |||
} | } | ||
-- | -- Pairs that merge into ONE diagonally-split icon when BOTH match the ability: | ||
-- | -- the first list fills the upper-left triangle, the second the lower-right. | ||
-- (Replaces suppressed_by for these pairs.) | |||
-- | local COMBINE = { | ||
local | { "reactivebarrier", "indomitable" }, | ||
} | } | ||
local | local DEF_BY_LIST = {} | ||
for _, def in ipairs(CONFIG) do | |||
DEF_BY_LIST[def.list] = def | |||
end | |||
-- | -- Renders one item icon as a title-less external link (so Page Previews / Popups | ||
local function | -- ignores it) wrapping just the image. | ||
local | 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 | ||
local function | -- A normal single hint icon. | ||
local function single_icon(def) | |||
return '<span class="ability-hint">' .. icon_img(def.item) | |||
.. '<span class="ability-hint-tip">' .. def.tip .. '</span></span>' | |||
end | end | ||
-- | -- A combined icon split along the diagonal: tl = upper-left, br = lower-right. | ||
-- | -- Each half links to its own item; the tooltip lists both notes. | ||
local function | local function split_icon(tl, br) | ||
return '<span class="ability-hint ability-hint--split">' | |||
.. '<span class="ability-hint-half ability-hint-half--tl">' .. icon_img(tl.item) .. '</span>' | |||
.. '<span class="ability-hint-half ability-hint-half--br">' .. icon_img(br.item) .. '</span>' | |||
.. '<span class="ability-hint-tip">' .. tl.tip .. '<br>' .. br.tip .. '</span>' | |||
.. '</span>' | |||
end | end | ||
-- 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 member = {} | |||
local | for _, def in ipairs(CONFIG) do | ||
member[def.list] = AbilityTable.is_member(def.list, record, num) | |||
end | end | ||
-- Resolve combos: when both lists match, the second is consumed and drawn as | |||
-- the lower-right half of the first list's icon. | |||
local split_with = {} | |||
local | local consumed = {} | ||
for _, | for _, c in ipairs(COMBINE) do | ||
local tl, br = c[1], c[2] | |||
if member[tl] and member[br] then | |||
split_with[tl] = br | |||
consumed[br] = true | |||
end | |||
end | end | ||
local | local icons = {} | ||
for _, def in ipairs(CONFIG) do | for _, def in ipairs(CONFIG) do | ||
if | if member[def.list] and not consumed[def.list] | ||
and not (def.suppressed_by and member[def.suppressed_by]) then | |||
if split_with[def.list] then | |||
table.insert(icons, split_icon(def, DEF_BY_LIST[split_with[def.list]])) | |||
table.insert( | |||
else | else | ||
table.insert( | table.insert(icons, single_icon(def)) | ||
end | end | ||
end | end | ||
end | end | ||
if #icons == 0 then return '' end | |||
if # | |||
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 | ||