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

Module:Game List

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. local p = {}
  2. local getArgs = require('Module:Arguments').getArgs
  3. local data = require('Module:Game List/Data')
  4. local template_zero = mw.getCurrentFrame():expandTemplate{ title = "0" }
  5. function split(text)
  6. return mw.text.split(string.gsub(text, '<br%s*/?>', '/'), '[/、]')
  7. end
  8. function parse_season(text)
  9. if string.find(text, "^[1-3]月") then
  10. return "1-3月"
  11. elseif string.find(text, "^[4-6]月") then
  12. return "4-6月"
  13. elseif string.find(text, "^[7-9]月") then
  14. return "7-9月"
  15. elseif string.find(text, "^1[0-2]月") then
  16. return "10-12月"
  17. else
  18. return "未定"
  19. end
  20. end
  21. function p._row(frame, args)
  22. -- 标题、链接
  23. local title = args['title'] or args[1] or "无标题"
  24. local link = args['link'] or title
  25. -- 开发商、发行商
  26. local developers = split(args['developer'] or args[2] or "")
  27. for i, v in ipairs(developers) do
  28. developers[i] = data.publishers[string.lower(v)] or v
  29. end
  30. local publishers = split(args['publisher'] or args[3] or "")
  31. for i, v in ipairs(publishers) do
  32. publishers[i] = data.publishers[string.lower(v)] or v
  33. end
  34. -- 发售日期
  35. local release_date = string.gsub(args['release_date'] or args[4] or "未定", template_zero, "")
  36. local y, m, d, formated_date
  37. y, m, d = mw.ustring.match(release_date, '(%d+)[年%-%./](%d+)[月%-%./](%d+)[日]?')
  38. if y then
  39. formated_date = mw.ustring.gsub(string.format('%04d年%02d月%02d日', y, m, d), '([年月])0', '%1{{0}}')
  40. else
  41. y, m = mw.ustring.match(release_date, '(%d+)[年%-%./](%d+)[月%-%./]')
  42. d = 32
  43. if y then
  44. formated_date = mw.ustring.gsub(string.format('%04d年%02d月', y, m), '([年])0', '%1{{0}}')
  45. else
  46. y, m = mw.ustring.match(release_date, '(%d+)[年%-%./]?([春夏秋冬内內初末底]?)')
  47. if y then
  48. formated_date = string.format('%04d年%s', y, m)
  49. m, d = 13, string.find('春夏秋冬内內初末底', m)
  50. else
  51. y, m, d = 9999, 13, 32
  52. formated_date = release_date
  53. end
  54. end
  55. end
  56. local date_wikitext = string.format('data-sort-value="%04d-%02d-%02d | %s', y, m, d, formated_date)
  57. -- 中文情况
  58. local chinese = args['chinese'] or args[5] or ""
  59. local chinese_wikitext = ""
  60. local chinese_simplified = string.find(chinese, '简') or string.find(chinese, '簡')
  61. local chinese_traditional = string.find(chinese, '繁')
  62. local chinese_available = string.find(chinese, '有')
  63. local chinese_not_available = string.find(chinese, '无')
  64. if chinese_available then
  65. chinese_wikitext = 'colspan="2" data-sort-value="-0.5" | 有中文'
  66. elseif chinese_not_available or chinese_simplified or chinese_traditional then
  67. chinese_wikitext = (chinese_simplified and 'data-sort-value="-1" | 简体中文' or 'data-sort-value="0" {{N/A|无}}') .. '\n| ' .. (chinese_traditional and 'data-sort-value="-1" | 繁體中文' or 'data-sort-value="0" {{N/A|无}}')
  68. elseif chinese == "" then
  69. chinese_wikitext = 'colspan="2" data-sort-value="-0.2" {{N/A|未公布}}'
  70. else
  71. chinese_wikitext = 'colspan="2" data-sort-value="0" | ' .. chinese
  72. end
  73. -- 备注
  74. local note = args['note'] or args[6] or ""
  75. local note_name = args['note_name'] or ""
  76. local note_wikitext = " {{#var_final:gl-note}}"
  77. if note ~= "" then
  78. note_wikitext = '\n| {{#tag:ref|' .. note .. '|group=注' .. (note_name ~= "" and '|name=' .. note_name or "") .. '}}'
  79. note_wikitext = note_wikitext .. '{{#vardefine:gl-note|{{!}}{{!}}}}{{#vardefine:gl-note-head|!! rowspan="2" {{!}} 备注}}'
  80. end
  81. -- 输出
  82. local wikitext = table.concat({
  83. "|-",
  84. "{{#ifexist:" .. link .. "|[[" .. link .. "|" .. title .. "]]|" .. title .."}}",
  85. table.concat(developers, "<br>"),
  86. table.concat(publishers, "<br>"),
  87. date_wikitext,
  88. chinese_wikitext
  89. }, "\n| ")
  90. wikitext = wikitext .. note_wikitext
  91. return frame:preprocess(wikitext)
  92. end
  93. function p.row(frame)
  94. return p._row(frame, getArgs(frame, {wrappers = "Template:Game List/Row"}))
  95. end
  96. function p._navbox(frame, args)
  97. local raw_wikitext = mw.title.new(args['page']):getContent()
  98. if raw_wikitext ~= "" then
  99. local last_season = ""
  100. local group = 0
  101. local navbox_args = args
  102. navbox_args['page'] = nil
  103. for content in string.gmatch(raw_wikitext, '{{%s*Game[ _]List/Row%s*\|%s*(.-)%s*}}%s*\n') do
  104. content = content .. "|"
  105. content = string.gsub(content, '{{0}}', '')
  106. local title = string.match(content, '^%s*(.-)%s*\|') or '无标题'
  107. local link = string.match(content, '\|%s*link%s*=%s*(.-)%s*\|') or title
  108. local date = string.match(content, '\|%s*%d+年(.-)%s*\|') or '未定'
  109. if string.find("春夏秋冬", date) then
  110. date = date .. "季"
  111. elseif string.find("内內初末底", date) then
  112. date = "年" .. date
  113. end
  114. local season = parse_season(date)
  115. if season ~= last_season then
  116. group = group + 1
  117. navbox_args['group' .. group] = season
  118. navbox_args['list' .. group] = ''
  119. last_season = season
  120. else
  121. navbox_args['list' .. group] = navbox_args['list' .. group] .. " • "
  122. end
  123. navbox_args['list' .. group] = navbox_args['list' .. group] .. "[[" .. ((link == title) and title or (link .. "|" .. title)) .. "]](" .. date .. ")"
  124. end
  125. return frame:expandTemplate({ title = 'Navbox', args = navbox_args})
  126. else
  127. return ""
  128. end
  129. end
  130. function p.navbox(frame)
  131. return p._navbox(frame, getArgs(frame))
  132. end
  133. return p