Editing Module:AbilityHints

Jump to navigation Jump to search
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.).
-- Small item icons on ability cards showing how an ability interacts with items (dispellable, reduced, blocked, etc.).
-- Used by Template:AbilitySection. Styles are there too.
-- Used by Template:AbilitySection. Styles are there too.
-- label_dict_key names the [[Data:Dictionary]] entry holding the tooltip text. It is
-- resolved at render time rather than here, so the tooltip follows the page language
-- and so no frame is needed while the module is still loading.
local CONFIG = {
    { list = "melee",            file = "Melee Lifesteal.png",  label_dict_key = "AbilityHintsMelee" },
    { list = "dontbreakstealth", file = "Veil Walker.png",      label_dict_key = "AbilityHintsDontBreakStealth" },
    { list = "movementbased",    file = "Slowing Hex.png",      label_dict_key = "AbilityHintsMovementBased" },
    { list = "debuffresist",    file = "Debuff Reducer.png",  label_dict_key = "AbilityHintsDebuffResist" },
    { list = "heal",            file = "Healing Booster.png",  label_dict_key = "AbilityHintsHeal" },
    { list = "healingtempo",    file = "Healing Tempo.png",    label_dict_key = "AbilityHintsHealingTempo" },
    { list = "reactivebarrier",  file = "Reactive Barrier.png", label_dict_key = "AbilityHintsReactiveBarrier" },
    { list = "dispelmagic",      file = "Dispel Magic.png",    label_dict_key = "AbilityHintsDispelMagic" },
    { list = "indomitable",      file = "Indomitable.png",      label_dict_key = "AbilityHintsIndomitable" },
    { 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
-- takes the item title as {{{1}}}, so translations can put the object where their
-- grammar wants it rather than always after the verb. The enhanced state has no entry
-- of its own: the glow already marks it, so it falls through to the normal wording.
local STATE_DICT_KEYS = {
    normal  = "AbilityHintsInteracts",
    disabled = "AbilityHintsInteractsNot",
    partial  = "AbilityHintsInteractsPartial",
}


local AbilityTable = require("Module:AbilityTable")
local AbilityTable = require("Module:AbilityTable")
local dictionary = require("Module:Dictionary")
local ability_data = mw.loadJsonData("Data:AbilityData.json")
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json")
local item_data = mw.loadJsonData("Data:ItemData.json")


local p = {}
local p = {}


-- Display order: item type (Weapon => Vitality => Spirit), then cost, then name.
-- Display order. Each entry: { list, file, link, tip }
local function sort_key(file)
local CONFIG = {
     local base = mw.ustring.lower((file:gsub('%.%w+$', '')))
     { list = "melee",          file = "Melee Charge.png",    link = "https://deadlock.wiki/Melee_Charge",    tip = "Benefits from melee items" },
     local entry = resource_lookup[base]
    { list = "movementbased",  file = "Slowing Hex.png",      link = "https://deadlock.wiki/Slowing_Hex",      tip = "Disabled by Slowing Hex" },
     local item = (entry ~= nil and entry.type == 'item') and item_data[entry.key] or nil
     { list = "debuffresist",    file = "Debuff Reducer.png",  link = "https://deadlock.wiki/Debuff_Reducer",  tip = "Debuff duration reduced by Debuff Resist" },
     if item == nil then
     { list = "heal",            file = "Healing Booster.png",  link = "https://deadlock.wiki/Healing_Booster",  tip = "Healing amplified by Healing Booster and affected by healing reduction" },
        return { 99, math.huge, base }
     { list = "reactivebarrier", file = "Reactive Barrier.png", link = "https://deadlock.wiki/Reactive_Barrier", tip = "Triggers Reactive Barrier" },
     end
    { list = "dispelmagic",     file = "Dispel Magic.png",    link = "https://deadlock.wiki/Dispel_Magic",     tip = "Effect can be dispelled" },
     local slot = item["Slot"]
     { list = "indomitable",    file = "Indomitable.png",      link = "https://deadlock.wiki/Indomitable",      tip = "Disable prevented by Indomitable" },
     local slot_rank = (slot == "Weapon" and 1) or (slot == "Armor" and 2) or (slot == "Tech" and 3) or 98
     { list = "unstoppable",     file = "Unstoppable.png",      link = "https://deadlock.wiki/Unstoppable",      tip = "Disable prevented by Unstoppable" },
     return {
    { list = "platedarmor",    file = "Plated Armor.png",    link = "https://deadlock.wiki/Plated_Armor",    tip = "On-shot effect prevented by Plated Armor" },
        slot_rank,
     { list = "summons",        file = "Monster Rounds.png",  link = "https://deadlock.wiki/Monster_Rounds",   tip = "Summons affected by Monster Rounds and Heroic Aura" },
         tonumber(item["Cost"]) or math.huge,
}
        mw.ustring.lower(item["Name"] or base),
    }
end


local function compare(a, b)
local function icon_img(file, link)
    for i = 1, 3 do
        if a.sort[i] ~= b.sort[i] then return a.sort[i] < b.sort[i] end
    end
    return false
end
 
-- partial: split the icon so the top-left half is grayscale (mirrors the iconbox-partial box icon).
-- An empty link makes the icon non-clickable; automatic hints link from their tooltip text instead.
local function icon_img(file, link, partial)
    link = link or ''
    if partial then
        return '<span class="ability-hint-icon"><span class="ability-hint-split">'
            .. '[[File:' .. file .. '|24px|link=' .. link .. ']]'
            .. '<span class="ability-hint-split-gray">[[File:' .. file .. '|24px|link=]]</span>'
            .. '</span></span>'
    end
     return '<span class="ability-hint-icon">[[File:' .. file .. '|24px|link=' .. link .. ']]</span>'
     return '<span class="ability-hint-icon">[[File:' .. file .. '|24px|link=' .. link .. ']]</span>'
end
end


local function hint_icon(def)
local function hint_icon(def)
     return '<span class="ability-hint">' .. icon_img(def.file)
     return '<span class="ability-hint">' .. icon_img(def.file, def.link)
         .. '<span class="ability-hint-tip">' .. dictionary.translate(def.label_dict_key) .. '</span></span>'
         .. '<span class="ability-hint-tip">' .. def.tip .. ". Click to go to item's page</span></span>"
end
end


local function manual_icon(m)
local function manual_icon(m)
     local cls = 'ability-hint'
     local cls = 'ability-hint'
    local dict_key = STATE_DICT_KEYS.normal
     if m.disabled then cls = cls .. ' ability-hint--disabled' end
    local partial = false
     return '<span class="' .. cls .. '">' .. icon_img(m.file, '#' .. m.anchor)
     if m.state == 'disabled' then
         .. '<span class="ability-hint-tip">' .. m.title .. ' Interaction. Click to reveal more info</span></span>'
        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
    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
end


Line 101: Line 40:
     manual = manual or {}
     manual = manual or {}


    -- Manual icons indexed by file so an override can take its automatic hint's slot.
     local manual_by_file = {}
     local manual_by_file = {}
     for _, m in ipairs(manual) do
     for _, m in ipairs(manual) do
Line 106: Line 46:
     end
     end


     local entries = {}
     local icons = {}
     local placed = {}
     local placed = {}


     local num = tonumber(ability_num)
     -- Automatic hints in CONFIG order; an overriding manual icon takes the slot.
    for _, def in ipairs(CONFIG) do
    local record = ability_data[ability_key]
        if AbilityTable.is_member(def.list, ability_key, num) then
    if record ~= nil then
            local key = mw.ustring.lower(def.file)
        local num = tonumber(ability_num)
            local m = manual_by_file[key]
        for _, def in ipairs(CONFIG) do
            if m ~= nil then
            if AbilityTable.is_member(def.list, record, num) then
                table.insert(entries, { file = m.file, html = manual_icon(m) })
                local key = mw.ustring.lower(def.file)
                placed[key] = true
                local m = manual_by_file[key]
            else
                if m ~= nil then
                table.insert(entries, { file = def.file, html = hint_icon(def) })
                    table.insert(icons, manual_icon(m))
                    placed[key] = true
                else
                    table.insert(icons, hint_icon(def))
                end
             end
             end
         end
         end
     end
     end


    -- Remaining manual icons (no automatic slot) in their original order.
     for _, m in ipairs(manual) do
     for _, m in ipairs(manual) do
         if not placed[mw.ustring.lower(m.file)] then
         if not placed[mw.ustring.lower(m.file)] then
             table.insert(entries, { file = m.file, html = manual_icon(m) })
             table.insert(icons, manual_icon(m))
         end
         end
     end
     end


     if #entries == 0 then return '' end
     if #icons == 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: