Site Notice
hello, world
Difference between revisions of "Module:SongsInAnime"
From Project-EPB Commons
([InPageEdit] 没有编辑摘要) |
|||
Line 58: | Line 58: | ||
for k, v in pairs(songsTable) do | for k, v in pairs(songsTable) do | ||
local thisEp = songsTable[k] | local thisEp = songsTable[k] | ||
− | if util. | + | mw.logObject(thisEp) |
− | table.insert(episodes, | + | mw.log(util.hasKey(thisEp, song)) |
+ | mw.log('--------------') | ||
+ | if util.hasKey(thisEp, song) then | ||
+ | table.insert(episodes, k) | ||
end | end | ||
end | end | ||
-- 没有剧集使用该音乐 | -- 没有剧集使用该音乐 | ||
+ | mw.logObject(episodes) | ||
+ | mw.log('======================================') | ||
if util.tableLength(episodes) < 1 then | if util.tableLength(episodes) < 1 then | ||
return '注意:没有动画剧集使用音乐[[' .. song .. ']]。' | return '注意:没有动画剧集使用音乐[[' .. song .. ']]。' | ||
Line 68: | Line 73: | ||
-- 创建列表 | -- 创建列表 | ||
local text = '<ul class="songs-table animes-have-song">' | local text = '<ul class="songs-table animes-have-song">' | ||
− | for k, v in | + | for k, v in ipairs(episodes) do |
local episode = episodes[k] | local episode = episodes[k] | ||
local time = songsTable[episode][song]['time'] | local time = songsTable[episode][song]['time'] |
Revision as of 01:33, 11 April 2020
注意:没有动画剧集使用音乐All Of You Is All Of Me。
-- Module Name: 动画音乐表
-- Author: 机智的小鱼君
-- Description:
--- 动画出现的全部音乐都可以使用这个模块查询,
--- 完善歌曲信息请前往子页面[[Module:SongsInAnime/table]]
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 '[[Module:Songs]]模块错误:未指定剧集。'
end
local songs = songsTable[episode]
-- 没有该集信息
if songs == nil then
return '注意:没有找到动画剧集[[' .. episode .. ']]!'
end
-- 没有音乐
if util.tableLength(songs) < 1 then
return '注意:动画[[' .. episode .. ']]中未找到相关音乐!'
end
-- 创建列表
local text = '<ul class="songs-table songs-in-anime">'
for k, v in pairs(songs) do
local song = k
local time = songs[k]['time'] or '未知时间'
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 '[[Module:Songs]]模块错误:未指定音乐名。'
end
-- 查询哪些剧集有该歌曲
local episodes = {}
for k, v in pairs(songsTable) do
local thisEp = songsTable[k]
mw.logObject(thisEp)
mw.log(util.hasKey(thisEp, song))
mw.log('--------------')
if util.hasKey(thisEp, song) then
table.insert(episodes, k)
end
end
-- 没有剧集使用该音乐
mw.logObject(episodes)
mw.log('======================================')
if util.tableLength(episodes) < 1 then
return '注意:没有动画剧集使用音乐[[' .. song .. ']]。'
end
-- 创建列表
local text = '<ul class="songs-table animes-have-song">'
for k, v in ipairs(episodes) do
local episode = episodes[k]
local time = songsTable[episode][song]['time']
local description = songsTable[episode][song]['description']
text =
text ..
'<li class="episode one-line"><b class="time-appear">' ..
time ..
'</b> [[' ..
episode ..
'|<span class="episode-name">' ..
episode .. '</span>]] <i class="song-description">' .. description .. '</i></li>'
end
-- 结束,返回列表
text = text .. '</ul>'
return text
end
function p.main()
return '[[Module:Songs]]模块说明:\n* 使用<code>anime</code>显示某集动画中的全部歌曲。\n* 使用<code>song</code>显示出现某歌曲的动画剧集。'
end
return p