Documentation for this module may be created at Module:C/doc
local p = {}
local tags = {
traits = {
undead = {
text = 'Undead',
link = 'Undead creatures',
symbol = 'πͺ¦',
},
corporeal = {
text = 'Corporeal',
link = 'Corporeal undead creatures',
symbol = 'π§ββοΈ',
},
skeletal = {
text = 'Skeletal',
link = 'Skeletal undead creatures',
symbol = 'π¦΄',
},
spectral = {
text = 'Spectral',
link = 'Spectral undead creatures',
symbol = 'π»',
},
minor = {
text = 'Minor',
link = 'Minor undead creatures',
symbol = 'π§',
},
full = {
text = 'Full',
link = 'Full undead creatures',
symbol = 'π',
},
greater = {
text = 'Greater',
link = 'Greater undead creatures',
symbol = 'π§',
},
outsider = {
text = 'Outsider',
link = 'Outsider creatures',
symbol = 'π½οΈ',
},
angelic = {
text = 'Angelic',
link = 'Angelic creatures',
symbol = 'π',
},
demonic = {
text = 'Demonic',
link = 'Demonic creatures',
symbol = 'πΏ',
},
elemental = {
text = 'Elemental',
link = 'Elemental creatures',
symbol = 'π',
},
plant = {
text = 'Plant',
link = 'Plant creatures',
symbol = 'πΏ'
},
construct = {
text = 'Construct',
link = 'Construct creatures',
symbol = 'πΏ'
},
draconic = {
text = 'Draconic',
link = 'Draconic creatures',
symbol = 'π²',
},
fae = {
text = 'Fae',
link = 'Fae creatures',
symbol = 'π§',
},
animal = {
text = 'Animal',
link = 'Animal creatures',
symbol = 'π¦',
},
common = {
text = 'Common',
link = 'Common animal creatures',
symbol = 'πΎ',
},
ooze = {
text = 'Ooze',
link = 'Ooze creatures',
symbol = 'π©',
},
monstrous = {
text = 'Monstrous',
link = 'Monstrous creatures',
symbol = 'π§',
},
humanoid = {
text = 'Humanoid',
link = 'Humanoid creatures',
symbol = 'π€',
},
partial = {
text = 'Partial',
link = 'Partial humanoid creatures',
symbol = 'π',
},
aquatic = {
text = 'Aquatic',
link = 'Aquatic creatures',
symbol = 'ποΈ',
},
}
}
local function sortString(s)
local items = {}
for item in string.gmatch(s, '([^,]+)') do
local trimmed_item = item:match("^%s*(.-)%s*$")
table.insert(items, trimmed_item)
end
table.sort(items)
return items
end
local function makeTag(frame, key, value, makeCat, transparent)
if not tags[key] or not tags[key][value] then
if value then
local out = frame:preprocess("{{ucfirst:" .. tostring(value) .. "}}")
-- local out = 'pranked'
if not ('.' == out:sub(-1)) then
out = out .. '.'
end
return out
else
return ''
end
end
local tag = tags[key][value]
if tag.no then
local out = frame:preprocess("{{ucfirst:" .. tag.text .. "}}")
if not ('.' == out:sub(-1)) then
out = out .. '.'
end
return out
end
if tag.tags then
local out = ''
for _, t in ipairs(tag.tags) do
out = out .. makeTag(frame, key, t, makeCat, transparent)
end
return out
end
local tagText = "{{Tag|{{ucfirst:" .. tag.text .. "}}"
if tag.symbol then
tagText = tagText .. "|" .. tag.symbol
end
if tag.link then
tagText = tagText .. "|l=:Category:{{ucfirst:" .. tag.link .. "}}"
end
if tag.color then
tagText = tagText .. "|c=" .. tag.color
end
if transparent then
tagText = tagText .. "|o=1"
end
tagText = tagText .. "}}"
-- out = frame:preprocess(tagText)
out = tagText
return out
end
function p.c ( frame )
local args = frame.args
local tagIn = ''
local abilitiesIn = ''
local hp = ''
local mp = ''
local name = args['name']
if not name then
return 'Must provide name.'
end
local catString = ''
if args['t'] then
tagIn = args['t']
end
if args['a'] then
abilitiesIn = args['a']
end
if args['hp'] then
hp = args['hp']
end
if args['mp'] then
mp = args['mp']
end
local tagItems = sortString(tagIn)
tagOut = ''
for _, item in ipairs(tagItems) do
tag = makeTag(frame, 'traits', item, true)
tagOut = tagOut .. tag
catString = catString .. '[[Category:' .. tags['traits'][item]['link'] .. ']]'
end
local page = mw.title.getCurrentTitle().text
local namespace = frame:preprocess('{{NAMESPACE}}')
local addCats = ((namespace == 'Creature') and (page == name))
local out = "'''CREATURE PAGES ARE A WORK IN PROGRESS'''\n\n"
out = out .. "'''Traits and Types:''' " .. tagOut .. '\n\n'
if hp ~= '' then
out = out .. "'''HP:''' " .. hp .. '\n\n'
end
if mp ~= '' then
out = out .. "'''MP:''' " .. mp .. '\n'
end
out = out .. "== Abilities ==\n"
out = out .. '{{AESort|' .. abilitiesIn .. '}}'
if addCats then
out = out .. catString
end
return frame:preprocess(out)
end
return p