Module:DesignerSong

来自Arcaea中文维基
Economy666讨论 | 贡献2024年7月24日 (三) 19:31的版本 (创建页面,内容为“p={} local DL = mw.loadJsonData 'User:Economy666/DesignersList.json' local multiId = mw.loadJsonData 'Template:Transition.json'.multiId local trans = mw.loadJsonData 'Template:Transition.json' local mad = require 'Module:AnotherData' local data = require "Module:Arcaea Data" local CL = require 'Module:ConvertLink' local CDL = DL.complex local SDL = DL.simple local specialSong = DL.special local queryMO = data.allSongInformation("id", "mobile") local queryNS…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

p={}
local DL = mw.loadJsonData 'User:Economy666/DesignersList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local trans = mw.loadJsonData 'Template:Transition.json'

local mad = require 'Module:AnotherData'
local data = require "Module:Arcaea Data"
local CL = require 'Module:ConvertLink'

local CDL = DL.complex
local SDL = DL.simple
local specialSong = DL.special

local queryMO = data.allSongInformation("id", "mobile")
local queryNS = data.allSongInformation("id", "ns")

local function readList()
	local pickList = {}
	local specialDesigner ={}
    local mobileList = {}
    local diffList = {'PST', 'PRS', 'FTR', 'BYD', 'ETR'}
    for _, song in ipairs(mad.listOf('songs', 'mobile')) do
    	for _,level in ipairs(song.difficulties) do
    		local designer = level.chartDesigner
    		local diff = level.ratingClass
    		if not pickList[designer] then
    			pickList[designer] = {}
    		end
    		if not pickList[designer][song.id] then
    			pickList[designer][song.id] = {}
    		end
    		pickList[designer][song.id][diffList[diff+1]]=true
    		mobileList[song.id]=true
    		if specialSong[song.id] then
    			specialDesigner[designer]=true
    		end
    	end
    end
    
    for _, song in ipairs(mad.listOf('songs', 'ns')) do
        if not mobileList[song.id] and not multiId[song.id] then
			for _,level in ipairs(song.difficulties) do
	    		local designer = level.chartDesigner
	    		local diff = level.ratingClass
	    		if not pickList[designer] then
	    			pickList[designer] = {}
	    		end
	    		if not pickList[designer][song.id] then
	    			pickList[designer][song.id] = {}
	    		end
	    		pickList[designer][song.id][diffList[diff+1]]=true
	    		if specialSong[song.id] then
	    			specialDesigner[designer]=true
	    		end
	    	end
		end
    end
	return pickList ,specialDesigner
end

local function genList(pickList ,specialDesigner)
	local function cate(singleList, cArtist, artist)
		local artist = artist or cArtist
		if not singleList[artist] then singleList[artist] = {} end
        for id,diff in pairs(pickList[cArtist]) do
        	singleList[artist][id] = diff
        end
        return singleList
	end
	
	local function otherDesigner(count)
		if count == 0 then return text end
	    local formatted_text = formatLangText(temp_text)
	    for placeholder, link_text in pairs(link_placeholders) do
	        formatted_text = string.gsub(formatted_text, placeholder, link_text)
	    end
	    return formatted_text
	end
	
    local singleList = {}
    
    for cDesigner,songids in pairs(pickList) do
    	local designerList={}
        if CDL[cDesigner] then
			if CDL[cDesigner].__FullData__ then
				for _,text in pairs(CDL[cDesigner].__FullData__) do
					if text.link then
	                    local designer = text['link']
						if not designerList[designer] then
							singleList = cate(singleList, cDesigner, designer)
							designerList[designer]=true
						end
					end
				end
			else
				for link in pairs(CDL[cDesigner]) do
                    local designer = link
					if not designerList[designer] then
						singleList = cate(singleList, cDesigner, designer)
						designerList[designer]=true
					end
				end
			end
        else
        	local temp_text = cDesigner
        	local count = 0
        	for _,data in ipairs(SDL) do
				local designer = data.link
				local dis = data.display
				if string.find(temp_text, dis) then
					singleList = cate(singleList, cDesigner, designer)
					designerList[designer]=true
					temp_text = string.gsub(temp_text, dis, '')
					count = count + 1
				end
			end
			if count == 0 then
				if specialDesigner[cDesigner] then
					singleList = cate(singleList, cDesigner, '与主线剧情相关的特殊名义')
				else
					singleList = cate(singleList, cDesigner, '其他未确认谱师名义')
				end
			end
        end
	end
    return singleList
end

-- Helper function to remove circular references
local function removeCircularReferences(tbl, seen)
    seen = seen or {}
    if seen[tbl] then
        return
    end
    seen[tbl] = true
    for k, v in pairs(tbl) do
        if type(v) == "table" then
            if seen[v] then
                tbl[k] = nil  -- Remove the circular reference
            else
                removeCircularReferences(v, seen)
            end
        end
    end
end

-- Your main function
-- function p.main()
--     readList()
--     local singleList = genList()
    
--     -- Remove circular references before encoding to JSON
--     removeCircularReferences(singleList)
    
--     return mw.text.jsonEncode(singleList)
-- end

function p.main()
	pickList ,specialDesigner = readList()
	singleList = genList(pickList ,specialDesigner)
	return unpack(singleList)
end

return p