Module:ChartConstant:修订间差异

来自Arcaea中文维基
(重写了重写了 vsc里一顿写之后预览一遍过给我自己都吓到了)
(修[anti]bug)
 
(未显示3个用户的14个中间版本)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local p = {}
local p = {}
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
-- ns待补充(ns也不需要这个)
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' })


 
local function itData(datas, cc)
 
cc = cc or 13
local function cv()
local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
local list = {}
cc = cc - step
for i,k in pairs(songlist['songs']) do
local id = format:format(cc)
list[k['id']] = {
local data = datas[id]
k['title_localized']['en'],
if not data then return nil end
k["date"],
return cc, id, data
nil,
nil
}
local byd = k["difficulties"][4]
if byd then
if byd["title_localized"] then
list[k['id']][3] = byd["title_localized"]["en"]
end
if byd["date"] then
list[k['id']][4] = byd["date"]
end
end
end
return list
end
end
function p.main()
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 {}
local link = mad.linkName(song) or titleBase
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
local name, link, timestamp, index
if nCc >= 11 then
local cvList = cv()
rowId = ('%d'):format(nCc)
 
sCc = ('%.1f'):format(nCc)
   local result = {}
else
   local mid_result = {}
rowId = ('%.1f'):format(nCc)
end
local get_table_index = function(i)
local rowData = datas[rowId]
if i>=11 then
if not rowData then
return math.floor(i)
rowData = {}
else return i end
datas[rowId] = rowData
end
table.insert(rowData, {
data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
sort = {nCc, rc, date}
})
until (true)
end
end
end


   for i, k in pairs(chartConstantList) do
local frame = mw.getCurrentFrame()
 
local text = mw.html.create 'div':addClass 'notaninfobox dstable'
name = cvList[i][1]
for _, rowId, rowData in itData, datas do
link = name
text = text
timestamp = cvList[i][2]
:tag 'div':addClass 'ds':wikitext(rowId):done()
 
:tag 'div':addClass 'number'
     if trans["songNameToDisplayName"][name] then
:wikitext(frame:expandTemplate {title = '组排列', args = {height = 'auto'}})
       link = trans["songNameToDisplayName"][name]
table.sort(rowData, function(a, b)
     end
a, b = a.sort, b.sort
     if trans["sameName"][name] then
if a[1] ~= b[1] then return a[1] > b[1] end
   link = trans["sameName"][name][i]
if a[2] ~= b[2] then return a[2] > b[2] end
   end
return a[3] < b[3]
if cvList[i][4] then
end)
timestamp = cvList[i][4]
for _, rowItem in ipairs(rowData) do
text:wikitext(frame:expandTemplate {title = '组排单元', args = rowItem.data})
end
end
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
end


for m, q in ipairs({ 2, 3, 4 }) do
return tostring(text)
if k[q] and tonumber(k[q]["constant"])>=8 and not k[q]["old"] then
end
 
index = get_table_index(k[q]["constant"])
     if not mid_result[index] then mid_result[index] = {} end
 
table.insert(mid_result[index], { i, name, k[q]["constant"], ({"","PRS","FTR","BYD"})[q], link, timestamp })


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
end
   end
for i = 2, 6 do
 
data[i] = data[i] or ' '
-- use template
-- 组排单元 第一个参数是曲名,第二个是id,第三个是难度,link字面意思
   for s, k in pairs(mid_result) do
if not(result[s]) then result[s] = {} end
index = get_table_index(k[1][3])
 
table.sort(k,
function (a, b)
if a[3]~=b[3] then
return a[3]>b[3]
end
return a[6]<b[6]
end)
 
for n, m in ipairs(k) do
local arguments = { m[2], m[1], m[4], link=m[5] }
if index >= 11 then arguments.CC = string.format("%.1f", m[3]) end
table.insert(result[index], mw.getCurrentFrame():expandTemplate { title = ' 组排单元', args = arguments })
end
end
   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)


-- sort constants
local texts = {}
local sortedTable = {}
local template = '|-\n|[[%s]]' .. ('||%s'):rep(5)
for i,k in pairs(result) do
for _, value in ipairs(datas) do
table.insert(sortedTable, {i, k})
table.insert(texts, template:format(unpack(value.data)))
end
end
table.sort(sortedTable, function(a,b) return a[1] > b[1] end)


-- add head and end
return table.concat(texts, '\n')
local finText = "<div class='notaninfobox dstable'>\n"
for i,k in ipairs(sortedTable) do
if k[1] == 11 or k[1] == 12 then
finText = finText
.. "<div class='ds'>" .. k[1] .. "</div>\n"
.. "<div class='number'>" .. mw.getCurrentFrame():expandTemplate { title = '组排列', args = { ['高度']="154px"  }  }
.. table.concat(k[2]) .. mw.getCurrentFrame():expandTemplate { title = ' 组排列-end' } .. "</div>\n"
else
finText = finText
.. "<div class='ds'>" .. string.format("%.1f", k[1]).."</div>\n"
.. "<div class='number'>" .. mw.getCurrentFrame():expandTemplate { title = ' 组排列' }
.. table.concat(k[2]) .. mw.getCurrentFrame():expandTemplate { title = '组排列-end' } .. "</div>\n"
end
end
finText = finText .. "</div>"
   return finText
end
end


return p
return p

2024年3月15日 (五) 00:57的最新版本

可在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 {}
		local link = mad.linkName(song) or titleBase
		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, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, 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 = {height = 'auto'}})
		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