local p = {}
local function wikitext(text1)
return mw.getCurrentFrame():preprocess(text1)
end
-- 工具函数:获取Old分支的颜色(T12/T34/T56)
local function getOldColor(sty, type)
local colors = {
Blue = "E0FFFF",
Green = "F0FFF0",
Red = "FFD9E6",
Yellow = "FFFFE0"
}
-- 按类型区分颜色判断逻辑(T12/T34/T56)
if type == "T12" then
if sty == "蓝色" then return colors.Blue
elseif sty == "绿色" then return colors.Green
elseif sty == "红色" then return colors.Red
else return colors.Yellow end
elseif type == "T34" then
if sty == "蓝色" then return colors.Blue
elseif sty == "绿色" then return colors.Green
elseif sty == "黄色" then return colors.Yellow
else return colors.Red end
elseif type == "T56" then
if sty == "红色" then return colors.Red
elseif sty == "绿色" then return colors.Green
elseif sty == "黄色" then return colors.Yellow
else return colors.Blue end
end
return colors.Yellow -- 默认黄色
end
-- 1. Old分支处理函数
function p.old(frame)
local args = frame.args
local groupname = args.groupname or "未命名"
-- 获取T12/T34/T56颜色
local t12Color = getOldColor(args.sty12, "T12")
local t34Color = getOldColor(args.sty34, "T34")
local t56Color = getOldColor(args.sty56, "T56")
-- 表格行生成(1-6名,按颜色分组)
local rows = {}
-- 2. 为所有参数添加默认值,避免nil
local num1 = args.num1 or "未设置"
local wlt1 = args["wlt1"] or "0/0" -- 处理带特殊字符的参数名
local mpt1 = args["mpt1"] or "0"
local pt1 = args["pt1"] or "0"
local num2 = args.num2 or "未设置"
local wlt2 = args["wlt2"] or "0/0"
local mpt2 = args["mpt2"] or "0"
local pt2 = args["pt2"] or "0"
local num3 = args.num3 or "未设置"
local wlt3 = args["wlt3"] or "0/0"
local mpt3 = args["mpt3"] or "0"
local pt3 = args["pt3"] or "0"
local num4 = args.num4 or "未设置"
local wlt4 = args["wlt4"] or "0/0"
local mpt4 = args["mpt4"] or "0"
local pt4 = args["pt4"] or "0"
local num5 = args.num5 or "未设置"
local wlt5 = args["wlt5"] or "0/0"
local mpt5 = args["mpt5"] or "0"
local pt5 = args["pt5"] or "0"
local num6 = args.num6 or "未设置"
local wlt6 = args["wlt6"] or "0/0"
local mpt6 = args["mpt6"] or "0"
local pt6 = args["pt6"] or "0"
-- 3. 颜色计算(保持原逻辑)
local t12Color = getOldColor(sty12, "T12")
local t34Color = getOldColor(sty34, "T34")
local t56Color = getOldColor(sty56, "T56")
-- 4. 表格行拼接(确保所有参数都是字符串)
local rows = {}
-- 第1行
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''1'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t12Color, t12Color, num1, -- 此处已确保num1是字符串
t12Color, wlt1,
t12Color, mpt1,
t12Color, pt1
))
-- 第2行
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''2'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t12Color, t12Color, num2,
t12Color, wlt2,
t12Color, mpt2,
t12Color, pt2
))
-- 第3行(T34颜色)
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''3'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t34Color, t34Color, num3,
t34Color, wlt3,
t34Color, mpt3,
t34Color, pt3
))
-- 第4行(T34颜色)
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''4'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t34Color, t34Color, num4,
t34Color, wlt4,
t34Color, mpt4,
t34Color, pt4
))
-- 第5行(T56颜色)
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''5'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t56Color, t56Color, num5,
t56Color, wlt5,
t56Color, mpt5,
t56Color, pt5
))
-- 第6行(T56颜色)
table.insert(rows, string.format(
"|style=\"background:#%s; text-align:center;\"|'''6'''||style=\"background:#%s;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s||style=\"background:#%s; text-align:center;\"|%s",
t56Color, t56Color, num6,
t56Color, wlt6,
t56Color, mpt6,
t56Color, pt6
))
-- 拼接完整表格
local tableHtml = string.format([[
{|class="wikitable"
|-
! colspan="5"|%s组
|-
!排名!!战队名!!胜负场!!净胜分!!积分
|-
%s
|-
|}
]], groupname, table.concat(rows, "\n|- \n"))
return wikitext(tableHtml)
end
-- 2. Preseason分支处理函数
function p.preseason(frame)
local args = frame.args
local group = args.group or "X"
-- 颜色样式定义(绿/黄/红)
local colorStyles = {
green = { cell = 'align="center" style="background:#F0FFF0;"', row = 'style="background:#F0FFF0;"' },
yellow = { cell = 'align="center" style="background:#FFFFE0;"', row = 'style="background:#FFFFE0;"' },
red = { cell = 'align="center" style="background:#FFD9E6;"', row = 'style="background:#FFD9E6;"' }
}
-- 循环生成8行表格(1-8名)
local rows = {}
for i = 1, 8 do
local big = args["big"..i] or "6-1"
local small = args["small"..i] or "0-0"
local team = args["team"..i] or ""
local logo = args["logo"..i] or "Nowritting"
local logosize = args["logosize"..i] or "20px"
-- 计算积分(P)和净胜分(D)
local vu = tonumber(big) or 6 -- 原模板#expr:VU{i}
local two = vu + 7
local ll = two / 2
local p = string.format("'''%s''' pt", ll)
local absdifs = tonumber(small) or 0 -- 原模板#expr:absdifs{i}
local d = absdifs > 0 and ("+" .. absdifs) or tostring(absdifs)
-- 处理战队Logo和名称
local logoName = logo == "Nowritting" and team or logo
local logoHtml = string.format("{{ClubIcon|%s|%s}}", logoName, logosize)
local teamHtml = logoHtml .. team
-- 确定颜色和资格(1-3绿/S组,4-6黄/A组,7-8红/B组)
local style, qualification
if i <= 3 then
style = colorStyles.green
qualification = "'''S组'''"
elseif i <= 6 then
style = colorStyles.yellow
qualification = "'''A组'''"
else
style = colorStyles.red
qualification = "'''B组'''"
end
-- 插入行
table.insert(rows, string.format(
"|%s|'''%d'''||%s|%s||%s|%s||%s|%s||%s|%s||%s|%s||%s|%s",
style.cell, i, style.row, teamHtml, style.cell, big, style.cell, small,
style.cell, d, style.cell, p, style.cell, qualification
))
end
-- 拼接表格
local tableHtml = string.format([[
{|class="wikitable"
|-
! colspan="7"|%s组
|-
!排名!!战队名!!大场!!小场!!净胜分!!积分!!资格
|-
%s
|-
|}
]], group, table.concat(rows, "\n|- \n"))
return wikitext(tableHtml)
end
-- 3. New分支处理函数
function p.new(frame)
local args = frame.args
local tournament = args.tournament or "S组"
local teamNumber = tonumber(args.teamnumber) or 6
local mnb = teamNumber - 1 -- 原模板MNB = TeamNumber -1
-- 颜色样式定义(绿/黄/红/蓝)
local colorMap = { -- 颜色参数映射(中文→简写)
["绿色"] = "G", ["绿"] = "G", ["Green"] = "G",
["黄色"] = "Y", ["黄"] = "Y", ["Yellow"] = "Y",
["红色"] = "R", ["红"] = "R", ["Red"] = "R",
["蓝色"] = "B", ["蓝"] = "B", ["Blue"] = "B"
}
local colorStyles = {
G = { cell = 'align="center" style="background:#F0FFF0;"', row = 'style="background:#F0FFF0;"' },
Y = { cell = 'align="center" style="background:#FFFFE0;"', row = 'style="background:#FFFFE0;"' },
R = { cell = 'align="center" style="background:#FFD9E6;"', row = 'style="background:#FFD9E6;"' },
B = { cell = 'align="center" style="background:#E0FFFF;"', row = 'style="background:#E0FFFF;"' }
}
-- 循环生成TeamNumber行表格
local rows = {}
for i = 1, teamNumber do
-- 获取参数
local big = args["big"..i] or "5-0"
local small = args["small"..i] or "15-0"
local diff = args["diff"..i] or "NoEnter"
local pts = args["pts"..i] or "NoEnter"
local team = args["team"..i] or "IG"
local logo = args["logo"..i] or "NowritingEnter"
local logosize = args["logosize"..i] or "20px"
local color = args["color"..i] or "Green"
local colorShort = colorMap[color] or "G" -- 颜色简写
local style = colorStyles[colorShort]
-- 计算积分P(优先用Pts,否则自动计算)
local p
if pts ~= "NoEnter" then
p = pts
else
local evu = tonumber(big) or 5
local two = evu + mnb
local ll = two / 2
p = string.format("'''%s'''P", ll)
end
-- 计算净胜D(优先用Diff,否则自动计算)
local d
if diff ~= "NoEnter" then
d = diff
else
local ccd = tonumber(small) or 15
d = ccd > 0 and ("+" .. ccd) or tostring(ccd)
end
-- 处理战队Logo和名称
local logoName = logo == "NowritingEnter" and team or logo
local logoHtml = string.format("{{ClubIcon|%s|%s}}", logoName, logosize)
local teamHtml = logoHtml .. team
-- 插入行
table.insert(rows, string.format(
"|%s|'''%d'''||%s|%s||%s|%s||%s|%s||%s|%s||%s|%s",
style.cell, i, style.row, teamHtml, style.cell, big, style.cell, small,
style.cell, d, style.cell, p
))
end
-- 拼接表格
local tableHtml = string.format([[
{|class="wikitable"
|-
! colspan="7"|%s
|-
!#!!战队名!!大场!!小场!!净胜!!积分
|-
%s
|-
|}
]], tournament, table.concat(rows, "\n|- \n"))
return wikitext(tableHtml)
end
return p