Module:TableturfCard

local p = {}

function p.main(frame) local args = frame:getParent.args local number = args[1] or args["number"] or "??" local name = args[2] or args["name"] or "?" local spaces = args[3] or args["spaces"] or 0 local special = args[4] or args["special"] or 0 local category = args[5] or args["category"] or "Unsorted" local rarity = args[6] or args["rarity"] or "Common" local full_season = args[7] or args["release"] or "Drizzle Season 2022" local sort_value = args[8] or args["sort-value"] or "99_9999" local size = tonumber(args["size"]) or 64 local custom_link = args["custom-link"]

local rarity_colors = { ["Common"] = "#533ada", ["Rare"] = "#927002", ["Fresh"] = "#0B579D", }   local rarity_color = rarity_colors[rarity] local rarity_sorts = { ["Common"] = 0, ["Rare"] = 1, ["Fresh"] = 2, }   local rarity_sort = rarity_sorts[rarity] local season_index, year_index = p.parseSeason(full_season) -- The -2 is because year seasons start with Chill, but the first season was Drizzle. local release_sort = tonumber((year_index * 4) + season_index) - 2 -- version is the sort +1, then specifically for the first season it's 1.1.0, otherwise it's n.0.0. local release_version = (release_sort + 1) .. (release_sort ~= 0 and ".0.0" or ".1.0") local special_cost_text = frame:expandTemplate { title="TableturfSpecialCost", args={special} } local card_shape = frame:expandTemplate { title="TableturfCardShape", args={name} } local version_text = frame:expandTemplate { title="Ver", args={"S3", release_version} } local result = mw.ustring.format(       "| %s ||  || %s || %d || data-sort-value=\"%d\"|%s\n" ..        "| data-sort-value=\"%s\"|%s\n" ..        "| data-sort-value=\"%s\"|%s || %s\n" ..        "| data-sort-value=\"%s\"|%s (%s)",        number, name, size, custom_link or ""..name.."", spaces, special, special_cost_text,        sort_value, category,        rarity_sort, rarity_color, rarity, card_shape,        release_sort, version_text, full_season    ) return result end

function p.parseSeason(full_season) -- Define a table to map season names to their corresponding indices local seasons = { "Fresh", "Sizzle", "Drizzle", "Chill" }

-- Extract the season name and year from the input string local season, year = mw.ustring.match(full_season, "(%a+) Season (%d+)", 0)

-- If the season name is found, determine its index local seasonIndex = 0 if season then for i, name in ipairs(seasons) do           if name == season then seasonIndex = i - 1 -- Adjust index to start from 0 break end end end

-- Return the season index and year as indexes, or nil if not found local yearIndex = (tonumber(year) or 2022) - 2022 return seasonIndex, yearIndex end

return p