“模块:VoiceTable”的版本间的差异

来自维阿百科
跳转至: 导航搜索
1.38>牛腩面
(导入1个版本)
 
(导入1个版本)
 
(没有差异)

2022年7月8日 (五) 21:16的最新版本

备注

参考已使用该模板的页面:分类:从者语音

该模板会生成以下三种分类:
分类:文本不全的从者语音 需要收集或听写日文语音文本
分类:翻译不全的从者语音 需要将日文语音文本翻译为中文
分类:语音不全的从者语音 需要上传语音文件

有信息缺失时,标题会显示为红色。

模板内每个条目:

|标题X=
|日文X=
|中文X=
|条件X=
|语音X=

1.条件X可选,放语音的开放条件,比如“持有xxx”,“羁绊等级xxx”,不需要加括号。其他的就算没有最好也留空。
2.换行请使用<br />。个人意见尽量少用强制换行,因为表格实在太长了……

工具

[语音表格制作工具]


local p = {}

function p.table(frame)
	local max_pieces = 50
	local args = (frame == mw.getCurrentFrame() and frame.args) or frame
	
	res_table = {}
	table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayerJS'})
	
	local playable = ((args["可播放"] or "") ~= "")
	local title = mw.text.trim(args["表格标题"] or "")
	local path = mw.text.trim(args["目录"] or "")
	
	local lack_file = false
	local lack_text = false
	local lack_tran = false
	
	local table_class = playable and "wikitable" or "wikitable mw-collapsible mw-collapsed"
	
	-- Desktop Table
	table.insert(res_table, string.format("\n{|class=\"%s %s\" ", table_class, "nomobile"))
	table.insert(res_table, "style=\"width:835px;max-width:100%;line-height:18px;text-align:center;display:table;white-space:normal;\"\n")
	
	if not playable then table.insert(res_table, string.format("|-\n! colspan=\"3\" |'''%s'''", title)) end
	
	for i = 1, max_pieces do
		local piece_title = mw.text.trim(args["标题" .. i] or "")
		if piece_title ~= "" then
			local piece_jp = mw.text.trim(args["日文" .. i] or "")
			local piece_cn = mw.text.trim(args["中文" .. i] or "")
			local piece_cond = mw.text.trim(args["条件" .. i] or "")
			local piece_file = mw.text.trim(args["语音" .. i] or "")
			
			local piece_lack_file = (piece_file == "")
			local piece_lack_text = (piece_jp == "" and piece_cn == "")
			local piece_lack_tran = (piece_jp ~= "" and piece_cn == "")
			
			local piece_lack_info = piece_lack_file or piece_lack_text or piece_lack_tran
			
			table.insert(res_table, string.format("\n|-\n!style=\"width:120px;%s\"|'''%s'''\n", (piece_lack_info and "color:#A00D00;" or ""), piece_title))
			table.insert(res_table, "|style=\"text-align:left;\"|")
			
			if playable and piece_jp ~= "" and piece_cn ~= "" then
				table.insert(res_table, "<p lang=\"ja\" style=\"margin:5px;margin-bottom:10px\">" .. piece_jp .. "</p><p style=\"margin:5px;\">" .. piece_cn)
			elseif piece_cn ~= "" then
				table.insert(res_table, "<p style=\"margin:5px;\">" .. piece_cn)
			else
				table.insert(res_table, "<p lang=\"ja\" style=\"margin:5px;\">" .. piece_jp)
			end

			table.insert(res_table, ((piece_cond ~= "") and string.format("'''(%s)'''</p>", piece_cond) or "</p>"))
			
			table.insert(res_table, string.format("\n|style=\"width:%dpx;\"|", playable and 80 or 40))
			
			if piece_file ~= "" then
				if piece_file == "-" then
					table.insert(res_table, "—")
				else
					local piece_file_url = (path == "") and frame:callParserFunction{name = 'filepath:' .. piece_file} or (path .. piece_file)
					local player_args = {icon_width = '36px', src = piece_file_url}
					if not playable then player_args["download_style"] = "display:none;" end
					
					table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayer', args = player_args})
				end
			end
			
			lack_file = lack_file or piece_lack_file
			lack_text = lack_text or piece_lack_text
			lack_tran = lack_tran or piece_lack_tran
		end
	end
	
	table.insert(res_table, "\n|}")
	
	-- Mobile Table
	table.insert(res_table, string.format("\n{|class=\"%s %s\" ", table_class, "nodesktop"))
	table.insert(res_table, "style=\"width:100%;line-height:18px;text-align:center;display:table;white-space:normal;font-size:unset;\"\n")
	
	if not playable then table.insert(res_table, string.format("|-\n! colspan=\"2\" |'''%s'''", title)) end
	
	for i = 1, max_pieces do
		local piece_title = mw.text.trim(args["标题" .. i] or "")
		if piece_title ~= "" then
			local piece_jp = mw.text.trim(args["日文" .. i] or "")
			local piece_cn = mw.text.trim(args["中文" .. i] or "")
			local piece_cond = mw.text.trim(args["条件" .. i] or "")
			local piece_file = mw.text.trim(args["语音" .. i] or "")
			
			table.insert(res_table, string.format("\n|-\n!'''%s'''\n", piece_title))
			
			table.insert(res_table, string.format("\n!style=\"width:%dpx;\"|", playable and 60 or 30))
			
			if piece_file ~= "" then
				local piece_file_url = frame:callParserFunction{name = 'filepath:' .. piece_file}
				local player_args = {icon_width = '27px', src = piece_file_url}
				if not playable then player_args["download_style"] = "display:none;" end
				
				table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayer', args = player_args})
			end
			
			table.insert(res_table, string.format("\n|-\n|colspan=\"%d\" style=\"text-align:left;\"|", (playable and 3 or 2)))
			
			if playable and piece_jp ~= "" and piece_cn ~= "" then
				table.insert(res_table, "<p lang=\"ja\" style=\"margin:5px;margin-bottom:10px\">" .. piece_jp .. "</p><p style=\"margin:5px;\">" .. piece_cn)
			elseif piece_cn ~= "" then
				table.insert(res_table, "<p style=\"margin:5px;\">" .. piece_cn)
			else
				table.insert(res_table, "<p lang=\"ja\" style=\"margin:5px;\">" .. piece_jp)
			end

			table.insert(res_table, ((piece_cond ~= "") and string.format("'''(%s)'''</p>", piece_cond) or "</p>"))
		end
	end
	
	table.insert(res_table, "\n|}")
	
	if (playable and (mw.title.getCurrentTitle().namespace == 0)) then
		local category = "从者语音"
		category = mw.text.trim(args["类别"] or category)
		table.insert(res_table, string.format("[[分类:%s]]", category))
		
		if lack_file then table.insert(res_table, string.format("[[分类:语音不全的%s]]", category)) end
		if lack_text then table.insert(res_table, string.format("[[分类:文本不全的%s]]", category)) end
		if lack_tran then table.insert(res_table, string.format("[[分类:翻译不全的%s]]", category)) end
	end
	
	return table.concat(res_table)
end

return p