Module:SongCollection:修订间差异

来自Arcaea中文维基
(难度标签)
(fix)
 
第18行: 第18行:
end
end
return versionNames[l]
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
end


local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local langJa = '<span lang="ja">-{%s}-</span>'
local function main(plat, args, durArgs)
local function main(plat, args, durArgs)
local mid = {}
local view = {}
-- 不对song下述提及的字段存在性做检验
-- 不对song下述提及的字段存在性做检验
for _, song in ipairs(mad.listOf('songs', plat)) do
for _, song in ipairs(mad.listOf('songs', plat)) do
local id = song.id
local id = song.id
local function input(...) return args[table.concat({id, ...}, '.')] end
local function input(...) return args[table.concat({id, ...}, '.')] end
local packItem = mad.packQueryWrap(song.set, plat)
local data = setmetatable({}, {__index = table})
if id ~= 'lasteternity' then
if id ~= 'lasteternity' then
local query = mad.songQueryWrap(song)
table.insert(view, {
local packItem = mad.packQueryWrap(song.set, plat)
data = data,
local row = setmetatable({}, {__index = table})
table.insert(mid, {
data = row,
sort = {sectionCode[packItem['section']], packItem['numero'], song.date}
sort = {sectionCode[packItem['section']], packItem['numero'], song.date}
})
})
end


row:insert(id)
data:insert(id)
local title = input '标题'
-- otherTitles
if not title then
data:insert(input '标题' or table.concat({'[[' .. mad.linkTitle(song) .. ']]', unpack(otherTitles(song))}, '<br>'))
local titles = {'[[' .. query.linkTitle .. ']]'}
data:insert(input '音乐家' or mw.ustring.gsub(
local titleJa = song.title_localized.ja
song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+',
if titleJa then table.insert(titles, langJa:format(titleJa)) end
function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end
table.insert(titles, song.title_localized['zh-Hans'])
))
local titleByd = query.bydTitle
data:insert(input '所属曲包' or packItem['name'])
if titleByd then table.insert(titles, titleByd .. ' ' .. frame:expandTemplate {title = '难度标签', args = {'Beyond'}}) end
local bpm = tonumber(input 'BPM') or song.bpm_base
title = table.concat(titles, '<br />')
data:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
end
data:insert(durArgs[id] or ' @ ')
row:insert(title)
if plat ~= 'ns' then
row:insert(input '音乐家' or mw.ustring.gsub(song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', function(v) return langJa:format(v) end))
data:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
row:insert(input '所属曲包' or packItem['name'])
end
local bpm = tonumber(input 'BPM') or song.bpm_base
-- diffs
row:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
for i = 1, 4 do
row:insert(durArgs[id] or ' @ ')
diff = song.difficulties[i]
if plat ~= 'ns' then
data:insert(input('等级', i) or (diff and diff.rating .. (diff.ratingPlus and '+' or '')) or '/')
row:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
end
for _, key in ipairs {'PST', 'PRS', 'FTR', 'BYD'} do
row:insert(input('等级', key) or query[lang:lc(key) .. 'Rating'] or '/')
end
end
end
end
end
table.sort(mid, function(a, b)
table.sort(view, function(a, b)
a, b = a.sort, b.sort
a, b = a.sort, b.sort
for i = 1, 3 do
for i = 1, 3 do
第73行: 第83行:
local res = {}
local res = {}
local template = '|-\n|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
local template = '|-\n|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
for idx, value in ipairs(mid) do
for idx, value in ipairs(view) do
res[idx] = template:format(unpack(value.data))
res[idx] = template:format(unpack(value.data))
end
end

2024年3月31日 (日) 20:49的最新版本

可在Module:SongCollection/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 sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local function main(plat, args, durArgs)
	local view = {}
	-- 不对song下述提及的字段存在性做检验
	for _, song in ipairs(mad.listOf('songs', plat)) do
		local id = song.id
		local function input(...) return args[table.concat({id, ...}, '.')] end
		local packItem = mad.packQueryWrap(song.set, plat)
		local data = setmetatable({}, {__index = table})
		if id ~= 'lasteternity' then
			table.insert(view, {
				data = data,
				sort = {sectionCode[packItem['section']], packItem['numero'], song.date}
			})
		end

		data:insert(id)
		-- otherTitles
		data:insert(input '标题' or table.concat({'[[' .. mad.linkTitle(song) .. ']]', unpack(otherTitles(song))}, '<br>'))
		data:insert(input '音乐家' or mw.ustring.gsub(
			song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+',
			function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end
		))
		data:insert(input '所属曲包' or packItem['name'])
		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 ' @ ')
		if plat ~= 'ns' then
			data:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
		end
		-- diffs
		for i = 1, 4 do
			diff = song.difficulties[i]
			data:insert(input('等级', i) or (diff and diff.rating .. (diff.ratingPlus and '+' or '')) or '/')
		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|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
	for idx, value in ipairs(view) do
		res[idx] = template:format(unpack(value.data))
	end
	return table.concat(res, '\n')
end

function p.mobile(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('mobile', frame:getParent().args, frame.args)
end
function p.ns(frame) return main('ns', frame:getParent().args, frame.args) end

return p