Module:ChartConstant

Star0讨论 | 贡献2022年8月26日 (五) 23:24的版本 (创建页面,内容为“local p = {} local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' }) local songlistAppend = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist append.json' }) local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' }) local getArgs = require('Module:Arguments').getArgs function p.getInfList() -- 返回一个数据表。 local songlistE = {} l…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

local p = {}
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local songlistAppend = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist append.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' })

local getArgs = require('Module:Arguments').getArgs

function p.getInfList()
	-- 返回一个数据表。
	local songlistE = {}
	local appendList = {} -- 记录在songlistAppend中存在的曲目,避免重复列举
	local ratingClass
	for _,songInf in ipairs(songlistAppend["songs"])
	do
		for _,diffInf in ipairs(songInf["difficulties"])
		do
			if diffInf["ratingClass"] ~= 0 or diffInf["ratingClass"] ~= 1
			then
				if diffInf["ratingReal"] == 2 then ratingClass = "难度III" else ratingClass = "难度IV" end
				table.insert(songlistE,{
					songInf["id"],
					songInf["title_localized"]["default"] ,
					ratingClass,
					diffInf["ratingReal"]
				})
			end
		end
		appendList[songInf["id"]] = true
	end

	
	for _,songInf in ipairs(songlist["songs"])
	do
		if songInf["difficulties"] and not(appendList[songInf["id"]])
		then
			for _,diffInf in ipairs(songInf["difficulties"])
			do
				if diffInf["ratingClass"] ~= 0 or diffInf["ratingClass"] ~= 1
				then
					if diffInf["ratingReal"] == 2 then ratingClass = "难度III" else ratingClass = "难度IV" end
					table.insert(songlistE,{
						songInf["id"],
						songInf["title_localized"]["default"] ,
						ratingClass,
						diffInf["ratingReal"]
					})
				end
			end
		end
	end
	mw.logObject(songlistE)
	return songlistE
end



function p.main(frame)
    local args = getArgs(frame)
    return p._main(args)
end

function p._main(args)
	local inf = getInfList()

	local listReplyA = {}
	for _,k in ipairs(inf)
	do
		if listReplyA[inf[4]] == nil then listReplyA[inf[4]] = {} end
		table.insert(listReplyA, k)
	end

	local listReplyB = {}


    for s, k in pairs(listReplyA) do
		if listReplyB[s] == nil then listReplyB[s]={} end
		for _, m in pairs(k) do
			table.insert(listReplyB[s],mw.getCurrentFrame():expandTemplate { title = '组排单元', args = { m[2], m[1], m[3]} } )
		end
    end

	-- add head and end
	local finText = "<div class='notaninfobox dstable'>\n"

	for _,k in ipairs(listReplyB)
	do	
		finText = finText .. "<div class='ds'>"..string.format("%.1f", k[1]).."</div>\n"
		finText = finText .. "<div class='number'>"..mw.getCurrentFrame():expandTemplate { title = '组排列' }
				..table.concat(k[2])..mw.getCurrentFrame():expandTemplate { title = '组排列-end' }.."</div>\n"
	end
	
	finText = finText .. "</div>"


    return finText
end

return p