Module:沙盒/盐棋/Sandbox1

来自Arcaea中文维基
< Module:沙盒
盐棋讨论 | 贡献2022年3月12日 (六) 11:51的版本 (恢复误删字母)

可在Module:沙盒/盐棋/Sandbox1/doc创建此模块的帮助文档

local p = {
	plat={""," NS"}
}

function LoadJson(filename)
    return mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = filename })
end

function QuerySong(json,index,queryById,...)
	local r
	if queryById then
		for _, v in ipairs(json["songs"]) do
        	if v['id'] == index then
        		r = v
				break
        	end
		end
	else
		for _, v in ipairs(json["songs"]) do
        	if v['title_localized']['en'] == index then
        		r = v
				break
        	end
		end
	end
	for _, v in ipairs({...}) do
		if type(v)~="function" then
			error("You Input Illegal Filter Type")
		end
		r=v(r)
	end
	return r
end

function NSBydFilter(info)
	local NsBydSet={["tempestissimo"] = true}
	if info["difficulties"][4] and info["difficulties"][4]["ratingClass"]~=3 then
		error("Do NS Have April Fool's Chart?")
	end
	if not NsBydSet[info["id"]] then
		info["difficulties"][4] = nil
	end
	return info
end

function p.GetSong(args)
	local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'])
	local NS = QuerySong(LoadJson("Songlist NS"),args['曲名'],args['id'],NSBydFilter)
	return mw.text.jsonEncode({Mobile=Mobile, NS=NS, args=args},mw.text.JSON_PRESERVE_KEYS)
end

return p