Module:AbilityHints: Difference between revisions

Changed melee icon to melee charge since I think it's more intuitive/readable
Tags: Mobile edit Mobile web edit Advanced mobile edit
Vergir (talk | contribs)
m support manual ability hints
Line 1: Line 1:
-- Ability interaction hints: small item icons on ability cards showing how an
-- Small item icons on ability cards showing how an ability interacts with items (dispellable, reduced, blocked, etc.).
-- ability interacts with items (dispellable, reduced, blocked, etc.).
-- Used by Template:AbilitySection. Styles are there too.
-- 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")
Line 10: Line 8:


-- Display order. Each entry: { list, file, link, tip }
-- Display order. Each entry: { list, file, link, tip }
--  list  AbilityTable list whose membership shows the icon
--  file  image file to display, e.g. "Reactive Barrier.png"
--  link  URL opened when the icon is clicked. Use a full/absolute URL: it keeps
--        the anchor title-less, so MediaWiki Page Previews (Popups) ignores it.
--  tip  hover tooltip text (may contain simple HTML such as <br> or <b>)
local CONFIG = {
local CONFIG = {
     { list = "melee",          file = "Melee Charge.png",    link = "https://deadlock.wiki/Melee_Charge",    tip = "Benefits from melee items" },
     { list = "melee",          file = "Melee Charge.png",    link = "https://deadlock.wiki/Melee_Charge",    tip = "Benefits from melee items" },
     { list = "movementbased",  file = "Slowing Hex.png",      link = "https://deadlock.wiki/Slowing_Hex",      tip = "Disabled by Slowing Hex" },
     { list = "movementbased",  file = "Slowing Hex.png",      link = "https://deadlock.wiki/Slowing_Hex",      tip = "Disabled by Slowing Hex" },
{ list = "debuffresist",    file = "Debuff Reducer.png",  link = "https://deadlock.wiki/Debuff_Reducer",  tip = "Debuff duration reduced by Debuff Resist" },
    { list = "debuffresist",    file = "Debuff Reducer.png",  link = "https://deadlock.wiki/Debuff_Reducer",  tip = "Debuff duration reduced by Debuff Resist" },
     { list = "heal",            file = "Healing Booster.png",  link = "https://deadlock.wiki/Healing_Booster",  tip = "Healing amplified by Healing Booster and affected by healing reduction" },
     { list = "heal",            file = "Healing Booster.png",  link = "https://deadlock.wiki/Healing_Booster",  tip = "Healing amplified by Healing Booster and affected by healing reduction" },
     { list = "reactivebarrier", file = "Reactive Barrier.png", link = "https://deadlock.wiki/Reactive_Barrier", tip = "Triggers Reactive Barrier" },
     { list = "reactivebarrier", file = "Reactive Barrier.png", link = "https://deadlock.wiki/Reactive_Barrier", tip = "Triggers Reactive Barrier" },
Line 28: Line 21:
}
}


-- Renders one icon: a 24px image linking to `link`. A full URL as the link keeps
-- the anchor title-less so Page Previews / Popups ignores it. The wrapper span
-- nudges the icon up 2px to match how the card renders inline icons.
local function icon_img(file, link)
local function icon_img(file, link)
     return '<span style="position:relative;bottom:2px;">[[File:' .. file .. '|24px|link=' .. link .. ']]</span>'
     return '<span style="position:relative;bottom:2px;">[[File:' .. file .. '|24px|link=' .. link .. ']]</span>'
end
end


-- One full-size hint icon with a tooltip.
local function hint_icon(def)
local function hint_icon(def)
     return '<span class="ability-hint">' .. icon_img(def.file, def.link)
     return '<span class="ability-hint">' .. icon_img(def.file, def.link)
Line 41: Line 30:
end
end


-- Renders the interaction icon rail for one ability.
local function manual_icon(m)
--   ability_key  the ability's internal key (AbilityCards .Key)
    local cls = 'ability-hint'
--  ability_num  the ability's slot (1-4); coerced to number
    if m.disabled then cls = cls .. ' ability-hint--disabled' end
-- Returns rail HTML, or '' when the ability has no interactions.
    return '<span class="' .. cls .. '">' .. icon_img(m.file, '#' .. m.anchor)
function p.get_icons(ability_key, ability_num)
        .. '<span class="ability-hint-tip">' .. m.title .. ' Interaction. Click to see more</span></span>'
     local record = ability_data[ability_key]
end
     if record == nil then return '' end
 
     local num = tonumber(ability_num)
function p.get_icons(ability_key, ability_num, manual)
     manual = manual or {}
 
     -- Files claimed by a manual icon suppress the matching automatic icon.
     local manual_files = {}
    for _, m in ipairs(manual) do
        manual_files[mw.ustring.lower(m.file)] = true
    end


     local icons = {}
     local icons = {}
     for _, def in ipairs(CONFIG) do
 
        if AbilityTable.is_member(def.list, record, num) then
    local record = ability_data[ability_key]
            table.insert(icons, hint_icon(def))
     if record ~= nil then
        local num = tonumber(ability_num)
        for _, def in ipairs(CONFIG) do
            if AbilityTable.is_member(def.list, record, num)
                and not manual_files[mw.ustring.lower(def.file)] then
                table.insert(icons, hint_icon(def))
            end
         end
         end
    end
    for _, m in ipairs(manual) do
        table.insert(icons, manual_icon(m))
     end
     end