Module:ChartConstantDetail:修订间差异
DrLee lihr(讨论 | 贡献) (remove unused class) |
小 (去除硬编码改为使用转换表页面) |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local chartConstantList = | local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' }) | ||
local songlist = | local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' }) | ||
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' }) | |||
local specialSongNameConverter = {} | -- local specialSongNameConverter = {} | ||
specialSongNameConverter["#1f1e33"] ="#1f1e33" | -- specialSongNameConverter["#1f1e33"] ="#1f1e33" | ||
specialSongNameConverter["AI[UE]OON"] ="AI[UE]OON" | -- specialSongNameConverter["AI[UE]OON"] ="AI[UE]OON" | ||
specialSongNameConverter["Last | Eternity"]="Last" | -- specialSongNameConverter["Last | Eternity"]="Last" | ||
local specialSongNameDisplayConverter = {} | -- local specialSongNameDisplayConverter = {} | ||
specialSongNameDisplayConverter["Last | Eternity"]="Last \| Eternity" | -- specialSongNameDisplayConverter["Last | Eternity"]="Last \| Eternity" | ||
local function constantFormat (a) | local function constantFormat (a) | ||
第57行: | 第58行: | ||
for i, k in pairs(constantList) do | for i, k in pairs(constantList) do | ||
if | if trans["songNameToDisplayName"][k[2]] then | ||
if specialSongNameDisplayConverter[k[2]] then | -- if specialSongNameDisplayConverter[k[2]] then | ||
-- finText = finText .. "|-\n|[[" .. specialSongNameConverter[k[2]] | |||
-- .. "|" .. specialSongNameDisplayConverter[k[2]] .. "]]" | |||
else | -- else | ||
finText = finText .. "|-\n|[[" .. trans["songNameToDisplayName"][k[2]] | |||
.. "|" .. k[2] .. "]]" | |||
end | -- end | ||
else | else | ||
finText = finText .. "|-\n|[[" .. k[2] .. "]]" | finText = finText .. "|-\n|[[" .. k[2] .. "]]" |
2022年8月26日 (五) 20:46的版本
可在Module:ChartConstantDetail/doc创建此模块的帮助文档
local p = {}
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' })
-- local specialSongNameConverter = {}
-- specialSongNameConverter["#1f1e33"] ="#1f1e33"
-- specialSongNameConverter["AI[UE]OON"] ="AI[UE]OON"
-- specialSongNameConverter["Last | Eternity"]="Last"
-- local specialSongNameDisplayConverter = {}
-- specialSongNameDisplayConverter["Last | Eternity"]="Last \| Eternity"
local function constantFormat (a)
if not(a) then
return "<span class=\"old-constant\"> - </span>"
end
if a["old"] == true then
return "<span class=\"old-constant\">" .. string.format("%.1f", a["constant"]) .. "</span>"
else
return string.format("%.1f", a["constant"])
end
end
function p.main()
local finText =
[[{| class="wikitable sortable" style="text-align:center"
|-
! style="position:-webkit-sticky;position:sticky;top:0px;" |曲目
! style="color:#1082be;position:-webkit-sticky;position:sticky;top:0px;" |PST
! style="color:#648c3c;position:-webkit-sticky;position:sticky;top:0px;" |PRS
! style="color:#50194b;position:-webkit-sticky;position:sticky;top:0px;" |FTR
! style="color:#ff0000;position:-webkit-sticky;position:sticky;top:0px;" |BYD
]]
local constantList = {}
for i, k in pairs(chartConstantList) do
local realName = ""
for n, m in pairs(songlist["songs"]) do
if m["id"] == i then
realName = m["title_localized"]["en"]
break
end
end
table.insert(constantList, {k, realName})
end
table.sort(constantList, function (a, b)
if (not a[1][3]) or (not b[1][3]) then
return a[2] > b[2] -- 暂时补洞,解决方案再讨论
end
return a[1][3]["constant"]>b[1][3]["constant"] end)
for i, k in pairs(constantList) do
if trans["songNameToDisplayName"][k[2]] then
-- if specialSongNameDisplayConverter[k[2]] then
-- finText = finText .. "|-\n|[[" .. specialSongNameConverter[k[2]]
-- .. "|" .. specialSongNameDisplayConverter[k[2]] .. "]]"
-- else
finText = finText .. "|-\n|[[" .. trans["songNameToDisplayName"][k[2]]
.. "|" .. k[2] .. "]]"
-- end
else
finText = finText .. "|-\n|[[" .. k[2] .. "]]"
end
finText = finText .."||"
.. constantFormat(k[1][1]) .. "||"
.. constantFormat(k[1][2]) .. "||"
.. constantFormat(k[1][3]) .. "||"
if k[1][4] then
finText = finText .. constantFormat(k[1][4])
end
finText = finText .. "\n"
end
finText = finText .. "|}"
return finText
end
return p