模块:语音
来自卡厄思梦境WIKI
此模块的文档可以在模块:语音/doc创建
local p = {}
function p.main(frame)
local characterName = frame.args[1] or frame:getParent().args[1]
if not characterName or characterName == "" then
return "错误:请提供战斗员名称"
end
-- 尝试加载语音数据模块
local success, voiceData = pcall(require, "模块:语音/" .. characterName)
if not success then
return "错误:未找到战斗员 " .. characterName .. " 的语音数据"
end
-- 从文件名中提取角色ID
local characterId = ""
if voiceData[1] and voiceData[1].file then
characterId = voiceData[1].file:match("vo_(%d+)_")
end
-- 语音文件基础 URL (修改这里!)
local baseUrl = "https://cznwiki.com/voice"
-- 创建表格
local html = mw.html.create('table')
:addClass('wikitable voice-table')
-- 表头
local headerRow = html:tag('tr')
headerRow:tag('th'):wikitext('类型'):css('width', '15%')
headerRow:tag('th'):wikitext('韩语'):css('width', '5%'):css('text-align', 'center')
headerRow:tag('th'):wikitext('日语'):css('width', '5%'):css('text-align', 'center')
headerRow:tag('th'):wikitext('文本'):css('width', '75%')
-- 数据行
for _, voice in ipairs(voiceData) do
local row = html:tag('tr')
-- 类型
row:tag('td'):wikitext(voice.type)
-- 韩语播放按钮 (完整 URL)
local krPath = baseUrl .. "/kr/" .. characterId .. "/" .. voice.file
local krButton = mw.html.create('div')
:addClass('voice-play-button')
:attr('onclick', "VoicePlayer.play('" .. krPath .. "', this)")
:wikitext('▶')
row:tag('td')
:css('text-align', 'center')
:node(krButton)
-- 日语播放按钮 (完整 URL)
local jpPath = baseUrl .. "/jp/" .. characterId .. "/" .. voice.file
local jpButton = mw.html.create('div')
:addClass('voice-play-button')
:attr('onclick', "VoicePlayer.play('" .. jpPath .. "', this)")
:wikitext('▶')
row:tag('td')
:css('text-align', 'center')
:node(jpButton)
-- 文本内容
local textDiv = mw.html.create('div')
:addClass('voice-text')
:wikitext(
(voice.text_cn or "") .. "<br>" ..
(voice.text_kr or "") .. "<br>" ..
(voice.text_jp or "")
)
row:tag('td'):node(textDiv)
end
return tostring(html)
end
return p