Module:Memory Archive:修订间差异

来自Arcaea中文维基
(尝试自动按照官方分类生成曲目索引,效果不好就删掉)
 
(不再硬编码曲目索引模板的参数名)
 
(未显示2个用户的7个中间版本)
第2行: 第2行:
local songlist = mad.listOf 'songs'
local songlist = mad.listOf 'songs'
local songlistNS = mad.listOf('songs','ns')
local songlistNS = mad.listOf('songs','ns')
local dot='{{·}}'
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={}
local p={}
function p.main()
function p.main(frame)
   local dot=frame:expandTemplate {title ='·'}
local categories = {'poprec', 'partner', 'original', 'variety', 'musicgames'}
local categories = {'poprec', 'partner', 'original', 'variety', 'musicgames'}
local getCategory={}
local getCategory={}
第31行: 第20行:
local mobileId={}
local mobileId={}
for i,v in ipairs(songlistNS) do
for i,v in ipairs(songlistNS) do
if string.sub(v.set,1,6)=='single' then -- 处理 single_append_X
if v.set=='single' or mad.packQueryWrap(v.set,'ns')._parentId_=="single" then 
nsId[v.id]=1
nsId[v.id]=1
end
end
第47行: 第36行:
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
第56行: 第45行:
local categoryNames = {'流行/推荐', '搭档', '原创', '综合', '音乐游戏'}
local categoryNames = {'流行/推荐', '搭档', '原创', '综合', '音乐游戏'}
local final='{{曲目索引|曲包=[[Memory Archive]]|曲包封面=[[ 文件:Pack single.png|75px]]|name=Memory Archive曲目索引|color=#84daff'
local final={}
   for i, v in pairs(frame.args) do
     final[i]=v
   end
 
   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
 
for i=1,5 do
for i=1,5 do
local list=''
local list=''
第67行: 第71行:
if #songs[i].mobile ~= 0 then
if #songs[i].mobile ~= 0 then
if not first then list = list .. dot end
if not first then list = list .. dot end
list = list .. '{{仅| 移动版|' .. expand(songs[i].mobile) .. '}}'
list = list .. frame:expandTemplate{title = '仅',args={" 移动版",expand(songs[i].mobile)}}
first=false
first=false
end
end
if #songs[i].ns ~= 0 then
if #songs[i].ns ~= 0 then
if not first then list = list .. dot end
if not first then list = list .. dot end
list = list .. '{{仅|NS版|' .. expand(songs[i].ns) .. '}}'
list = list .. frame:expandTemplate{title = '仅',args={"NS版",expand(songs[i].ns)}}
first=false
first=false
end
end
final = final .. '|group' .. i .. '=' .. categoryNames[i]
final['group' .. i] = categoryNames[i]
final = final .. '|list' .. i .. '=' .. list
final['list' .. i] = list
end
end
return final .. '}}'
return frame:expandTemplate{title = '曲目索引',args=final}
end
end
return p
return p

2024年6月27日 (四) 14:41的最新版本

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

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

local p={}
function p.main(frame)
    local dot=frame:expandTemplate {title ='·'}
	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={}
    for i, v in pairs(frame.args) do
        final[i]=v
    end

    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

	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
		if #songs[i].mobile ~= 0 then
			if not first then list = list .. dot end
			list = list .. frame:expandTemplate{title = '仅',args={"移动版",expand(songs[i].mobile)}}
			first=false
		end
		if #songs[i].ns ~= 0 then
			if not first then list = list .. dot end
			list = list .. frame:expandTemplate{title = '仅',args={"NS版",expand(songs[i].ns)}}
			first=false
		end
		final['group' .. i] = categoryNames[i]
		final['list' .. i] = list
	end
	return frame:expandTemplate{title = '曲目索引',args=final}
end
return p