Module:PackSong:修订间差异
Economy666(讨论 | 贡献) 小无编辑摘要 |
Economy666(讨论 | 贡献) 小 (Economy666移动页面Module:沙盒/Economy666/PackSong至Module:PackSong,不留重定向:done) |
||
(未显示同一用户的2个中间版本) | |||
第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 | ||
第25行: | 第75行: | ||
local a2z = {} | local a2z = {} | ||
for name in pairs(songList[level]) do table.insert(a2z,name) end | for name in pairs(songList[level]) do table.insert(a2z,name) end | ||
table.sort(a2z) | table.sort(a2z, function(a, b) return string.lower(a) < string.lower(b) end) | ||
for _,name in ipairs(a2z) do | for _,name in ipairs(a2z) do | ||
line = line .. '\n*'..songList[level][name] | line = line .. '\n*'..songList[level][name] | ||
第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 |
2024年7月2日 (二) 18:26的最新版本
可在Module:PackSong/doc创建此模块的帮助文档
local p = {}
local mad = require 'Module:AnotherData'
local function collectSong(packId, plat)
local songList = {}
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 ...
if not songList[levelCate] then songList[levelCate]={} end
if songList[levelCate][mad.title(song)] then --如出现重名则在key后添加songid
songList[levelCate][mad.title(song)..song.id] = '[[' .. mad.linkTitle(song) .. ']]'
else -- 未重名则
songList[levelCate][mad.title(song)] = '[[' .. mad.linkTitle(song) .. ']]'
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
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 = ''
for level = 14,22 do -- 7 ~ 11
if songList[level] then
local a2z = {}
for name in pairs(songList[level]) do table.insert(a2z,name) end
table.sort(a2z, function(a, b) return string.lower(a) < string.lower(b) end)
for _,name in ipairs(a2z) do
line = line .. '\n*'..songList[level][name]
end
end
end
return line
end
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)
if frame.args and frame.args['packId'] then
local id = frame.args['packId']
local plat = frame.args['plat'] or 'mobile'
return singlePlat(id, plat)
else
return 'No args: packId input!'
end
end
function p.multi(frame)
if frame.args and frame.args['packId'] then
local id = frame.args['packId']
return multiPlat(id)
else
return 'No args: packId input!'
end
end
return p