local p = {}
local getArgs = require('Module:Arguments').getArgs
local data = require('Module:Game List/Data')
local template_zero = mw.getCurrentFrame():expandTemplate{ title = "0" }
function split(text)
return mw.text.split(string.gsub(text, '<br%s*/?>', '/'), '[/、]')
end
function parse_season(text)
if string.find(text, "^[1-3]月") then
return "1-3月"
elseif string.find(text, "^[4-6]月") then
return "4-6月"
elseif string.find(text, "^[7-9]月") then
return "7-9月"
elseif string.find(text, "^1[0-2]月") then
return "10-12月"
else
return "未定"
end
end
function p._row(frame, args)
-- 标题、链接
local title = args['title'] or args[1] or "无标题"
local link = args['link'] or title
-- 开发商、发行商
local developers = split(args['developer'] or args[2] or "")
for i, v in ipairs(developers) do
developers[i] = data.publishers[string.lower(v)] or v
end
local publishers = split(args['publisher'] or args[3] or "")
for i, v in ipairs(publishers) do
publishers[i] = data.publishers[string.lower(v)] or v
end
-- 发售日期
local release_date = string.gsub(args['release_date'] or args[4] or "未定", template_zero, "")
local y, m, d, formated_date
y, m, d = mw.ustring.match(release_date, '(%d+)[年%-%./](%d+)[月%-%./](%d+)[日]?')
if y then
formated_date = mw.ustring.gsub(string.format('%04d年%02d月%02d日', y, m, d), '([年月])0', '%1{{0}}')
else
y, m = mw.ustring.match(release_date, '(%d+)[年%-%./](%d+)[月%-%./]')
d = 32
if y then
formated_date = mw.ustring.gsub(string.format('%04d年%02d月', y, m), '([年])0', '%1{{0}}')
else
y, m = mw.ustring.match(release_date, '(%d+)[年%-%./]?([春夏秋冬内內初末底]?)')
if y then
formated_date = string.format('%04d年%s', y, m)
m, d = 13, string.find('春夏秋冬内內初末底', m)
else
y, m, d = 9999, 13, 32
formated_date = release_date
end
end
end
local date_wikitext = string.format('data-sort-value="%04d-%02d-%02d | %s', y, m, d, formated_date)
-- 中文情况
local chinese = args['chinese'] or args[5] or ""
local chinese_simplified_wikitext = ""
local chinese_traditional_wikitext = ""
local chinese_simplified = string.find(chinese, '简') or string.find(chinese, '簡')
local chinese_traditional = string.find(chinese, '繁')
local chinese_available = string.find(chinese, '有')
local chinese_not_available = string.find(chinese, '无')
if chinese_available then
-- 有中文 - 分别填充两列
chinese_simplified_wikitext = 'data-sort-value="-0.5" | 有中文'
chinese_traditional_wikitext = 'data-sort-value="-0.5" | 有中文'
elseif chinese_not_available or chinese_simplified or chinese_traditional then
-- 分别处理简体和繁体
chinese_simplified_wikitext = chinese_simplified and 'data-sort-value="-1" | 简体中文' or 'data-sort-value="0" {{N/A|无}}'
chinese_traditional_wikitext = chinese_traditional and 'data-sort-value="-1" | 繁體中文' or 'data-sort-value="0" {{N/A|无}}'
elseif chinese == "" then
-- 未公布
chinese_simplified_wikitext = 'data-sort-value="-0.2" {{N/A|未公布}}'
chinese_traditional_wikitext = 'data-sort-value="-0.2" {{N/A|未公布}}'
else
-- 其他情况
chinese_simplified_wikitext = 'data-sort-value="0" | ' .. chinese
chinese_traditional_wikitext = 'data-sort-value="0" | ' .. chinese
end
-- 备注
local note_content = args['note'] or args[6] or ""
local note_name = args['note_name'] or ""
local has_note = (note_content ~= "" or note_name ~= "")
local note_wikitext = ""
if note_content ~= "" then
local name_part = ""
if note_name ~= "" then
name_part = "|name=" .. note_name
end
note_wikitext = string.format('{{#tag:ref|%s|group=注%s}}', note_content, name_part)
elseif has_note then
note_wikitext = "" -- 空单元格占位
end
-- 构建输出
local wikitext_parts = {
"|-", -- 表格行开始
"{{#ifexist:" .. link .. "|[[" .. link .. "|" .. title .. "]]|" .. title .."}}", -- 标题
table.concat(developers, "<br>"), -- 开发商
table.concat(publishers, "<br>"), -- 发行商
date_wikitext, -- 发售日期
chinese_simplified_wikitext, -- 简体中文
chinese_traditional_wikitext -- 繁体中文
}
if has_note then
table.insert(wikitext_parts, note_wikitext)
end
local wikitext = table.concat(wikitext_parts, "\n| ")
return frame:preprocess(wikitext)
end
function p.row(frame)
return p._row(frame, getArgs(frame, {wrappers = "Template:Game List/Row"}))
end
-- navbox
function p._navbox(frame, args)
local raw_wikitext = mw.title.new(args['page']):getContent()
if raw_wikitext ~= "" then
local last_season = ""
local group = 0
local navbox_args = args
navbox_args['page'] = nil
for content in string.gmatch(raw_wikitext, '{{%s*Game[ _]List/Row%s*|%s*(.-)%s*}}%s*\n') do
content = content .. "|"
content = string.gsub(content, '{{0}}', '')
local title = string.match(content, '^%s*(.-)%s*|') or '无标题'
local link = string.match(content, '|%s*link%s*=%s*(.-)%s*|') or title
local date = string.match(content, '|%s*%d+年(.-)%s*|') or '未定'
if string.find("春夏秋冬", date) then
date = date .. "季"
elseif string.find("内內初末底", date) then
date = "年" .. date
end
local season = parse_season(date)
if season ~= last_season then
group = group + 1
navbox_args['group' .. group] = season
navbox_args['list' .. group] = ''
last_season = season
else
navbox_args['list' .. group] = navbox_args['list' .. group] .. " • "
end
navbox_args['list' .. group] = navbox_args['list' .. group] .. "[[" .. ((link == title) and title or (link .. "|" .. title)) .. "]](" .. date .. ")"
end
return frame:expandTemplate({ title = 'Navbox', args = navbox_args})
else
return ""
end
end
function p.navbox(frame)
return p._navbox(frame, getArgs(frame))
end
return p