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}}