Module:Memory Archive:修订间差异

来自Arcaea中文维基
(NS版曲包判断改用_parentId_)
(另一处NS版曲包判断也改用_parentId_)
第48行: 第48行:
end
end
for i,v in ipairs(songlistNS) do
for i,v in ipairs(songlistNS) do
if string.sub(v.set,1,6)=='single' then
if v.set=='single' or mad.packQueryWrap(v.set,'ns')._parentId_=="single" then 
if not mobileId[v.id] then
if not mobileId[v.id] then
-- 硬编码 gengaozo
-- 硬编码 gengaozo

2024年6月27日 (四) 13:23的版本

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

local mad = require 'Module:AnotherData'
local songlist = mad.listOf 'songs'
local songlistNS = mad.listOf('songs','ns')

local frame = mw.getCurrentFrame()
local dot=frame:expandTemplate {title ='·'}
function expand(t)
	local res=''
	for i,v in ipairs(t) do
		if i~=1 then
			res = res .. dot
		end
		res = res .. '[[' .. mad.linkTitle(v) .. ']]'
	end
	return res
end

local p={}
function p.main()
	local categories = {'poprec', 'partner', 'original', 'variety', 'musicgames'}
	local getCategory={}
	for i=1,5 do
		getCategory[categories[i]]=i
	end
	
	local songs={}
	for i=1,5 do
		songs[i]={both={}, mobile={}, ns={}}
	end
	
	local nsId={}
	local mobileId={}
	for i,v in ipairs(songlistNS) do
		if v.set=='single' or mad.packQueryWrap(v.set,'ns')._parentId_=="single" then 
			nsId[v.id]=1
		end
	end
	for i,v in ipairs(songlist) do
		if v.set=='single' then
			mobileId[v.id]=1
			local cate=getCategory[v.category]
			if nsId[v.id] then
				songs[cate].both[#songs[cate].both+1]=v
			else
				songs[cate].mobile[#songs[cate].mobile+1]=v
			end
		end
	end
	for i,v in ipairs(songlistNS) do
		if v.set=='single' or mad.packQueryWrap(v.set,'ns')._parentId_=="single" then 
			if not mobileId[v.id] then
				-- 硬编码 gengaozo
				songs[4].ns[#songs[4].ns+1]=v
			end
		end
	end
	
	local categoryNames = {'流行/推荐', '搭档', '原创', '综合', '音乐游戏'}
	local final={
		['曲包']='[[Memory Archive]]',
		['曲包封面']='[[文件:Pack single.png|75px]]',
		name='Memory Archive曲目索引',
		color='#84daff'
	}
	for i=1,5 do
		local list=''
		local first=true
		if #songs[i].both ~= 0 then
			if not first then list = list .. dot end
			list = list .. expand(songs[i].both)
			first=false
		end
		-- 鉴于自动展开 Template:仅 会爆炸这里手动展开
		if #songs[i].mobile ~= 0 then
			if not first then list = list .. dot end
			list = list .. "<abbr title='该内容仅在移动版上。'>" .. expand(songs[i].mobile)
			.. '</abbr><sup class="noprint Template-Fact">[仅[[Arcaea (移动版)|移动版]]]</sup>'
			first=false
		end
		if #songs[i].ns ~= 0 then
			if not first then list = list .. dot end
			list = list .. "<abbr title='该内容仅在Nintendo switch版上。'>" .. expand(songs[i].ns)
			.. '</abbr><sup class="noprint Template-Fact">[仅[[Arcaea (NS版)|NS版]]]</sup>'
			first=false
		end
		final['group' .. i] = categoryNames[i]
		final['list' .. i] = list
	end
	return frame:expandTemplate{title = '曲目索引',args=final}
end
return p