模块:VoiceScript
此模块的文档可以在模块:VoiceScript/doc创建
local p = {}
function p.table(frame)
local max_pieces = 200
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 has_fufu = false
local table_class = playable and "voicescripttable" or "voicescripttable mw-collapsible mw-collapsed"
table.insert(res_table, string.format("\n{|class=\"%s\" ", table_class))
table.insert(res_table, "style=\"width:835px;max-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_name_jp = mw.text.trim(args["日名" .. i] or "")
local piece_name_cn = mw.text.trim(args["中名" .. i] or "")
local piece_text_jp = mw.text.trim(args["日文" .. i] or "")
local piece_text_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_text_jp == "" and piece_text_cn == "")
local piece_lack_tran = (piece_text_jp ~= "" and piece_text_cn == "")
local piece_lack_info = piece_lack_file or piece_lack_text or piece_lack_tran
table.insert(res_table, "\n|-\n|style=\"width:40px;vertical-align:top;\"|")
if piece_file == "-" then
table.insert(res_table, "<p style=\"margin-top:5px;\">—</p>")
elseif piece_file ~= "" then
local piece_file_url = (path == "") and frame:callParserFunction{name = 'filepath:' .. piece_file} or (path .. piece_file)
local player_args = {icon_width = '27px', src = piece_file_url, download_style = "display:none;"}
table.insert(res_table, frame:callParserFunction{name = '#Widget:MiniAudioPlayer', args = player_args})
end
local cond_str1 = (piece_cond ~= "") and string.format(" (%s)", piece_cond) or ""
local cond_str2 = (piece_cond ~= "") and string.format("<br>'''(%s)'''", piece_cond) or ""
if piece_name_cn == "" then piece_name_cn = piece_name_jp end
if piece_text_cn == "" and piece_text_jp ~= "" then piece_text_cn = "待翻译......" end
table.insert(res_table, "\n|id=\"" .. piece_title .. "\" style=\"text-align:left;\"|")
if piece_name_jp ~= "" then
table.insert(res_table, string.format("<p class=\"voicescript-name-jp\">'''<span lang=\"ja\">%s</span>%s'''</p>", piece_name_jp, cond_str1))
table.insert(res_table, string.format("<p lang=\"ja\" class=\"voicescript-text-jp\" style=\"margin:5px 5px 5px 1em;\">%s</p>", piece_text_jp))
else
table.insert(res_table, string.format("<p class=\"voicescript-text-jp\" style=\"margin:5px 5px 5px 1em;\"><span lang=\"ja\">%s</span>%s</p>", piece_text_jp, cond_str2))
end
if piece_name_cn ~= "" then
table.insert(res_table, string.format("<p class=\"voicescript-name-cn\">'''%s%s'''</p>", piece_name_cn, cond_str1))
table.insert(res_table, string.format("<p class=\"voicescript-text-cn\" style=\"margin:5px 5px 5px 1em;\">%s</p>", piece_text_cn))
else
table.insert(res_table, string.format("<p class=\"voicescript-text-cn\" style=\"margin:5px 5px 5px 1em;\">%s%s</p>", piece_text_cn, cond_str2))
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
has_fufu = has_fufu or (string.find(piece_name_jp, "フォウ"))
end
end
table.insert(res_table, "\n|}")
if (playable and (mw.title.getCurrentTitle().namespace == 0)) then
local category = mw.text.trim(args["类别"] or "剧情语音")
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
if has_fufu then table.insert(res_table, string.format("[[分类:芙芙出场的%s]]", category)) end
end
return table.concat(res_table)
end
return p