Module:Shinies: Difference between revisions
automation |
automation |
||
| Line 22: | Line 22: | ||
local f = mw.title.new('File:Shiny' .. img) | local f = mw.title.new('File:Shiny' .. img) | ||
if f and f.exists then | if f and f.exists then | ||
local | local newblock = block:gsub('(Ut%-[^\n,;|}]+%.png)', 'Shiny%1', 1) | ||
out[#out + 1] = '{{ItemInfobox' .. newblock .. '}}' | |||
out[#out + 1] = ' | |||
end | end | ||
end | end | ||
end | end | ||
if #out == 0 then return "''No shinies yet.''" end | if #out == 0 then return "''No shinies yet.''" end | ||
return '< | return frame:preprocess('<div class="display-items">\n' .. table.concat(out, '\n') .. '\n</div>') | ||
end | end | ||
return p | return p | ||
Revision as of 12:55, 16 June 2026
Module:Shinies pulls the {{ItemInfobox}} blocks from a category template and re-renders only the items that have a "Shiny" sprite, swapping in the Shiny image so a page can show a gallery of shiny variants.
Overview
Some untiered items have a rarer "Shiny" version. The shiny version isn't stored as a separate infobox; instead its image is the normal item image with a Shiny prefix (e.g. File:Ut-Onyxblade.png → File:ShinyUt-Onyxblade.png).
This module scans a category template (like Template:Swords/Weapons), finds every {{ItemInfobox}} whose image is an untiered Ut-...png file and for which a matching File:ShinyUt-...png exists, and re-renders just those items with the shiny image substituted. The result is a gallery of all shiny variants for that category, used on the Shinies overview page. Items without a shiny file are skipped.
It is the same "read the source template live" pattern as {{Equipment}}m, so the Shinies page stays in sync with the item templates automatically.
Functions / entry points
| Function (#invoke) | What it does | Called by |
|---|---|---|
p.fromTemplate |
Loads Template:<arg1> (optionally narrowed to section arg2), finds each {{ItemInfobox}} with a Ut-...png image that has a corresponding File:ShinyUt-...png, rewrites the image to the Shiny file, wraps the results in and renders them. Returns No shinies yet. if none qualify. |
The {{Shinies}} listing page
|
How it's used
No shinies yet.
Real examples (from the Shinies listing template/page):
Swords={{#invoke:Shinies|fromTemplate|Swords/Weapons}}
Katanas={{#invoke:Shinies|fromTemplate|Katanas/Weapons}}
Emblems={{#invoke:Shinies|fromTemplate|Emblems/Abilities}}
- Argument 1 — category template title without
Template:(e.g.Swords/Weapons). - Argument 2 (optional) — section name to narrow to, same delimiting rules as
{{Equipment}}m(line starting<Section> =, cut at the next|-|).
Editors add the items themselves to the category templates; the Shinies page just invokes this module per category. You do not maintain a separate shiny list — uploading a correctly named ShinyUt-...png file is what makes an item appear here.
Notes
- File-naming scheme is load-bearing. Detection relies on the untiered-item naming convention: the base image must be
Ut-<Name>.png, and the shiny must be the same name prefixed withShiny, i.e.ShinyUt-<Name>.png. The image regex specifically matchesImages = Ut-...pngand rewrites only the first occurrence in the block. - Only items with an existing shiny file are emitted; everything else in the template is silently ignored.
- Output carries the extra
shiny-frameCSS class (on top ofdisplay-items) for the shiny gallery styling. {{Infobox}}mitself also auto-adds a Shiny tab to a single-image untiered infobox (sameShinyUt-rule). This module is the bulk/gallery counterpart: it lists shinies across a whole category rather than per item.- Related:
{{Equipment}}m(renders all items in a section),{{Infobox}}m(the rendering engine and the per-infobox Shiny tab),{{ItemInfobox}}.
local p = {}
function p.fromTemplate(frame)
local title = mw.text.trim(frame.args[1] or '')
local section = mw.text.trim(frame.args[2] or '')
if title == '' then return '' end
local page = mw.title.new('Template:' .. title)
local content = page and page:getContent()
if not content then return "''No shinies yet.''" end
if section ~= '' then
local s = content:find('\n' .. section .. '%s*=')
if not s then return "''No shinies yet.''" end
content = content:sub(s + 1)
local e = content:find('\n|%-|')
if e then content = content:sub(1, e - 1) end
end
local out = {}
for block in content:gmatch('{{ItemInfobox(.-)}}') do
local img = block:match('[Ii]mages%s*=%s*(Ut%-[^\n,;|}]+%.png)')
if img then
img = mw.text.trim(img)
local f = mw.title.new('File:Shiny' .. img)
if f and f.exists then
local newblock = block:gsub('(Ut%-[^\n,;|}]+%.png)', 'Shiny%1', 1)
out[#out + 1] = '{{ItemInfobox' .. newblock .. '}}'
end
end
end
if #out == 0 then return "''No shinies yet.''" end
return frame:preprocess('<div class="display-items">\n' .. table.concat(out, '\n') .. '\n</div>')
end
return p