Module:ChartConstant:修订间差异

来自Arcaea中文维基
(data模块调整适配)
(fixbug)
第28行: 第28行:
local title, date = mad.title(chart) or titleBase, chart.date or dateBase
local title, date = mad.title(chart) or titleBase, chart.date or dateBase


local rowId, sCc, rowAttr
local rowId, sCc
if nCc >= 11 then
if nCc >= 11 then
rowId = ('%d'):format(nCc)
rowId = ('%d'):format(nCc)
sCc = ('%.1f'):format(nCc)
sCc = ('%.1f'):format(nCc)
rowAttr = {['高度'] = '154px'}
else
else
rowId = ('%.1f'):format(nCc)
rowId = ('%.1f'):format(nCc)
第38行: 第37行:
local rowData = datas[rowId]
local rowData = datas[rowId]
if not rowData then
if not rowData then
rowData = {attr = rowAttr}
rowData = {}
datas[rowId] = rowData
datas[rowId] = rowData
end
end
第55行: 第54行:
:tag 'div':addClass 'ds':wikitext(rowId):done()
:tag 'div':addClass 'ds':wikitext(rowId):done()
:tag 'div':addClass 'number'
:tag 'div':addClass 'number'
:wikitext(frame:expandTemplate {title = '组排列', args = next(rowData).CC and {['高度'] = '154px'}})
:wikitext(frame:expandTemplate {title = '组排列', args = rowData[1].data.CC and {['高度'] = '154px'}})
table.sort(rowData, function(a, b)
table.sort(rowData, function(a, b)
a, b = a.sort, b.sort
a, b = a.sort, b.sort

2024年3月14日 (四) 17:45的版本

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

local mad = require 'Module:AnotherData'
local p = {}
-- ns待补充(ns也不需要这个)

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 datas = {}
	local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
	for _, song in ipairs(mad.listOf 'songs') do
		local id, titleBase, dateBase = song.id, mad.title(song), song.date
		local songCc = songCcs[id] or {}
		for _, chart in ipairs {}, song.difficulties, 1 do
			local rc = chart.ratingClass + 1
			local chartCc = songCc[rc]
			-- fk lua donot support continue. use single-loop & break for subst
			repeat
				if not chartCc or chartCc.old ~= false then break end
				local nCc = chartCc.constant
				if nCc < 8 then break end
				local title, date = mad.title(chart) or titleBase, chart.date or dateBase

				local rowId, sCc
				if nCc >= 11 then
					rowId = ('%d'):format(nCc)
					sCc = ('%.1f'):format(nCc)
				else
					rowId = ('%.1f'):format(nCc)
				end
				local rowData = datas[rowId]
				if not rowData then
					rowData = {}
					datas[rowId] = rowData
				end
				table.insert(rowData, {
					data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = mad.linkName(song), CC = sCc},
					sort = {nCc, rc, date}
				})
			until (true)
		end
	end

	local frame = mw.getCurrentFrame()
	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[1].data.CC and {['高度'] = '154px'}})
		table.sort(rowData, function(a, b)
			a, b = a.sort, b.sort
			if a[1] ~= b[1] then return a[1] > b[1] end
			if a[2] ~= b[2] then return a[2] > b[2] end
			return a[3] < b[3]
		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

function p.detail()
	local datas = {}
	local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
	for _, song in ipairs(mad.listOf 'songs') do
		local id = song.id
		local songCc = songCcs[id] or {}
		--
		local data = {mad.linkTitle(song)}
		local sort = {0, song.date}
		table.insert(datas, {data = data, sort = sort})
		for _, chart in ipairs(song.difficulties) do
			local rc = chart.ratingClass + 1
			local chartCc = songCc[rc]
			repeat
				if not chartCc then break end
				local nCc = chartCc.constant
				if not chart.date then sort[1] = nCc end
				local sCc = ('%.1f'):format(nCc)
				data[rc + 1] = chartCc.old ~= false and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc
			until (true)
		end
		for i = 2, 6 do
			data[i] = data[i] or ' '
		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(5)
	for _, value in ipairs(datas) do
		table.insert(texts, template:format(unpack(value.data)))
	end

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

return p