七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:缪斯计划/歌曲列表/行

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳转到导航 跳转到搜索
模块文档  [创建] [刷新]
local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
  local args = getArgs(frame)
  local level = args[1]
  local difficulty = p.getStars(args[2] or '0')
  local author = args[3]
  local desc = args[4]

  mw.logObject({ level, difficulty, author, desc })

  local html = mw.html.create()

  return html
    :tag('tr')
      -- level name
      :tag('th')
        :wikitext(level)
      :done()
      -- difficulty stars
      :tag('td')
        :wikitext(difficulty)
        -- for jqeury.tablesorter
        :attr('data-sort-value', tonumber(args[2]) * 10)
        :done()
      -- author name
      :tag('td')
        :wikitext(author)
      :done()
      -- description
      :tag('td')
        :wikitext(desc)
      :done()
    :done()
end

-- Returns the difficulty stars of the level
-- @example p.getStars("3.5") -> "★★★☆"
function p.getStars(raw)
  local main, sub = math.modf(tonumber(raw))
  local stars = ''
  for i = 1, main do
    stars = stars .. '★'
  end
  if sub == 0.5 then
    stars = stars .. '☆'
  end
  return stars
end

return p

-- @test
-- mw.log(p.main({'Level name', '3.5', 'Author', 'Description'}))
-- {{#invoke:Sandbox/ProjectMuseSongList|main|Level name|3.5|Author|Description}}