更多操作
此模块的文档可以在Module:SongsInAnime/doc创建
-- Module Name: 动画音乐表
-- Author: 机智的小鱼君
-- Description:
--- 动画出现的全部音乐都可以使用这个模块查询,
--- 完善歌曲信息请前往子页面[[Module:SongsInAnime/table]]
-- <nowiki>
local p = {}
local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local songsTable = require('Module:SongsInAnime/table')
-- 某集动画中的全部歌曲
function p.anime(frame)
local args = getArgs(frame)
local episode = args['episode'] or args[1]
-- 参数错误
if episode == nil then
return '<strong class="error">[[Module:SongsInAnime]]模块错误:未指定剧集。</strong>'
end
local songs = songsTable[episode]
-- 没有该集信息
if songs == nil then
return '<li><em>注意</em>:没有找到动画剧集[[' .. episode .. ']]!</li>'
end
-- 没有音乐
if util.tableLength(songs) < 1 then
return '<li><em>注意</em>:未在动画剧集[[' .. episode .. ']]中找到音乐数据!</li>'
end
-- 创建列表
local text =
'<i class="songs-table-description">动画《[[' .. episode .. ']]》使用了以下音乐:</i><ul class="songs-table songs-in-anime">'
for k, v in pairs(songs) do
local time = k
local endtime = songs[k]['end'] or ''
if endtime ~= '' then
time = time .. '-' .. endtime
end
local song = songs[k]['song']
local description = songs[k]['description'] or ''
text =
text ..
'<li class="song one-line"><b class="time-appear">' ..
time ..
'</b> [[' ..
song ..
'|<span class="song-name">' ..
song .. '</span>]] <i class="song-description">' .. description .. '</i></li>'
end
-- 结束,返回列表
text = text .. '</ul>'
return text
end
-- 出现某歌曲的动画剧集
function p.song(frame)
local args = getArgs(frame)
local song = args['song'] or args[1]
-- 参数错误
if song == nil then
return '<strong class="error">[[Module:SongsInAnime]]模块错误:未指定音乐名。</strong>'
end
-- 初始化表
local episodes = {}
-- 遍历剧集
for k1, v1 in pairs(songsTable) do
local thisEp = k1 -- 本次遍历的剧集名称
local thisEpTable = songsTable[k1] -- 本次遍历的剧集的表
-- 遍历时间节点
for k2, v2 in pairs(thisEpTable) do
local thisTime = k2 -- 本次遍历的时间
local thisTimeTable = thisEpTable[k2] -- 本次遍历的时间的表
local thisSong = thisTimeTable['song'] -- 本次遍历的时间的音乐名
-- 如果该时间节点的音乐名就是比对的音乐名
if thisSong == song then
-- 本集的表若不存在,先建立表
if type(episodes[thisEp]) == 'nil' then
episodes[thisEp] = {}
end
-- 将本时间节点的表插进表
episodes[thisEp][thisTime] = thisTimeTable
end
end
end
-- 没有剧集使用该音乐
if util.tableLength(episodes) < 1 then
return '<li><em>注意</em>:没有找到音乐[[' .. song .. ']]在动画剧集中的使用信息。</li>'
end
-- 创建列表
local text =
'<i class="songs-table-description">音乐《[[' .. song .. ']]》出现在以下动画剧集中:</i><ul class="songs-table animes-have-song">'
-- 遍历表
for k1, v1 in pairs(episodes) do
local episode = k1 -- 本次遍历的剧集
-- 遍历时间
for k2, v2 in pairs(episodes[episode]) do
local time = k2 -- 本次遍历的时间
local description = episodes[episode][k2]['description'] or ''
local endtime = episodes[episode][k2]['end'] or ''
if endtime ~= '' then
time = time .. '-' .. endtime
end
text =
text ..
'<li class="episode one-line">[[' ..
episode ..
'|<b class="episode-name">' ..
episode ..
'</b>]]' ..
' ' ..
'<span class="time-appear">' ..
time .. '</span> <i class="song-description">' .. description .. '</i></li>'
end
end
-- 结束,返回列表
text = text .. '</ul>'
return text
end
function p.main()
return '[[Module:SongsInAnime]]模块说明:\n' ..
'* 使用<code><nowiki>{{#invoke:SongsInAnime|anime}}</nowiki></code>显示某集动画中的全部歌曲。\n' ..
'* 使用<code><nowiki>{{#invoke:SongsInAnime|song}}</nowiki></code>显示出现某歌曲的动画剧集。'
end
return p
-- </nowiki>