Module:沙盒/盐棋/Sandbox1:修订间差异
小 (修bug完成了吗) |
小 (列表压栈) |
||
第3行: | 第3行: | ||
local 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 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 | end | ||
第20行: | 第29行: | ||
if p.byd then | if p.byd then | ||
if p.byd["title_localized"] then | if p.byd["title_localized"] then | ||
cfgPush("title",p.byd["title_localized"]["en"]) | |||
p.cfg["bydNameOverride"]=true | p.cfg["bydNameOverride"]=true | ||
end | end | ||
第31行: | 第40行: | ||
end | end | ||
if p.byd["jacketOverride"] then | if p.byd["jacketOverride"] then | ||
assert(not p.cfg["jacketOverride"],"多曲曲绘画出现byd,请更新代码") | -- assert(not p.cfg["jacketOverride"],"多曲曲绘画出现byd,请更新代码") | ||
cfgPush("jacketOverride","byd") | |||
end | end | ||
end | end | ||
第47行: | 第56行: | ||
local function NameAudioFilter(info) | local function NameAudioFilter(info) | ||
assert(info["title_localized"]["en"],"'en'字段必须存在") | 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 | return info | ||
end | end | ||
local function JacketFilter(info) | local function JacketFilter(info) | ||
if info["jacket_localized"] then-- solitarydream | if info["jacket_localized"] then-- solitarydream | ||
cfgPush("jacketOverride","lang") | |||
elseif info["difficulties"][1]["jacket_night"] then-- melodyoflove | elseif info["difficulties"][1]["jacket_night"] then-- melodyoflove | ||
cfgPush("jacketOverride","hour") | |||
elseif info["difficulties"][1]["jacketOverride"] then-- stager, avril | elseif info["difficulties"][1]["jacketOverride"] then-- stager, avril | ||
cfgPush("jacketOverride","pstprs") | |||
end | end | ||
return info | return info | ||
end | end | ||
第89行: | 第94行: | ||
p.cfg=r["__config"] | p.cfg=r["__config"] | ||
for _, v in ipairs({...}) do | for _, v in ipairs({...}) do | ||
assert(type(v)=="function","You Input Illegal Filter Type | assert(type(v)=="function","You Input Illegal Filter Type") | ||
if r~=nil then | if r~=nil then | ||
r=v(r) | r=v(r) | ||
第97行: | 第102行: | ||
end | end | ||
--bg,date,version | |||
function p.GetSong(args) | function p.GetSong(args) | ||
local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'],BGFilter,NameAudioFilter,JacketFilter,MobileBydFilter) | local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'],BGFilter,NameAudioFilter,JacketFilter,MobileBydFilter) |
2022年3月14日 (一) 10:59的版本
可在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 MobileBydFilter(info)
if p.byd then
if p.byd["title_localized"] then
cfgPush("title",p.byd["title_localized"]["en"])
p.cfg["bydNameOverride"]=true
end
if p.byd["audioOverride"] then
p.cfg["bydSongOverride"]={
artist=p.byd["artist"],
bpm=p.byd["bpm"],
bpm_base=p.byd["bpm_base"],
}
end
if p.byd["jacketOverride"] then
-- assert(not p.cfg["jacketOverride"],"多曲曲绘画出现byd,请更新代码")
cfgPush("jacketOverride","byd")
end
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 function NameAudioFilter(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","hour")
elseif info["difficulties"][1]["jacketOverride"] then-- stager, avril
cfgPush("jacketOverride","pstprs")
end
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
p.byd=r["difficulties"][4]
r["__config"]={} --magic
p.cfg=r["__config"]
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
--bg,date,version
function p.GetSong(args)
local Mobile = QuerySong(LoadJson("Songlist"),args['曲名'],args['id'],BGFilter,NameAudioFilter,JacketFilter,MobileBydFilter)
local NS = QuerySong(LoadJson("Songlist NS"),args['曲名'],args['id'],NSBydFilter,BGFilter,NameAudioFilter,JacketFilter)
return mw.text.jsonEncode({Mobile=Mobile, NS=NS, args=args},mw.text.JSON_PRETTY)
end
return p