918
次編輯
Economy666(對話 | 貢獻) 無編輯摘要 |
Economy666(對話 | 貢獻) 無編輯摘要 |
||
第2行: | 第2行: | ||
local mad = require 'Module:AnotherData' | local mad = require 'Module:AnotherData' | ||
local function | local function collectSong(packId, plat) | ||
local songList = {} | local songList = {} | ||
for _, song in ipairs(mad.listOf('songs', plat)) do | for _, song in ipairs(mad.listOf('songs', plat)) do | ||
if song.set == packId then | if song.set == packId then | ||
local ftrDiff = song.difficulties[3] or nil | local ftrDiff = song.difficulties[3] or nil | ||
local level = ftrDiff | local level = ftrDiff.rating or 0 | ||
local plus = ftrDiff | local plus = ftrDiff.ratingPlus and 1 or 0 | ||
local levelCate= level*2 + plus -- 7 -> 14 ;7+ -> 15 ... | local levelCate= level*2 + plus -- 7 -> 14 ;7+ -> 15 ... | ||
if not songList[levelCate] then songList[levelCate]={} end | if not songList[levelCate] then songList[levelCate]={} end | ||
if songList[levelCate][mad.title(song)] then | if songList[levelCate][mad.title(song)] then --如出现重名则在key后添加songid | ||
songList[levelCate][mad.title(song)..song.id] = '[[' .. mad.linkTitle(song) .. ']]' | songList[levelCate][mad.title(song)..song.id] = '[[' .. mad.linkTitle(song) .. ']]' | ||
else | else -- 未重名则 | ||
songList[levelCate][mad.title(song)] = '[[' .. mad.linkTitle(song) .. ']]' | songList[levelCate][mad.title(song)] = '[[' .. mad.linkTitle(song) .. ']]' | ||
end | end | ||
end | end | ||
end | |||
return songList | |||
end | |||
local function collectSongInfo(packId, plat) | |||
local infoList = {} | |||
local transId = mw.loadJsonData('Template:Transition.json').multiId | |||
for _, song in ipairs(mad.listOf('songs', plat)) do | |||
if song.set == packId then | |||
local ftrDiff = song.difficulties[3] or nil | |||
local level = ftrDiff.rating or 0 | |||
local plus = ftrDiff.ratingPlus and 1 or 0 | |||
local levelCate= level*2 + plus -- 7 -> 14 ;7+ -> 15 ... | |||
local id = (plat == 'ns') and transId[song.id] or song.id | |||
infoList[id] = {} | |||
infoList[id] = { | |||
['link']=mad.linkTitle(song), | |||
['name']=mad.title(song), | |||
['level']=levelCate | |||
} | |||
end | |||
end | |||
return infoList | |||
end | |||
local function collectSongList(infoList) | |||
local songList = {} | |||
local frame = mw.getCurrentFrame() | |||
local function onlyMobile(text) | |||
local om = frame:expandTemplate{title = '仅', args = {'移动版', text, '图片角标'}} | |||
return om | |||
end | |||
local function onlyNS(text) | |||
return frame:expandTemplate{title = '仅', args = {'NS版', text, '图片角标'}} | |||
end | end | ||
for id,info in pairs(infoList) do | |||
local level = info.level | |||
local link = '[[' .. info.link .. ']]' | |||
local name = info.name | |||
if not songList[level] then songList[level]={} end | |||
if info.onlyNS then link=onlyNS(link) end | |||
if info.onlyMobile then link=onlyMobile(link) end | |||
if songList[level][name] then --如出现重名则在key后添加songid | |||
songList[level][name..id] = link | |||
else -- 未重名则 | |||
songList[level][name] = link | |||
end | |||
end | |||
return songList | |||
end | |||
local function generateLine(songList) | |||
local line = '' | local line = '' | ||
for level = 14,22 do -- 7 ~ 11 | for level = 14,22 do -- 7 ~ 11 | ||
第35行: | 第85行: | ||
local function singlePlat(packId, plat) | |||
local songList = collectSong(packId, plat) | |||
-- 等同: | |||
-- local infoList = collectSongInfo(packId, plat) | |||
-- local songList = collectSongList(infoList) | |||
local line = generateLine(songList) | |||
return line | |||
end | |||
local function multiPlat(packId) | |||
-- packId: base single | |||
local transId = mw.loadJsonData 'Template:Transition.json'.multiId | |||
local infoListNS = collectSongInfo(packId, 'ns') | |||
local infoListMO = collectSongInfo(packId, 'mobile') | |||
local infoList = {} | |||
for id,info in pairs(infoListMO) do | |||
infoList[id] = info | |||
if infoListNS[id] then | |||
infoListNS[id] = nil | |||
else | |||
infoList[id]['onlyMobile'] = 1 | |||
end | |||
end | |||
for id,info in pairs(infoListNS) do | |||
infoList[id] = info | |||
infoList[id]['onlyNS'] = 1 | |||
end | |||
local songList = collectSongList(infoList) | |||
local line = generateLine(songList) | |||
return line | |||
end | |||
function p.single(frame) | function p.single(frame) | ||
if frame.args and frame.args['packId'] then | if frame.args and frame.args['packId'] then | ||
local id = frame.args['packId'] | local id = frame.args['packId'] | ||
local plat = frame.args['plat'] or 'mobile' | local plat = frame.args['plat'] or 'mobile' | ||
return | return singlePlat(id, plat) | ||
else | else | ||
return 'No args: packId input!' | return 'No args: packId input!' | ||
第46行: | 第134行: | ||
function p.multi(frame) | function p.multi(frame) | ||
return ' | if frame.args and frame.args['packId'] then | ||
local id = frame.args['packId'] | |||
return multiPlat(id) | |||
else | |||
return 'No args: packId input!' | |||
end | |||
end | end | ||
return p | return p |
次編輯