Module:ChartConstantSingle:修订间差异
DrLee lihr(讨论 | 贡献) (创建页面,内容为“local p = {} local chartConstantList = require("Module:LoadJson").ChartConstant() local songlist = require("Module:LoadJson").Songlist() function p.main(songName) local m = {} for i, k in pairs(songlist["songs"]) do if k["name"] == songName then m = chartConstantList[k["id"]] end end local function constantFormat (a) if not(a) then return "<span style=\"old-constant\"> - </span>" end…”) |
DrLee lihr(讨论 | 贡献) 小 (fix) |
||
(未显示同一用户的5个中间版本) | |||
第2行: | 第2行: | ||
local chartConstantList = require("Module:LoadJson").ChartConstant() | local chartConstantList = require("Module:LoadJson").ChartConstant() | ||
local songlist = require("Module:LoadJson").Songlist() | local songlist = require("Module:LoadJson").Songlist() | ||
local getArgs = require('Module:Arguments').getArgs | |||
function p.main(songName | |||
local m | 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 | for i, k in pairs(songlist["songs"]) do | ||
if k[" | 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 | ||
return "<span style=\" | return "<span style=\"font-weight:lighter; color:silver; font-style:italic;\"> - </span>" | ||
end | end | ||
if a["old"] == true then | if a["old"] == true then | ||
return "<span style=\" | return "<span style=\"font-weight:lighter; color:silver; font-style:italic;\">" .. string.format("%.1f", a["constant"]) .. "</span>" | ||
else | else | ||
return string.format("%.1f", a["constant"]) | return string.format("%.1f", a["constant"]) | ||
end | end | ||
end | end | ||
local | local arguments = { | ||
constantFormat(m[1]), | PST = constantFormat(m[1]), | ||
constantFormat(m[2]), | PRS = constantFormat(m[2]), | ||
constantFormat(m[3]), | FTR = constantFormat(m[3]), | ||
} | } | ||
if m[4] then | if m[4] then arguments["BYD"] = constantFormat(m[4]) end | ||
return mw.getCurrentFrame():expandTemplate { title = '曲目定数', args = | return mw.getCurrentFrame():expandTemplate { title = '曲目定数', args = arguments } | ||
end | end | ||
return p | return p |
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