置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Umavoice

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

这是供模板:赛马娘角色语音使用的模块,使用方法详见模板说明文档。

  1. local p = {}
  2. local getArgs = require('Module:Arguments').getArgs
  3. local frame = nil
  4. local function check_skip(arg)
  5. if mw.ustring.match(arg, "_%d+$", -3) then -- 跳过以“_数字”结尾的参数
  6. return false
  7. elseif mw.ustring.match(arg, "_[zZjJ][hHaA]$", -3) then -- 跳过以“_zh”、“_ja”结尾的参数
  8. return false
  9. elseif mw.ustring.match(arg, "^__") then -- 以“__”开头的参数供模板使用
  10. return false
  11. end
  12. return true
  13. end
  14. local function check_table(table, value)
  15. if table == nil then
  16. return false
  17. end
  18. for k,v in ipairs(table) do
  19. if v == value then
  20. return true
  21. end
  22. end
  23. return false
  24. end
  25. local function generate_voice(key, args)
  26. local data = {}
  27. local zh_text = args[key .. "_zh"] or args[key .. "_Zh"] or args[key .. "_zH"] or args[key .. "_ZH"] or "''(暂无文本)''"
  28. local ja_text = args[key .. "_ja"] or args[key .. "_Ja"] or args[key .. "_jA"] or args[key .. "_JA"] or "''(暂无文本)''"
  29. local note = args[key .. "_note"] or ""
  30. data["zh_text"] = mw.ustring.format('<div class="textToggleDisplay hidden" data-id="uma-voice-zh">%s</div>', zh_text)
  31. data["ja_text"] = mw.ustring.format('<div class="textToggleDisplay hidden" data-id="uma-voice-ja"><hr><span lang="ja">-{%s}-</span></div>', ja_text)
  32. data["note"] = note
  33. local voice = ""
  34. if args[key] then
  35. voice = mw.ustring.format('<div class="uma-voice-file">%s', frame:preprocess("<sm2>" .. args[key] .. "</sm2>"))
  36. end
  37. local counter = 0
  38. while counter < 10 do
  39. if args[key .. "_" .. counter] == nil then
  40. break
  41. end
  42. voice = voice .. frame:preprocess('<sm2>' .. args[key .. "_" .. counter] .. '</sm2>')
  43. counter = counter + 1
  44. end
  45. data["voice"] = voice .. "</div>"
  46. return data
  47. end
  48. function p.main(_frame)
  49. local args = getArgs(_frame, { parentOnly = true })
  50. frame = _frame
  51. return p._main(args)
  52. end
  53. function p._main(args)
  54. local output = ""
  55. for i, k in ipairs(args) do
  56. v = args[k] or ""
  57. if check_skip(k) then
  58. if mw.ustring.match(k, "^_横栏") then -- 生成横栏
  59. output = output .. mw.ustring.format('|-\n! colspan="4" | %s\n', v)
  60. else -- 生成语音行
  61. local num = mw.ustring.match(k, "%d+$", -3)-- 仅在数字为1或不存在时处理
  62. if num == "1" then
  63. local name = mw.ustring.sub(k, 1, -mw.ustring.len(num) - 1)
  64. local counter = 1
  65. local output_a = ""
  66. while true do
  67. if check_table(args, name .. counter) == false then
  68. counter = counter - 1
  69. break
  70. end
  71. local data = generate_voice(name .. counter, args)
  72. if data["note"] == "" then
  73. output_a = output_a .. mw.ustring.format('|| %s%s \n|| %s \n|-\n', data["zh_text"], data["ja_text"], data["voice"])
  74. else
  75. output_a = output_a .. mw.ustring.format('|style="border-left:none;margin-left:0;"|<div style="display:flex;align-items:center;"><div class="note">%s</div>%s</div>%s || %s\n|-\n', data["note"], data["zh_text"], data["ja_text"], data["voice"])
  76. end
  77. counter = counter + 1
  78. end
  79. output_a = mw.ustring.sub(output_a, 1, -5)
  80. if counter > 1 then
  81. output = output .. mw.ustring.format('|-\n| rowspan="%d" style="width:0;white-space: nowrap;text-align:center;" | %s \n%s\n', counter, name, output_a)
  82. else
  83. output = output .. mw.ustring.format('|-\n | style="width:0;white-space: nowrap;text-align:center;" | %s \n%s\n', name, output_a)
  84. end
  85. elseif num == nil then
  86. local data = generate_voice(k, args)
  87. if data["note"] == "" then
  88. output = output .. mw.ustring.format('|-\n| style="width:0;white-space: nowrap;text-align:center;" | %s \n|| %s%s || %s\n', k, data["zh_text"], data["ja_text"], data["voice"])
  89. else
  90. output = output .. mw.ustring.format('|-\n| style="width:0;white-space: nowrap;text-align:center;" | %s \n|style="border-left:none;margin-left:0;"| <div style="display:flex;align-items:center;"><div class="note">%s</div>%s</div>%s || %s\n', k, data["note"], data["zh_text"], data["ja_text"], data["voice"])
  91. end
  92. end
  93. end
  94. end
  95. end
  96. return output
  97. end
  98. return p