◆少前百科是非盈利性、非官方的少女前线维基百科。 ◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!点这里 加入少前百科。 ◆有任何意见、建议、纠错,欢迎在 GFwiki:反馈与建议 提出和讨论。编辑事务讨论QQ群:597764980,微博@GFwiki少前百科 ◆To foreigners,You can use twitter to contact us. |
模块:CharaVoice
此模块的文档可以在模块:CharaVoice/doc创建
local p = {} local languages = {'jp', 'kr', 'en'} local args local charavoice local voiceGroups = {} local langGroups local names = {} local root local function renderGroup(group, name) local voiceTable = root:tag('table'):addClass('voice-table') for _, voice in ipairs(group) do if not group.is_hidden then local tr = voiceTable:tag('tr') tr:tag('td'):wikitext(voice.name) local textCell = tr:tag('td') textCell:tag('p'):addClass('cn-text'):wikitext((mw.ustring.gsub(voice.text, '<>', '<br>'))) for _, lang in ipairs(languages) do if langGroups and langGroups[lang] and langGroups[lang][name] then local langText = langGroups[lang][name][string.sub(voice.code, 2, -4)] if langText then textCell:tag('p'):addClass(lang .. '-text'):wikitext(langText) end end end tr:tag('td'):attr('data-filename', name .. voice.code) end end end local function sortVoices(table1, table2) return table1.id < table2.id end local function cloneTable(t) local c = {} for k, v in pairs(t) do c[k] = v end return c end local function groupLine(line, language) local row = mw.text.split(line, '|', true) if not charavoice[row[2]] then return end if not voiceGroups[row[1]] then voiceGroups[row[1]] = {} table.insert(names, row[1]) end if language then if not langGroups[language] then langGroups[language] = {} end if not langGroups[language][row[1]] then langGroups[language][row[1]] = {} end langGroups[language][row[1]][row[2]] = row[3] else local voice = cloneTable(charavoice[row[2]]) voice.text = row[3] table.insert(voiceGroups[row[1]], voice) end end local function main() local lines = mw.text.split(args[1], '\n', true) for _, line in ipairs(lines) do groupLine(line) end for _, lang in ipairs(languages) do lines = args[lang] if lines then if not langGroups then langGroups = {} end lines = mw.text.split(lines, '\n', true) for _, line in ipairs(lines) do groupLine(line, lang) end end end root = mw.html.create() for _, name in ipairs(names) do local group = voiceGroups[name] table.sort(group, sortVoices) renderGroup(group, name) end return tostring(root) end function p.sangvis(frame) charavoice = mw.loadData('模块:CharaVoice/sangvis') args = frame.args return main() end function p.gun(frame) charavoice = mw.loadData('模块:CharaVoice/gun') args = frame.args return main() end return p