Module:Sandbox/InvalidData/AichanTable

来自Arcaea中文维基
< Module:Sandbox
InvalidData讨论 | 贡献2024年9月22日 (日) 20:26的版本 (传上来才发现有点毛病,修)

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

local getArgs = require('Module:Arguments').getArgs
local data = require 'Module:Arcaea Data'
local query = data.allSongInformation("id", "mobile")
local srcFileName = 'InvalidData/preferdata.json'
local p = {}

local function getList()
	return mw.text.jsonDecode(mw.title.new(srcFileName,'User'):getContent())['aichan']
end

local function linkName(name) -- 重写Module:AnotherData的linkName
	local trans = mw.loadJsonData 'Template:Transition.json'
	local res = trans.songNameToDisplayName[name]
	if res then return res end
	res = trans.sameName[name]
	if res then return res[song.id] end
end

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

function p._main(args)
	-- args:
	--     index: 序号
	--     序号以2024年4月为1, 一个月加1
	--     例如2024年11月为8, 2025年3月为12
	--     year: 年份, 不填index时使用
	--     month: 月份, 不填index时使用
	local frame = mw.getCurrentFrame()
	local index = args['index'] or (args['year']-2024)*12+args['month']-3
	local prefList = getList()[index]['prefer']
	local year = args['year'] or getList[index]['year']
	local month = args['month'] or getList[index]['month']
	local wikiText = "== " .. year .. "年" .. month .. "月 ==\n"
	local delta = 0
	if index == 1 then delta = 1 end -- 硬编码处理24年4月
	wikiText = wikiText .. '{| class="wikitable mw-collapsible mw-collapsed" border="1" cellspacing="0" cellpadding="5" style="text-align:center"\n|-\n'
	wikiText = wikiText .. '! scope="col" style="position:-webkit-sticky;position:sticky;top:0px;"|日期 !! scope="col" style="position:-webkit-sticky;position:sticky;top:0px;"|曲目\n'

	local function tableUnit(day,songs)
		local text = '|-\n'
		text = text .. '| ' .. day .. '日\n'
		text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}}
		for i in 1,#songs,1 do
			local id = songs[i]
			local title = query(id,"title")
			local link = linkName(title) or title
			text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}}
		end
		text = text .. frame:expandTemplate{title = '组排列-end'} .. '\n'
		return text
	end

	for i in 1,#prefList,1 do
		local date = i + delta
		local dayPref = prefList[i]
		wikiText = wikiText .. tableUnit(date, dayPref)
	end

	return wikiText .. '|}\n'
end

return p