Editing Module:AbilityHints

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
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:
-- Small item icons on ability cards showing how an ability interacts with items (dispellable, reduced, blocked, etc.).
-- Ability interaction hints: small item icons on ability cards showing how an
-- Used by Template:AbilitySection. Styles are there too.
-- 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.


-- label_dict_key names the [[Data:Dictionary]] entry holding the tooltip text. It is
local AbilityTable = require("Module:AbilityTable")
-- resolved at render time rather than here, so the tooltip follows the page language
local icon_module  = require("Module:Icon")
-- and so no frame is needed while the module is still loading.
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",           file = "Melee Lifesteal.png",  label_dict_key = "AbilityHintsMelee" },
     { list = "melee",           item = "Melee Lifesteal",  tip = "Benefits from melee items" },
    { list = "dontbreakstealth", file = "Veil Walker.png",     label_dict_key = "AbilityHintsDontBreakStealth" },
{ list = "reactivebarrier", item = "Reactive Barrier", tip = "Triggers Reactive Barrier" },
    { list = "movementbased",    file = "Slowing Hex.png",     label_dict_key = "AbilityHintsMovementBased" },
{ list = "debuffresist",    item = "Debuff Reducer",   tip = "Duration reduced by Debuff Resist" },
     { list = "debuffresist",     file = "Debuff Reducer.png",   label_dict_key = "AbilityHintsDebuffResist" },
     { list = "movementbased",   item = "Slowing Hex",     tip = "Disabled by Slowing Hex" },
     { list = "heal",             file = "Healing Booster.png",  label_dict_key = "AbilityHintsHeal" },
     { list = "heal",           item = "Healing Booster",  tip = "Healing amplified by Healing Booster and affected by healing reduction" },
    { list = "healingtempo",    file = "Healing Tempo.png",    label_dict_key = "AbilityHintsHealingTempo" },
     { list = "dispelmagic",    item = "Dispel Magic",    tip = "Effect can be dispelled" },
     { list = "reactivebarrier",  file = "Reactive Barrier.png", label_dict_key = "AbilityHintsReactiveBarrier" },
     { list = "indomitable",     item = "Indomitable",      tip = "Effect blocked by Indomitable" },
     { list = "dispelmagic",      file = "Dispel Magic.png",    label_dict_key = "AbilityHintsDispelMagic" },
     { list = "unstoppable",     item = "Unstoppable",      tip = "Disable prevented by Unstoppable" },
     { list = "indomitable",     file = "Indomitable.png",      label_dict_key = "AbilityHintsIndomitable" },
     { list = "platedarmor",     item = "Plated Armor",    tip = "Bullet effect prevented by Plated Armor" },
     { list = "unstoppable",     file = "Unstoppable.png",      label_dict_key = "AbilityHintsUnstoppable" },
     { list = "platedarmor",     file = "Plated Armor.png",    label_dict_key = "AbilityHintsPlatedArmor" },
    { list = "summons",          file = "Monster Rounds.png",  label_dict_key = "AbilityHintsSummons" },
}
}


-- Tooltip wording for a manually placed icon, keyed by its iconbox state. Each entry
-- Pairs that merge into ONE diagonally-split icon when BOTH match the ability:
-- takes the item title as {{{1}}}, so translations can put the object where their
-- the first list fills the upper-left triangle, the second the lower-right.
-- grammar wants it rather than always after the verb. The enhanced state has no entry
-- (Replaces suppressed_by for these pairs.)
-- of its own: the glow already marks it, so it falls through to the normal wording.
local COMBINE = {
local STATE_DICT_KEYS = {
     { "reactivebarrier", "indomitable" },
     normal  = "AbilityHintsInteracts",
    disabled = "AbilityHintsInteractsNot",
    partial  = "AbilityHintsInteractsPartial",
}
}


local AbilityTable = require("Module:AbilityTable")
local DEF_BY_LIST = {}
local dictionary = require("Module:Dictionary")
for _, def in ipairs(CONFIG) do
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json")
    DEF_BY_LIST[def.list] = def
local item_data = mw.loadJsonData("Data:ItemData.json")
end
 
local p = {}


-- Display order: item type (Weapon => Vitality => Spirit), then cost, then name.
-- Renders one item icon as a title-less external link (so Page Previews / Popups
local function sort_key(file)
-- ignores it) wrapping just the image.
     local base = mw.ustring.lower((file:gsub('%.%w+$', '')))
local function icon_img(item)
     local entry = resource_lookup[base]
     local url = tostring(mw.uri.canonicalUrl(item))
    local item = (entry ~= nil and entry.type == 'item') and item_data[entry.key] or nil
     return icon_module._render(item, { size = '24px', ['icon-only'] = 'true', link = url })
    if item == nil then
        return { 99, math.huge, base }
    end
    local slot = item["Slot"]
    local slot_rank = (slot == "Weapon" and 1) or (slot == "Armor" and 2) or (slot == "Tech" and 3) or 98
    return {
        slot_rank,
        tonumber(item["Cost"]) or math.huge,
        mw.ustring.lower(item["Name"] or base),
    }
end
end


local function compare(a, b)
-- A normal single hint icon.
     for i = 1, 3 do
local function single_icon(def)
         if a.sort[i] ~= b.sort[i] then return a.sort[i] < b.sort[i] end
     return '<span class="ability-hint">' .. icon_img(def.item)
    end
         .. '<span class="ability-hint-tip">' .. def.tip .. '</span></span>'
    return false
end
end


-- partial: split the icon so the top-left half is grayscale (mirrors the iconbox-partial box icon).
-- A combined icon split along the diagonal: tl = upper-left, br = lower-right.
-- An empty link makes the icon non-clickable; automatic hints link from their tooltip text instead.
-- Each half links to its own item; the tooltip lists both notes.
local function icon_img(file, link, partial)
local function split_icon(tl, br)
     link = link or ''
     return '<span class="ability-hint ability-hint--split">'
    if partial then
        .. '<span class="ability-hint-half ability-hint-half--tl">' .. icon_img(tl.item) .. '</span>'
        return '<span class="ability-hint-icon"><span class="ability-hint-split">'
        .. '<span class="ability-hint-half ability-hint-half--br">' .. icon_img(br.item) .. '</span>'
            .. '[[File:' .. file .. '|24px|link=' .. link .. ']]'
        .. '<span class="ability-hint-tip">' .. tl.tip .. '<br>' .. br.tip .. '</span>'
            .. '<span class="ability-hint-split-gray">[[File:' .. file .. '|24px|link=]]</span>'
        .. '</span>'
            .. '</span></span>'
    end
    return '<span class="ability-hint-icon">[[File:' .. file .. '|24px|link=' .. link .. ']]</span>'
end
end


local function hint_icon(def)
-- Renders the interaction icon rail for one ability.
    return '<span class="ability-hint">' .. icon_img(def.file)
--  ability_key  the ability's internal key (AbilityCards .Key)
        .. '<span class="ability-hint-tip">' .. dictionary.translate(def.label_dict_key) .. '</span></span>'
--  ability_num  the ability's slot (1-4); coerced to number
end
-- 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 function manual_icon(m)
     local member = {}
     local cls = 'ability-hint'
     for _, def in ipairs(CONFIG) do
     local dict_key = STATE_DICT_KEYS.normal
         member[def.list] = AbilityTable.is_member(def.list, record, num)
    local partial = false
    if m.state == 'disabled' then
         cls = cls .. ' ability-hint--disabled'
        dict_key = STATE_DICT_KEYS.disabled
    elseif m.state == 'partial' then
        dict_key = STATE_DICT_KEYS.partial
        partial = true
    elseif m.state == 'enhanced' then
        cls = cls .. ' ability-hint--enhanced'
     end
     end
    local tip = dictionary.translate(dict_key, nil, nil, { m.title })
        .. '<br>' .. dictionary.translate('AbilityHintsClickReveal')
    return '<span class="' .. cls .. '">' .. icon_img(m.file, '#' .. m.anchor, partial)
        .. '<span class="ability-hint-tip">' .. tip .. '</span></span>'
end


function p.get_icons(ability_key, ability_num, manual)
    -- Resolve combos: when both lists match, the second is consumed and drawn as
     manual = manual or {}
    -- the lower-right half of the first list's icon.
 
     local split_with = {}
     local manual_by_file = {}
     local consumed = {}
     for _, m in ipairs(manual) do
     for _, c in ipairs(COMBINE) do
         manual_by_file[mw.ustring.lower(m.file)] = m
         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 entries = {}
     local icons = {}
    local placed = {}
 
    local num = tonumber(ability_num)
     for _, def in ipairs(CONFIG) do
     for _, def in ipairs(CONFIG) do
         if AbilityTable.is_member(def.list, ability_key, num) then
         if member[def.list] and not consumed[def.list]
            local key = mw.ustring.lower(def.file)
          and not (def.suppressed_by and member[def.suppressed_by]) then
             local m = manual_by_file[key]
             if split_with[def.list] then
            if m ~= nil then
                 table.insert(icons, split_icon(def, DEF_BY_LIST[split_with[def.list]]))
                 table.insert(entries, { file = m.file, html = manual_icon(m) })
                placed[key] = true
             else
             else
                 table.insert(entries, { file = def.file, html = hint_icon(def) })
                 table.insert(icons, single_icon(def))
             end
             end
         end
         end
     end
     end


    for _, m in ipairs(manual) do
     if #icons == 0 then return '' end
        if not placed[mw.ustring.lower(m.file)] then
            table.insert(entries, { file = m.file, html = manual_icon(m) })
        end
    end
 
     if #entries == 0 then return '' end
 
    for _, e in ipairs(entries) do e.sort = sort_key(e.file) end
    table.sort(entries, compare)
 
    local icons = {}
    for _, e in ipairs(entries) do table.insert(icons, e.html) 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
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Pages included on this page: