Module:ChartConstant:修订间差异

来自Arcaea中文维基
(合并detail)
(细节)
第2行: 第2行:
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local p = {}
local p = {}
local function songMap()
local res = {}
for _, song in ipairs(mad.listOf 'songs') do res[song.id] = song end
-- ns待补充
return res
end


local function itData(datas, cc)
local function itData(datas, cc)
第12行: 第19行:
return cc, id, data
return cc, id, data
end
end
function p.main()
function p.main()
local mSong = {}
local mSong = songMap()
for _, song in ipairs(mad.listOf 'songs') do
mSong[song.id] = song
end
-- ns待补充
 
local datas = {}
local datas = {}
-- CD: constant data
-- CD: constant data
第79行: 第80行:
if not a then return ' ' end
if not a then return ' ' end
local sCC = ('%.1f'):format(a.constant)
local sCC = ('%.1f'):format(a.constant)
if a.old then
return a.old and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCC)) or sCC
return tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCC))
else
return sCC
end
end
end
function p.detail()
function p.detail()
local mSong = {}
local mSong = songMap()
for _, song in ipairs(mad.listOf 'songs') do
mSong[song.id] = song
end
-- ns待补充
 
local datas = {}
local datas = {}
-- CD: constant data
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
local song = mSong[id]
local song = mSong[id]

2024年2月24日 (六) 15:41的版本

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

local mad = require 'Module:AnotherData'
local frame = mw.getCurrentFrame()
local p = {}

local function songMap()
	local res = {}
	for _, song in ipairs(mad.listOf 'songs') do res[song.id] = song end
	-- ns待补充
	return res
end

local function itData(datas, cc)
	cc = cc or 13
	local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
	cc = cc - step
	local id = format:format(cc)
	local data = datas[id]
	if not data then return nil end
	return cc, id, data
end
function p.main()
	local mSong = songMap()
	local datas = {}
	-- CD: constant data
	for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
		local song = mSong[id]
		local query = mad.songQueryWrap(song)
		local title, date = query.title, song.date
		local link = query.linkName or title
		for diffIdx = 2, 4 do
			-- fk lua donot support continue. use single-loop & break for subst
			repeat
				local diffCD = songCD[diffIdx] or {}
				if diffCD.old ~= false then break end
				local cc = diffCD.constant
				if cc < 8 then break end
				if diffIdx == 4 then
					title = query.bydTitle or title
					date = query.bydDate or date
				end
				local rowId, diasplayCC, rowAttr
				if cc >= 11 then
					rowId = ('%d'):format(cc)
					diasplayCC = ('%.1f'):format(cc)
					rowAttr = {['高度'] = '154px'}
				else
					rowId = ('%.1f'):format(cc)
				end
				local rowData = datas[rowId] or {attr = rowAttr}
				datas[rowId] = rowData
				table.insert(rowData, {
					data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC},
					sort = {cc, date}
				})
			until (true)
		end
	end

	local text = mw.html.create 'div':addClass 'notaninfobox dstable'
	for _, rowId, rowData in itData, datas do
		text = text
			:tag 'div':addClass 'ds':wikitext(rowId):done()
			:tag 'div':addClass 'number'
			:wikitext(frame:expandTemplate {title = '组排列', args = rowData.attr})
		table.sort(rowData, function(a, b)
			a, b = a.sort, b.sort
			if a[1] == b[1] then return a[2] < b[2] end
			return a[1] > b[1]
		end)
		for _, rowItem in ipairs(rowData) do
			text:wikitext(frame:expandTemplate {title = '组排单元', args = rowItem.data})
		end
		text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
	end

	return tostring(text)
end

local function constantFormat(a)
	if not a then return ' ' end
	local sCC = ('%.1f'):format(a.constant)
	return a.old and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCC)) or sCC
end
function p.detail()
	local mSong = songMap()
	local datas = {}
	for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
		local song = mSong[id]
		local query = mad.songQueryWrap(song)
		local data = {query.linkTitle}
		local rowData = {data = data, sort = {(songCD[query.bydDate and 3 or 4] or songCD[3]).constant * 10, song.date}}
		table.insert(datas, rowData)
		for i = 1, 4 do
			table.insert(data, constantFormat(songCD[i]))
		end
	end

	table.sort(datas, function(a, b)
		a, b = a.sort, b.sort
		if a[1] == b[1] then return a[2] < b[2] end
		return a[1] > b[1]
	end)

	local texts = {}
	local template = '|-\n|[[%s]]' .. ('||%s'):rep(4)
	for _, value in ipairs(datas) do
		table.insert(texts, template:format(unpack(value.data)))
	end

	return table.concat(texts, '\n')
end

return p