Module:Enemy Icon
Cached copy of the original page · revision 1659977 · refresh
| Main | Documentation | Usage |

Module for {{Enemy Icon}} and for the enemy cells of {{Questbody}}.
The module has two entry points.
main is {{Enemy Icon}}. It turns an enemy's article name into that enemy's icon, File:NameIcon.png, linked to the article. A / in the name becomes -, and so does a : together with the space after it: Beast III/R gives File:Beast III-RIcon.png, and Beast IV: L gives File:Beast IV-LIcon.png. The icon is wrapped in <span class="enemy_icon">, and inum adds a {{Inum}} caption. Other modules call the same code as _main with a table of arguments.
questbody is called by {{Questbody}} once for each enemy, as {{#invoke:Enemy Icon|questbody|23}} for en23. It reads en23, en23icon, en23stage and en23stats from the Questbody call and returns the cell as {{Questbodyenemy}} shows it, each part on its own line:
- the icon (see below);
- the name: the part of
en23before the first;; en23stats, when set;- the stats: the part between the first and the second
;. Text after a second;is dropped.
An empty en23 returns nothing, which is how Questbodyenemy knows how many enemies a row has.
The cell is split here rather than with #explode. #explode stops with "String exceeds 1,000 character limit" on longer text, such as a cell with several {{HPBar}}s, and removes <nowiki/> and similar tags from the text.
Questbody icons
- The icon is that of
en23iconwhen set, otherwise that of the first article link in the name. Links to files, categories and other wikis are skipped, so text in front of the enemy's link is fine. - A playable Servant (a key of Module:Servant Icon/data) gets the frameless
{{Servant Icon}}(rawimage=y) at stageen23stage. Any other page gets the iconmainmakes. Both are 50px. The icon links to the page the name links to, even whenen23iconnames another page; a name without a link gives an icon linked to theen23iconpage. - Nothing checks that the file exists: that is an expensive call, and a page can hold hundreds of enemies. A link to a page without an icon, such as a redirect, shows a broken file and puts the page in Category:Pages with broken file links.
- The pages in
QUESTBODY_NO_ICONS, at the top of the module, get no icons. A page goes there when its icons would push its post-expand include size past the wiki's 2 MB limit, past which the rest of the page is no longer rendered; each icon adds a few hundred bytes. Add a page that lands in Category:Pages where template include size is exceeded. To show icons on it again, split it into subpages, as Main Quest: Id and Main Quest: Avalon le Fae/Part II were.
Uses Module:Arguments, Module:Servant Icon, Module:Servant Icon/data and {{Inum}}.
To update:
QUESTBODY_NO_ICONSin this module: pages that show no Questbody icons
The parameters are documented at Template:Enemy Icon and, for the enemy cells, at Template:Questbody#Enemy icons.
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrapper = { 'Template:Enemy Icon' }
})
return p._main(args)
end
function p._main(args)
local pagename = args.name or args[1] or ""
local size = args.size or args[2] or 75
local link = args.link or pagename or ""
-- Replace "/" and ":" to "-" because Wiki's page name can't put them.
local iconFileName = string.gsub(pagename, "/", "-")
iconFileName = string.gsub(iconFileName, ":%s?", "-")
local node_result = mw.html.create()
local filePath = '[[File:' .. iconFileName .. 'Icon.png|' .. size .. 'px|link=' .. link .. ']]'
local inumText = args.inum or nil
if inumText ~= nil then
node_result
:tag('span')
:addClass('enemy_icon')
:wikitext(mw.getCurrentFrame():expandTemplate{ title = 'Inum', args = { filePath, inumText } })
:done()
else
node_result
:tag('span')
:addClass('enemy_icon')
:wikitext(filePath)
:done()
end
return node_result
end
-- Pages where the icons would push the post-expand include size past 2 MB (about 650 bytes per enemy cell; measured 2026-11-15).
-- Add a page here if it lands in [[:Category:Pages where template include size is exceeded]]. User blogs are left out on purpose.
local QUESTBODY_NO_ICONS = {
["Akihabara Explosion (US)/Tower Quests/Tower 3"] = true,
["Amazones.com ~CEO Crisis 2022~ (US)/Tower Quests/Tower 3"] = true,
}
-- The icon of an enemy cell, on its own line: of en11icon if given, else of the first article link in the cell's name.
-- Playable Servants (keys of Module:Servant Icon/data) get their frameless Servant Icon at stage en11stage, everything else Enemy Icon.
-- shortcut: a link through a redirect, or to an enemy without <name>Icon.png, shows a broken file; fix the link, set en11icon or upload the icon.
local function questbodyIcon(args, key, name)
if QUESTBODY_NO_ICONS[mw.title.getCurrentTitle().prefixedText] then
return ''
end
local link
for target in name:gmatch('%[%[([^|%]#]+)') do
local title = mw.title.new(mw.text.trim(target))
if title and title.namespace == 0 and title.interwiki == '' then
link = title.text
break
end
end
local iconName = mw.text.trim(args[key .. 'icon'] or '')
if iconName == '' then
iconName = link
end
if not iconName then
return ''
end
local icon
if mw.loadData('Module:Servant Icon/data')[iconName] then
icon = require('Module:Servant Icon')._main({ name = iconName, size = 50, rawimage = 'y', stage = args[key .. 'stage'], link = link })
else
icon = p._main({ name = iconName, size = 50, link = link })
end
return tostring(icon) .. '<br/>'
end
-- For Template:Questbody: {{#invoke:Enemy Icon|questbody|11}} is cell en11 as Template:Questbodyenemy shows it:
-- the icon, the name (the part before the first ';'), en11stats, and the stats (the part between the first and the second ';'), each on its own line.
-- Split here rather than with #explode, which fails on text over 1,000 characters, such as a cell with several HP bars.
function p.questbody(frame)
local args = frame:getParent().args
local key = 'en' .. frame.args[1]
local cell = args[key] or ''
if cell == '' then
return ''
end
local parts = mw.text.split(cell, ';', true)
local out = questbodyIcon(args, key, parts[1]) .. parts[1]
local stats = mw.text.trim(args[key .. 'stats'] or '')
if stats ~= '' then
out = out .. '<br/>' .. stats
end
if parts[2] and mw.text.trim(parts[2]) ~= '' then
out = out .. '<br/>' .. parts[2]:match('^(.-)%s*$')
end
return out
end
return p;