|
|
| (One intermediate revision by the same user not shown) |
| Line 1: |
Line 1: |
| -- Module:Monster
| |
| local p = {}
| |
| local data = require('Module:MonsterData')
| |
|
| |
|
| ----------------------------------------------------------
| |
| -- Return a single stat
| |
| ----------------------------------------------------------
| |
| function p.get(frame)
| |
| local args = frame.args
| |
| local name = args.name or args[1]
| |
| local stat = args.stat or args[2]
| |
|
| |
| local e = data[name]
| |
| if not e then
| |
| return "Monster not found: " .. tostring(name)
| |
| end
| |
| if not stat or not e[stat] then
| |
| return "Stat not found: " .. tostring(stat)
| |
| end
| |
|
| |
| return e[stat]
| |
| end
| |
|
| |
| ----------------------------------------------------------
| |
| -- Return a single wikitable row (two columns for drops with left-aligned bullet points)
| |
| ----------------------------------------------------------
| |
| function p.row(frame)
| |
| local args = frame.args
| |
| local name = args.name or args[1]
| |
| local e = data[name]
| |
|
| |
| if not e then
| |
| return "Monster not found: " .. tostring(name)
| |
| end
| |
|
| |
| -- Handle drops
| |
| local drops = e.drops or '—'
| |
| if type(drops) == "table" then
| |
| local lines = {}
| |
| for _, drop in ipairs(drops) do
| |
| local icon = drop.icon and frame:expandTemplate{title = drop.icon} .. " " or ""
| |
| local quantity = drop.quantity and drop.quantity .. " " or ""
| |
| local chance = drop.chance and " – " .. drop.chance or ""
| |
| table.insert(lines, string.format("<li>%s[[%s]] %s%s</li>", icon, drop.name, quantity, chance))
| |
| end
| |
| drops = "<div style='column-count:2; -moz-column-count:2; -webkit-column-count:2; text-align:left'><ul>"
| |
| .. table.concat(lines, "") .. "</ul></div>"
| |
| end
| |
|
| |
| return string.format(
| |
| '|-\n| [[File:%s|50px]] || [[%s]] || %s || %s || %s || %s || %s || %s || %s || %s || %s',
| |
| e.image or '',
| |
| name,
| |
| e.element or '',
| |
| e.level or '',
| |
| e.exp or '',
| |
| e.hp or '',
| |
| e.atk or '',
| |
| e.def or '',
| |
| e.mp or '',
| |
| e.spd or '',
| |
| drops
| |
| )
| |
| end
| |
|
| |
| ----------------------------------------------------------
| |
| -- Generate a Portable Infobox (single-column drops with icons, left-aligned)
| |
| ----------------------------------------------------------
| |
| function p.infobox(frame)
| |
| local args = frame.args
| |
| local name = args.name or args[1]
| |
| local e = data[name]
| |
|
| |
| if not e then
| |
| return "Monster not found: " .. tostring(name)
| |
| end
| |
|
| |
| local infobox_params = {
| |
| name = string.format('[[%s|%s]]', name, e.name or name),
| |
| image = e.image and string.format('[[File:%s]]', e.image) or "",
| |
| element = e.element or "—",
| |
| level = e.level or "—",
| |
| exp = e.exp or "—",
| |
| hp = e.hp or "—",
| |
| atk = e.attack or "—",
| |
| def = e.defence or "—",
| |
| mp = e.mp or "—",
| |
| spd = e.spd or "—"
| |
| }
| |
|
| |
| -- Single-column drops, left-aligned bullet list
| |
| local drops = e.drops or '—'
| |
| if type(drops) == "table" then
| |
| local lines = {}
| |
| for _, drop in ipairs(drops) do
| |
| local icon = drop.icon and "{{" .. drop.icon .. "}} " or ""
| |
| local quantity = drop.quantity and drop.quantity .. " " or ""
| |
| local chance = drop.chance and " – " .. drop.chance or ""
| |
| table.insert(lines, string.format('* %s[[%s]] %s%s', icon, drop.name, quantity, chance))
| |
| end
| |
| -- Add newline before first bullet to ensure proper wikitext rendering
| |
| infobox_params.drops = "<div style='text-align:left'><ul>\n" .. table.concat(lines, "\n") .. "\n</ul></div>"
| |
| else
| |
| infobox_params.drops = drops
| |
| end
| |
|
| |
| return frame:expandTemplate{
| |
| title = "Monster/Infobox",
| |
| args = infobox_params
| |
| }
| |
| end
| |
|
| |
| return p
| |