From Arms of God Wiki
bot: shared module |
bot: documentation pass — editor-facing docs (data descriptions, module comments, template usage, Help rewrite) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- Module:CrossRef — | -- Module:CrossRef — "related entities" sections on detail pages. | ||
-- | -- | ||
-- | -- WHAT IT DOES | ||
-- | -- Computes cross-reference sections at render time: | ||
-- | -- * 'Base variant' / 'Upgraded variant' links between a blessing or | ||
-- | -- upgrade and its '<X> Plus' version (matched within the category). | ||
-- | -- * The "<Category> with this tag" member sections on Tag pages | ||
-- (delegated to Module:TagIndex). | |||
-- Nothing is stored: every link recomputes from the source Data pages | |||
-- on purge, so renaming an entity there updates all references. | |||
-- | |||
-- HOW TO INVOKE (wired by the per-category modules) | |||
-- {{#invoke:Blessings|crossRefs|id=Blessed_Bounty}} | |||
-- {{#invoke:Tags|crossRefs|id=Tag-Melee}} | |||
-- | |||
-- SOURCE DATA IT READS (via Module:Core) | |||
-- Data:Blessings.json, Data:Upgrades.json (variant pairing); | |||
-- the tag-bearing categories via Module:TagIndex for Tag pages. | |||
local Core = require('Module:Core') | |||
local p = {} | local p = {} | ||
-- Render a single labelled section: '== <label> ==' | -- Render a single labelled section: '== <label> ==' + icon-link bullets. | ||
- | |||
function p.renderSection(label, refs) | function p.renderSection(label, refs) | ||
if not refs or #refs == 0 then return '' end | if not refs or #refs == 0 then return '' end | ||
local out = {'', '== ' .. label .. ' =='} | local out = {'', '== ' .. label .. ' =='} | ||
for _, | for _, rec in ipairs(refs) do | ||
out[#out + 1] = '* ' .. Core.iconLink(rec, 24) | |||
end | end | ||
return table.concat(out, '\n') | return table.concat(out, '\n') | ||
end | end | ||
-- | -- Variant pairing: RAW id first ('<X> Plus' / '<x>-plus' -> base), then | ||
-- | -- display name ('<Name> Plus'). Id wins because Upgrades' display-name | ||
-- the | -- split means base and Plus can show unrelated display names (e.g. id | ||
-- 'Shield Transform' displays 'Lifesteal Chamber'); the name fallback | |||
-- covers Blessings, whose kebab-case ids ('blessed-bounty-plus') pair by | |||
if | -- either rule. | ||
local VARIANT_CATS = {Blessings = true, Upgrades = true} | |||
local | local _byName = {} | ||
for | local function byName(cat) | ||
if _byName[cat] == nil then | |||
if | local m = {} | ||
for _, r in ipairs(Core.load(cat)) do | |||
if r.name then m[r.name] = r end | |||
end | end | ||
_byName[cat] = m | |||
end | end | ||
return _byName[cat] | |||
end | |||
local function variantSections(cat, rec) | |||
if not VARIANT_CATS[cat] then return '' end | |||
local ids, names = Core.byId(cat), byName(cat) | |||
local id, name = rec.id or '', rec.name or '' | |||
local out = {} | local out = {} | ||
local base = nil | |||
if id:sub(-5) == ' Plus' then base = ids[id:sub(1, -6)] end | |||
if | if not base and id:sub(-5) == '-plus' then base = ids[id:sub(1, -6)] end | ||
if not base and name:sub(-5) == ' Plus' then base = names[name:sub(1, -6)] end | |||
if base and base ~= rec then | |||
out[#out + 1] = p.renderSection('Base variant', {base}) | |||
elseif not (id:sub(-5) == ' Plus' or id:sub(-5) == '-plus' | |||
or name:sub(-5) == ' Plus') then | |||
local plus = ids[id .. ' Plus'] or ids[id .. '-plus'] or names[name .. ' Plus'] | |||
if plus and plus ~= rec then | |||
out[#out + 1] = p.renderSection('Upgraded variant', {plus}) | |||
end | |||
end | end | ||
return table.concat(out, '\n') | return table.concat(out, '\n') | ||
end | |||
-- Full computed cross-ref block for one record (no frame needed). | |||
function p.compute(cat, rec) | |||
if cat == 'Tags' then | |||
local TagIndex = require('Module:TagIndex') | |||
return TagIndex.sectionsFor(rec.id or rec.name) | |||
end | |||
return variantSections(cat, rec) | |||
end | |||
-- Frame entry used by the per-category shims. | |||
function p.entry(cat, frame) | |||
local rec, missing = Core.resolveRec(cat, frame) | |||
if missing then return missing end | |||
if not rec then return '' end | |||
local body = p.compute(cat, rec) | |||
if body == '' then return '' end | |||
return mw.getCurrentFrame():preprocess(body) | |||
end | end | ||
return p | return p | ||
Latest revision as of 16:04, 10 June 2026
Shared helper that renders cross-reference link lists between categories.
Library module shipped by the publishing bot; shared across categories. Bot-published — edits are overwritten on re-publish.
-- Module:CrossRef — "related entities" sections on detail pages.
--
-- WHAT IT DOES
-- Computes cross-reference sections at render time:
-- * 'Base variant' / 'Upgraded variant' links between a blessing or
-- upgrade and its '<X> Plus' version (matched within the category).
-- * The "<Category> with this tag" member sections on Tag pages
-- (delegated to Module:TagIndex).
-- Nothing is stored: every link recomputes from the source Data pages
-- on purge, so renaming an entity there updates all references.
--
-- HOW TO INVOKE (wired by the per-category modules)
-- {{#invoke:Blessings|crossRefs|id=Blessed_Bounty}}
-- {{#invoke:Tags|crossRefs|id=Tag-Melee}}
--
-- SOURCE DATA IT READS (via Module:Core)
-- Data:Blessings.json, Data:Upgrades.json (variant pairing);
-- the tag-bearing categories via Module:TagIndex for Tag pages.
local Core = require('Module:Core')
local p = {}
-- Render a single labelled section: '== <label> ==' + icon-link bullets.
function p.renderSection(label, refs)
if not refs or #refs == 0 then return '' end
local out = {'', '== ' .. label .. ' =='}
for _, rec in ipairs(refs) do
out[#out + 1] = '* ' .. Core.iconLink(rec, 24)
end
return table.concat(out, '\n')
end
-- Variant pairing: RAW id first ('<X> Plus' / '<x>-plus' -> base), then
-- display name ('<Name> Plus'). Id wins because Upgrades' display-name
-- split means base and Plus can show unrelated display names (e.g. id
-- 'Shield Transform' displays 'Lifesteal Chamber'); the name fallback
-- covers Blessings, whose kebab-case ids ('blessed-bounty-plus') pair by
-- either rule.
local VARIANT_CATS = {Blessings = true, Upgrades = true}
local _byName = {}
local function byName(cat)
if _byName[cat] == nil then
local m = {}
for _, r in ipairs(Core.load(cat)) do
if r.name then m[r.name] = r end
end
_byName[cat] = m
end
return _byName[cat]
end
local function variantSections(cat, rec)
if not VARIANT_CATS[cat] then return '' end
local ids, names = Core.byId(cat), byName(cat)
local id, name = rec.id or '', rec.name or ''
local out = {}
local base = nil
if id:sub(-5) == ' Plus' then base = ids[id:sub(1, -6)] end
if not base and id:sub(-5) == '-plus' then base = ids[id:sub(1, -6)] end
if not base and name:sub(-5) == ' Plus' then base = names[name:sub(1, -6)] end
if base and base ~= rec then
out[#out + 1] = p.renderSection('Base variant', {base})
elseif not (id:sub(-5) == ' Plus' or id:sub(-5) == '-plus'
or name:sub(-5) == ' Plus') then
local plus = ids[id .. ' Plus'] or ids[id .. '-plus'] or names[name .. ' Plus']
if plus and plus ~= rec then
out[#out + 1] = p.renderSection('Upgraded variant', {plus})
end
end
return table.concat(out, '\n')
end
-- Full computed cross-ref block for one record (no frame needed).
function p.compute(cat, rec)
if cat == 'Tags' then
local TagIndex = require('Module:TagIndex')
return TagIndex.sectionsFor(rec.id or rec.name)
end
return variantSections(cat, rec)
end
-- Frame entry used by the per-category shims.
function p.entry(cat, frame)
local rec, missing = Core.resolveRec(cat, frame)
if missing then return missing end
if not rec then return '' end
local body = p.compute(cat, rec)
if body == '' then return '' end
return mw.getCurrentFrame():preprocess(body)
end
return p