2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:Pokemon Game

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [创建] [刷新]
local p = {}
local getArgs = require('Module:Arguments').getArgs
local data = require('Module:Pokemon Game/Data')

function p._link(frame, args)
	local showpokemon = false
	local output = {}
	local error = {}
	for _, v in ipairs(args) do
		v = string.upper(v)
		if data.keywords[v] then
			if data.keywords[v] == "Pokemon" then
				showpokemon = true
			end
		elseif data.games[v] then
			if type(data.games[v][1]) == "table" then
				for k2, v2 in ipairs(data.games[v][1]) do
					if #output > 0 and output[#output][1] == v2 then
						output[#output][2] = output[#output][2] + data.separator + (data.games[v][2] or data.games[v][1])[k2]
					else
						table.insert(output, {v2, (data.games[v][2] or data.games[v][1])[k2], prefix = (data.games[v].prefix or ""), series = (data.games[v].series or "")})
					end
				end
			else
				if #output > 0 and output[#output][1] == data.games[v][1] then
					output[#output][2] = output[#output][2] .. data.separator .. (data.games[v][2] or data.games[v][1])
				else
					table.insert(output, {data.games[v][1], data.games[v][2] or data.games[v][1], prefix = (data.games[v].prefix or ""), series = (data.games[v].series or "")})
				end
			end
		else
			table.insert(error, v)
		end
	end
	local outputstring = ""
	for k, v in ipairs(output) do
		outputstring = outputstring .. "[[" .. (v.series ~= "" and v.series or (v.prefix .. data.series)) .. v[1] .. "|" .. (showpokemon and (v.series ~= "" and v.series or (v.prefix .. data.series)) or "") .. v[2] .. "]]"
		showpokemon = false
		if k ~= #output then
			outputstring = outputstring .. data.separator
		end
	end
	return outputstring
end

function p.link(frame)
	return p._link(frame, getArgs(frame, {wrappers = "Template:Pokemon Game"}))
end

return p