Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 19:27, 11 February 2025 by Gpe (talk | contribs) (// via Wikitext Extension for VSCode)

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 = '๐Ÿ‘ป',
		},
		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 = '๐Ÿ‘ค',
		},
		aquatic = {
			text = 'Aquatic',
			link = 'Aquatic creatures',
			symbol = '๐ŸŸ๏ธ',
		}
	}
}

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 = ''
	if args['t'] then
		tagIn = args['t']
	end
	local tagItems = sortString(tagIn)
	tagOut = ''
	for _, item in ipairs(tagItems) do
		tag = makeTag(frame, traits, item, true)
		tagOut = tagOut .. tag
	end
	return frame:preprocess(tagOut)
end

return p