Module:沙盒/盐棋/Sandbox1:修订间差异

来自Arcaea中文维基
(恢复误删字母)
(local bg Filter)
第3行: 第3行:
}
}


function LoadJson(filename)
local function LoadJson(filename)
    return mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = filename })
    return mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = filename })
end
local 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
local function BGFilter(info)
local board={"light","conflict"}
info["bg"] = info["bg"]~="" and info["bg"] or "base_"..board[info["side"]]
end
end


第31行: 第47行:
end
end
return r
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
end


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


return p
return p

2022年3月12日 (六) 12:26的版本

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

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

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

local 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

local function BGFilter(info)
	local board={"light","conflict"}
	info["bg"] = info["bg"]~="" and info["bg"] or "base_"..board[info["side"]]
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 p.GetSong(args)
	local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'],BGFilter)
	local NS = QuerySong(LoadJson("Songlist NS"),args['曲名'],args['id'],BGFilter,NSBydFilter)
	return mw.text.jsonEncode({Mobile=Mobile, NS=NS, args=args},mw.text.JSON_PRESERVE_KEYS)
end

return p