1,554
次編輯
(按 ratingPlus 查找难度,并增加 etr 难度支持) |
(重构,抽取从单曲信息中获取内容的部分,避免重复代码,同时修复上一个编辑中的Bug) |
||
第47行: | 第47行: | ||
end | end | ||
function | function extractInfoFromSingleSongData(info, key) | ||
-- | -- 如果info无 值 即无法在songlist中 查找 到 索引值,则 返回nil 。 | ||
if info == nil then | |||
mw.log( ' 无法在Songlist中发现目标, 索引值为:'..index ) | |||
return nil | |||
if | |||
end | end | ||
local difficulties={} | |||
if info["difficulties"] then | |||
for _, difficulty in ipairs(info["difficulties"]) do | for _, difficulty in ipairs(info["difficulties"]) do | ||
difficulties[difficulty["ratingClass"]] = difficulty | difficulties[difficulty["ratingClass"]] = difficulty | ||
end | end | ||
end | |||
-- 此处定义一个switch table以达到switch函数的效用。如果需要查找的参数在switch中不存在,返回nil。 | |||
local switch = { | |||
["id"] = function() return info["id"] end, | |||
["title"] = function() return info['title_localized']['en'] end, | |||
["artist"] = function() return info["artist"] end, | |||
["bpm"] = function() return info["bpm"] end, | |||
["set"] = function() return info["set"] end, | |||
["side"] = function() return info["side"] end, | |||
["date"] = function() return info["date"] end, | |||
["version"] = function() return info["version"] end, | |||
["bg"] = function() | |||
if info["bg"] ~= "" then | |||
return info["bg"] | |||
else | |||
if info["side"] == 0 then | |||
return 'base_light' | |||
else | else | ||
if info[ | if info['side'] ==1 then | ||
return ' | return 'base_conflict' | ||
else | else | ||
return 'undefined' | |||
end | end | ||
end | end | ||
end, | end | ||
end, | |||
["pstChartDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[0]['chartDesigner'] | |||
end, | end | ||
[" | end, | ||
["pstJacketDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[0]['jacketDesigner'] | |||
end | |||
end, | |||
["pstRating"] = function() | |||
if difficulties[0]['ratingPlus'] then | |||
return difficulties[0]['rating'] .. '+' | |||
else | |||
return difficulties[0]['rating'] | |||
end | |||
end, | |||
["prsChartDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[1]['chartDesigner'] | |||
end | |||
end, | |||
["prsJacketDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[1]['jacketDesigner'] | |||
end | |||
end, | |||
["prsRating"] = function() | |||
if difficulties[1]['ratingPlus'] then | |||
return difficulties[1]['rating'] .. '+' | |||
else | |||
return difficulties[1]['rating'] | |||
end | |||
end, | |||
["ftrChartDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[2]['chartDesigner'] | |||
end | |||
end, | |||
["ftrJacketDesigner"] = function() | |||
if info["difficulties"] then | |||
return difficulties[2]['jacketDesigner'] | |||
end | |||
end, | |||
["ftrRating"] = function() | |||
if info["difficulties"] then | |||
if difficulties[2]['ratingPlus'] then | |||
return difficulties[2]['rating'] .. '+' | |||
else | |||
return difficulties[2]['rating'] | |||
end | end | ||
end, | end | ||
[" | end, | ||
if difficulties[ | ["bydChartDesigner"] = function() | ||
return difficulties[ | if info["difficulties"] and difficulties[3] then | ||
return difficulties[3]['chartDesigner'] | |||
end | |||
end, | |||
["bydJacketDesigner"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[3]['jacketDesigner'] | |||
end | |||
end, | |||
["bydRating"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
if difficulties[3]['ratingPlus'] then | |||
return difficulties[3]['rating'] .. '+' | |||
else | else | ||
return difficulties[ | return difficulties[3]['rating'] | ||
end | end | ||
end, | end | ||
end, | |||
["etrChartDesigner"] = function() | |||
if info["difficulties"] and difficulties[4] then | |||
return difficulties[4]['chartDesigner'] | |||
end | |||
end, | |||
["etrJacketDesigner"] = function() | |||
if info["difficulties"] and difficulties[4] then | |||
return difficulties[4]['jacketDesigner'] | |||
end | |||
end, | |||
if difficulties[ | ["etrRating"] = function() | ||
return difficulties[ | if info["difficulties"] and difficulties[4] then | ||
if difficulties[4]['ratingPlus'] then | |||
return difficulties[4]['rating'] .. '+' | |||
else | else | ||
return difficulties[4]['rating'] | |||
end | end | ||
end | end | ||
} | end, | ||
["pstChange"] = function() | |||
if info["difficulties"] and difficulties[0] then | |||
return difficulties[0]['has_controller_alt_chart'] | |||
end | |||
end, | |||
["prsChange"] = function() | |||
if info["difficulties"] and difficulties[1] then | |||
return difficulties[1]['has_controller_alt_chart'] | |||
end | |||
end, | |||
["ftrChange"] = function() | |||
if info["difficulties"] and difficulties[2] then | |||
return difficulties[2]['has_controller_alt_chart'] | |||
end | |||
end, | |||
["bydChange"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[2]['has_controller_alt_chart'] | |||
end | |||
end, | |||
["etrChange"] = function() | |||
if info["difficulties"] and difficulties[4] then | |||
return difficulties[2]['has_controller_alt_chart'] | |||
end | |||
end, | |||
["bydAudioChange"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[3]['audioOverride'] | |||
end | |||
end, | |||
["bydBg"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[3]['bg'] | |||
end | |||
end, | |||
["bydBPM"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[3]['bpm'] | |||
end | |||
end, | |||
["bydArtist"] = function() | |||
if info["difficulties"] and difficulties[3] then | |||
return difficulties[3]['artist'] | |||
end | |||
end | |||
} | |||
if switch[key] == nil | |||
then | |||
mw.log( '未定义的索引类型,请检查是否拼写错误。' ) | |||
return nil | |||
end | |||
return switch[key]() | |||
end | |||
function jsonAssayForSingleSong(json, index, indexTyped) | |||
-- 传入JSON文件,索引值和 索引 值 类型 (索引是ID还是曲名)。分析JSON文件以获得曲目信息 , 返回的是一个查找单一曲目中信息的函数。仅获取单一曲目的信息。table中的索引名 请查 看下方switch表。 | |||
-- Songlist 是 以数字为索引值,因此遍历Songlist,直到发现需要找的曲目,将信息存入info变量中 。 | |||
local s, info = "", {} | |||
-- 如果模式是ID则遍历songlist直至发现id值为索引值为止,并获取内容。曲名同理。 | |||
if indexTyped == "id" then | |||
for i, k in ipairs(json['songs']) do | |||
if k['id'] == index then info = k end | |||
end | end | ||
else | |||
for i, k in ipairs(json['songs']) do | |||
if string.lower(k['title_localized']['en']) == string.lower(index) then info = k end | |||
end | |||
end | |||
return | -- 此处返回一个函数用于查询内容。 | ||
return function(key) | |||
return extractInfoFromSingleSongData(info, key) | |||
end | end | ||
end | end | ||
第291行: | 第294行: | ||
return function(index, key) | return function(index, key) | ||
return extractInfoFromSingleSongData(info[index], key) | |||
end | end | ||
次編輯