Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

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 = '[[Category:Creatures]]'
	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