Editing Module:AbilityHintsGive feedback
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. | ||
local AbilityTable = require("Module:AbilityTable") | local AbilityTable = require("Module:AbilityTable") | ||
local | local ability_data = mw.loadJsonData("Data:AbilityData.json") | ||
local p = {} | local p = {} | ||
-- Display order: | -- Display order. Each entry: { list, file, tip } | ||
local | local CONFIG = { | ||
{ list = "melee", file = "Melee Charge.png", tip = "Benefits from melee items ([[Melee Charge]])" }, | |||
{ 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 = "Disable prevented 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]]" }, | |||
} | |||
-- partial: split the icon so the top-left half is grayscale (mirrors the ai-partial box icon). | |||
-- partial: split the icon so the top-left half is grayscale (mirrors the | |||
-- An empty link makes the icon non-clickable; automatic hints link from their tooltip text instead. | -- An empty link makes the icon non-clickable; automatic hints link from their tooltip text instead. | ||
local function icon_img(file, link, partial) | local function icon_img(file, link, partial) | ||
| Line 76: | Line 36: | ||
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">' .. | .. '<span class="ability-hint-tip">' .. def.tip .. '</span></span>' | ||
end | end | ||
local function manual_icon(m) | local function manual_icon(m) | ||
local cls = 'ability-hint' | local cls = 'ability-hint' | ||
local | local verb = 'Interacts with' | ||
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' | |||
elseif m.state == 'partial' then | elseif m.state == 'partial' then | ||
verb = 'Interacts partially with' | |||
partial = true | partial = true | ||
end | end | ||
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">' .. | .. '<span class="ability-hint-tip">' .. verb .. ' ' .. m.title .. '.<br>Click to reveal more info.</span></span>' | ||
end | end | ||
| Line 101: | Line 57: | ||
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 63: | ||
end | end | ||
local | local icons = {} | ||
local placed = {} | local placed = {} | ||
local num = tonumber(ability_num) | -- Automatic hints in CONFIG order; an overriding manual icon takes the slot. | ||
local record = ability_data[ability_key] | |||
if record ~= nil then | |||
local num = tonumber(ability_num) | |||
for _, def in ipairs(CONFIG) do | |||
if AbilityTable.is_member(def.list, record, num) then | |||
local key = mw.ustring.lower(def.file) | |||
local m = manual_by_file[key] | |||
if m ~= nil then | |||
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( | table.insert(icons, manual_icon(m)) | ||
end | end | ||
end | end | ||
if # | if #icons == 0 then return '' 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 | ||