Module:Songtable

Star0讨论 | 贡献2021年2月3日 (三) 21:35的版本

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

local p = {}

function Mergecheck(ta,tb,tc,td)
	--输入4个值,检查合并关系
	--输出一个带两个值的table,分别为合并后的块数和一个带有“第几块向右合并几块“的table

	local pst=tostring(ta)
	local prs=tostring(tb)
	local ftr=tostring(tc)
	local byd=tostring(td)
	local blocksnum=nil --合并后有多少块
	local mergenum={1,1,1,1} --在哪块向右合并多少
	local result={}

	local trun1,trun2,trun3,bydyes=false,false,false,false
	if (pst==prs) then trun1=true  end
	if (prs==ftr) then trun2=true  end
	if (ftr==byd) then trun3=true  end
	if (byd~=nil) then bydyes=true end
	--trun1 aaxx trun2 xaax trun3 xxaa
	--genre1:aaaa genre2:abbb genre3:aaab genre4:aabb
	--genre5:aabc genre6:abbc genre7:abcc genre8:abcd
	if bydyes then
		if trun1       and trun2        and trun3      then blocksnum=1 mergenum[1]=4    end
		if not(trun1)  and trun2       and trun3       then blocksnum=2 mergenum[2]=3   end
		if trun1       and trun2        and not(trun3) then blocksnum=2 mergenum[1]=3    end
		if trun1       and not(trun2)  and trun3       then blocksnum=2 mergenum[1]=2 mergenum[2]=2 end
		if trun1       and not(trun2)  and not(trun3)  then blocksnum=3 mergenum[1]=2   end
		if not(trun1)  and trun2       and not(trun3)  then blocksnum=3 mergenum[2]=2   end
		if not(trun1)  and not(trun2)  and trun3       then blocksnum=3 mergenum[3]=2   end
		if not(trun1)  and not(trun2)  and not(trun3) then blocksnum=4                  end
	else
		if trun1  and trun2   then blocksnum=3 mergenum[1]=3 end
		if not(trun1) and trun2   then blocksnum=2 mergenum[2]=2 end
		if trun1  and not(trun2)  then blocksnum=2 mergenum[1]=2 end
		if not(trun1) and not(trun2)  then blocksnum=3               end
	end


	result[1]=blocksnum
	result[2]=mergenum

	return result

end

function RegularText(text,byd)
	local o=1
	local Secondarybox={}
	local result=""
	for i=1,11 do
		Secondarybox[o] =mw.html.create("div")
		Secondarybox[o]
			:wikitext(text[o])
			:addClass("Sbox"..o)
		if byd==true and (o==1 or o==2) then Secondarybox[o]:cssText("grid-column: 1 / span 5;") end
		if o==3 or o==5 or o==7 or o==9 or o==11 then Secondarybox[o]:cssText("grid-column: 1 / span 1;") end
		if byd==true and (o==4 or o==6 or o==8 or o==10) then Secondarybox[o]:cssText("grid-column: 2 / span 4;") end
		if byd==false and (o==1 or o==2) then Secondarybox[o]:cssText("grid-column: 1 / span 4;") end
		if byd==false and (o==4 or o==6 or o==8 or o==10) then Secondarybox[o]:cssText("grid-column: 2 / span 3;") end
		result=result..tostring(Secondarybox[o])
		o=o+1
	end
	
	return result
end

function SplitText(text)
	local Mergecheck=Mergecheck(text[1],text[2],text[3],text[4]) --获取合成的转换信息
	local Secondarybox={}
	local result=""
	
	for i=1,3 do
	local op=1
		for i=1,4 do
			if text[op]==nil then text[op],text[op+1]=text[op+1],text[op] end
			if text[op]==text[op-1] then text[op]=text[op+1] end
			op=op+1
		end
	end
	
	local c,p,o=1,1,12
	for i=1,Mergecheck[1] do
		local mergenumber=Mergecheck[2][p]
		Secondarybox[o] =mw.html.create("div")
		Secondarybox[o]
			:wikitext(tostring(text[p]))
			:addClass("Sbox"..o)
			:cssText("grid-column: "..tostring(c+1).." / span "..mergenumber) --第几个块获取第几个块的合成信息
		result=result..tostring(Secondarybox[o])
		c=c+mergenumber
		o=o+1
		p=p+1
	end
	
	return tostring(result)
end

function EasySplitText(ain,byd)
	text=ain
	local Secondarybox={}
	local result=""
	
	if byd==true
	then
		local o,p=1,21
		for i=1,15 do
			Secondarybox[o]=mw.html.create("div")
			Secondarybox[o]
				:wikitext(tostring(text[o]))
				:addClass("Sbox"..p)
			result=result..tostring(Secondarybox[o])
			o,p=o+1,p+1
		end
	else
		local o,p=1,21
		for i=1,14 do
			if o~=5 and o~=10 
			then
				Secondarybox[o]=mw.html.create("div")
				Secondarybox[o]
					:wikitext(text[o])
					:addClass("Sbox"..p)
			result=result..tostring(Secondarybox[o])
			end
		o,p=o+1,p+1
		end
		
	end
	
	Secondarybox[16]=mw.html.create("div")
	Secondarybox[16]
		:wikitext(text[16])
		:addClass("Sbox36")
	result=result..tostring(Secondarybox[16])

	
	if byd==true 
	then 
		
		if text[18]==nil 
		then
			Secondarybox[17]=mw.html.create("div")
			Secondarybox[17]
				:wikitext(text[17])
				:addClass("Sbox37")
				:cssText("grid-column: 2 / span 4;")
			result=result..tostring(Secondarybox[17])
		else
			Secondarybox[17]=mw.html.create("div")
			Secondarybox[17]
				:wikitext(text[17])
				:addClass("Sbox37")
				:cssText("grid-column: 2 / span 3;")
			result=result..tostring(Secondarybox[17])
			
			Secondarybox[18]=mw.html.create("div")
			Secondarybox[18]
				:wikitext(text[18])
				:addClass("Sbox38")
			result=result..tostring(Secondarybox[18])
		end
	else
		Secondarybox[17]=mw.html.create("div")
		Secondarybox[17]
			:wikitext(text[17])
			:addClass("Sbox37")
			:cssText("grid-column: 2 / span 3;")
		result=result..tostring(Secondarybox[17])
	end
	
	return tostring(result)
end

function autoimage(image)
	
end

function p.box(frame)
	--主函数
	local RegularGroup={} --不会进行拆分的组
	local SplitGroup={} --会进行4等拆分的组
	local EasySplitGroup={} --会进行2等拆分的组
	
	local bydyes
	local column=""
	local byd=tonumber(frame:getParent().args["Beyond等级"])
	if byd then bydyes=true else bydyes=false end
	if bydyes==true then column="10% 22.5% 22.5% 22.5% 22.5%" else column="10% 30% 30% 30%" end
	
	local songname=frame:getParent().args["曲名"]
	
	if frame:getParent().args["第二曲名"] then songname=songname..frame:getParent().args["第二曲名"] end
	
	-- 1-11对应表 example: image class:Sbox1
	RegularGroup[1]="image"
	RegularGroup[2]=songname
	RegularGroup[3]="编曲"
	RegularGroup[4]=frame:getParent().args["编曲"]
	RegularGroup[5]="曲包"
	RegularGroup[6]=frame:getParent().args["曲包"]
	RegularGroup[7]="时长"
	RegularGroup[8]=frame:getParent().args["时长"]
	RegularGroup[9]="BPM"
	RegularGroup[10]=frame:getParent().args["BPM"]
	RegularGroup[11]="谱师"
	
	local notewrite=frame:getParent().args["Note编写"] --临时转换
	
	if notewrite~=nil then SplitGroup[1],SplitGroup[2],SplitGroup[3],SplitGroup[4]=notewrite,notewrite,notewrite,notewrite end
	--如果没有分难度谱师参数输入,直接用谱师的值
	
	-- 12-14 四谱师 如空留位
	SplitGroup[1]=frame:getParent().args["PastNote编写"] 
	SplitGroup[2]=frame:getParent().args["PresentNote编写"] 
	SplitGroup[3]=frame:getParent().args["FutureNote编写"] 
	SplitGroup[4]=frame:getParent().args["BeyondNote编写"] 
	
	--依次对应21-33
	EasySplitGroup[1]="难度"
	EasySplitGroup[2]="Past"
	EasySplitGroup[3]="Present"
	EasySplitGroup[4]="Future"
	EasySplitGroup[5]="Beyond"
	EasySplitGroup[6]="等级"
	EasySplitGroup[7]=frame:getParent().args["Past等级"]
	EasySplitGroup[8]=frame:getParent().args["Present等级"]
	EasySplitGroup[9]=frame:getParent().args["Future等级"]
	EasySplitGroup[10]=frame:getParent().args["Beyond等级"]
	EasySplitGroup[11]="物量"
	EasySplitGroup[12]=frame:getParent().args["PastNote"]
	EasySplitGroup[13]=frame:getParent().args["PresentNote"]
	EasySplitGroup[14]=frame:getParent().args["FutureNote"]
	EasySplitGroup[15]=frame:getParent().args["BeyondNote"]
	EasySplitGroup[16]="画师"
	EasySplitGroup[17]=frame:getParent().args["画师"]
	EasySplitGroup[18]=frame:getParent().args["Beyond画师"]
	EasySplitGroup[19]="更新时间"
	EasySplitGroup[20]=frame:getParent().args["更新版本"]
	EasySplitGroup[21]=frame:getParent().args["Beyond更新版本"]
	EasySplitGroup[22]=frame:getParent().args["更新时间"]
	EasySplitGroup[23]=frame:getParent().args["Beyond更新时间"]
	

	local texta,textb,textc="","",""
	texta=RegularText(RegularGroup,bydyes)
	textb=SplitText(SplitGroup)
	textc=EasySplitText(EasySplitGroup,bydyes)
	--将参数封装为table变量,输入进函数返回转换后的字符串。
	
	local endstring=texta..textb..textc
	
	local box =mw.html.create("div")
	box
		:addClass("box")
		:cssText("grid-template-columns:"..tostring(column))
		:wikitext(endstring)
	
	return tostring(box)
	
end

return p