Module:ChartConstant:修订间差异

添加19字节 、​ 2024年3月15日 (星期五)
修[anti]bug
(合并detail)
(修[anti]bug)
 
(未显示同一用户的8个中间版本)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
local frame = mw.getCurrentFrame()
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 mSong = {}
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
mSong[song.id] = song
local id, titleBase, dateBase = song.id, mad.title(song), song.date
end
local songCc = songCcs[id] or {}
-- ns待补充
local link = mad.linkName(song) or titleBase
 
for _, chart in ipairs {}, song.difficulties, 1 do
local datas = {}
local rc = chart.ratingClass + 1
-- CD: constant data
local chartCc = songCc[rc]
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
local song = mSong[id]
local query = mad.songQueryWrap(song)
local title, date = query.title, song.date
local link = query.linkName or title
for diffIdx = 2, 4 do
-- fk lua donot support continue. use single-loop & break for subst
-- fk lua donot support continue. use single-loop & break for subst
repeat
repeat
local diffCD = songCD[diffIdx] or {}
if not chartCc or chartCc.old ~= false then break end
if diffCD.old ~= false then break end
local nCc = chartCc.constant
local cc = diffCD.constant
if nCc < 8 then break end
if cc < 8 then break end
local title, date = mad.title(chart) or titleBase, chart.date or dateBase
if diffIdx == 4 then
 
title = query.bydTitle or title
local rowId, sCc
date = query.bydDate or date
if nCc >= 11 then
rowId = ('%d'):format(nCc)
sCc = ('%.1f'):format(nCc)
else
rowId = ('%.1f'):format(nCc)
end
end
local rowId, diasplayCC, rowAttr
local rowData = datas[rowId]
if cc >= 11 then
if not rowData then
rowId = ('%d'):format(cc)
rowData = {}
diasplayCC = ('%.1f'):format(cc)
datas[rowId] = rowData
rowAttr = {['高度'] = '154px'}
else
rowId = ('%.1f'):format(cc)
end
end
local rowData = datas[rowId] or {attr = rowAttr}
datas[rowId] = rowData
table.insert(rowData, {
table.insert(rowData, {
data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC},
data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
sort = {cc, date}
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 = rowData.attr})
: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[1] then return a[2] < b[2] end
if a[1] ~= b[1] then return a[1] > b[1] end
return a[1] > b[1]
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


local function constantFormat(a)
if not a then return ' ' end
local sCC = ('%.1f'):format(a.constant)
if a.old then
return tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCC))
else
return sCC
end
end
function p.detail()
function p.detail()
local mSong = {}
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
mSong[song.id] = song
local id = song.id
end
local songCc = songCcs[id] or {}
-- ns待补充
--
 
local data = {mad.linkTitle(song)}
local datas = {}
local sort = {0, song.date}
-- CD: constant data
table.insert(datas, {data = data, sort = sort})
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
for _, chart in ipairs(song.difficulties) do
local song = mSong[id]
local rc = chart.ratingClass + 1
local query = mad.songQueryWrap(song)
local chartCc = songCc[rc]
local data = {query.linkTitle}
repeat
local rowData = {data = data, sort = {(songCD[query.bydDate and 3 or 4] or songCD[3]).constant * 10, song.date}}
if not chartCc then break end
table.insert(datas, rowData)
local nCc = chartCc.constant
for i = 1, 4 do
if not chart.date then sort[1] = nCc end
table.insert(data, constantFormat(songCD[i]))
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(4)
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)))
1,136

个编辑