Module:ChartConstant:修订间差异
小 (ChartConstant美化) |
小 (sb ipairs, sb lasteternity) |
||
第20行: | 第20行: | ||
local cvList = cv() | local cvList = cv() | ||
for i = 1, 3 do chartConstantList['lasteternity'][i] = { constant = 0 } end | |||
local mid_result = {} | local mid_result = {} | ||
-- song key/value : str/array(table) | -- song key/value : str/array(table) |
2022年9月14日 (三) 13:31的版本
可在Module:ChartConstant/doc创建此模块的帮助文档
local p = {}
local null = require('Module:Nullish')
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 = 'Transition.json' })
local function cv()
local list = {}
for i, k in pairs(songlist['songs']) do
list[k['id']] = {
k['title_localized']['en'], k["date"],
((k["difficulties"][4] / null)["title_localized"] / null)["en"],
(k["difficulties"][4] / null)["date"]
}
end
return list
end
function p.main()
local cvList = cv()
for i = 1, 3 do chartConstantList['lasteternity'][i] = { constant = 0 } end
local mid_result = {}
-- song key/value : str/array(table)
for skey, sval in pairs(chartConstantList) do
local name, timestamp = cvList[skey][1], cvList[skey][2]
local link = trans["songNameToDisplayName"][name] or (trans["sameName"][name] / null)[skey] or name
-- chart index/value : int1~4/{constant=float,old=bool}
for cid, cval in ipairs(sval) do
if tonumber(cval.constant) >= 8 and not cval.old then
if cid == 4 then
if cvList[skey][3] then name = cvList[skey][3] end
if cvList[skey][4] then timestamp = cvList[skey][4] end
end
-- 每排前面的数字
local rowtag = cval.constant >= 11 and math.floor(cval.constant) or cval.constant
mid_result[rowtag] = mid_result[rowtag] or {}
table.insert(mid_result[rowtag], {
skey, name, cval.constant,
({"PST", "PRS", "FTR", "BYD"})[cid], link, timestamp
})
end
end
end
-- {{组排单元|曲名|id|难度|link=页面链接|CC=定数}}
local result = {}
-- row key/value : float/array({str,str,float,str,str,time})
for rkey, rval in pairs(mid_result) do
-- 组内:时间升序(<11)、定数降序(>=11)
table.sort(rval, function(a, b)
if a[3] == b[3] then
return a[6] < b[6]
else
return a[3] > b[3]
end
end)
local units = { ds = rkey }
-- chart discription
for _, cdisc in ipairs(rval) do
table.insert(units, mw.getCurrentFrame():expandTemplate{
title = '组排单元',
args = {
cdisc[2], cdisc[1], cdisc[4], link = cdisc[5],
CC = rkey >= 11 and string.format("%.1f", cdisc[3]) or nil
}
})
end
table.insert(result, units)
end
-- 组间排序
table.sort(result, function(a, b) return a.ds > b.ds end)
-- final text
local finText = "<div class='notaninfobox dstable'>\n"
for _, units in ipairs(result) do
finText = finText .. table.concat{
"<div class='ds'>",
units.ds >= 11 and units.ds or string.format("%.1f", units.ds),
"</div>\n",
"<div class='number'>",
mw.getCurrentFrame():expandTemplate{ title = '组排列', args = units.ds >= 11 and {['高度'] = "154px"} or nil },
table.concat(units),
mw.getCurrentFrame():expandTemplate{ title = '组排列-end' },
"</div>\n"
}
end
finText = finText .. "</div>"
return finText
end
return p