member
171
edits
(Created page with "-- 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[...") |
No edit summary |
||
| Line 2: | Line 2: | ||
local p = {} | local p = {} | ||
local data = require('Module:MonsterData') | local data = require('Module:MonsterData') | ||
---------------------------------------------------------- | |||
-- Helper: Format drops | |||
-- two_columns: boolean, whether to make it 2-column (row) or 1-column (infobox) | |||
---------------------------------------------------------- | |||
local function formatDrops(drops, frame, two_columns) | |||
if not drops then return "—" end | |||
if type(drops) ~= "table" then return drops end | |||
local lines = {} | |||
for _, drop in ipairs(drops) do | |||
local drop_icon = drop.name | |||
if frame and frame.expandTemplate then | |||
drop_icon = frame:expandTemplate{ | |||
title = "FaviconPaste", | |||
args = { Name = drop.name } | |||
} | |||
end | |||
local quantity = drop.quantity and (" " .. drop.quantity) or "" | |||
local chance = drop.chance and (" – " .. drop.chance) or "" | |||
local line = (two_columns and "<li>" or "* ") .. drop_icon .. quantity .. chance .. (two_columns and "</li>" or "") | |||
table.insert(lines, line) | |||
end | |||
if two_columns then | |||
return "<div style='column-count:2; -moz-column-count:2; -webkit-column-count:2; text-align:left'><ul>" | |||
.. table.concat(lines, "") .. "</ul></div>" | |||
else | |||
return "<div style='text-align:left'><ul>\n" .. table.concat(lines, "\n") .. "\n</ul></div>" | |||
end | |||
end | |||
---------------------------------------------------------- | ---------------------------------------------------------- | ||
| Line 15: | Line 46: | ||
return "Monster not found: " .. tostring(name) | return "Monster not found: " .. tostring(name) | ||
end | end | ||
if not stat or | if not stat or e[stat] == nil then | ||
return "Stat not found: " .. tostring(stat) | return "Stat not found: " .. tostring(stat) | ||
end | end | ||
| Line 23: | Line 54: | ||
---------------------------------------------------------- | ---------------------------------------------------------- | ||
-- Return a single wikitable row ( | -- Return a single wikitable row (2-column drops) | ||
---------------------------------------------------------- | ---------------------------------------------------------- | ||
function p.row(frame) | function p.row(frame) | ||
| Line 34: | Line 65: | ||
end | end | ||
-- | -- Format drops (2 columns) | ||
local | local drops_html = formatDrops(e.drops, frame, true) | ||
-- Format element | |||
local element = e.element and string.format('<span class="Element %s">%s</span>', e.element, e.element) or '—' | |||
-- Image with name below image | |||
local image_and_name = e.image and string.format( | |||
'<div style="text-align:center">[[File:%s|50px|link=%s]]<br>[[%s]]</div>', | |||
e.image, name, name | |||
) or '' | |||
return string.format( | return string.format( | ||
'|-\n| | '|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %s || %s', | ||
image_and_name, | |||
element, | |||
e.level or '', | e.level or '', | ||
e.exp or '', | e.exp or '', | ||
| Line 60: | Line 88: | ||
e.mp or '', | e.mp or '', | ||
e.spd or '', | e.spd or '', | ||
drops_html | |||
) | ) | ||
end | end | ||
---------------------------------------------------------- | ---------------------------------------------------------- | ||
-- Generate a Portable Infobox (single-column drops | -- Return only drops (single-column) | ||
---------------------------------------------------------- | |||
function p.drops(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 | |||
return formatDrops(e.drops, frame, false) | |||
end | |||
---------------------------------------------------------- | |||
-- Generate a Portable Infobox (single-column drops) | |||
---------------------------------------------------------- | ---------------------------------------------------------- | ||
function p.infobox(frame) | function p.infobox(frame) | ||
| Line 78: | Line 121: | ||
local infobox_params = { | local infobox_params = { | ||
name = string.format('[[%s|%s]]', name, e.name or name), | name = string.format('[[%s|%s]]', name, e.name or name), | ||
image = e.image and string.format('[[File:%s]]', e.image) or "", | image = e.image and string.format('[[File:%s|link=%s]]', e.image, name) or "", | ||
element = e.element or "—", | element = e.element and string.format('<span class="Element %s">%s</span>', e.element, e.element) or "—", | ||
level = e.level or "—", | level = e.level or "—", | ||
exp = e.exp or "—", | exp = e.exp or "—", | ||
hp = e.hp or "—", | hp = e.hp or "—", | ||
atk = e. | atk = e.atk or "—", | ||
def = e. | def = e.def or "—", | ||
mp = e.mp or "—", | mp = e.mp or "—", | ||
spd = e.spd or "—" | spd = e.spd or "—", | ||
drops = formatDrops(e.drops, frame, false) | |||
} | } | ||
return frame:expandTemplate{ | return frame:expandTemplate{ | ||