Module:Arcaea Data:修订间差异

删除5,106字节 、​ 2024年3月12日 (星期二)
重构,抽取从单曲信息中获取内容的部分,避免重复代码,同时修复上一个编辑中的Bug
(非FTR难度的ratingPlus处理)
(重构,抽取从单曲信息中获取内容的部分,避免重复代码,同时修复上一个编辑中的Bug)
 
(未显示同一用户的1个中间版本)
第45行: 第45行:
    end
    end
    return result
    return result
end
function extractInfoFromSingleSongData(info, key)
   -- 如果info无值即无法在songlist中查找到索引值,则返回nil。
   if info == nil then
     mw.log( '无法在Songlist中发现目标,索引值为:'..index )
     return nil
   end
   local difficulties={}
   if info["difficulties"] then
     for _, difficulty in ipairs(info["difficulties"]) do
       difficulties[difficulty["ratingClass"]] = difficulty
     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
           if info['side'] ==1 then
             return 'base_conflict'
           else
             return 'undefined'
           end
         end
       end
     end,
     ["pstChartDesigner"] = function()
       if info["difficulties"] then
         return difficulties[0]['chartDesigner']
       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,
     ["bydChartDesigner"] = function()
       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
           return difficulties[3]['rating']
         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,
     ["etrRating"] = function()
       if info["difficulties"] and difficulties[4] then
         if difficulties[4]['ratingPlus'] then
           return difficulties[4]['rating'] .. '+'
         else
           return difficulties[4]['rating']
         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
end


第66行: 第253行:


    return function(key)
    return function(key)
 
      return extractInfoFromSingleSongData(info, key)
      -- 如果info无值即无法在songlist中查找到索引值,则返回nil。
    
     if info == nil
     then
       mw.log( '无法在Songlist中发现目标,索引值为:'..index )
       return nil
     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
             if info['side'] ==1 then
               return 'base_conflict'
             else
               return 'undefined'
             end
           end
         end
       end,
       ["pstChartDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][1]['chartDesigner']
       end
       end,
       ["pstJacketDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][1]['jacketDesigner']
         end
       end,
       ["pstRating"] = function()
         if info["difficulties"][1]['ratingPlus'] then
           return info["difficulties"][1]['rating'] .. '+'
         else
           return info["difficulties"][1]['rating']
         end
       end,
       ["prsChartDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][2]['chartDesigner']
         end
       end,
       ["prsJacketDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][2]['jacketDesigner']
         end
       end,
       ["prsRating"] = function()
         if info["difficulties"][2]['ratingPlus'] then
           return info["difficulties"][2]['rating'] .. '+'
         else
           return info["difficulties"][2]['rating']
         end
       end,
       ["ftrChartDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][3]['chartDesigner']
         end
       end,
       ["ftrJacketDesigner"] = function()
       if info["difficulties"] then
         return info["difficulties"][3]['jacketDesigner']
         end
       end,
       ["ftrRating"] = function()
       if info["difficulties"] then
         if info["difficulties"][3]['ratingPlus'] then
           return info["difficulties"][3]['rating'] .. '+'
         else
           return info["difficulties"][3]['rating']
         end
       end
       end,
       ["bydChartDesigner"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['chartDesigner']
         end
       end,
       ["bydJacketDesigner"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['jacketDesigner']
         end
       end,
       ["bydRating"] = function()
         if info["difficulties"] and info["difficulties"][4] then
         if info["difficulties"][4]['ratingPlus'] then
           return info["difficulties"][4]['rating'] .. '+'
         else
           return info["difficulties"][4]['rating']
         end
         end
       end,
       ["pstChange"] = function()
         if info["difficulties"] and info["difficulties"][1] then
           return info["difficulties"][1]['has_controller_alt_chart']
         end
       end,
       ["prsChange"] = function()
         if info["difficulties"] and info["difficulties"][2] then
           return info["difficulties"][2]['has_controller_alt_chart']
         end
       end,
       ["ftrChange"] = function()
         if info["difficulties"] and info["difficulties"][3] then
           return info["difficulties"][3]['has_controller_alt_chart']
         end
       end,
       ["bydAudioChange"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['audioOverride']
         end
       end,
       ["bydBg"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['bg']
         end
       end,
       ["bydBPM"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['bpm']
         end
       end,
       ["bydArtist"] = function()
         if info["difficulties"] and info["difficulties"][4] then
           return info["difficulties"][4]['artist']
         end
       end
     }
 
     if switch[key] == nil
     then
       mw.log( '未定义的索引类型,请检查是否拼写错误。' )
       return nil
     end
 
     return switch[key]()
    end
    end
end
end
第256行: 第294行:


    return function(index, key)
    return function(index, key)
 
      return extractInfoFromSingleSongData(info[index], key)
      -- 如果info无值即无法在songlist中查找到索引值,则返回nil。
    
     if info[index] == nil
     then
       mw.log( '无法在Songlist中发现目标,索引值为:'..index )
       return nil
     end
 
     -- 此处定义一个switch table以达到switch函数的效用。如果需要查找的参数在switch中不存在,返回nil。
     local switch = {
       ["id"] = function() return info[index]["id"] end,
       ["title"] = function() return info[index]['title_localized']['en'] end,
       ["artist"] = function() return info[index]["artist"] end,
       ["bpm"] = function() return info[index]["bpm"] end,
       ["set"] = function() return info[index]["set"] end,
       ["side"] = function() return info[index]["side"] end,
       ["date"] = function() return info[index]["date"] end,
       ["version"] = function() return info[index]["version"] end,
       ["bg"] = function()
         if info[index]["bg"] ~= "" then
           return info[index]["bg"]
         else
           if info[index]["side"] == 0 then
             return 'base_light'
           else
             if info[index]['side'] ==1 then
               return 'base_conflict'
             else
               return 'undefined'
             end
           end
         end
       end,
       ["pstChartDesigner"] = function()
       if info[index]["difficulties"][1] then
         return info[index]["difficulties"][1]['chartDesigner']
         else
         return "PST谱师暂缺"
         end
       end,
       ["pstJacketDesigner"] = function()
         return info[index]["difficulties"][1]['jacketDesigner']
       end,
       ["pstRating"] = function()
         if info[index]["difficulties"][1]['ratingPlus'] then
           return info[index]["difficulties"][1]['rating'] .. '+'
         else
           return info[index]["difficulties"][1]['rating']
         end
       end,
       ["prsChartDesigner"] = function()
         return info[index]["difficulties"][2]['chartDesigner']
       end,
       ["prsJacketDesigner"] = function()
         return info[index]["difficulties"][2]['jacketDesigner']
       end,
       ["prsRating"] = function()
         if info[index]["difficulties"][2]['ratingPlus'] then
           return info[index]["difficulties"][2]['rating'] .. '+'
         else
           return info[index]["difficulties"][2]['rating']
         end
       end,
       ["ftrChartDesigner"] = function()
         return info[index]["difficulties"][3]['chartDesigner']
       end,
       ["ftrJacketDesigner"] = function()
         return info[index]["difficulties"][3]['jacketDesigner']
       end,
       ["ftrRating"] = function()
         if info[index]["difficulties"][3]['ratingPlus'] then
           return info[index]["difficulties"][3]['rating'] .. '+'
         else
           return info[index]["difficulties"][3]['rating']
         end
       end,
       ["bydChartDesigner"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['chartDesigner']
         end
       end,
       ["bydJacketDesigner"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['jacketDesigner']
         end
       end,
       ["bydRating"] = function()
         if info[index]["difficulties"][4]['ratingPlus'] then
           return info[index]["difficulties"][4]['rating'] .. '+'
         else
           return info[index]["difficulties"][4]['rating']
         end
       end,
       ["pstChange"] = function()
         if info[index]["difficulties"][1] then
           return info[index]["difficulties"][1]['has_controller_alt_chart']
         end
       end,
       ["prsChange"] = function()
         if info[index]["difficulties"][2] then
           return info[index]["difficulties"][2]['has_controller_alt_chart']
         end
       end,
       ["ftrChange"] = function()
         if info[index]["difficulties"][3] then
           return info[index]["difficulties"][3]['has_controller_alt_chart']
         end
       end,
       ["bydAudioChange"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['audioOverride']
         end
       end,
       ["bydBg"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['bg']
         end
       end,
       ["bydBPM"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['bpm']
         end
       end,
       ["bydArtist"] = function()
         if info[index]["difficulties"][4] then
           return info[index]["difficulties"][4]['artist']
         end
       end
     }
 
     if switch[key] == nil
     then
       mw.log( '未定义的索引类型,请检查是否拼写错误。' )
       return nil
     end
 
     return switch[key]()
    end
    end


1,269

个编辑