Module:沙盒/Economy666/SongCollectionMulti:修订间差异
Economy666(讨论 | 贡献) 无编辑摘要 |
Economy666(讨论 | 贡献) 小 (i) |
||
第129行: | 第129行: | ||
local artist_list = cal[string.gsub(song.artist, ' ' , '')] | local artist_list = cal[string.gsub(song.artist, ' ' , '')] | ||
if artist_list then | if artist_list then | ||
for _, data in | for _, data in ipairs(artist_list) do | ||
local display_ja = formatJapaneseText(data.display) | local display_ja = formatJapaneseText(data.display) | ||
if data.link then | if data.link then |
2024年6月30日 (日) 02:11的版本
可在Module:沙盒/Economy666/SongCollectionMulti/doc创建此模块的帮助文档
local mad = require 'Module:AnotherData'
local lang = mw.language.getContentLanguage()
local frame = mw.getCurrentFrame()
local p = {}
local dates, versionNames = {}, {}
local function verQuery(sec)
local date = tonumber(lang:formatDate('ymd', '@' .. sec)) - 1
if date > dates[#dates] then return '@' end
local l, r = 1, #dates
while l < r do
local m = math.floor((l + r) / 2)
if dates[m] < date then
l = m + 1
else
r = m
end
end
return versionNames[l]
end
local function otherTitles(song)
local res = {}
local titleJa = song.title_localized.ja
if titleJa then table.insert(res, ('<span lang="ja">-{%s}-</span>'):format(titleJa)) end
table.insert(res, song.title_localized['zh-Hans'])
for _, diff in ipairs(song.difficulties) do
if diff.title_localized then
table.insert(res, diff.title_localized.en .. ' ' .. mad.color {
rc = diff.ratingClass,
txt = ('[%s]'):format(({[3] = 'Beyond'})[diff.ratingClass])
})
end
end
return res
end
local cal = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json' --'Template:ComplexArtistsList.json'
local trans = mw.loadJsonData 'Template:Transition.json'
local function link(l, d)
if d then
return '[[' .. l .. '|' .. d .. ']]'
else
return '[[' .. l .. ']]'
end
end
local function formatJapaneseText(text)
return mw.ustring.gsub(
text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+',
function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end
)
end
local onlyMobile = frame:expandTemplate{title = '仅', args = {'移动版', '', '图片角标'}}
local onlyNS = frame:expandTemplate{title = '仅', args = {'NS版', '', '图片角标'}}
local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local function main(args, durArgs)
local view = {}
-- local plat = 'mobile'
-- 不对song下述提及的字段存在性做检验
local diffId = {['edenwacca']='eden'}
local multi_song={}
local ns_song={}
local multi_id={}
local mobile_id={}
local ns_id={}
for _, song in ipairs(mad.listOf('songs', 'mobile')) do
mobile_id[song.id] = 1
multi_id[song.id] = 1
multi_song[song.id] = song
end
for _, song in ipairs(mad.listOf('songs', 'ns')) do
ns_id[song.id] = 1
ns_song[song.id] = song
if not multi_id[song.id] then
multi_id[song.id] = 1
multi_song[song.id] = song
end
end
for _,v in pairs(diffId) do
multi_song[v] = nil
end
for _, song in pairs(multi_song) do
local id = song.id
local packItem = mad.packQueryWrap(song.set, 'mobile')
local data = setmetatable({}, {__index = table})
local function input(...) return args[table.concat({id, ...}, '.')] end
if id ~= 'lasteternity' then
table.insert(view, {
data = data,
sort = {sectionCode[packItem['section']], packItem['numero'], song.date}
})
end
local display_plat = ''
local NSid = id
if mobile_id[id] then
display_plat = display_plat .. '[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]'
end
if ns_id[id] then
display_plat = display_plat .. '[[文件:Icon Nintendo switch.png|16px|link=曲目列表 (Nintendo Switch版)]]'
elseif diffId[id] then
display_plat = display_plat .. '[[文件:Icon Nintendo switch.png|16px|link=曲目列表 (Nintendo Switch版)]]'
NSid = diffId[id]
end
if display_plat == '' then
display_plat = '无'
end
data:insert(display_plat)
data:insert(id)
-- otherTitles
data:insert(input '标题' or table.concat({'[[' .. mad.linkTitle(song) .. ']]', unpack(otherTitles(song))}, '<br>'))
-- local artist = cal[string.gsub(song.artist, ' ' , '') ]
-- if not artist then
-- artist = formatJapaneseText(song.artist)
-- artist = '[[曲师列表#'..song.artist..'|'..artist..']]'
-- end
-- data:insert(input '音乐家' or artist)
local artist = ''
local artist_list = cal[string.gsub(song.artist, ' ' , '')]
if artist_list then
for _, data in ipairs(artist_list) do
local display_ja = formatJapaneseText(data.display)
if data.link then
artist = artist .. link('曲师列表#' .. data.link, display_ja)
else
artist = artist .. display_ja
end
end
else
artist = formatJapaneseText(song.artist)
artist = link('曲师列表#' .. song.artist, artist)
end
data:insert(input '音乐家' or artist)
local cc = 'Collaboration %- Collaboration'
local ccl = 'Collaboration#Collaboration'
local ccd = 'Collaboration'
local pack_main = string.gsub(trans.packName[song.set] or packItem['name'], cc, ccl)
local pack_md = string.gsub(pack_main, ccl, ccd)
if mobile_id[id] and ns_id[NSid] then
local song_ns = ns_song[NSid]
packItem_ns = mad.packQueryWrap(song_ns.set, 'ns')
local pack_ns = string.gsub(trans.packName[ns_song[NSid].set] or packItem_ns['name'], cc, ccl)
local pack_nd = string.gsub(pack_ns, ccl, ccd)
if pack_ns == pack_main then
pack = link(pack_main, pack_md)
else
pack = link(pack_main, pack_md) .. onlyMobile .. '<br \>' ..link(pack_ns, pack_nd) .. onlyNS
end
elseif mobile_id[id] then
pack = link(pack_main, pack_md) .. onlyMobile
else
pack = link(pack_main, pack_md) .. onlyNS
end
data:insert(input '所属曲包' or pack)
local bpm = tonumber(input 'BPM') or song.bpm_base
data:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
data:insert(durArgs[id] or ' @ ')
data:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
-- diffs
local main_diffi = {}
for _,diffi in pairs(song.difficulties) do
main_diffi[diffi.ratingClass] = diffi.rating .. (diffi.ratingPlus and '+' or '')
end
if mobile_id[id] and ns_id[NSid] then
local song_ns = ns_song[NSid]
local ns_diffi = {}
local c_chart = {}
for _,diffi in pairs(song_ns.difficulties) do
ns_diffi[diffi.ratingClass] = diffi.rating .. (diffi.ratingPlus and '+' or '')
if diffi.has_controller_alt_chart then
c_chart[diffi.ratingClass] = 1
end
end
for i = 0, 4 do
--main_diffi[i] = main_diffi[i] or '/'
--ns_diffi[i] = ns_diffi[i] or '/'
if main_diffi[i] and ns_diffi[i] then
if c_chart[i] then
difficulty = main_diffi[i] ..'ctrl 1<br />'.. ns_diffi[i].. 'ctrl 2'
elseif main_diffi[i] == ns_diffi[i] then
difficulty = main_diffi[i]
else
difficulty = main_diffi[i] ..'<br />'.. ns_diffi[i]
end
elseif main_diffi[i] then
difficulty = main_diffi[i] .. 'only mobile'
elseif ns_diffi[i] then
difficulty = ns_diffi[i] .. 'only NS'
else
difficulty = main_diffi[i] or '/'
end
data:insert(input('等级', i) or difficulty)
end
else
for i = 0, 4 do
difficulty = main_diffi[i] or '/'
data:insert(input('等级', i) or difficulty)
end
end
end
table.sort(view,
function(a, b)
a, b = a.sort, b.sort
for i = 1, 3 do
local d = a[i] - b[i]
if d ~= 0 then return d < 0 end
end
return false
end)
local res = {}
local template = '|-\n|%s' .. '||[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(11)
for idx, value in ipairs(view) do
res[idx] = template:format(unpack(value.data))
end
return table.concat(res, '\n')
end
function p.multi(frame)
for record in mw.text.gsplit(frame.args._ver_, '%s') do
local date, name = record:match '(%d+):(.*)'
table.insert(dates, tonumber(date))
table.insert(versionNames, name)
end
return main(frame:getParent().args, frame.args)
end
return p