Module:ChartConstant:修订间差异
小 (sb ipairs, sb lasteternity) |
小 (use new data mod) |
||
第1行: | 第1行: | ||
local mad = require 'Module:AnotherData' | |||
local frame = mw.getCurrentFrame() | |||
local p = {} | local p = {} | ||
local function | local function itData(datas, cc) | ||
local | cc = cc or 13 | ||
local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'}) | |||
cc = cc - step | |||
local id = format:format(cc) | |||
local data = datas[id] | |||
if not data then return nil end | |||
return cc, id, data | |||
end | |||
return | |||
end | end | ||
function p.main() | function p.main() | ||
local | local mSong = {} | ||
for _, song in ipairs(mad.listOf 'songs') do | |||
mSong[song.id] = song | |||
end | |||
-- ns待补充 | |||
local datas = {} | |||
local | -- CD: constant data | ||
-- | for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do | ||
for | local song = mSong[id] | ||
local | local query = mad.songQueryWrap(song) | ||
local | local title, date = query.title, song.date | ||
local link = query.linkName or title | |||
for | for diffIdx = 2, 4 do | ||
if | -- fk lua donot support continue. use single-loop & break for subst | ||
if | repeat | ||
if | local diffCD = songCD[diffIdx] or {} | ||
if diffCD.old ~= false then break end | |||
local cc = diffCD.constant | |||
if cc < 8 then break end | |||
if diffIdx == 4 then | |||
title = query.bydTitle or title | |||
date = query.bydDate or date | |||
end | |||
local rowId, diasplayCC, rowAttr | |||
if cc >= 11 then | |||
rowId = ('%d'):format(cc) | |||
diasplayCC = ('%.1f'):format(cc) | |||
rowAttr = {['高度'] = '154px'} | |||
else | |||
rowId = ('%.1f'):format(cc) | |||
end | end | ||
local rowData = datas[rowId] or {attr = rowAttr} | |||
local | datas[rowId] = rowData | ||
table.insert(rowData, { | |||
table.insert( | data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC}, | ||
sort = {cc, date} | |||
}) | }) | ||
until (true) | |||
end | end | ||
end | end | ||
local text = mw.html.create 'div':addClass 'notaninfobox dstable' | |||
local | for _, rowId, rowData in itData, datas do | ||
text = text | |||
for | :tag 'div':addClass 'ds':wikitext(rowId):done() | ||
:tag 'div':addClass 'number' | |||
table.sort( | :wikitext(frame:expandTemplate {title = '组排列', args = rowData.attr}) | ||
if a[ | table.sort(rowData, function(a, b) | ||
a, b = a.sort, b.sort | |||
if a[1] == b[1] then return a[2] < b[2] end | |||
return a[1] > b[1] | |||
end) | end) | ||
for _, rowItem in ipairs(rowData) do | |||
text:wikitext(frame:expandTemplate {title = '组排单元', args = rowItem.data}) | |||
for _, | |||
end | end | ||
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done() | |||
end | end | ||
return tostring(text) | |||
end | end | ||
return p | return p |
2024年2月24日 (六) 12:54的版本
可在Module:ChartConstant/doc创建此模块的帮助文档
local mad = require 'Module:AnotherData'
local frame = mw.getCurrentFrame()
local p = {}
local function itData(datas, cc)
cc = cc or 13
local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
cc = cc - step
local id = format:format(cc)
local data = datas[id]
if not data then return nil end
return cc, id, data
end
function p.main()
local mSong = {}
for _, song in ipairs(mad.listOf 'songs') do
mSong[song.id] = song
end
-- ns待补充
local datas = {}
-- CD: constant data
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
repeat
local diffCD = songCD[diffIdx] or {}
if diffCD.old ~= false then break end
local cc = diffCD.constant
if cc < 8 then break end
if diffIdx == 4 then
title = query.bydTitle or title
date = query.bydDate or date
end
local rowId, diasplayCC, rowAttr
if cc >= 11 then
rowId = ('%d'):format(cc)
diasplayCC = ('%.1f'):format(cc)
rowAttr = {['高度'] = '154px'}
else
rowId = ('%.1f'):format(cc)
end
local rowData = datas[rowId] or {attr = rowAttr}
datas[rowId] = rowData
table.insert(rowData, {
data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC},
sort = {cc, date}
})
until (true)
end
end
local text = mw.html.create 'div':addClass 'notaninfobox dstable'
for _, rowId, rowData in itData, datas do
text = text
:tag 'div':addClass 'ds':wikitext(rowId):done()
:tag 'div':addClass 'number'
:wikitext(frame:expandTemplate {title = '组排列', args = rowData.attr})
table.sort(rowData, function(a, b)
a, b = a.sort, b.sort
if a[1] == b[1] then return a[2] < b[2] end
return a[1] > b[1]
end)
for _, rowItem in ipairs(rowData) do
text:wikitext(frame:expandTemplate {title = '组排单元', args = rowItem.data})
end
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
end
return tostring(text)
end
return p