モジュール:MK大会結果表

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

ここに呼び出す説明文 『 モジュール:MK大会結果表/doc 』 が作成されていません。

local p = {}

-- 順位に応じた背景色
local rank_colors = {
    [1] = "#fff5a6", -- 金
    [2] = "#d6fcff", -- 銀
    [3] = "#ffca75"  -- 銅
}

-- team番号に応じた名前欄の背景色
local team_colors = {
    ["1"] = "#f05000",
    ["2"] = "#ff9e00",
    ["3"] = "#00c16a",
    ["4"] = "#50a0ff",
    ["5"] = "#d5b0ff",
    ["6"] = "#fffc59"
}

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame)

    local team = args.team or "1"
    local name = args.name or ""
    local total = args.total or ""
    local rank = tonumber(args.rank)

    local res = {}

    -- ユーザー名
    local team_bg = team_colors[team] or "transparent"
    table.insert(res, 'style="background-color:' .. team_bg .. ';"|' .. name)

    -- 12レースの結果処理
    for i = 1, 12 do
        local val = args[i] or ""
        local cell_content = ""

        -- 数値として比較するために tonumber を使用
        local num_val = tonumber(val)
        if num_val and rank_colors[num_val] then
            cell_content = 'style="background-color:' .. rank_colors[num_val] .. ';"|' .. val
        else
            cell_content = val
        end

        table.insert(res, cell_content)
    end

    -- 合計得点
    local total_style = ""
    if rank and rank_colors[rank] then
        total_style = 'style="background-color:' .. rank_colors[rank] .. ';"|'
    end

    table.insert(res, total_style .. total)

    return '|-\n|' .. table.concat(res, "||")
end

return p