Module:AbilityHints: Difference between revisions

Vergir (talk | contribs)
mNo edit summary
Replace the reactive/indomitable split icon with a grouped single icon whose image and tooltip depend on which of the two lists match (with help from vergir-bot LLM)
Line 10: Line 10:
local p = {}
local p = {}


-- Display order. Each entry:
-- Display order. Each entry is either:
--  list           AbilityTable list name (Module:AbilityTable/Lists)
--  { list = "...", item = "...", tip = "..." }   a single icon shown when the ability is in `list`
--   item          item whose icon represents the interaction
--  { group = "..." }                            a grouped relationship (see GROUPS)
--  tip            short hover text
--  suppressed_by  optional: hide this icon when the named list is also a member
local CONFIG = {
local CONFIG = {
     { list = "melee",          item = "Melee Lifesteal",  tip = "Benefits from melee items" },
     { list = "melee",          item = "Melee Lifesteal",  tip = "Benefits from melee items" },
Line 20: Line 18:
{ list = "debuffresist",    item = "Debuff Reducer",  tip = "Duration reduced by Debuff Resist" },
{ 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" },
     { list = "heal",            item = "Healing Booster",  tip = "Healing amplified by Healing Booster and affected by healing reduction" },
     { list = "reactivebarrier", item = "Reactive Barrier", tip = "Triggers Reactive Barrier" },
     { group = "reactive_indomitable" },
     { list = "dispelmagic",    item = "Dispel Magic",    tip = "Effect can be dispelled" },
     { list = "dispelmagic",    item = "Dispel Magic",    tip = "Effect can be dispelled" },
    { list = "indomitable",    item = "Indomitable",      tip = "Effect blocked by Indomitable" },
     { list = "unstoppable",    item = "Unstoppable",      tip = "Disable prevented by Unstoppable" },
     { list = "unstoppable",    item = "Unstoppable",      tip = "Disable prevented by Unstoppable" },
     { list = "platedarmor",    item = "Plated Armor",    tip = "On-shot effect prevented by Plated Armor" },
     { list = "platedarmor",    item = "Plated Armor",    tip = "On-shot effect prevented by Plated Armor" },
}
}


-- Pairs that merge into ONE diagonally-split icon when BOTH match the ability:
-- Grouped relationships: two related lists collapse into ONE full-size icon
-- the first list fills the upper-left triangle, the second the lower-right.
-- whose item and tooltip depend on which of the two the ability matches.
-- (Replaces suppressed_by for these pairs.)
local GROUPS = {
local COMBINE = {
     reactive_indomitable = {
     { "reactivebarrier", "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 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
-- Renders one item icon as a title-less external link (so Page Previews / Popups
Line 46: Line 43:
end
end


-- A normal single hint icon.
-- One full-size hint icon with a tooltip.
local function single_icon(def)
local function hint_icon(item, tip)
    return '<span class="ability-hint">' .. icon_img(def.item)
     return '<span class="ability-hint">' .. icon_img(item)
        .. '<span class="ability-hint-tip">' .. def.tip .. '</span></span>'
         .. '<span class="ability-hint-tip">' .. tip .. '</span></span>'
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 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


Line 71: Line 58:
     local num = tonumber(ability_num)
     local num = tonumber(ability_num)


    -- Membership for every list referenced by CONFIG or GROUPS.
     local member = {}
     local member = {}
    local function check(list)
        if list ~= nil and member[list] == nil then
            member[list] = AbilityTable.is_member(list, record, num)
        end
    end
     for _, def in ipairs(CONFIG) do
     for _, def in ipairs(CONFIG) do
         member[def.list] = AbilityTable.is_member(def.list, record, num)
         if def.list then
    end
            check(def.list)
 
        elseif def.group then
    -- Resolve combos: when both lists match, the second is consumed and drawn as
            local g = GROUPS[def.group]
    -- the lower-right half of the first list's icon.
             check(g.a)
    local split_with = {}
             check(g.b)
    local consumed = {}
    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
     end
Line 90: Line 77:
     local icons = {}
     local icons = {}
     for _, def in ipairs(CONFIG) do
     for _, def in ipairs(CONFIG) do
         if member[def.list] and not consumed[def.list]
         if def.group then
          and not (def.suppressed_by and member[def.suppressed_by]) then
            local g = GROUPS[def.group]
             if split_with[def.list] then
            local ma, mb = member[g.a], member[g.b]
                 table.insert(icons, split_icon(def, DEF_BY_LIST[split_with[def.list]]))
            local case
             else
             if ma and mb then
                 table.insert(icons, single_icon(def))
                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
             end
        elseif def.list and member[def.list] then
            table.insert(icons, hint_icon(def.item, def.tip))
         end
         end
     end
     end