Module:AbilityHints: Difference between revisions

Jump to navigation Jump to search
wording for debuff resist: "duration" => "debuff duration"
Vergir (talk | contribs)
Expand config contract: entries now specify an arbitrary display file and click URL instead of an item; migrate current items to explicit file/link (with help from vergir-bot LLM)
Line 5: Line 5:


local AbilityTable = require("Module:AbilityTable")
local AbilityTable = require("Module:AbilityTable")
local icon_module  = require("Module:Icon")
local ability_data = mw.loadJsonData("Data:AbilityData.json")
local ability_data = mw.loadJsonData("Data:AbilityData.json")


local p = {}
local p = {}


-- Display order. Each entry: { list = "...", item = "...", tip = "..." }
-- Display order. Each entry: { list, file, link, tip }
-- The icon is shown when the ability is a member of `list`.
--  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",          item = "Melee Lifesteal",  tip = "Benefits from melee items" },
     { list = "melee",          file = "Melee Lifesteal.png",  link = "https://deadlock.wiki/Melee_Lifesteal",  tip = "Benefits from melee items" },
     { list = "movementbased",  item = "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",    item = "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",            item = "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", item = "Reactive Barrier", tip = "Triggers Reactive Barrier" },
     { list = "reactivebarrier", file = "Reactive Barrier.png", link = "https://deadlock.wiki/Reactive_Barrier", tip = "Triggers Reactive Barrier" },
     { list = "dispelmagic",    item = "Dispel Magic",    tip = "Effect can be dispelled" },
     { list = "dispelmagic",    file = "Dispel Magic.png",    link = "https://deadlock.wiki/Dispel_Magic",    tip = "Effect can be dispelled" },
     { list = "indomitable",    item = "Indomitable",      tip = "Disable prevented by Indomitable" },
     { list = "indomitable",    file = "Indomitable.png",      link = "https://deadlock.wiki/Indomitable",      tip = "Disable prevented by Indomitable" },
     { list = "unstoppable",    item = "Unstoppable",      tip = "Disable prevented by Unstoppable" },
     { list = "unstoppable",    file = "Unstoppable.png",      link = "https://deadlock.wiki/Unstoppable",      tip = "Disable prevented by Unstoppable" },
     { list = "platedarmor",    item = "Plated Armor",    tip = "On-shot effect prevented by Plated Armor" },
     { list = "platedarmor",    file = "Plated Armor.png",    link = "https://deadlock.wiki/Plated_Armor",    tip = "On-shot effect prevented by Plated Armor" },
}
}


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


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


Line 49: Line 52:
     for _, def in ipairs(CONFIG) do
     for _, def in ipairs(CONFIG) do
         if AbilityTable.is_member(def.list, record, num) then
         if AbilityTable.is_member(def.list, record, num) then
             table.insert(icons, hint_icon(def.item, def.tip))
             table.insert(icons, hint_icon(def))
         end
         end
     end
     end