模块:VoiceTable

来自PRTS
跳到导航 跳到搜索

来源与须知

本模块搬运自Mooncell,原作者为Uksin

备注

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

该模板会生成以下三种分类:
分类:日文文本不全的干员语音 需要收集或听写日文语音文本
分类:中文文本不全的干员语音 需要填入中文台词内容
分类:语音文件不全的干员语音 需要上传语音文件

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

模板内每个条目:

|标题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_jp = false
	local lack_cn = false
	
	local table_class = playable and "wikitable voice-table" or "wikitable voice-table 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_file_cn = mw.text.trim(args["中文语音" .. i] or "")
			
			local piece_lack_file = (piece_file == "")
			local piece_lack_jp = (piece_jp == "" and piece_cn ~= "")
			local piece_lack_cn = (piece_jp ~= "" and piece_cn == "")
			
			local piece_lack_info = piece_lack_file or piece_lack_jp or piece_lack_cn
			
			table.insert(res_table, string.format("\n|-\n!style=\"width:120px;%s\"|'''%s'''\n", (piece_lack_info and "color:#000;" 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 piece_file_url_cn = ""
					if piece_file_cn ~= "" then
                        piece_file_url_cn = (path == "") and frame:callParserFunction{name = 'filepath:' .. piece_file_cn} or (path .. piece_file_cn)
                    end
                    local player_args = {icon_width = '36px', src = piece_file_url}
					if piece_file_url == "" then
						player_args["download_style"] = "display:none;"
						player_args["play_style"] = "display:none;"
					end
					if not playable then player_args["download_style"] = "display:none;" end
					
					table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayer', args = player_args})
                    if piece_file_url_cn ~= "" then
                    	local player_args = {icon_width = '36px', src = piece_file_url_cn}
						player_args["download_style"] = "display:none;"
						player_args["play_style"] = "display:none;"
                        table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayer', args = player_args})
                    end
				end
			end
			
			lack_file = lack_file or piece_lack_file
			lack_cn = lack_cn or piece_lack_cn
			lack_jp = lack_jp or piece_lack_jp
		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!style=\"position:sticky;top:0;\"|'''%s'''\n", piece_title))
			
			table.insert(res_table, string.format("\n!style=\"position:sticky;top:0;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 piece_file_url == "" then
					player_args["download_style"] = "display:none;"
					player_args["play_style"] = "display:none;"
				end
				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 then
		--local category="干员语音"
		local category = (string.find(frame:getParent():getTitle(), "用户:") == 1) and "用户自定义语音" or "干员语音"
		--[从当前页面的父页面的标题中查找是否带有“用户:”这个关键词]  存在返回“用户自定义语音” 否则返回“干员语音”
		
		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_jp then table.insert(res_table, string.format("[[分类:日文文本不全的%s]]", category)) end
		if lack_cn then table.insert(res_table, string.format("[[分类:中文文本不全的%s]]", category)) end
	end
	
	return table.concat(res_table)
end

return p