Module:DesignerSong:修订间差异
Economy666(讨论 | 贡献) (《合并同类项》) |
Economy666(讨论 | 贡献) (补充信息;bydAppend(lasteternity)) |
||
第15行: | 第15行: | ||
local queryNS = data.allSongInformation("id", "ns") | local queryNS = data.allSongInformation("id", "ns") | ||
local diffList = {'PST', 'PRS', 'FTR', 'BYD', 'ETR'} | local diffList = {'PST', 'PRS', 'FTR', 'BYD', 'ETR'} | ||
local bydAppend = {[284]='last'} | |||
local songDiffDesigner={} | local songDiffDesigner={} | ||
local specialDesigner ={} | local specialDesigner ={} | ||
local LinkedDesignerList={} | local LinkedDesignerList={} | ||
local bydAppendInfo={} | |||
local function readList() | local function readList() | ||
local function linkDesigner(designer, songid) | local function linkDesigner(designer, songid) | ||
第29行: | 第32行: | ||
local pickList = {} | local pickList = {} | ||
local mobileList = {} | local mobileList = {} | ||
local listMO = mad.listOf('songs', 'mobile') | |||
for index, id in pairs(bydAppend) do | |||
bydAppendInfo[id] = listMO[index].difficulties[4] | |||
bydAppendInfo[id].id=listMO[index].id | |||
end | |||
for index, song in ipairs(listMO) do | |||
local songid = song.id | |||
songDiffDesigner[songid]={} | |||
local lastDesigner=nil | local lastDesigner=nil | ||
local sameCount = 0 | local sameCount = 0 | ||
local num = 0 | local num = 0 | ||
for _,level in ipairs( | local songDiffList = song.difficulties | ||
if bydAppendInfo[songid] then table.insert(songDiffList,bydAppendInfo[songid]) end | |||
if not bydAppend[index] then | |||
for _,level in ipairs(songDiffList) do | |||
local designer = level.chartDesigner | local designer = level.chartDesigner | ||
local diff = level.ratingClass | local diff = level.ratingClass | ||
第42行: | 第57行: | ||
pickList[designer] = {} | pickList[designer] = {} | ||
end | end | ||
if not pickList[designer][ | if not pickList[designer][songid] then | ||
pickList[designer][ | pickList[designer][songid] = {} | ||
end | end | ||
pickList[designer][ | pickList[designer][songid][diffList[diff+1]]=true | ||
mobileList[ | mobileList[songid]=true | ||
table.insert(songDiffDesigner[ | table.insert(songDiffDesigner[songid], {diffList[diff+1], linkDesigner(designer, songid)}) | ||
if specialSong[ | if specialSong[songid] then | ||
specialDesigner[designer]=true | specialDesigner[designer]=true | ||
end | end | ||
lastDesigner=designer | lastDesigner=designer | ||
else | |||
sameCount=sameCount+1 | sameCount=sameCount+1 | ||
table.insert(songDiffDesigner[ | table.insert(songDiffDesigner[songid], {diffList[diff+1], nil}) | ||
songDiffDesigner[ | songDiffDesigner[songid][num-sameCount+1][3]=sameCount+1 | ||
end | end | ||
num=num+1 | |||
end | |||
end | end | ||
end | end | ||
第75行: | 第91行: | ||
-- end | -- end | ||
-- pickList[designer][song.id][diffList[diff+1]]=true | -- pickList[designer][song.id][diffList[diff+1]]=true | ||
-- table.insert(songDiffDesigner[song.id], {diffList[diff+1], linkDesigner(designer, song.id)}) | -- table.insert(songDiffDesigner[song.id].data, {diffList[diff+1], linkDesigner(designer, song.id)}) | ||
-- if specialSong[song.id] then | -- if specialSong[song.id] then | ||
-- specialDesigner[designer]=true | -- specialDesigner[designer]=true | ||
第82行: | 第98行: | ||
-- else | -- else | ||
-- sameCount=sameCount+1 | -- sameCount=sameCount+1 | ||
-- table.insert(songDiffDesigner[song.id], {diffList[diff+1], nil}) | -- table.insert(songDiffDesigner[song.id].data, {diffList[diff+1], nil}) | ||
-- songDiffDesigner[song.id][num-sameCount+1][3]=sameCount+1 | -- songDiffDesigner[song.id].data[num-sameCount+1][3]=sameCount+1 | ||
-- end | -- end | ||
-- num=num+1 | -- num=num+1 | ||
第89行: | 第105行: | ||
-- end | -- end | ||
-- end | -- end | ||
-- for appendId, id in pairs(bydAppend) do | |||
-- for _,data in ipairs(songDiffDesigner[appendId]) do | |||
-- if data[1] == 'BYD' then | |||
-- table.insert(songDiffDesigner[id].append, data) | |||
-- end | |||
-- end | |||
-- songDiffDesigner[appendId] = nil | |||
-- end | |||
return pickList | return pickList | ||
end | end | ||
第170行: | 第196行: | ||
toPrint = toPrint .. string.rep(" ", indent) .. "}" | toPrint = toPrint .. string.rep(" ", indent) .. "}" | ||
return toPrint | return toPrint | ||
end | |||
local function songTitle(id,byd) | |||
local display | |||
local title = queryMO(id, 'title') or queryNS(id, 'title') | |||
if byd then | |||
display = queryMO(id, 'bydSongName') | |||
-- 如果有新的ns独占byd曲目再使用 | |||
-- display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD' | |||
if not display then | |||
return nil | |||
end | |||
else | |||
display = title | |||
end | |||
local res = trans.songNameToDisplayName[title] | |||
if res then return res..'|'..display end | |||
res = trans.sameName[title] | |||
if res then return res[id]..'|'..display end | |||
if title then return title..'|'..display | |||
else return nil end | |||
end | |||
local function songPack(id) | |||
local packid,plat,isNS | |||
-- if queryNS(id, 'set') then | |||
-- packid = queryNS(id, 'set') | |||
-- plat = 'ns' | |||
-- isNS = 1 | |||
if queryMO(id, 'set') then | |||
packid = queryMO(id, 'set') | |||
else | |||
return nil | |||
end | |||
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name | |||
local packLink = CL.packLink(packName,1,isNS) | |||
return packLink | |||
end | |||
local frame = mw.getCurrentFrame() | |||
local function color(diff, text) | |||
return frame:expandTemplate{ title = "color", args = {diff, text} } | |||
end | end | ||
第179行: | 第247行: | ||
local function songUnit(songid,text) | local function songUnit(songid,text) | ||
if not songDiffDesigner[songid] then return '' end | |||
local data = songDiffDesigner[songid] | local data = songDiffDesigner[songid] | ||
local pack = | local name = songTitle(songid) | ||
local nameBYD = {songTitle(songid,true)} | |||
table.insert(nameBYD, bydAppendInfo[songid] and songTitle(bydAppendInfo[songid].id)) | |||
local pack = songPack(songid) | |||
local wikiText = '' | local wikiText = '' | ||
local rowspan = '|rowspan='.. #data ..'|' | local rowspanSong = nameBYD and ('|rowspan='.. #data-#nameBYD ..'|') or ('|rowspan='.. #data ..'|') | ||
wikiText = wikiText .. '|-\n'.. | local rowspan ='|rowspan='.. #data ..'|' | ||
wikiText = wikiText .. '|-\n'..rowspanSong ..'[['..name..']]'..'\n' | |||
wikiText = wikiText .. rowspan ..pack ..'\n' | wikiText = wikiText .. rowspan ..pack ..'\n' | ||
local j = 1 | |||
for num, i in ipairs(data) do | for num, i in ipairs(data) do | ||
local diffFormat = '| '..(i[1] or '') | if nameBYD[1] and i[1] == 'BYD' then | ||
wikiText = wikiText ..'|'..'[['..(nameBYD[1] or '')..']]'..'\n' | |||
-- j = j + 1 | |||
end | |||
local diffFormat = '| '..(i[1] and color(i[1], i[1]) or '') | |||
local designerFormat = i[3] and '||rowspan='.. i[3] ..'|' ..i[2] or (i[2] and '||'..i[2] or '') | local designerFormat = i[3] and '||rowspan='.. i[3] ..'|' ..i[2] or (i[2] and '||'..i[2] or '') | ||
wikiText = wikiText .. diffFormat ..designerFormat..'\n' | wikiText = wikiText .. diffFormat ..designerFormat..'\n' | ||
wikiText = wikiText .. (num == 1 and rowspan .. (text or '')..'\n' or '') | |||
wikiText = wikiText .. '|-\n' | wikiText = wikiText .. '|-\n' | ||
end | end | ||
第213行: | 第289行: | ||
-- text = text .. songUnit(i) | -- text = text .. songUnit(i) | ||
-- end | -- end | ||
-- return tableToString(songDiffDesigner) | -- return tableToString(bydAppendInfo) .. tableToString(songDiffDesigner) | ||
-- return tableToString(bydAppendInfo) | |||
-- return list1 | -- return list1 | ||
2024年7月25日 (四) 16:02的版本
可在Module:DesignerSong/doc创建此模块的帮助文档
p={}
local DL = mw.loadJsonData 'User:Economy666/DesignersList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local trans = mw.loadJsonData 'Template:Transition.json'
local mad = require 'Module:AnotherData'
local data = require "Module:Arcaea Data"
local CL = require 'Module:沙盒/Economy666/CL'
local CDL = DL.complex
local SDL = DL.simple
local specialSong = DL.special
local queryMO = data.allSongInformation("id", "mobile")
local queryNS = data.allSongInformation("id", "ns")
local diffList = {'PST', 'PRS', 'FTR', 'BYD', 'ETR'}
local bydAppend = {[284]='last'}
local songDiffDesigner={}
local specialDesigner ={}
local LinkedDesignerList={}
local bydAppendInfo={}
local function readList()
local function linkDesigner(designer, songid)
if LinkedDesignerList[designer] then return LinkedDesignerList[designer] end
local Linked = CL.designerLink(designer, songid)
LinkedDesignerList[designer] = Linked
return Linked
end
local pickList = {}
local mobileList = {}
local listMO = mad.listOf('songs', 'mobile')
for index, id in pairs(bydAppend) do
bydAppendInfo[id] = listMO[index].difficulties[4]
bydAppendInfo[id].id=listMO[index].id
end
for index, song in ipairs(listMO) do
local songid = song.id
songDiffDesigner[songid]={}
local lastDesigner=nil
local sameCount = 0
local num = 0
local songDiffList = song.difficulties
if bydAppendInfo[songid] then table.insert(songDiffList,bydAppendInfo[songid]) end
if not bydAppend[index] then
for _,level in ipairs(songDiffList) do
local designer = level.chartDesigner
local diff = level.ratingClass
if lastDesigner ~= designer then
sameCount = 0
if not pickList[designer] then
pickList[designer] = {}
end
if not pickList[designer][songid] then
pickList[designer][songid] = {}
end
pickList[designer][songid][diffList[diff+1]]=true
mobileList[songid]=true
table.insert(songDiffDesigner[songid], {diffList[diff+1], linkDesigner(designer, songid)})
if specialSong[songid] then
specialDesigner[designer]=true
end
lastDesigner=designer
else
sameCount=sameCount+1
table.insert(songDiffDesigner[songid], {diffList[diff+1], nil})
songDiffDesigner[songid][num-sameCount+1][3]=sameCount+1
end
num=num+1
end
end
end
-- for _, song in ipairs(mad.listOf('songs', 'ns')) do
-- if not mobileList[song.id] and not multiId[song.id] then
-- for _,level in ipairs(song.difficulties) do
-- local designer = level.chartDesigner
-- local diff = level.ratingClass
-- if lastDesigner ~= designer then
-- sameCount = 0
-- if not pickList[designer] then
-- pickList[designer] = {}
-- end
-- if not pickList[designer][song.id] then
-- pickList[designer][song.id] = {}
-- end
-- pickList[designer][song.id][diffList[diff+1]]=true
-- table.insert(songDiffDesigner[song.id].data, {diffList[diff+1], linkDesigner(designer, song.id)})
-- if specialSong[song.id] then
-- specialDesigner[designer]=true
-- end
-- lastDesigner=designer
-- else
-- sameCount=sameCount+1
-- table.insert(songDiffDesigner[song.id].data, {diffList[diff+1], nil})
-- songDiffDesigner[song.id].data[num-sameCount+1][3]=sameCount+1
-- end
-- num=num+1
-- end
-- end
-- end
-- for appendId, id in pairs(bydAppend) do
-- for _,data in ipairs(songDiffDesigner[appendId]) do
-- if data[1] == 'BYD' then
-- table.insert(songDiffDesigner[id].append, data)
-- end
-- end
-- songDiffDesigner[appendId] = nil
-- end
return pickList
end
local function genList(pickList)
local function cate(singleList, cArtist, artist)
local artist = artist or cArtist
if not singleList[artist] then singleList[artist] = {} end
for id,diff in pairs(pickList[cArtist]) do
singleList[artist][id]=diff
end
return singleList
end
local singleList = {}
for cDesigner,songids in pairs(pickList) do
local designerList={}
if CDL[cDesigner] then
if CDL[cDesigner].__FullData__ then
for _,text in pairs(CDL[cDesigner].__FullData__) do
if text.link then
local designer = text['link']
if not designerList[designer] then
singleList = cate(singleList, cDesigner, designer)
designerList[designer]=true
end
end
end
else
for link in pairs(CDL[cDesigner]) do
local designer = link
if not designerList[designer] then
singleList = cate(singleList, cDesigner, designer)
designerList[designer]=true
end
end
end
else
local temp_text = cDesigner
local count = 0
for _,data in ipairs(SDL) do
local designer = data.link
local dis = data.display
if string.find(temp_text, dis) then
singleList = cate(singleList, cDesigner, designer)
designerList[designer]=true
temp_text = string.gsub(temp_text, dis, '')
count = count + 1
end
end
if count == 0 then
if specialDesigner[cDesigner] then
singleList = cate(singleList, cDesigner, '与主线剧情相关的特殊名义')
else
singleList = cate(singleList, cDesigner, '其他未确认谱师名义')
end
end
end
end
return singleList
end
-- Function to convert table to string
local function tableToString(tbl, indent)
indent = indent or 0
local toPrint = string.rep(" ", indent) .. "{\n"
for k, v in pairs(tbl) do
local keyString = tostring(k)
local valueString
if type(v) == "table" then
valueString = tableToString(v, indent + 2)
else
valueString = tostring(v)
end
toPrint = toPrint .. string.rep(" ", indent + 2) .. "[" .. keyString .. "] = " .. valueString .. ",\n"
end
toPrint = toPrint .. string.rep(" ", indent) .. "}"
return toPrint
end
local function songTitle(id,byd)
local display
local title = queryMO(id, 'title') or queryNS(id, 'title')
if byd then
display = queryMO(id, 'bydSongName')
-- 如果有新的ns独占byd曲目再使用
-- display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD'
if not display then
return nil
end
else
display = title
end
local res = trans.songNameToDisplayName[title]
if res then return res..'|'..display end
res = trans.sameName[title]
if res then return res[id]..'|'..display end
if title then return title..'|'..display
else return nil end
end
local function songPack(id)
local packid,plat,isNS
-- if queryNS(id, 'set') then
-- packid = queryNS(id, 'set')
-- plat = 'ns'
-- isNS = 1
if queryMO(id, 'set') then
packid = queryMO(id, 'set')
else
return nil
end
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
local packLink = CL.packLink(packName,1,isNS)
return packLink
end
local frame = mw.getCurrentFrame()
local function color(diff, text)
return frame:expandTemplate{ title = "color", args = {diff, text} }
end
local head = '{| class="wikitable" border="1" cellspacing="1" cellpadding="5" style="text-align:center" width="100%"\n'
head = head .. '! width="20%" style="position:-webkit-sticky;position:sticky;top:0px;" |曲名 \n'
head = head .. '! width="20%" style="position:-webkit-sticky;position:sticky;top:0px;" |所属曲包 \n'
head = head .. '! colspan="2" width="40%" style="position:-webkit-sticky;position:sticky;top:0px;" |谱师名义 \n'
head = head .. '! width="20%" style="position:-webkit-sticky;position:sticky;top:0px;" |备注 \n'
local function songUnit(songid,text)
if not songDiffDesigner[songid] then return '' end
local data = songDiffDesigner[songid]
local name = songTitle(songid)
local nameBYD = {songTitle(songid,true)}
table.insert(nameBYD, bydAppendInfo[songid] and songTitle(bydAppendInfo[songid].id))
local pack = songPack(songid)
local wikiText = ''
local rowspanSong = nameBYD and ('|rowspan='.. #data-#nameBYD ..'|') or ('|rowspan='.. #data ..'|')
local rowspan ='|rowspan='.. #data ..'|'
wikiText = wikiText .. '|-\n'..rowspanSong ..'[['..name..']]'..'\n'
wikiText = wikiText .. rowspan ..pack ..'\n'
local j = 1
for num, i in ipairs(data) do
if nameBYD[1] and i[1] == 'BYD' then
wikiText = wikiText ..'|'..'[['..(nameBYD[1] or '')..']]'..'\n'
-- j = j + 1
end
local diffFormat = '| '..(i[1] and color(i[1], i[1]) or '')
local designerFormat = i[3] and '||rowspan='.. i[3] ..'|' ..i[2] or (i[2] and '||'..i[2] or '')
wikiText = wikiText .. diffFormat ..designerFormat..'\n'
wikiText = wikiText .. (num == 1 and rowspan .. (text or '')..'\n' or '')
wikiText = wikiText .. '|-\n'
end
return wikiText
end
function p.main()
pickList = readList()
singleList = genList(pickList)
local wikiText =''
for designer,songs in pairs(singleList) do
wikiText = wikiText .."'''".. designer.."'''\n"
wikiText = wikiText .. head
for songid,diff in pairs(songs) do
wikiText = wikiText .. songUnit(songid)
end
wikiText = wikiText .. '|}'
end
-- for i,ii in pairs(songDiffDesigner) do
-- text = text .. songUnit(i)
-- end
-- return tableToString(bydAppendInfo) .. tableToString(songDiffDesigner)
-- return tableToString(bydAppendInfo)
-- return list1
return wikiText
end
return p