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

Module:C: Difference between revisions

From Teriock
Content deleted Content added
// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Tag: Reverted
Line 107: Line 107:


local function makeTag(frame, key, value, makeCat, transparent)
local function makeTag(frame, key, value, makeCat, transparent)
if not tags[key] or not tags[key][value] then
-- if not tags[key] or not tags[key][value] then
if value then
-- if value then
local out = frame:preprocess("{{ucfirst:" .. tostring(value) .. "}}")
-- local out = frame:preprocess("{{ucfirst:" .. tostring(value) .. "}}")
-- local out = 'pranked'
-- -- local out = 'pranked'
if not ('.' == out:sub(-1)) then
-- if not ('.' == out:sub(-1)) then
out = out .. '.'
-- out = out .. '.'
end
-- end
return out
-- return out
else
-- else
return ''
-- return ''
end
-- end
end
-- end
local tag = tags[key][value]
local tag = tags[key][value]
if tag.no then
if tag.no then

Revision as of 19:29, 11 February 2025

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 = '🐟️',
		}
	}
}

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 = ''
	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