Module:沙盒/盐棋/Sandbox:修订间差异

来自Arcaea中文维基
(曲目信息)
 
(expandTemplate)
 
(未显示同一用户的39个中间版本)
第1行: 第1行:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require 'Module:Arguments'.getArgs
local link = require('Module:Link')._link
-- local link = require 'Module:Link'._link
local getData = require("Module:data")
local mad = require 'Module:AnotherData'
local lang = mw.language.getContentLanguage()
local p = {}
local p = {}


function timeCov(t)
local bgLinkF = '[[:分类:采用%s背景的曲目|%s]]'
return os.date("(%Y/%m/%d)", t)
local bgCatF = '采用%s背景的曲目'
local function array(...) return setmetatable({...}, {__index = table}) end
local function onlySupScript(s) return mw.getCurrentFrame():expandTemplate {title = '仅', args = {s, '', '图片角标'}} end
local function vdValidation(v, d) return v and d and {v, d} end
local function labelText(text) return mw.html.create 'span':addClass 'bg-c label':wikitext(text) end
local br = mw.html.create 'br'
local function dateCov(dateBox, data, plat)
if not data then return end
local version, date = unpack(data)
dateBox:tag 'div':node(labelText(plat)):node(br):wikitext(version):node(br):wikitext('(', date, ')'):done()
end
end
local function span(len) if len > 1 then return 'gc-s' .. len end end


function dateArg(v,d,t)
-- .container
if not(v and d) then return nil end
-- .img-tab#tab-a
local box,a,b,c = mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' )
-- .img-tab-part.{cls} * n
box:addClass( "date-box" )
-- {text}
a:wikitext(t)
-- .tab-text-a.active? * n
b:wikitext(v..'<br>'..'('..tostring(d)..')')
-- {file}[画师]{jacket}
box:wikitext(tostring(a))
---@param view table<integer,table<integer,string>>
  :wikitext(tostring(b))
---@param activeIdx integer?
  :wikitext(tostring(c))
---@return table
return tostring(box)
local function createContainer(view, activeIdx)
activeIdx = activeIdx or 1
local container = mw.html.create 'div':addClass 'container'
local tab = container:tag 'div':addClass 'img-tab':attr('id', 'tab-a')
for _, v in ipairs(view) do
local text, cls = v[1], v[2] or 'normal'
tab:tag 'div':wikitext(text):addClass 'img-tab-part':addClass(cls):done()
end
for idx, v in ipairs(view) do
local file, jacket = v[3], v[4]
container
:tag 'div':addClass 'tab-text-a':addClass(idx == activeIdx and 'active' or nil)
:wikitext('[[文件:', file, '|', 256, 'px|none]]')
:node(labelText '画师')
:wikitext(jacket)
:done()
end
return container
end
end
local function getImage(args, song)
function dateData(v,d,t)
local id = song and song.id
if not(v and d) then return nil end
local argPic = args['图片'] or args['曲绘']
local box,a,b,c = mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' )
local argArtist = args['画师']
box:addClass( "date-box" )
if args['Beyond画师'] then
a:wikitext(t)
return createContainer {
b:wikitext('v'..v..'<br>'..tostring(timeCov(d)))
{'Normal', nil, argPic, argArtist},
box:wikitext(tostring(a))
{'Beyond', 'byd', args['Beyond曲绘'], args['Beyond画师']},
  :wikitext(tostring(b))
}
  :wikitext(tostring(c))
end
return tostring(box)
return mw.html.create 'div'
:wikitext('[[文件:', id and ('Songs ' .. id .. '.jpg') or argPic, '|', 256, 'px|none]]')
:node(labelText '画师')
:wikitext(argArtist)
end
end
 
local function tabCustom(args)
function bgCov(bg)
local i = 1
if bg==nil
local res = array()
then
while args['tab' .. i] do
return nil
res:insert {mw.ustring.match(args['tab' .. i], '([^/]*)/([^/]*)/([^/]*)/(.*)')}
else
i = i + 1
return '[[:分类:采用'..bg..' 背景的曲目|'..bg..']]'
end
end
return res, args['默认图片序号']
end
end
 
local function merge(charts, field)
function getImage(id,all,pst,prs,ftr,byd,second,normalJacketArgs,bydJacketArgs,normalJacketData,bydJacketData,bydyes,type)
local res = array()
local container,tab=mw.html.create('div'),mw.html.create('div')
local cur, len = charts[1][field], 1
local tab1,tab2,tab3,part1,part2,part3,jacket1,jacket2
for _, c in ipairs {}, charts, 1 do
container:addClass( 'container' )
local e = c[field]
tab:attr( 'id','tab-'..type ) tab:addClass( 'img-tab' )
if e == cur then
len = len + 1
local normalJacket,bydJacket
if normalJacketArgs
then
if bydJacketArgs
then
normalJacket,bydJacket=normalJacketArgs,bydJacketArgs
else
else
normalJacket,bydJacket=normalJacketArgs,normalJacketArgs
res:insert {cur, len}
cur = e
len = 1
end
end
end
res:insert {cur, len}
return res
end
local function getSet(sm, sns)
--% 要求名字相同
local qm, qns = mad.packQueryWrap(sm and sm.set, 'mobile'), mad.packQueryWrap(sns and sns.set, 'ns')
local namem, namens = qm.section ~= 'unknown' and qm.name or nil, qns.section ~= 'unknown' and qns.name or nil
local name = namem or namens
if not name then return nil end
local res = {name}
if namens and namens ~= name then table.insert(res, namens .. onlySupScript 'NS版') end
if #res > 1 then res[1] = res[1] .. onlySupScript '移动版' end
return table.concat(res, '<br>')
end
-- TODO:displaytitle lowercase
local function getById(list, id)
for _, k in ipairs(list) do if k.id == id then return k end end
end
local function getByTitle(list, title)
for _, k in ipairs(list) do if k.title_localized.en == title then return k end end
end
local function auto(args)
local category = {}
local function addCategory(item)
table.insert(category, '[[分类:' .. item .. ']]')
end
local notice = {}
--% "曲名"必存在,"id"必非空串
local songKey, getDatum = args['id'], getById
if not songKey then songKey, getDatum = mw.text.decode(args['曲名']), getByTitle end
local lm, lns
if args['愚人节'] then
lm, lns = mad.listOfReserve(), array()
elseif songKey == 'Last' then
lm, lns = mad.listOfReserve(), mad.listOfReserve()
else
else
if normalJacketData=="" or normalJacketData==nil
lm, lns = mad.listOf('songs', 'mobile'), mad.listOf('songs', 'ns')
then
end
normalJacket,bydJacket=' 未知',' 未知'
local sm, sns = getDatum(lm, songKey), getDatum(lns, songKey)
else
--% 可能平台不一致
normalJacket,bydJacket=link({' 画师',tostring(normalJacketData)}),link({'画师',tostring(bydJacketData)})
local set = args[' 曲包'] or getSet(sm, sns)
end
local platCode = (sm and 1 or 0) + (sns and 2 or 0)
local song = sm or sns
if not (sns and sns ~= song) then sns = {difficulties = array()} end
if not song then
notice.data = true
song = mad.listOfReserve()[1]
song.title_localized.en = songKey
end
end


if pst and prs and ftr
local box = mw.html.create 'div':addClass 'infotable'
then
local header = box:tag 'div':addClass 'header bg-c fs-l':wikitext(song.title_localized.en)
tab1,tab2,tab3,part1,part2,part3=mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div')
if song.title_localized.ja then header:node(br):node 'span':attr {lang = 'ja'}:wikitext(song.title_localized.ja) end
if song.title_localized['zh-Hans'] then header:node(br):wikitext(song.title_localized['zh-Hans']) end
box:tag 'div':addClass 'figure central':node(args['tab1'] and createContainer(tabCustom(args)) or getImage(args, song))
--% :create''
local main = box:tag 'div':addClass 'main'


tab1:wikitext('Past') tab2:wikitext('Present') tab3:wikitext('Future')
addCategory(({'移动版曲目', 'NS版曲目', ' 双平台曲目'})[platCode])
tab1:addClass('img-tab-part pst') tab2:addClass('img-tab-part prs') tab3:addClass('img-tab-part ftr') 
local sideCode = (tonumber(args[' ']) or song.side) + 1
tab:wikitext(tostring(tab1)) tab:wikitext(tostring(tab2)) tab:wikitext(tostring(tab3))
box:addClass(({'light', 'conflict', 'colorless'})[sideCode])
container:wikitext(tostring(tab))
addCategory(({'光芒侧曲目', '纷争侧曲目', '消色侧曲目'})[sideCode])
local colTags = array()
part1:wikitext('[[ 文件:'..pst..'|256px|none]]画师:'..normalJacket) part2:wikitext('[[文件:'..prs..'|256px|none]]画师:'..normalJacket)  part3:wikitext('[[文件:'..ftr..'|256px|none]]画师:'..normalJacket)
for idx, diff in ipairs(song.difficulties) do
part1:addClass('tab-text-'..type) part2:addClass('tab-text-'..type) part3:addClass('active tab-text-'..type)
colTags[idx] = diff['@tag'] or ({[0] = 'Past', 'Present', 'Future', 'Beyond', 'Eternal'})[diff.ratingClass]
container:wikitext(tostring(part1)) container:wikitext(tostring(part2)) container:wikitext(tostring(part3))
return tostring(container)
end
end
main:addClass('repeat-' .. #colTags)
if byd
then
tab1,tab2,part1,part2=mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div')


tab1:wikitext('Normal') tab2:wikitext('Beyond')
local artist = args['编曲'] or args['曲师'] or song.artist
tab1:addClass('img-tab-part normal') tab2:addClass('img-tab-part byd')
if not set then notice.pack = true end
tab:wikitext(tostring(tab1)) tab:wikitext(tostring(tab2))
-- addCategory %set曲包曲目
container:wikitext(tostring(tab))
local duration = args[' 时长']
if not duration then notice.duration = true end
part1:wikitext('[[文件:'..all..'|256px|none]]画师:'..normalJacket) part2:wikitext('[[文件:'..byd..'|256px|none]]画师:'..tostring(bydJacket)
local bpm = args['BPM'] or song.bpm
part1:addClass('active tab-text-'..type) part2:addClass('tab-text-'..type)
main:tag 'div':addClass 'gc-1 bg-c fs-m':wikitext '曲目信息'
container:wikitext(tostring(part1)) container:wikitext(tostring(part2)
for _, v in ipairs {{' 曲师', artist}, {' 曲包', set}, {' 时长', duration}, {'BPM', bpm},} do
local tag, data = unpack(v)
return tostring(container)
main:tag 'div':addClass 'bg-c central':wikitext(tag):done()
:tag 'div':addClass 'gc-2':wikitext(data)
end
end
if second
then
tab1,tab2,part1,part2=mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div')


tab1:wikitext(' 第一曲绘') tab2:wikitext('第二曲绘')
local bg = args[' 背景'] or song.bg
tab1:addClass('img-tab-part normal') tab2:addClass('img-tab-part normal')
if bg then addCategory(bgCatF:format(bg)) end
tab:wikitext(tostring(tab1)) tab:wikitext(tostring(tab2))
local vd = vdValidation(args[' 更新版本'], args[' 更新时间'])
container:wikitext(tostring(tab))
if not vd then notice.vd = true end
local vdNS
part1:wikitext('[[ 文件:'..all..'|256px|none]] 画师:'..normalJacket) part2:wikitext('[[文件:'..second..'|256px|none]]画师:'..normalJacket
if sns.id then
part1:addClass('active tab-text-'..type) part2:addClass('tab-text-'..type)
vdNS = vdValidation(args[' 更新版本NS'], args[' 更新时间NS'])
container:wikitext(tostring(part1)) container:wikitext(tostring(part2))
if not vdNS then notice.vd = true end
return tostring(container)
end
end
if id and bydyes
then
tab1,tab2,part1,part2=mw.html.create('div'),mw.html.create('div'),mw.html.create('div'),mw.html.create('div')


tab1:wikitext('Normal') tab2:wikitext('Beyond')
local charts = array()
tab1:addClass('img-tab-part normal') tab2:addClass('img-tab-part byd')
--% 假定ns难度序列是主难度序列的前缀
tab:wikitext(tostring(tab1)) tab:wikitext(tostring(tab2))
for idx, tag in ipairs(colTags) do
container:wikitext(tostring(tab))
local chart = {}
charts:insert(chart)
part1:wikitext('[[文件:Songs '..id..'.jpg|256px|none]]画师:'..normalJacket) part2:wikitext('[[文件:Songs '..id..' byd.jpg|256px|none]]画师:'..tostring(bydJacket)
local diff = song.difficulties[idx]
part1:addClass('active tab-text-'..type) part2:addClass('tab-text-'..type)
container:wikitext(tostring(part1)) container:wikitext(tostring(part2))
return tostring(container)
end
if id
then
return '<div>[[文件:Songs '..id..'.jpg|256px|none]]画师:'..normalJacket..'</div>'
end
return '<div>[[文件:'..all..'|256px|none]]画师:'..normalJacket..'</div>'
end


function merge(list)
local class = ({[0] = 'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[diff.ratingClass]
local merge
local function chartBasic(df, vd_, s)
if list[4] then merge={1,1,1,1} else merge={1,1,1} end
chart['rating' .. s] = args[tag .. '等级' .. s] or (df.rating .. (df.ratingPlus and '+' or ''))
local o
chart['note' .. s] = args[tag .. 'Note' .. s]
if list[4] then o=4 else o=3 end
chart['vdOverride' .. s] = vdValidation(args[tag .. '更新版本' .. s], args[tag .. '更新时间' .. s])
if df.date and not chart['vdOverride' .. s] then notice.vd = true end
chart['vdOverride' .. s] = chart['vdOverride' .. s] or vd_
end


if list[4] then
chartBasic(diff, vd, '')
if list[4]==list[3] then merge[3]=merge[3]+merge[4] merge[4]=0 end
if not chart.note then notice.note = true end
end


if list[3]==list[2] then merge[2]=merge[2]+merge[3] merge[3]=0 end
chart.display = ('<b class="text-%s">[%s]</b>'):format(lang:lc(class), tag)
 
addCategory(class .. chart.rating .. '级曲目')
if list[2]==list[1] then merge[1]=merge[1]+merge[2] merge[2]=0 end
chart.designer = args[tag .. 'Note编写'] or args['note编写'] or diff.chartDesigner
 
chart.bgOverride = args[tag .. '背景'] or diff.bg
for i=1,o do
if chart.bgOverride then addCategory(bgCatF:format(chart.bgOverride)) end
if merge[i]==0 then
chart.bgOverride = chart.bgOverride or bg
merge[i]='display:none'
if diff.title_localized then header:node(br):wikitext(diff.title_localized.en, ' ', chart.display) end
else
local diffNS = sns.difficulties[idx]
merge[i]='grid-column-start: span '..merge[i]..';'
if diffNS then
chartBasic(diffNS, vdNS, 'NS')
if diffNS.has_controller_alt_chart then
notice.alt = true
if not chart.noteNS then notice.note = true end
end
if chart.ratingNS and chart.ratingNS ~= chart.rating then
notice.ratingDiffer = true
end
end
end
end
end
main:tag 'div':addClass 'gc-1 bg-c fs-m':wikitext '谱面信息'
return merge
main:tag 'div':addClass 'bg-c central':wikitext '难度'
end
for _, c in ipairs(charts) do
 
main:tag 'div':addClass 'central fd-c':wikitext(c.display,
function re0()
not notice.ratingDiffer and not c.ratingNS and '仅移动版' or nil)
return nil
end
end
main:tag 'div':addClass 'bg-c central':wikitext '等级'
 
for _, c in ipairs(charts) do
function p.main(frame)
main:tag 'div':wikitext(c.rating)
local args = getArgs(frame)
end
return p._main(args)
main:tag 'div':addClass 'bg-c central':wikitext 'note数量'
end
for _, c in ipairs(charts) do
 
main:tag 'div':wikitext(c.note)
function p._main(args)
end
local category=''
main:tag 'div':addClass 'bg-c central':wikitext '谱面设计'
local data,dataNs
for _, tp in ipairs(merge(charts, 'designer')) do
local argsLength = 0
local data, len = unpack(tp)
for _,_ in pairs(args) do argsLength=argsLength+1 end
main:tag 'div':addClass(span(len)):wikitext(data)
end
if argsLength>=16
if notice.ratingDiffer then
then
main:tag 'div':addClass 'bg-c central':wikitext ' 等级NS'
data,dataNs=re0,getData.getNS(args[' 曲名'])
for _, c in ipairs(charts) do
else
main:tag 'div':wikitext(c.ratingNS)
data,dataNs=getData.getMobile(args[' 曲名']),getData.getNS(args[' 曲名'])
end
end
end
if notice.alt then
local byd
addCategory ' 多模式谱面有差异的曲目'
if args['Beyond等级'] or data('bydRating') then byd=true else byd=false end
main:tag 'div':addClass 'bg-c central':wikitext 'note 数量<br>(Joy-Con)'
for _, c in ipairs(charts) do
local getChartDesigner={
main:tag 'div':wikitext(c.noteNS)
[1]={ 'mobile' , 'PastNote编写' , 'note编写' , 'pstChartDesigner' },
[2]={ 'mobile' , 'PresentNote编写' , 'note 编写' , 'prsChartDesigner' },
[3]={ 'mobile' , 'FutureNote编写' , 'note编写' , 'ftrChartDesigner' },
[4]={ 'mobile' , 'BeyondNote编写' , 'note编写' , 'bydChartDesigner' },
[5]={ 'ns' , 'PastNote编写NS' , 'note编写NS' , 'pstChartDesigner' },
[6]={ 'ns' , 'PresentNote编写NS' , 'note编写NS' , 'prsChartDesigner' },
[7]={ 'ns' , 'FutureNote编写NS' , 'note编写NS' , 'ftrChartDesigner' }
}
local chartDesigner={}
for i,k in ipairs(getChartDesigner)
do
if args[k[2]]
then
chartDesigner[i]=args[k[2]]
else
if args[k[3]]
then
chartDesigner[i]=args[k[3]]
else
if chartDesigner[i-1] and argsLength>=16 and i~=5 and i~=6 and i~=7
then
chartDesigner[i]=chartDesigner[i-1]
else
if k[1]=='mobile'
then
chartDesigner[i]=link({ '谱师',tostring(data(k[4])) })
else
chartDesigner[i]=link({ '谱师',tostring(dataNs(k[4])) })
end
end
end
end
end
end
end
main:tag 'div':addClass 'bg-c central':wikitext '背景'
local span,spanNs
for _, tp in ipairs(merge(charts, 'bgOverride')) do
if byd then
local data, len = unpack(tp)
span=merge({ chartDesigner[1],chartDesigner[2],chartDesigner[3],chartDesigner[4] })
main:tag 'div':addClass(span(len)):wikitext(data and bgLinkF:format(data, data))
else
span=merge({ chartDesigner[1],chartDesigner[2],chartDesigner[3] })
end
end
spanNs=merge({ chartDesigner[1],chartDesigner[2],chartDesigner[3] })


if args['曲名']=='Tempestissimo' then spanNs={'grid-column-start: span 1','grid-column-start: span 1','grid-column-start: span 1','grid-column-start: span 1'}  end
local imageA=getImage(data('id'),args['图片'],args['Past曲绘'],args['Present曲绘'],args['Future曲绘'],args['Beyond曲绘'],args['第二曲绘图片'],args['画师'],args['Beyond画师'],data('ftrJacketDesigner'),data('bydJacketDesigner'),byd,'a')
local imageB=getImage(data('id'),args['图片'],args['Past曲绘'],args['Present曲绘'],args['Future曲绘'],args['Beyond曲绘'],args['第二曲绘图片'],args['画师'],args['Beyond画师'],data('ftrJacketDesigner'),data('bydJacketDesigner'),byd,'b')
local infoList={
[1]={
args['曲名'],data('title'),{ ['id']='title' }
},
[2]={
imageA,'image',{ ['id']='top-image' }
},
[3]={
imageB,'image',{ ['id']='right-image' }
},
[4]={
'曲目信息','',{ ['class']='header' }
},
[5]={
'曲师','',{ ['class']='label' }
},
[6]={
args['编曲'],link({ '曲师',tostring(data('artist')) }),{ ['class']='data' }
},
[7]={
'曲包','',{ ['class']='label' }
},
[8]={
args['曲包'],getData.pack({data('set')}),{ ['class']='data' }
},
[9]={
'时长','',{ ['class']='label' }
},
[10]={
args['时长'],'空',{ ['class']='data' }
},
[11]={
'BPM','',{ ['class']='label' }
},
[12]={
args['BPM'],data('bpm'),{ ['class']='data' }
},
[13]={
'谱面信息(双模式)','',{ ['id']='all-play-header' , ['class']='header' }
},
[14]={
'谱面信息(触控)','',{ ['id']='mobile-play-header' , ['class']='header' }
},
[15]={
'难度','',{ ['class']='label' }
},
[16]={
'[Past]','',{ ['class']='pst-label' }
},
[17]={
'[Present]','',{ ['class']='prs-label' }
},
[18]={
'[Future]','',{ ['class']='ftr-label' }
},
[19]={
'[Beyond]','',{ ['class']='byd-label' }
},
[20]={
'等级','',{ ['class']='label' }
},
[21]={
args['Past等级'],data('pstRating'),{ ['class']='pst-data' }
},
[22]={
args['Present等级'],data('prsRating'),{ ['class']='prs-data' }
},
[23]={
args['Future等级'],data('ftrRating'),{ ['class']='ftr-data' }
},
[24]={
args['Beyond等级'],data('bydRating'),{ ['class']='byd-data' }
},
[25]={
'note数量','',{ ['class']='label' }
},
[26]={
args['PastNote'],'空',{ ['class']='pst-data' }
},
[27]={
args['PresentNote'],'空',{ ['class']='prs-data' }
},
[28]={
args['FutureNote'],'空',{ ['class']='ftr-data' }
},
[29]={
args['BeyondNote'],'空',{ ['class']='byd-data' }
},
[30]={
'谱面设计','',{ ['class']='label' }
},
[31]={
chartDesigner[1],'无',{ ['class']='pst-data' },span[1]
},
[32]={
chartDesigner[2],'无',{ ['class']='prs-data' },span[2]
},
[33]={
chartDesigner[3],'无',{ ['class']='ftr-data' },span[3]
},
[34]={
chartDesigner[4],'无',{ ['class']='byd-data' },span[4]
},
[35]={
'谱面信息(Joy-Con)','',{ ['class']='header ns',['id']='ns-play-header' }
},
[36]={
'难度','',{ ['class']='label ns' }
},
[37]={
'[Past]','',{ ['class']='pst-label ns' }
},
[38]={
'[Present]','',{ ['class']='prs-label ns' }
},
[39]={
'[Future]','',{ ['class']='ftr-label ns' }
},
[40]={
'[Beyond]','',{ ['class']='byd-label ns' }
},
[41]={
'等级','',{ ['class']='label ns' }
},
[42]={
args['Past等级NS'],dataNs('pstRating'),{ ['class']='pst-data ns' }
},
[43]={
args['Present等级NS'],dataNs('prsRating'),{ ['class']='prs-data ns' }
},
[44]={
args['Future等级NS'],dataNs('ftrRating'),{ ['class']='ftr-data ns' }
},
[45]={
args['Beyond等级NS'],'无',{ ['class']='byd-data ns' }
},
[46]={
'note数量','',{ ['class']='label ns' }
},
[47]={
args['PastNoteNS'],args['PastNote'],{ ['class']='pst-data ns' }
},
[48]={
args['PresentNoteNS'],args['PresentNote'],{ ['class']='prs-data ns' }
},
[49]={
args['FutureNoteNS'],args['FutureNote'],{ ['class']='ftr-data ns' }
},
[50]={
args['BeyondNoteNS'],'无',{ ['class']='byd-data ns' }
},
[51]={
'谱面设计','',{ ['class']='label ns' }
},
[52]={
chartDesigner[5],chartDesigner[1],{ ['class']='pst-data ns' },spanNs[1]
},
[53]={
chartDesigner[6],chartDesigner[2],{ ['class']='prs-data ns' },spanNs[2]
},
[54]={
chartDesigner[7],chartDesigner[3],{ ['class']='ftr-data ns' },spanNs[3]
},
[55]={
args['BeyondNote编写NS'],'无',{ ['class']='byd-data ns' },spanNs[4]
},
[56]={
'背景','',{ ['class']='label' }
},
[57]={
bgCov(args['背景']),bgCov(data('bg')),{ ['class']='data' }
},
[58]={
'更新时间','',{ ['id']='update-data-label',['class']='label' }
},
[59]={
dateArg(args['更新版本'] , args['更新时间'] , '移动版:' ) , dateData( data('version') , tonumber(data('date')) , '移动版:' ) ,{ ['id']='mobile-date-normal',['class']='data'}
},
[60]={
dateArg(args['Beyond更新版本'] , args['Beyond更新时间'] ,''  ) ,'空',{ ['id']='mobile-date-byd',['class']='data'}
},
[61]={
dateArg(args['更新版本NS'] , args['更新时间NS'] , 'NS版:' ),dateArg('v1.0.0c' ,'2021/05/18' , 'NS版:' ),{ ['id']='ns-date-normal',['class']='data ns'}
},
[62]={
'无','',{ ['id']='ns-date-byd',['class']='data ns'}
}
}


local box = mw.html.create( 'div' )
main:tag 'div':addClass 'bg-c central':addClass(platCode == 3 and 'gr-s2' or nil):wikitext '更新时间'
box:addClass( "songbox" )
for _, tp in ipairs(merge(charts, 'vdOverride')) do
if byd then box:addClass( "byd" ) end
local data, len = unpack(tp)
if dataNs('side')==1 then box:addClass( "conflict" ) else box:addClass( "light" ) end
dateCov(main:tag 'div':addClass(span(len)), data, ' 移动 版')
if args[' 更新 本NS'] or dataNs('id') 
end
then
if platCode == 3 then
box:addClass( "ns-box" )
for _, tp in ipairs(merge(charts, 'vdOverrideNS')) do
if not( dataNs('pstChange') or dataNs('prsChange') or dataNs('ftrChange') or byd )
local data, len = unpack(tp)
then
dateCov(main:tag 'div':addClass(span(len)), data, 'NS版')
box:addClass( "ns-same" )
end
end
category=category..'[[分类:双模式曲目]]'
else
category=category..'[[分类:仅触摸模式曲目]]'
end
end
if args['Beyond更新版本'] and args['Beyond更新时间'] then box:addClass( 'mobile-byd-date' ) end
if args['曲名']=='Tempestissimo' then box:addClass( 'ns-byd-date' ) box:addClass( 'ns-date-span' )  end
if dataNs('pstChange') or dataNs('prsChange') or dataNs('ftrChange') then category=category..'[[分类:多模式谱面有差异的曲目]]' end
if args['nocat'] then category='' end


local boxList={}
local noticeText = ''
for _, v in ipairs {
for i,o in ipairs(infoList) do
{'data', '在Songlist中无法检查到此曲目。请尝试更新[[模板:Songlist]],检查页面名或填写正确的<code>曲名</code>参数。'},
boxList[i] = mw.html.create( 'div' )
{'duration', '此模板缺少<code>时长</code>参数,此参数无法自动读取。'},
boxList[i]
{'pack', '未更新Packlist。曲目信息模板无法进行曲包分类。'},
:attr( infoList[i][3] )
{'vd', '此模板的更新版本是未完整状态。请添加<code>更新版本</code>与<code>更新时间</code>参数。'},
:cssText( infoList[i][4] )
{'note', '此模板缺少某种<code>Note</code>参数,此参数无法自动读取。'},
if infoList[i][1]
} do
then
local msg, text = unpack(v)
boxList[i]:wikitext( infoList[i][1] )
if notice[msg] then noticeText = noticeText .. text end
else
end
boxList[i]:wikitext( infoList[i][2] )
if noticeText ~= '' then
end
noticeText = mw.getCurrentFrame():expandTemplate {title = 'Collapse', args = {['标题'] = '曲目信息模板提示信息', ['状态'] = '折叠',
box:wikitext(tostring(boxList[i]))
['标题文字方向'] = 'center', ['标题颜色'] = '#dddddd',
['内容颜色'] = '#eeeeee', ['内容样式'] = 'width:800px',
['style'] = 'display:table;width:200px', ['class'] = 'nomobile',
['内容'] = noticeText}}
addCategory '缺少参数的曲目信息模板'
end
end
return tostring(box) .. noticeText .. (args['nocat'] and '' or table.concat(category))
return tostring(box)..category
-- .. tostring(mw.html.create 'pre':wikitext(mw.dumpObject(charts)))
end
-- p.dateCov = dateCov
function p.main(frame)
local args = getArgs(frame)
return auto(args)
end
end


return p
return p

2024年3月13日 (三) 05:32的最新版本

可在Module:沙盒/盐棋/Sandbox/doc创建此模块的帮助文档

local getArgs = require 'Module:Arguments'.getArgs
-- local link = require 'Module:Link'._link
local mad = require 'Module:AnotherData'
local lang = mw.language.getContentLanguage()
local p = {}

local bgLinkF = '[[:分类:采用%s背景的曲目|%s]]'
local bgCatF = '采用%s背景的曲目'
local function array(...) return setmetatable({...}, {__index = table}) end
local function onlySupScript(s) return mw.getCurrentFrame():expandTemplate {title = '仅', args = {s, '', '图片角标'}} end
local function vdValidation(v, d) return v and d and {v, d} end
local function labelText(text) return mw.html.create 'span':addClass 'bg-c label':wikitext(text) end
local br = mw.html.create 'br'
local function dateCov(dateBox, data, plat)
	if not data then return end
	local version, date = unpack(data)
	dateBox:tag 'div':node(labelText(plat)):node(br):wikitext(version):node(br):wikitext('(', date, ')'):done()
end
local function span(len) if len > 1 then return 'gc-s' .. len end end

--	.container
--		.img-tab#tab-a
--			.img-tab-part.{cls} * n
--				{text}
--		.tab-text-a.active? * n
--			{file}[画师]{jacket}
---@param view table<integer,table<integer,string>>
---@param activeIdx integer?
---@return table
local function createContainer(view, activeIdx)
	activeIdx = activeIdx or 1
	local container = mw.html.create 'div':addClass 'container'
	local tab = container:tag 'div':addClass 'img-tab':attr('id', 'tab-a')
	for _, v in ipairs(view) do
		local text, cls = v[1], v[2] or 'normal'
		tab:tag 'div':wikitext(text):addClass 'img-tab-part':addClass(cls):done()
	end
	for idx, v in ipairs(view) do
		local file, jacket = v[3], v[4]
		container
			:tag 'div':addClass 'tab-text-a':addClass(idx == activeIdx and 'active' or nil)
			:wikitext('[[文件:', file, '|', 256, 'px|none]]')
			:node(labelText '画师')
			:wikitext(jacket)
			:done()
	end
	return container
end
local function getImage(args, song)
	local id = song and song.id
	local argPic = args['图片'] or args['曲绘']
	local argArtist = args['画师']
	if args['Beyond画师'] then
		return createContainer {
			{'Normal', nil, argPic, argArtist},
			{'Beyond', 'byd', args['Beyond曲绘'], args['Beyond画师']},
		}
	end
	return mw.html.create 'div'
		:wikitext('[[文件:', id and ('Songs ' .. id .. '.jpg') or argPic, '|', 256, 'px|none]]')
		:node(labelText '画师')
		:wikitext(argArtist)
end
local function tabCustom(args)
	local i = 1
	local res = array()
	while args['tab' .. i] do
		res:insert {mw.ustring.match(args['tab' .. i], '([^/]*)/([^/]*)/([^/]*)/(.*)')}
		i = i + 1
	end
	return res, args['默认图片序号']
end
local function merge(charts, field)
	local res = array()
	local cur, len = charts[1][field], 1
	for _, c in ipairs {}, charts, 1 do
		local e = c[field]
		if e == cur then
			len = len + 1
		else
			res:insert {cur, len}
			cur = e
			len = 1
		end
	end
	res:insert {cur, len}
	return res
end
local function getSet(sm, sns)
	--% 要求名字相同
	local qm, qns = mad.packQueryWrap(sm and sm.set, 'mobile'), mad.packQueryWrap(sns and sns.set, 'ns')
	local namem, namens = qm.section ~= 'unknown' and qm.name or nil, qns.section ~= 'unknown' and qns.name or nil
	local name = namem or namens
	if not name then return nil end
	local res = {name}
	if namens and namens ~= name then table.insert(res, namens .. onlySupScript 'NS版') end
	if #res > 1 then res[1] = res[1] .. onlySupScript '移动版' end
	return table.concat(res, '<br>')
end
-- TODO:displaytitle lowercase
local function getById(list, id)
	for _, k in ipairs(list) do if k.id == id then return k end end
end
local function getByTitle(list, title)
	for _, k in ipairs(list) do if k.title_localized.en == title then return k end end
end
local function auto(args)
	local category = {}
	local function addCategory(item)
		table.insert(category, '[[分类:' .. item .. ']]')
	end
	local notice = {}

	--% "曲名"必存在,"id"必非空串
	local songKey, getDatum = args['id'], getById
	if not songKey then songKey, getDatum = mw.text.decode(args['曲名']), getByTitle end
	local lm, lns
	if args['愚人节'] then
		lm, lns = mad.listOfReserve(), array()
	elseif songKey == 'Last' then
		lm, lns = mad.listOfReserve(), mad.listOfReserve()
	else
		lm, lns = mad.listOf('songs', 'mobile'), mad.listOf('songs', 'ns')
	end
	local sm, sns = getDatum(lm, songKey), getDatum(lns, songKey)
	--% 可能平台不一致
	local set = args['曲包'] or getSet(sm, sns)
	local platCode = (sm and 1 or 0) + (sns and 2 or 0)
	local song = sm or sns
	if not (sns and sns ~= song) then sns = {difficulties = array()} end
	if not song then
		notice.data = true
		song = mad.listOfReserve()[1]
		song.title_localized.en = songKey
	end

	local box = mw.html.create 'div':addClass 'infotable'
	local header = box:tag 'div':addClass 'header bg-c fs-l':wikitext(song.title_localized.en)
	if song.title_localized.ja then header:node(br):node 'span':attr {lang = 'ja'}:wikitext(song.title_localized.ja) end
	if song.title_localized['zh-Hans'] then header:node(br):wikitext(song.title_localized['zh-Hans']) end
	box:tag 'div':addClass 'figure central':node(args['tab1'] and createContainer(tabCustom(args)) or getImage(args, song))
	--% :create''
	local main = box:tag 'div':addClass 'main'

	addCategory(({'移动版曲目', 'NS版曲目', '双平台曲目'})[platCode])
	local sideCode = (tonumber(args['侧']) or song.side) + 1
	box:addClass(({'light', 'conflict', 'colorless'})[sideCode])
	addCategory(({'光芒侧曲目', '纷争侧曲目', '消色侧曲目'})[sideCode])
	local colTags = array()
	for idx, diff in ipairs(song.difficulties) do
		colTags[idx] = diff['@tag'] or ({[0] = 'Past', 'Present', 'Future', 'Beyond', 'Eternal'})[diff.ratingClass]
	end
	main:addClass('repeat-' .. #colTags)

	local artist = args['编曲'] or args['曲师'] or song.artist
	if not set then notice.pack = true end
	-- addCategory %set曲包曲目
	local duration = args['时长']
	if not duration then notice.duration = true end
	local bpm = args['BPM'] or song.bpm
	main:tag 'div':addClass 'gc-1 bg-c fs-m':wikitext '曲目信息'
	for _, v in ipairs {{'曲师', artist}, {'曲包', set}, {'时长', duration}, {'BPM', bpm},} do
		local tag, data = unpack(v)
		main:tag 'div':addClass 'bg-c central':wikitext(tag):done()
			:tag 'div':addClass 'gc-2':wikitext(data)
	end

	local bg = args['背景'] or song.bg
	if bg then addCategory(bgCatF:format(bg)) end
	local vd = vdValidation(args['更新版本'], args['更新时间'])
	if not vd then notice.vd = true end
	local vdNS
	if sns.id then
		vdNS = vdValidation(args['更新版本NS'], args['更新时间NS'])
		if not vdNS then notice.vd = true end
	end

	local charts = array()
	--% 假定ns难度序列是主难度序列的前缀
	for idx, tag in ipairs(colTags) do
		local chart = {}
		charts:insert(chart)
		local diff = song.difficulties[idx]

		local class = ({[0] = 'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[diff.ratingClass]
		local function chartBasic(df, vd_, s)
			chart['rating' .. s] = args[tag .. '等级' .. s] or (df.rating .. (df.ratingPlus and '+' or ''))
			chart['note' .. s] = args[tag .. 'Note' .. s]
			chart['vdOverride' .. s] = vdValidation(args[tag .. '更新版本' .. s], args[tag .. '更新时间' .. s])
			if df.date and not chart['vdOverride' .. s] then notice.vd = true end
			chart['vdOverride' .. s] = chart['vdOverride' .. s] or vd_
		end

		chartBasic(diff, vd, '')
		if not chart.note then notice.note = true end

		chart.display = ('<b class="text-%s">[%s]</b>'):format(lang:lc(class), tag)
		addCategory(class .. chart.rating .. '级曲目')
		chart.designer = args[tag .. 'Note编写'] or args['note编写'] or diff.chartDesigner
		chart.bgOverride = args[tag .. '背景'] or diff.bg
		if chart.bgOverride then addCategory(bgCatF:format(chart.bgOverride)) end
		chart.bgOverride = chart.bgOverride or bg
		if diff.title_localized then header:node(br):wikitext(diff.title_localized.en, ' ', chart.display) end
		local diffNS = sns.difficulties[idx]
		if diffNS then
			chartBasic(diffNS, vdNS, 'NS')
			if diffNS.has_controller_alt_chart then
				notice.alt = true
				if not chart.noteNS then notice.note = true end
			end
			if chart.ratingNS and chart.ratingNS ~= chart.rating then
				notice.ratingDiffer = true
			end
		end
	end
	main:tag 'div':addClass 'gc-1 bg-c fs-m':wikitext '谱面信息'
	main:tag 'div':addClass 'bg-c central':wikitext '难度'
	for _, c in ipairs(charts) do
		main:tag 'div':addClass 'central fd-c':wikitext(c.display,
			not notice.ratingDiffer and not c.ratingNS and '仅移动版' or nil)
	end
	main:tag 'div':addClass 'bg-c central':wikitext '等级'
	for _, c in ipairs(charts) do
		main:tag 'div':wikitext(c.rating)
	end
	main:tag 'div':addClass 'bg-c central':wikitext 'note数量'
	for _, c in ipairs(charts) do
		main:tag 'div':wikitext(c.note)
	end
	main:tag 'div':addClass 'bg-c central':wikitext '谱面设计'
	for _, tp in ipairs(merge(charts, 'designer')) do
		local data, len = unpack(tp)
		main:tag 'div':addClass(span(len)):wikitext(data)
	end
	if notice.ratingDiffer then
		main:tag 'div':addClass 'bg-c central':wikitext '等级NS'
		for _, c in ipairs(charts) do
			main:tag 'div':wikitext(c.ratingNS)
		end
	end
	if notice.alt then
		addCategory '多模式谱面有差异的曲目'
		main:tag 'div':addClass 'bg-c central':wikitext 'note数量<br>(Joy-Con)'
		for _, c in ipairs(charts) do
			main:tag 'div':wikitext(c.noteNS)
		end
	end
	main:tag 'div':addClass 'bg-c central':wikitext '背景'
	for _, tp in ipairs(merge(charts, 'bgOverride')) do
		local data, len = unpack(tp)
		main:tag 'div':addClass(span(len)):wikitext(data and bgLinkF:format(data, data))
	end


	main:tag 'div':addClass 'bg-c central':addClass(platCode == 3 and 'gr-s2' or nil):wikitext '更新时间'
	for _, tp in ipairs(merge(charts, 'vdOverride')) do
		local data, len = unpack(tp)
		dateCov(main:tag 'div':addClass(span(len)), data, '移动版')
	end
	if platCode == 3 then
		for _, tp in ipairs(merge(charts, 'vdOverrideNS')) do
			local data, len = unpack(tp)
			dateCov(main:tag 'div':addClass(span(len)), data, 'NS版')
		end
	end

	local noticeText = ''
	for _, v in ipairs {
		{'data', '在Songlist中无法检查到此曲目。请尝试更新[[模板:Songlist]],检查页面名或填写正确的<code>曲名</code>参数。'},
		{'duration', '此模板缺少<code>时长</code>参数,此参数无法自动读取。'},
		{'pack', '未更新Packlist。曲目信息模板无法进行曲包分类。'},
		{'vd', '此模板的更新版本是未完整状态。请添加<code>更新版本</code>与<code>更新时间</code>参数。'},
		{'note', '此模板缺少某种<code>Note</code>参数,此参数无法自动读取。'},
	} do
		local msg, text = unpack(v)
		if notice[msg] then noticeText = noticeText .. text end
	end
	if noticeText ~= '' then
		noticeText = mw.getCurrentFrame():expandTemplate {title = 'Collapse', args = {['标题'] = '曲目信息模板提示信息', ['状态'] = '折叠',
			['标题文字方向'] = 'center', ['标题颜色'] = '#dddddd',
			['内容颜色'] = '#eeeeee', ['内容样式'] = 'width:800px',
			['style'] = 'display:table;width:200px', ['class'] = 'nomobile',
			['内容'] = noticeText}}
		addCategory '缺少参数的曲目信息模板'
	end
	return tostring(box) .. noticeText .. (args['nocat'] and '' or table.concat(category))
	-- .. tostring(mw.html.create 'pre':wikitext(mw.dumpObject(charts)))
end
-- p.dateCov = dateCov
function p.main(frame)
	local args = getArgs(frame)
	return auto(args)
end

return p