Module:Sandbox/InvalidData/AichanTable:修订间差异

来自Arcaea中文维基
(传上来才发现有点毛病,修)
(完成(?)
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require 'Module:Arguments'.getArgs
local data = require 'Module:Arcaea Data'
local data = require 'Module:Arcaea Data'
local query = data.allSongInformation("id", "mobile")
local query = data.allSongInformation("id", "mobile")
第5行: 第5行:
local p = {}
local p = {}


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


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


第31行: 第31行:
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local index = args['index'] or (args['year']-2024)*12+args['month']-3
local index = args['index'] or (args['year']-2024)*12+args['month']-3
local prefList = getList()[index]['prefer']
local prefList = p.getList()[index]['prefer']
local year = args['year'] or getList[index]['year']
local year = args['year'] or getList[index]['year']
local month = args['month'] or getList[index]['month']
local month = args['month'] or getList[index]['month']
第44行: 第44行:
text = text .. '| ' .. day .. '日\n'
text = text .. '| ' .. day .. '日\n'
text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}}
text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}}
for i in 1,#songs,1 do
for i = 1,#songs,1 do
local id = songs[i]
local id = songs[i]
local title = query(id,"title")
local title = query(id,"title")
local link = linkName(title) or title
local link = p.linkName(id,title) or title
text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}}
text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}}
end
end
第54行: 第54行:
end
end


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



2024年9月22日 (日) 22:29的最新版本

可在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 = {}

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

function p.linkName(id,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[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 = p.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 = 1,#songs,1 do
			local id = songs[i]
			local title = query(id,"title")
			local link = p.linkName(id,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 = 1,#prefList,1 do
		local d = i + delta
		local dayPref = prefList[i]
		wikiText = wikiText .. tableUnit(d, dayPref)
	end

	return wikiText .. '|}\n'
end

return p