Module:ChartConstant:修订间差异

(修复link错误(被anotherdata)删掉了)
(新定数)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
local frame = mw.getCurrentFrame()
local p = {}
local p = {}
 
-- ns待补充 (ns也不需要这个)
local function songMap()
local res = {}
for _, song in ipairs(mad.listOf 'songs') do res[song.id] = song end
-- ns待补充
return res
end


local function itData(datas, cc)
local function itData(datas, cc)
第20行: 第13行:
end
end
function p.main()
function p.main()
local mSong = songMap()
local datas = {}
local datas = {}
-- CD: constant data
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
for _, song in ipairs(mad.listOf 'songs') do
local song = mSong[id]
local id, titleBase, dateBase = song.id, song.title_localized.en, song.date
local songCc = songCcs[id] or {}
--
local query = mad.songQueryWrap(song)
local query = mad.songQueryWrap(song)
local title, date = query.title, song.date
local link = query.linkTitle:match '([^%|]+)'
local link = query.linkTitle
for _, chart in ipairs {}, song.difficulties, 1 do
link = link and link:match '([^%|]+)' or title
local rc = chart.ratingClass + 1
for diffIdx = 2, 4 do
local chartCc = songCc[rc]
-- 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 = (chart.title_localized or {}).en or titleBase, chart.date or dateBase
if diffIdx == 4 then
 
title = query.bydTitle or title
local rowId, sCc, rowAttr
date = query.bydDate or date
if nCc >= 11 then
end
rowId = ('%d'):format(nCc)
local rowId, diasplayCC, rowAttr
sCc = ('%.1f'):format(nCc)
if cc >= 11 then
rowId = ('%d'):format(cc)
diasplayCC = ('%.1f'):format(cc)
rowAttr = {['高度'] = '154px'}
rowAttr = {['高度'] = '154px'}
else
else
rowId = ('%.1f'):format(cc)
rowId = ('%.1f'):format(nCc)
end
end
local rowData = datas[rowId]
local rowData = datas[rowId]
第54行: 第45行:
end
end
table.insert(rowData, {
table.insert(rowData, {
data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC},
data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
sort = {cc, diffIdx, date}
sort = {nCc, rc, date}
})
})
until (true)
until (true)
第61行: 第52行:
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
第82行: 第74行:
end
end


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


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)))