Module:SongCollection:修订间差异

来自Arcaea中文维基
(用于曲目列表 (移动版))
 
(抽离多变部分)
第10行: 第10行:
local function verQuery(sec)
local function verQuery(sec)
local date = tonumber(lang:formatDate('ymd', '@' .. sec)) - 1
local date = tonumber(lang:formatDate('ymd', '@' .. sec)) - 1
if date > dates[#dates] then return '?' end
if date > dates[#dates] then return '@' end
local l, r = 1, #dates
local l, r = 1, #dates
while l < r do
while l < r do
第25行: 第25行:
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 langJa = '<span lang="ja">-{%s}-</span>'
local function main(plat, args)
local function main(plat, args, durArgs)
local mid = {}
local mid = {}
-- 不对song下述提及的字段存在性做检验
-- 不对song下述提及的字段存在性做检验
第54行: 第54行:
local bpm = tonumber(input 'BPM') or song.bpm_base
local bpm = tonumber(input 'BPM') or song.bpm_base
row:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
row:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
row:insert(input '时长' or ' - ')
row:insert(durArgs[id] or ' @ ')
if plat ~= 'ns' then
if plat ~= 'ns' then
row:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
row:insert(song.version .. '.' .. (input '收录版本' or verQuery(song.date)))
第86行: 第86行:
table.insert(versionNames, name)
table.insert(versionNames, name)
end
end
return main('mobile', frame.args)
return main('mobile', frame:getParent().args, frame.args)
end
end
function p.ns(frame) return main('ns', frame.args) end
function p.ns(frame) return main('ns', frame:getParent().args, frame.args) end


return p
return p

2024年2月25日 (日) 00:54的版本

可在Module:SongCollection/doc创建此模块的帮助文档

local mad = require 'Module:AnotherData'
local lang = mw.language.getContentLanguage()
local p = {}

local function opt(format, value, default)
	return value and format:format(tostring(value)) or default
end

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 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 mid = {}
	-- 不对song下述提及的字段存在性做检验
	for _, song in ipairs(mad.listOf('songs', plat)) do
		local id = song.id
		local function input(...) return args[table.concat({id, ...}, '.')] end
		if id ~= 'lasteternity' then
			local query = mad.songQueryWrap(song)
			local packItem = mad.packQueryWrap(song.set, plat)
			local row = setmetatable({}, {__index = table})
			table.insert(mid, {
				data = row,
				sort = {sectionCode[packItem['section']], packItem['numero'], song.date}
			})

			row:insert(id)
			local title = input '标题'
			if not title then
				local titles = {'[[' .. query.linkTitle .. ']]'}
				table.insert(titles, opt(langJa, song.title_localized.ja))
				table.insert(titles, song.title_localized['zh-Hans'])
				table.insert(titles, opt('%s <span style=color:#822328>[Beyond]</span>', query.bydTitle))
				title = table.concat(titles, '<br />')
			end
			row:insert(title)
			row:insert(input '音乐家' or mw.ustring.gsub(song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', function(v) return langJa:format(v) end))
			row:insert(input '所属曲包' or packItem['name'])
			local bpm = tonumber(input 'BPM') or song.bpm_base
			row:insert((tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
			row:insert(durArgs[id] or ' @ ')
			if plat ~= 'ns' then
				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
	table.sort(mid, 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(mid) 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