Module:Songtable

来自Arcaea中文维基
Star0讨论 | 贡献2021年5月22日 (六) 15:41的版本

可在Module:Songtable/doc创建此模块的帮助文档

local getArgs = require('Module:Arguments').getArgs
local getData = require("Module:data")
local p = {}

function timeCov(t)
	return os.date("(%Y/%m/%d)", t)
end

function dateArg(v,d,t)
	if not(v and d) then return nil end
	local box,a,b,c = mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' )
	box:addClass( "date-box" )
	a:wikitext(t)
	b:wikitext(v..'<br>'..'('..tostring(d)..')')
	box:wikitext(tostring(a))
	   :wikitext(tostring(b))
	   :wikitext(tostring(c))
	return tostring(box)
end
	
function dateData(v,d,t)
	if not(v and d) then return nil end
	local box,a,b,c = mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' ),mw.html.create( 'div' )
	box:addClass( "date-box" )
	a:wikitext(t)
	b:wikitext('v'..v..'<br>'..tostring(timeCov(d)))
	box:wikitext(tostring(a))
	   :wikitext(tostring(b))
	   :wikitext(tostring(c))
	return tostring(box)
end
	

function merge(list)
	local merge
	if list[4] then merge={1,1,1,1} else merge={1,1,1} end
	local o
	if list[4] then o=4 else o=3 end

	if list[4] then
		if list[4]==list[3] then merge[3]=merge[3]+merge[4] merge[4]=0 end
	end

	if list[3]==list[2] then merge[2]=merge[2]+merge[3] merge[3]=0 end

	if list[2]==list[1] then merge[1]=merge[1]+merge[2] merge[2]=0 end

	for i=1,o do
		if merge[i]==0 then
			merge[i]='display:none'
		else
			merge[i]='grid-column-start: span '..merge[i]..';'
		end
	end
	
	return merge
end

function re0()
	return nil
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local data,dataNs
	local argsLength = 0
	for _,_ in pairs(args) do  argsLength=argsLength+1 end
	
	if argsLength>=16
	then
		data,dataNs=re0,getData.getNS(args['曲名'])
	else
		data,dataNs=getData.getMobile(args['曲名']),getData.getNS(args['曲名'])
	end
	
	local byd
	if args['Beyond等级'] or data('bydRating') then byd=true else byd=false end
	
	local pstCd,prsCd,ftrCd,bydCd
	if args['note编写'] then
		pstCd,prsCd,ftrCd,bydCd=args['note编写'],args['note编写'],args['note编写'],args['note编写']
	else
		if args['FutureNote编写'] then
			pstCd,prsCd,ftrCd,bydCd=args['PastNote编写'],args['PresentNote编写'],args['FutureNote编写'],args['BeyondNote编写']
		else
			pstCd,prsCd,ftrCd,bydCd=data('pstChartDesigner'),data('prsChartDesigner'),data('ftrChartDesigner'),data('bydChartDesigner')
		end
	end
	
	local span
	if byd then
		span=merge({ pstCd,prsCd,ftrCd,bydCd })
	else
		span=merge({ pstCd,prsCd,ftrCd })
	end
	
	local pstCdNs,prsCdNs,ftrCdNs,bydCdNs
	if args['note编写NS'] then
		pstCdNs,prsCdNs,ftrCdNs=args['note编写'],args['note编写'],args['note编写']
	else
		if args['PastNote编写NS'] and args['PresentNote编写NS'] and args['FutureNote编写NS'] then
			pstCdNs,prsCdNs,ftrCdNs=args['PastNote编写NS'],args['PresentNote编写NS'],args['FutureNote编写NS']
		else
			pstCdNs,prsCdNs,ftrCdNs=dataNs('pstChartDesigner'),dataNs('prsChartDesigner'),dataNs('ftrChartDesigner')
		end
	end
	local spanNs=merge({ pstCdNs,prsCdNs,ftrCdNs })
	
	local infoList={
		[1]={
			args['曲名'],data('title'),{ ['id']='title' }
		},
		[2]={
			'[[文件:'..args['图片']..'|256px]]','image',{ ['id']='top-image' }
		},
		[3]={
			'[[文件:'..args['图片']..'|256px]]','image',{ ['id']='right-image' }
		},
		[4]={
			'曲目信息','',{ ['class']='header' }
		},
		[5]={
			'曲师','',{ ['class']='label' }
		},
		[6]={
			args['编曲'],data('artist'),{ ['class']='data' }
		},
		[7]={
			'曲包','',{ ['class']='label' }
		},
		[8]={
			args['曲包'],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]={
			pstCd,data('pstChartDesigner'),{ ['class']='pst-data' },span[1]
		},
		[32]={
			prsCd,data('prsChartDesigner'),{ ['class']='prs-data' },span[2]
		},
		[33]={
			ftrCd,data('ftrChartDesigner'),{ ['class']='ftr-data' },span[3]
		},
		[34]={
			bydCd,data('bydChartDesigner'),{ ['class']='byd-data' },span[4]
		},
		[35]={
			'NS版手柄 谱面信息','',{ ['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'],dataNs('bydRating'),{ ['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]={
			'无','空',{ ['class']='byd-data ns' }
		},
		[51]={
			'谱面设计','',{ ['class']='label ns' }
		},
		[52]={
			pstCdNs,dataNs('pstChartDesigner'),{ ['class']='pst-data ns' },spanNs[1]
		},
		[53]={
			prsCdNs,dataNs('prsChartDesigner'),{ ['class']='prs-data ns' },spanNs[2]
		},
		[54]={
			frtCdNs,dataNs('ftrChartDesigner'),{ ['class']='ftr-data ns' },spanNs[3]
		},
		[55]={
			'无','',{ ['class']='byd-data ns' },spanNs[4]
		},
		[56]={
			'背景','',{ ['class']='label' }
		},
		[57]={
			args['背景'],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('1.0.0c' ,'2021/5/18' , 'NS版:' ),{ ['id']='ns-date-normal',['class']='data ns'}
		},
		[62]={
			'无','',{ ['id']='ns-date-byd',['class']='data ns'}
		}
	}

	local box = mw.html.create( 'div' )
	box:addClass( "songbox" )
	if byd then box:addClass( "byd" ) end
	if data('side')==1 then box:addClass( "conflict" ) else box:addClass( "light" ) end
	if args['更新版本NS'] or dataNs('version') then 
		box:addClass( "ns-box" ) 
		if 
		args['Past等级NS'] or args['Present等级NS'] or args['Future等级NS'] or args['PastNote编写NS'] or args['PresentNote编写NS'] or args['FutureNote编写NS'] or 
		args['PastNoteNS'] or args['PresentNoteNS'] or args['FutureNoteNS'] or
		data('pstRating')~=dataNs('pstRating') or data('prsRating')~=dataNs('prsRating') or data('ftrRating')~=dataNs('ftrRating') or
		data('pstChartDesigner')~=dataNs('pstChartDesigner') or data('prsChartDesigner')~=dataNs('prsChartDesigner') or data('ftrChartDesigner')~=dataNs('ftrChartDesigner')

		then else box:addClass( "ns-same" ) end
	end
	if args['Beyond更新版本'] and args['Beyond更新时间'] then box:addClass( 'mobile-byd-date' ) end
	
	
	local boxList={}
	
	for i,o in ipairs(infoList) do
		boxList[i] = mw.html.create( 'div' )
		boxList[i]
			:attr( infoList[i][3] )
			:cssText( infoList[i][4] )
		if infoList[i][1]
		then
			boxList[i]:wikitext( infoList[i][1] )
		else
			boxList[i]:wikitext( infoList[i][2] )
		end
		box:wikitext(tostring(boxList[i]))
	end
	
	return box
end

return p