Module:沙盒/盐棋/Sandbox1

来自Arcaea中文维基
< Module:沙盒
盐棋讨论 | 贡献2022年3月26日 (六) 11:36的版本 (beyond)

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

local p={byd=nil,cfg=nil}

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

local function cfgPush(key,val)
	if val~=nil then
		if p.cfg[key]==nil then
			p.cfg[key]={}
		end
		p.cfg[key][#p.cfg[key]+1]=val
	end
end

local function NSBydFilter(info)
	-- assert(
	-- 	p.byd()==nil or p.byd()["ratingClass"]==3,
	-- 	"NS不会有愚人节谱"
	-- )
	local NsBydSet={["tempestissimo"] = true}
	if not NsBydSet[info["id"]] then
		info["difficulties"][4] = nil
	end
	return info
end

local function AudioFilter(info)
	if p.byd() then
		if p.byd()["audioOverride"] then
			if p.byd()["title_localized"] then
				cfgPush("title",p.byd()["title_localized"]["en"])
			end
			p.cfg["bydSongOverride"]={
				title=p.byd()["title_localized"]~=nil,
				artist=p.byd()["artist"],
				bpm=p.byd()["bpm"],
				bpm_base=p.byd()["bpm_base"],
			}
		end
	end
	return info
end

local function BGFilter(info)
	assert(info["bg"],"'bg'字段必须存在")
	local board={[0]="light",[1]="conflict"}
	info["bg"] = info["bg"]~="" and info["bg"] or "base_"..board[info["side"]]
	return info
end

local function TitleFilter(info)
	assert(info["title_localized"]["en"],"'en'字段必须存在")
	cfgPush("title",info["title_localized"]["en"])
	cfgPush("title",info["title_localized"]["ja"])
	cfgPush("title",info["title_localized"]["zh-Hans"])
	return info
end

local function JacketFilter(info)
	if info["jacket_localized"] then-- solitarydream
		cfgPush("jacketOverride","lang")
	elseif info["difficulties"][1]["jacket_night"] then-- melodyoflove
		cfgPush("jacketOverride","sunset")
	elseif info["difficulties"][1]["jacketOverride"] then-- stager, avril
		cfgPush("jacketOverride","pstprs")
	elseif p.byd() and p.byd()["jacketOverride"] then
		-- assert(not p.cfg["jacketOverride"],"多曲曲绘画出现byd,请更新代码")
		cfgPush("jacketOverride","byd")
	end
	return info
end

function QuerySong(json,index,queryById,...)
	local r
	if not queryById then
		index=mw.text.decode(index,true)
		for _, v in ipairs(json["songs"]) do
			if mw.ustring.gsub(v['title_localized']['en'],"^%l",mw.ustring.upper) == index then
				r = v
				break
			end
		end
	else
	-- quon,ifi,aiueoon
		for _, v in ipairs(json["songs"]) do
			if v['id'] == index then
				r = v
				break
			end
		end
	end
	if not r then
		return-- nil
	end
	p.byd=function ()return r["difficulties"][4]end
	p.cfg={}
	for _, v in ipairs({...}) do
		assert(type(v)=="function","You Input Illegal Filter Type")
		v(r)
	end
	r["__config"]=p.cfg--magic
	return r
end

--bg,date,version
function p.GetSong(args)
	local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'],BGFilter,TitleFilter,JacketFilter,AudioFilter)
	local NS = QuerySong(LoadJson("Songlist NS"),args['曲名'],args['id'],NSBydFilter,BGFilter,TitleFilter,JacketFilter)
	local main=Mobile or NS
	if Mobile and NS then
		
	end
	return mw.text.jsonEncode({Mobile=Mobile, NS=NS, args=args},mw.text.JSON_PRETTY)
end

return p