Module:AbilitySection: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
Add Interactions tab/parameter alongside Notes and Tips (with help from vergir-bot LLM)
Vergir (talk | contribs)
m support creating ability hints from interactions tab
Line 1: Line 1:
-- see /doc for docs
-- See /doc for docs


local p = {}
local p = {}
Line 27: Line 27:
end
end


local function build_tabber(wikitext_map)
local function process_interactions(html, ability_num)
local manual, idx, seen = {}, 0, {}
local out = html:gsub('(<div class="ai%-box)([^>]*)(>)', function(pre, attrs, post)
local file = attrs:match('data%-ai%-icon="([^"]*)"')
if file and file ~= '' then
local base  = mw.ustring.lower((file:gsub('%.%w+$', '')))
local entry = resource_lookup[base]
if entry ~= nil and entry.type == 'item' and not seen[base] then
seen[base] = true
idx = idx + 1
local box_id = 'ai-int-' .. ability_num .. '-' .. idx
table.insert(manual, {
file    = file,
title    = attrs:match('data%-ai%-title="([^"]*)"') or '',
disabled = attrs:find('ai%-disabled') ~= nil,
anchor  = box_id,
})
return pre .. attrs .. ' id="' .. box_id .. '"' .. post
end
end
return pre .. attrs .. post
end)
return out, manual
end
 
local function build_tabber(wikitext_map, tab_overrides)
tab_overrides = tab_overrides or {}
local filled = {}
local filled = {}
for _, tab in ipairs(TABS) do
for _, tab in ipairs(TABS) do
if wikitext_map[tab.key] ~= '' then
if wikitext_map[tab.key] ~= '' then
table.insert(filled, { key = tab.key, label = tab.label, wikitext = wikitext_map[tab.key] })
local tab_wt = tab_overrides[tab.key]
if tab_wt == nil or tab_wt == '' then tab_wt = wikitext_map[tab.key] end
table.insert(filled, {
key   = tab.key,
label = tab.label,
tab_wt = tab_wt,
all_wt = wikitext_map[tab.key],
})
end
end
end
end
Line 43: Line 76:
table.insert(tabs, {
table.insert(tabs, {
label  = section.label,
label  = section.label,
content = '<div class="ability-details-panel">\n' .. section.wikitext .. '\n</div>',
content = '<div class="ability-details-panel">\n' .. section.tab_wt .. '\n</div>',
})
})
end
end


-- "Show All" tab wraps each section's wikitext in a <div> to give the parser
-- a fresh block context per section, preventing html mangling.
if #filled >= 2 then
if #filled >= 2 then
local all_parts = {}
local all_parts = {}
Line 54: Line 85:
table.insert(all_parts,
table.insert(all_parts,
'<div class="ability-details-section-header">' .. section.label .. '</div>'
'<div class="ability-details-section-header">' .. section.label .. '</div>'
.. '<div class="ability-details-section-content">\n' .. section.wikitext .. '\n</div>'
.. '<div class="ability-details-section-content">\n' .. section.all_wt .. '\n</div>'
)
)
end
end
Line 99: Line 130:
}
}


local hints_col = ''
local interactions_ided, manual = interactions, {}
if ability_key ~= nil then
if interactions ~= '' then
hints_col = AbilityHints.get_icons(ability_key, ability_num)
interactions_ided, manual = process_interactions(interactions, ability_num)
end
end


Line 110: Line 141:
}
}


local tabber = build_tabber(wikitext_map)
local tabber = build_tabber(wikitext_map, { interactions = interactions_ided })
 
local hints_col = ''
if ability_key ~= nil or #manual > 0 then
hints_col = AbilityHints.get_icons(ability_key, ability_num, manual)
end
 
local details_col = ''
local details_col = ''
if tabber ~= '' then
if tabber ~= '' then
Line 116: Line 153:
end
end


-- Group the card and the hint rail together so the rail wraps with the card
-- (never onto the notes' line). Abilities with no interactions have no rail,
-- so they keep the flat single-card structure.
local card_block = '<div class="ability-section-card">' .. card .. '</div>'
local card_block = '<div class="ability-section-card">' .. card .. '</div>'
local left_col
local left_col