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

来自Arcaea中文维基
(居然TM不支持getdisplaytitle解析器)
(try)
标签替换
 
(未显示同一用户的120个中间版本)
第1行: 第1行:
local p={}
local p = {}
 
function p.len(frame)
local function LoadJson(filename)
return #frame.args.a
   return mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = filename })
end
end
 
function p.explode(frame)
local function NSBydFilter(info)
return mw.dumpObject({mw.ustring.byte(frame.args.a,1,-1)})
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
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
return p

2024年2月27日 (二) 03:17的最新版本

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

local p = {}
function p.len(frame)
	return #frame.args.a
end
function p.explode(frame)
	return mw.dumpObject({mw.ustring.byte(frame.args.a,1,-1)})
end
return p