Module:ChartConstantSingle:修订间差异
DrLee lihr(讨论 | 贡献) 无编辑摘要 |
DrLee lihr(讨论 | 贡献) 小 (fix) |
||
(未显示同一用户的2个中间版本) | |||
第8行: | 第8行: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local songName = args[1] | local songName = args[1] | ||
local m | local m | ||
-- 这里这个逻辑是优先进行id匹配,以区分两个 Quon —— DrLee_lihr | |||
for i, k in pairs(songlist["songs"]) do | for i, k in pairs(songlist["songs"]) do | ||
if k["title_localized"]["en"] == songName then | if k["id"] == songName then | ||
m = chartConstantList[k["id"]] | |||
break | |||
end | |||
end | |||
if not(m) then | |||
for i, k in pairs(songlist["songs"]) do | |||
if k["title_localized"]["en"] == songName then | |||
m = chartConstantList[k["id"]] | |||
break | |||
end | |||
end | end | ||
end | end | ||
if not m then | |||
error("song not found") | |||
end | |||
local function constantFormat (a) | local function constantFormat (a) | ||
if not(a) then | if not(a) then |
2022年7月21日 (四) 22:46的最新版本
可在Module:ChartConstantSingle/doc创建此模块的帮助文档
local p = {}
local chartConstantList = require("Module:LoadJson").ChartConstant()
local songlist = require("Module:LoadJson").Songlist()
local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame)
local songName = args[1]
local m
-- 这里这个逻辑是优先进行id匹配,以区分两个 Quon —— DrLee_lihr
for i, k in pairs(songlist["songs"]) do
if k["id"] == songName then
m = chartConstantList[k["id"]]
break
end
end
if not(m) then
for i, k in pairs(songlist["songs"]) do
if k["title_localized"]["en"] == songName then
m = chartConstantList[k["id"]]
break
end
end
end
if not m then
error("song not found")
end
local function constantFormat (a)
if not(a) then
return "<span style=\"font-weight:lighter; color:silver; font-style:italic;\"> - </span>"
end
if a["old"] == true then
return "<span style=\"font-weight:lighter; color:silver; font-style:italic;\">" .. string.format("%.1f", a["constant"]) .. "</span>"
else
return string.format("%.1f", a["constant"])
end
end
local arguments = {
PST = constantFormat(m[1]),
PRS = constantFormat(m[2]),
FTR = constantFormat(m[3]),
}
if m[4] then arguments["BYD"] = constantFormat(m[4]) end
return mw.getCurrentFrame():expandTemplate { title = '曲目定数', args = arguments }
end
return p