Module:ArtistSong:修订间差异

来自Arcaea中文维基
(排序)
(添加其他名称;中文曲师不转换)
第83行: 第83行:
end
end


-- 排序 (ChatGPT)
-- 排序
local function customSort(a, b)
local function customSort(a, b)
   -- 检查字符串的第一个字符是否为字母
    local function isLetter(char)
    local function isLetter(char)
      return char:match("%a") ~= nil
      return char:match("%a") ~= nil
    end
    end


   -- 获取字符串的第一个字符
    local a1 = isLetter(a:sub(1, 1))
    local a_first = a:sub(1, 1)
    local b1 = isLetter(b:sub(1, 1))
    local b_first = b:sub(1, 1)


   -- 如果 a 是字母开头,b 不是,则 a 排在前面
    if a1 and not b1 then
    if isLetter(a_first) and not isLetter(b_first) then
      return true
      return true
   -- 如果 b 是字母开头,a 不是,则 b 排在前面
    elseif b1 and not a1 then
    elseif isLetter(b_first) and not isLetter(a_first) then
      return false
      return false
    -- 否则,按字典顺序排序
    elseif a1 and b1 then
   local a2 = isLetter(a:sub(2, 2))
   local b2 = isLetter(b:sub(2, 2))
   if a2 and not b2 then
     return true
   elseif b2 and not a2 then
     return false
   else
   return string.lower(a) < string.lower(b)
   end
    else
    else
      return string.lower(a) < string.lower(b)
      return string.lower(a) < string.lower(b)
    end
    end
   return string.lower(a) < string.lower(b)
end
end


第113行: 第120行:
    rl,rlb,cl = nil
    rl,rlb,cl = nil
    
    
   local NotJaName = {['旅人E']='Tabibito E'}
    local wikiText = ""
    local wikiText = ""
    
    
第120行: 第128行:
local enName
local enName
if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
enName = frame.args[name .. '.enName'] or 'Unknown enName: '.. name--nil
enName = frame.args[name .. '.enName'] or name--nil
gl2[enName] = gl[name]
gl2[enName] = gl[name]
gl2[enName].jaName =name
gl2[enName].localName = name
if  NotJaName[name] then
gl2[enName].notJa = 1
end
else
else
enName = name
enName = name
gl2[enName] = gl[name]
gl2[enName] = gl[name]
end
end
gl2[enName].otherName = frame.args[name .. '.otherName'] or nil
table.insert(a2z,enName) 
table.insert(a2z,enName) 
end
end
第134行: 第146行:
    local item = gl2[name]
    local item = gl2[name]
    local displayName, usingName
    local displayName, usingName
    if item.jaName then
    if item.localName then
    usingName = item.jaName
    usingName = item.localName
    displayName = usingName ..' (' .. name ..')'
    if item.notJa then
   displayName = usingName ..' (' .. name ..')'
   else
   displayName = '<span lang="ja">' .. usingName .. '</span>' ..' (' .. name ..')'
   end
    else
    else
    usingName = name
    usingName = name
    displayName = name
    displayName = name
    end
    end
   if item.otherName then
   displayName = displayName .. '(' .. item.otherName .. ')'
   end
  
    wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    wikiText = wikiText .. "==".. displayName .." ==\n"
    wikiText = wikiText .. "==".. displayName .." ==\n"
   wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
    wikiText = wikiText .. '{| class=\"wikitable\"\n'
    wikiText = wikiText .. '{| class=\"wikitable\"\n'
    wikiText = wikiText .. "! Artist !! Songs\n"
    wikiText = wikiText .. "! Artist !! Songs\n"
      if item.beyond and item.normal then
      if item.beyond and item.normal then
        wikiText = wikiText .. "|-\n| rowspan=\"2\" | " .. name .. "\n"
        wikiText = wikiText .. "|-\n| rowspan=\"2\" | " .. usingName .. "\n"
        wikiText = wikiText .. "| " .. mw.text.jsonEncode(item.normal) .. "\n"
        wikiText = wikiText .. "| " .. mw.text.jsonEncode(item.normal) .. "\n"
        wikiText = wikiText .. "|-\n|'''BYD''':" .. mw.text.jsonEncode(item.beyond) .. "\n"
        wikiText = wikiText .. "|-\n|'''BYD''':" .. mw.text.jsonEncode(item.beyond) .. "\n"
      else
      else
        wikiText = wikiText .. "|-\n| " .. name .. " || "
        wikiText = wikiText .. "|-\n| " .. usingName .. " || "
        if item.normal then
        if item.normal then
          wikiText = wikiText .. mw.text.jsonEncode(item.normal) .. "\n"
          wikiText = wikiText .. mw.text.jsonEncode(item.normal) .. "\n"

2024年7月5日 (五) 19:09的版本

可在Module:ArtistSong/doc创建此模块的帮助文档

p={}
local CAL = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local mad = require 'Module:AnotherData'

local function readList()
    local pickList = {}
    local pickListBYD = {}
    for _, song in ipairs(mad.listOf('songs', 'mobile')) do
    	local artist = song.artist
        pickList[song.id] = song.artist
        if song.difficulties[4] and (song.difficulties[4].artist or song.difficulties[4].title_localized) then
        	local bydArtist = song['difficulties'][4]['artist'] or song.artist
            pickListBYD[song['id']] = bydArtist
        end
    end
    
    for _, song in ipairs(mad.listOf('songs', 'ns')) do
        if not pickList[song.id] and not multiId[song.id] then
			pickList[song.id] = song.artist
			if song.difficulties[4] and song.difficulties[4].artist or song.difficulties[4].title_localized then
        		local bydArtist = song['difficulties'][4]['artist'] or song.artist
				pickListBYD[song['id']] = bydArtist
			end
		end
	end

    return pickList, pickListBYD
end

local function convertPick(pickList, pickListBYD)
    convertList = {}
    for _id,_ in pairs(pickList) do
        local artist = pickList[_id]
        if not convertList[artist] then convertList[artist] = {} end
        if not convertList[artist].normal then convertList[artist]['normal'] = {} end
        table.insert(convertList[artist]['normal'], _id)
    end

    for _id in pairs(pickListBYD) do
    	local artist = pickListBYD[_id]
    	if not convertList[artist] then convertList[artist] = {} end
    	if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
    	table.insert(convertList[artist]['beyond'], _id)
    end

    return convertList
end

local function genList(convertList)
	local function cate(singleList, cArtist, artist)
		local artist = artist or cArtist
		if not singleList[artist] then singleList[artist] = {} end
        if convertList[cArtist].beyond then
            if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
            for _,i in pairs(convertList[cArtist]['beyond']) do
            	table.insert(singleList[artist]['beyond'],i)
            end
        end
        if convertList[cArtist].normal then
        	if not singleList[artist].normal then singleList[artist]['normal'] = {} end
            for _,i in pairs(convertList[cArtist]['normal']) do
            	table.insert(singleList[artist]['normal'],i)
            end
        end
        return singleList
    end
	
    local singleList = {}
    for cArtist in pairs(convertList) do
        if CAL[cArtist] then
            for _,text in pairs(CAL[cArtist]) do
                if text.link then
                    artist = text['link']
                    singleList = cate(singleList, cArtist, artist)
                end
            end
        else
            singleList = cate(singleList, cArtist)
        end
	end
    return singleList
end

-- 排序
local function customSort(a, b)
    local function isLetter(char)
        return char:match("%a") ~= nil
    end

    local a1 = isLetter(a:sub(1, 1))
    local b1 = isLetter(b:sub(1, 1))

    if a1 and not b1 then
        return true
    elseif b1 and not a1 then
        return false
    elseif a1 and b1 then
    	local a2 = isLetter(a:sub(2, 2))
    	local b2 = isLetter(b:sub(2, 2))
    	if a2 and not b2 then
	        return true
	    elseif b2 and not a2 then
	        return false
	    else
	    	return string.lower(a) < string.lower(b)
	    end
    else
        return string.lower(a) < string.lower(b)
    end

    return string.lower(a) < string.lower(b)
end


function p.main(frame)
    local rl, rlb = readList()
    local cl = convertPick(rl, rlb)
    local gl = genList(cl)
    rl,rlb,cl = nil
    
    local NotJaName = {['旅人E']='Tabibito E'}
    local wikiText = ""
    
    local a2z = {}
    local gl2 = {}
	for name in pairs(gl) do
		local enName
		if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
			enName = frame.args[name .. '.enName'] or name--nil
			gl2[enName] = gl[name]
			gl2[enName].localName = name
			if  NotJaName[name] then
				gl2[enName].notJa = 1
			end
		else
			enName = name
			gl2[enName] = gl[name]
		end
		gl2[enName].otherName = frame.args[name .. '.otherName'] or nil
		table.insert(a2z,enName) 
	end
	table.sort(a2z, customSort)
    
    for _, name in pairs(a2z) do
    	local item = gl2[name]
    	local displayName, usingName
    	if item.localName then
    		usingName = item.localName
    		if item.notJa then
    			displayName = usingName ..' (' .. name ..')'
    		else
    			displayName = '<span lang="ja">' .. usingName .. '</span>' ..' (' .. name ..')'
    		end
    	else
    		usingName = name
    		displayName = name
    	end
    	if item.otherName then
    		displayName = displayName .. '(' .. item.otherName .. ')'
    	end
    	
    	wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    	wikiText = wikiText .. "==".. displayName .." ==\n"
    	wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
    	wikiText = wikiText .. '{| class=\"wikitable\"\n'
    	wikiText = wikiText .. "! Artist !! Songs\n"
        if item.beyond and item.normal then
            wikiText = wikiText .. "|-\n| rowspan=\"2\" | " .. usingName .. "\n"
            wikiText = wikiText .. "| " .. mw.text.jsonEncode(item.normal) .. "\n"
            wikiText = wikiText .. "|-\n|'''BYD''':" .. mw.text.jsonEncode(item.beyond) .. "\n"
        else
            wikiText = wikiText .. "|-\n| " .. usingName .. " || "
            if item.normal then
                wikiText = wikiText .. mw.text.jsonEncode(item.normal) .. "\n"
            elseif item.beyond then
                wikiText = wikiText .. " '''BYD''' :" .. mw.text.jsonEncode(item.beyond) .. "\n"
            end
        end
        wikiText = wikiText .. "|}\n"
    end
    
    return wikiText
end

return p