「Module:Arcaea Data」:修訂間差異

移除 6,809 位元組 、​ 2024年3月12日 (星期二)
重构,抽取从单曲信息中获取内容的部分,避免重复代码,同时修复上一个编辑中的Bug
(按 ratingPlus 查找难度,并增加 etr 难度支持)
(重构,抽取从单曲信息中获取内容的部分,避免重复代码,同时修复上一个编辑中的Bug)
行 47: 行 47:
end
end


function jsonAssayForSingleSong(json, index, indexTyped)
function extractInfoFromSingleSongData(info, key)
    --  传入JSON文件,索引 和索引值类型(索引是ID还是曲名)。分析JSON文件以获得曲目信息,返回的是一个 查找 单一曲目中信息的函数。仅获取单一曲目的信息。table中的索引名请查看下方switch表。
    --  如果info无 即无法在songlist中 查找 索引值,则 返回nil
 
    if info == nil then 
   -- Songlist是以数字为 索引值, 因此遍历Songlist,直到发现需要找的曲目,将信息存入info变量中。
      mw.log( ' 无法在Songlist中发现目标, 索引值为:'..index )
   local s, info = "", {}
      return nil
   -- 如果模式是ID 遍历songlist直至发现id值为索引值为止,并获取内容。曲名同理
    if indexTyped == "id" then
      for i, k in ipairs(json['songs']) do
       if k['id'] == index then info = k 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
    end


    -- 此处返回一个函数用于查询内容。
    local difficulties={}
 
   return function(key)


     -- 如果info无值即无法在songlist中查找到索引值,则返回nil。
   if info["difficulties"] then
    
     if info == nil
     then 
       mw.log( '无法在Songlist中发现目标,索引值为:'..index )
       return nil
     end
 
     local difficulties={}
  
      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。
   -- 此处定义一个switch table以达到switch函数的效用。如果需要查找的参数在switch中不存在,返回nil。
     local switch = {
   local switch = {
       ["id"] = function() return info["id"] end,
     ["id"] = function() return info["id"] end,
       ["title"] = function() return info['title_localized']['en'] end,
     ["title"] = function() return info['title_localized']['en'] end,
       ["artist"] = function() return info["artist"] end,
     ["artist"] = function() return info["artist"] end,
       ["bpm"] = function() return info["bpm"] end,
     ["bpm"] = function() return info["bpm"] end,
       ["set"] = function() return info["set"] end,
     ["set"] = function() return info["set"] end,
       ["side"] = function() return info["side"] end,
     ["side"] = function() return info["side"] end,
       ["date"] = function() return info["date"] end,
     ["date"] = function() return info["date"] end,
       ["version"] = function() return info["version"] end,
     ["version"] = function() return info["version"] end,
       ["bg"] = function()
     ["bg"] = function()
         if info["bg"] ~= "" then
       if info["bg"] ~= "" then
           return info["bg"]
         return info["bg"]
       else
         if info["side"] == 0 then
           return 'base_light'
          else
          else
            if info["side"] == 0 then
            if info['side'] ==1 then
              return 'base_light'
              return 'base_conflict'
            else
            else
              if info['side'] ==1 then
              return 'undefined'
               return 'base_conflict'
             else
               return 'undefined'
             end
            end
            end
          end
          end
        end,
        end
       ["pstChartDesigner"] = function()
     end,
       if info["difficulties"] then
     ["pstChartDesigner"] = function()
         return difficulties[0]['chartDesigner']
       if info["difficulties"] then
       end
         return difficulties[0]['chartDesigner']
        end,
       end
        ["pstJacketDesigner"] = function()
     end,
       if info["difficulties"] then
     ["pstJacketDesigner"] = function()
         return difficulties[0]['jacketDesigner']
       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
        ["pstRating"] = function()
     end,
          if difficulties[0]['ratingPlus'] then
     ["bydChartDesigner"] = function()
            return difficulties[0]['rating'] .. '+'
       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[0]['rating']
            return difficulties[3]['rating']
          end
          end
        end,
        end
       ["prsChartDesigner"] = function()
     end,
       if info["difficulties"] then
     ["etrChartDesigner"] = function()
         return difficulties[1]['chartDesigner']
       if info["difficulties"] and difficulties[4] then
         end
         return difficulties[4]['chartDesigner']
       end,
       end
       ["prsJacketDesigner"] = function()
     end,
       if info["difficulties"] then
     ["etrJacketDesigner"] = function()
         return difficulties[1]['jacketDesigner']
       if info["difficulties"] and difficulties[4] then
         end
         return difficulties[4]['jacketDesigner']
       end,
       end
       ["prsRating"] = function()
     end,
          if difficulties[1]['ratingPlus'] then
     ["etrRating"] = function()
            return difficulties[1]['rating'] .. '+'
       if info["difficulties"] and difficulties[4] then
          if difficulties[4]['ratingPlus'] then
            return difficulties[4]['rating'] .. '+'
          else
          else
            return difficulties[1]['rating']
            return difficulties[4]['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
        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


     if switch[key] == nil
function jsonAssayForSingleSong(json, index, indexTyped)
     then
   -- 传入JSON文件,索引值和 索引 类型 (索引是ID还是曲名)。分析JSON文件以获得曲目信息 返回的是一个查找单一曲目中信息的函数。仅获取单一曲目的信息。table中的索引名 请查 看下方switch表。
       mw.log( '未定义的 索引类型,请 查是 否拼写错误 。' )
 
        return nil
   -- 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 switch[key]()
   -- 此处返回一个函数用于查询内容。
 
   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)
      -- 如果info无值即无法在songlist中查找到索引值,则返回nil。
    
     if info[index] == nil
     then
       mw.log( '无法在Songlist中发现目标,索引值为:'..index )
       return nil
     end
 
     local difficulties={}
 
     for _, difficulty in ipairs(info[index]["difficulties"]) do
       difficulties[difficulty["ratingClass"]] = difficulty
     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 difficulties[0] then
         return difficulties[0]['chartDesigner']
         else
         return "PST谱师暂缺"
         end
       end,
       ["pstJacketDesigner"] = function()
         return difficulties[0]['jacketDesigner']
       end,
       ["pstRating"] = function()
         if difficulties[0]['ratingPlus'] then
           return difficulties[0]['rating'] .. '+'
         else
           return difficulties[0]['rating']
         end
       end,
       ["prsChartDesigner"] = function()
         return difficulties[1]['chartDesigner']
       end,
       ["prsJacketDesigner"] = function()
         return difficulties[1]['jacketDesigner']
       end,
       ["prsRating"] = function()
         if difficulties[1]['ratingPlus'] then
           return difficulties[1]['rating'] .. '+'
         else
           return difficulties[1]['rating']
         end
       end,
       ["ftrChartDesigner"] = function()
         return difficulties[2]['chartDesigner']
       end,
       ["ftrJacketDesigner"] = function()
         return difficulties[2]['jacketDesigner']
       end,
       ["ftrRating"] = function()
         if difficulties[2]['ratingPlus'] then
           return difficulties[2]['rating'] .. '+'
         else
           return difficulties[2]['rating']
         end
       end,
       ["bydChartDesigner"] = function()
         if difficulties[3] then
           return difficulties[3]['chartDesigner']
         end
       end,
       ["bydJacketDesigner"] = function()
         if difficulties[3] then
           return difficulties[3]['jacketDesigner']
         end
       end,
       ["bydRating"] = function()
         if difficulties[3]['ratingPlus'] then
           return difficulties[3]['rating'] .. '+'
         else
           return difficulties[3]['rating']
         end
       end,
       ["etrChartDesigner"] = function()
         if difficulties[4] then
           return difficulties[4]['chartDesigner']
         end
       end,
       ["etrJacketDesigner"] = function()
         if difficulties[4] then
           return difficulties[4]['jacketDesigner']
         end
       end,
       ["etrRating"] = function()
         if difficulties[4]['ratingPlus'] then
           return difficulties[4]['rating'] .. '+'
         else
           return difficulties[4]['rating']
         end
       end,
       ["pstChange"] = function()
         if difficulties[0] then
           return difficulties[0]['has_controller_alt_chart']
         end
       end,
       ["prsChange"] = function()
         if difficulties[1] then
           return difficulties[1]['has_controller_alt_chart']
         end
       end,
       ["ftrChange"] = function()
         if difficulties[2] then
           return difficulties[2]['has_controller_alt_chart']
         end
       end,
       ["bydChange"] = function()
         if difficulties[3] then
           return difficulties[3]['has_controller_alt_chart']
         end
       end,
       ["etrChange"] = function()
         if difficulties[4] then
           return difficulties[4]['has_controller_alt_chart']
         end
       end,
       ["bydAudioChange"] = function()
         if difficulties[3] then
           return difficulties[3]['audioOverride']
         end
       end,
       ["bydBg"] = function()
         if difficulties[3] then
           return difficulties[3]['bg']
         end
       end,
       ["bydBPM"] = function()
         if difficulties[3] then
           return difficulties[3]['bpm']
         end
       end,
       ["bydArtist"] = function()
         if difficulties[3] then
           return difficulties[3]['artist']
         end
       end
     }
 
     if switch[key] == nil
     then
       mw.log( '未定义的索引类型,请检查是否拼写错误。' )
       return nil
     end
 
     return switch[key]()
    end
    end


1,554

次編輯