Module:AbilityHints: Difference between revisions

Vergir (talk | contribs)
m unstoppable clarification
Use the standard interacts text for the enhanced state (with help from vergir-bot LLM)
 
(7 intermediate revisions by 4 users not shown)
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 ability_data = mw.loadJsonData("Data:AbilityData.json")
local dictionary = require("Module:Dictionary")
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json")
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json")
local item_data = mw.loadJsonData("Data:ItemData.json")
local item_data = mw.loadJsonData("Data:ItemData.json")
Line 9: Line 37:
local p = {}
local p = {}


-- Automatic hints that get shown without corresponding {{AbilityInteraction}}. Powered by Module:AbilityTable
-- Display order: item type (Weapon => Vitality => Spirit), then cost, then name.
local CONFIG = {
    { list = "melee",            file = "Melee Charge.png",    tip = "Benefits from melee items (e.g. [[Melee Charge]])" },
    { list = "dontbreakstealth", file = "Veil Walker.png",      tip = "Casting does not break from [[Veil Walker]] or [[Shadow Weave]]" },
    { list = "movementbased",    file = "Slowing Hex.png",      tip = "Disabled by [[Slowing Hex]]" },
    { list = "debuffresist",    file = "Debuff Reducer.png",  tip = "Debuff duration reduced by [[Debuff Resist]]" },
    { list = "heal",            file = "Healing Booster.png",  tip = "[[Healing]] amplified by [[Healing Booster]] and affected by healing reduction" },
    { list = "reactivebarrier",  file = "Reactive Barrier.png", tip = "Triggers [[Reactive Barrier]]" },
    { list = "dispelmagic",      file = "Dispel Magic.png",    tip = "Effect can be [[Dispel Magic|dispelled]]" },
    { list = "indomitable",      file = "Indomitable.png",      tip = "Disable prevented by [[Indomitable]]" },
    { list = "unstoppable",      file = "Unstoppable.png",      tip = "Negative status effects suppressed by [[Unstoppable]]" },
    { list = "platedarmor",      file = "Plated Armor.png",    tip = "On-shot effect prevented by [[Plated Armor]]" },
    { list = "summons",          file = "Monster Rounds.png",  tip = "Summons affected by [[Monster Rounds]] and [[Heroic Aura]]" },
}
 
-- Display order: item slot (Weapon, then Vitality, then Spirit), then cost, then name.
local function sort_key(file)
local function sort_key(file)
     local base = mw.ustring.lower((file:gsub('%.%w+$', '')))
     local base = mw.ustring.lower((file:gsub('%.%w+$', '')))
Line 63: Line 76:
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)
         .. '<span class="ability-hint-tip">' .. def.tip .. '</span></span>'
         .. '<span class="ability-hint-tip">' .. dictionary.translate(def.label_dict_key) .. '</span></span>'
end
end


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


Line 92: Line 109:
     local placed = {}
     local placed = {}


     local record = ability_data[ability_key]
     local num = tonumber(ability_num)
    if record ~= nil then
    for _, def in ipairs(CONFIG) do
        local num = tonumber(ability_num)
        if AbilityTable.is_member(def.list, ability_key, num) then
        for _, def in ipairs(CONFIG) do
            local key = mw.ustring.lower(def.file)
            if AbilityTable.is_member(def.list, record, num) then
            local m = manual_by_file[key]
                local key = mw.ustring.lower(def.file)
            if m ~= nil then
                local m = manual_by_file[key]
                table.insert(entries, { file = m.file, html = manual_icon(m) })
                if m ~= nil then
                placed[key] = true
                    table.insert(entries, { file = m.file, html = manual_icon(m) })
            else
                    placed[key] = true
                table.insert(entries, { file = def.file, html = hint_icon(def) })
                else
                    table.insert(entries, { file = def.file, html = hint_icon(def) })
                end
             end
             end
         end
         end