1,582
次編輯
小 (合并detail) |
小 (修[anti]bug) |
||
(未顯示同一使用者於中間所作的 8 次修訂) | |||
行 1: | 行 1: | ||
local mad = require 'Module:AnotherData' | local mad = require 'Module:AnotherData' | ||
local p = {} | local p = {} | ||
-- ns待补充(ns也不需要这个) | |||
local function itData(datas, cc) | local function itData(datas, cc) | ||
行 12: | 行 12: | ||
return cc, id, data | return cc, id, data | ||
end | end | ||
function p.main() | function p.main() | ||
local | local datas = {} | ||
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent()) | |||
for _, song in ipairs(mad.listOf 'songs') do | for _, song in ipairs(mad.listOf 'songs') do | ||
local id, titleBase, dateBase = song.id, mad.title(song), song.date | |||
local songCc = songCcs[id] or {} | |||
local link = mad.linkName(song) or titleBase | |||
for _, chart in ipairs {}, song.difficulties, 1 do | |||
local rc = chart.ratingClass + 1 | |||
local chartCc = songCc[rc] | |||
local | |||
local | |||
-- fk lua donot support continue. use single-loop & break for subst | -- fk lua donot support continue. use single-loop & break for subst | ||
repeat | repeat | ||
if not chartCc or chartCc.old ~= false then break end | |||
local nCc = chartCc.constant | |||
local | if nCc < 8 then break end | ||
if | local title, date = mad.title(chart) or titleBase, chart.date or dateBase | ||
if | |||
local rowId, sCc | |||
if nCc >= 11 then | |||
rowId = ('%d'):format(nCc) | |||
sCc = ('%.1f'):format(nCc) | |||
else | |||
rowId = ('%.1f'):format(nCc) | |||
end | end | ||
local rowId | local rowData = datas[rowId] | ||
if | if not rowData then | ||
rowData = {} | |||
datas[rowId] = rowData | |||
rowId = | |||
end | end | ||
table.insert(rowData, { | table.insert(rowData, { | ||
data = {title, | data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc}, | ||
sort = { | sort = {nCc, rc, date} | ||
}) | }) | ||
until (true) | until (true) | ||
行 56: | 行 49: | ||
end | end | ||
local frame = mw.getCurrentFrame() | |||
local text = mw.html.create 'div':addClass 'notaninfobox dstable' | local text = mw.html.create 'div':addClass 'notaninfobox dstable' | ||
for _, rowId, rowData in itData, datas do | for _, rowId, rowData in itData, datas do | ||
行 61: | 行 55: | ||
:tag 'div':addClass 'ds':wikitext(rowId):done() | :tag 'div':addClass 'ds':wikitext(rowId):done() | ||
:tag 'div':addClass 'number' | :tag 'div':addClass 'number' | ||
:wikitext(frame:expandTemplate {title = '组排列', args = | :wikitext(frame:expandTemplate {title = '组排列', args = {height = 'auto'}}) | ||
table.sort(rowData, function(a, b) | table.sort(rowData, function(a, b) | ||
a, b = a.sort, b.sort | a, b = a.sort, b.sort | ||
if a[1] == b[ | if a[1] ~= b[1] then return a[1] > b[1] end | ||
return a[ | if a[2] ~= b[2] then return a[2] > b[2] end | ||
return a[3] < b[3] | |||
end) | end) | ||
for _, rowItem in ipairs(rowData) do | for _, rowItem in ipairs(rowData) do | ||
行 76: | 行 71: | ||
end | end | ||
function p.detail() | function p.detail() | ||
local | local datas = {} | ||
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent()) | |||
for _, song in ipairs(mad.listOf 'songs') do | for _, song in ipairs(mad.listOf 'songs') do | ||
local id = song.id | |||
local songCc = songCcs[id] or {} | |||
-- | |||
local data = {mad.linkTitle(song)} | |||
local sort = {0, song.date} | |||
table.insert(datas, {data = data, sort = sort}) | |||
for _, chart in ipairs(song.difficulties) do | |||
local | local rc = chart.ratingClass + 1 | ||
local chartCc = songCc[rc] | |||
local | repeat | ||
if not chartCc then break end | |||
local nCc = chartCc.constant | |||
for i = | if not chart.date then sort[1] = nCc end | ||
local sCc = ('%.1f'):format(nCc) | |||
data[rc + 1] = chartCc.old ~= false and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc | |||
until (true) | |||
end | |||
for i = 2, 6 do | |||
data[i] = data[i] or ' ' | |||
end | end | ||
end | end | ||
行 112: | 行 104: | ||
local texts = {} | local texts = {} | ||
local template = '|-\n|[[%s]]' .. ('||%s'):rep( | local template = '|-\n|[[%s]]' .. ('||%s'):rep(5) | ||
for _, value in ipairs(datas) do | for _, value in ipairs(datas) do | ||
table.insert(texts, template:format(unpack(value.data))) | table.insert(texts, template:format(unpack(value.data))) |
次編輯