Site Notice

hello, world

Module:SongsInAnime

From Project-EPB Commons
Revision as of 01:12, 11 April 2020 by 机智的小鱼君 (talk | contribs) ([InPageEdit] 没有编辑摘要)

Edit Module:SongsInAnime/doc

注意:没有动画剧集使用音乐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]
    if util.hasValue(thisEp, song) then
      table.insert(episodes, thisEp)
    end
  end
  -- 没有剧集使用该音乐
  if util.tableLength(episodes) < 1 then
    return '注意:没有动画剧集使用音乐[[' .. song .. ']]。'
  end
  -- 创建列表
  local text = '<ul class="songs-table animes-have-song">'
  for k, v in pairs(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