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

来自Arcaea中文维基
(单引号)
(try)
标签替换
 
(未显示同一用户的100个中间版本)
第1行: 第1行:
local p={byd=nil,cfg=nil}
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 cfgPush(key,val)
return mw.dumpObject({mw.ustring.byte(frame.args.a,1,-1)})
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
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["audioOverride"] then
if p.byd["title_localized"] then
cfgPush("title",p.byd["title_localized"]["en"])
end
p.cfg["bydSongOverride"]={
title=p.byd["title_localized"]["en"],
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={[0]="light",[1]="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","sunset")
elseif info["difficulties"][1]["jacketOverride"] then-- stager, avril
cfgPush("jacketOverride","pstprs")
end
return info
end
function QuerySong(json,index,queryById,...)
index=string.gsub(index,"'","'")
-- Quon
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 mw.ustring.gsub(v['title_localized']['en'],"^%l",mw.ustring.upper) == index then
r = v
break
end
end
end
if not r then
return
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")
r=v(r)
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, len=string.len(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