Module:Songconstant:修订间差异
(判空) |
(判空,区别自动读取名称和传入名称) |
||
第20行: | 第20行: | ||
function p._main(args) | function p._main(args) | ||
-- arg: id, name, diff | -- arg: id, name, nameAuto, diff | ||
-- id 优先于 name | -- id 优先于 name 优先于 nameAuto | ||
-- diff 是难度, 为 0~4 | -- diff 是难度, 为 0~4 | ||
-- 不存在返回空, 存在返回定数 | -- 不存在返回空, 存在返回定数 | ||
第27行: | 第27行: | ||
if args["id"] and args["id"] ~= "" then | if args["id"] and args["id"] ~= "" then | ||
id=args["id"] | id=args["id"] | ||
elseif args["name"] then | elseif args["name"] or args["nameAuto"] then | ||
local name=args["name"] | local name='' | ||
if args["name"] then | |||
name=args["name"] | |||
else | |||
name=args["nameAuto"] | |||
end | |||
if specialTransition[name] then | if specialTransition[name] then | ||
id=specialTransition[name] | id=specialTransition[name] | ||
第35行: | 第40行: | ||
end | end | ||
end | end | ||
if id=='' then | if id=='' or id==nil then | ||
return '' | return '' | ||
end | end |
2024年3月30日 (六) 02:37的版本
可在Module:Songconstant/doc创建此模块的帮助文档
local getArgs = require('Module:Arguments').getArgs
local getData = require("Module:Arcaea Data")
local constantTable = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
local specialTransition={
["Quon (DJ Noriken)"]="quonwacca",
["Quon (Feryquitous)"]="quon",
["Genesis (Iris)"]="genesis",
["Genesis (Morrigan)"]="genesischunithm",
["#1f1e33"]="ifi",
["AI[UE]OON"]="aiueoon",
["[X]"]="infinity",
}
-- 你维好像没有关于这个的 直接的 东西
local p={}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- arg: id, name, nameAuto, diff
-- id 优先于 name 优先于 nameAuto
-- diff 是难度, 为 0~4
-- 不存在返回空, 存在返回定数
local id=''
if args["id"] and args["id"] ~= "" then
id=args["id"]
elseif args["name"] or args["nameAuto"] then
local name=''
if args["name"] then
name=args["name"]
else
name=args["nameAuto"]
end
if specialTransition[name] then
id=specialTransition[name]
else
id=getData.singleSongInformation(name,"name","mobile")("id")
end
end
if id=='' or id==nil then
return ''
end
local diff=tonumber(args['diff'])
if constantTable[id][diff] then
return string.format("%.1f",constantTable[id][diff]["constant"])
end
return ""
end
return p