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

来自Arcaea中文维基
(修bug6)
(居然TM不支持getdisplaytitle解析器)
第91行: 第91行:


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


return p
return p

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

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

local p={}

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

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

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

local once={}
function once:new(o)
	o = o or {
		val=nil
	}
	setmetatable(o, self)
	self.__index = self
	return o
end
function once:set(val)
	if self.val~=nil then
		if val~=nil then
			error("重复赋值")
		end
	else
		self.val=val
	end
end
local function NameAudioFilter(info)
	assert(info["title_localized"]["en"],"'en'字段必须存在")
	local first=info["title_localized"]["en"]
	local second=once:new()
	local bydOverride=nil
	second:set(info["title_localized"]["ja"])
	second:set(info["title_localized"]["zh-Hans"])
	if info["difficulties"][4] and info["difficulties"][4]["audioOverride"] then
		assert(info["difficulties"][4]["title_localized"]["en"],"byd'en'字段必须存在")
		second:set(info["difficulties"][4]["title_localized"]["en"])
		bydOverride={
			title=info["difficulties"][4]["title_localized"]["en"],
			artist=info["difficulties"][4]["artist"],
			bpm=info["difficulties"][4]["bpm"],
			bpm_base=info["difficulties"][4]["bpm_base"],
		}
	end
	info["title_localized"]={first,second.val}--,bydOverride
	info["bydOverride"]=bydOverride --magic
	return info
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
		assert(type(v)=="function","You Input Illegal Filter Type?")
		if r~=nil then
			r=v(r)
		end
	end
	return r
end

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

return p