模块:GameTag

来自Minecraft Wiki
跳转到导航 跳转到搜索

使用文档请见Template:GameTag/doc

数据模块

  • data:正式版数据模块。
  • snap:快照数据模块。
  • TagType:标签类型配置模块。

数据模块可通过脚本生成(下载:不含实验性内容含实验性内容),使用方法请参阅说明文档

报错分类

[ 查看 | 编辑 | 历史 | 刷新 ]上述文档引用自Module:GameTag/doc
local p = {}
local all = mw.loadData("Module:GameTag/data")
local tagType = mw.loadData("Module:GameTag/TagType")
local snap = mw.loadData("Module:GameTag/snap")

local i18n = {
	['WrongID'] = "'''未知的ID或无标签'''[[Category:未知的ID]]",
	['WrongTag'] = "'''未知的标签'''[[Category:未知标签]]",
	['WrongType'] = "'''未知的标签类型[[Category:未知标签类型]]'''",
	['Different Group'] = "'''不同标签被分类到一组[[Category:错误合并的标签]]'''",
	['Empty'] = "''无''"
}

function p.main(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	
	local objtype
	objtype = tagType[mw.text.trim(args[1])]
	
	if not objtype then
		return i18n['WrongType']
	end
	
	local outtable = {}
	local sptable = {}
	local id = ''
	local diff = false
	local err = ''
	local id = string.gsub(string.lower(args[2] or ''),' ','_')
	local data
	local concat_d = ', '
	local prefix = ''
	local subfix = ''
	local allowidempty = args['cd'] ~= nil and args['cd'] ~= ''
	
	if allowidempty then
		concat_d = '</code><br><code>'
		prefix = '<code>'
		subfix = '</code>'
	end
	
	if args['tagpage'] == '1' or args['tagpage'] == 'y' or args['tagpage'] == 'true' then
		if not snap['tag_ori'][objtype] then
			if not all['tag_ori'][objtype] then
				return i18n['WrongType']
			end
		end
		
		if snap['tag_ori'][objtype] then
			if snap['tag_ori'][objtype][id] then
				data = snap
			else
				if all['tag_ori'][objtype] then
					if all['tag_ori'][objtype][id] then
						data = all
					else
						return i18n['WrongTag']..id
					end
				else
					return i18n['WrongType']..objtype
				end
			end
		else
			if all['tag_ori'][objtype][id] then
				data = all
			else
				return i18n['WrongTag']
			end
		end
		
			for i,v in ipairs(data['tag_ori'][objtype][id]) do
				if string.find(v,'#') == 1 then
					table.insert(outtable,
						--[[#blocks flowers|#flowers]]
						table.concat({
							'[[#',
							objtype,
							' ',
							string.sub(v,12),
							'|#',
							string.sub(v,12),
							']]'
							})
						)
				else
					table.insert(outtable,string.sub(v,11))
				end
			end
		return prefix..table.concat(outtable,concat_d)..subfix
	
	else
		if not snap['ID'][objtype] then
			if not all['ID'][objtype] then
				return i18n['WrongType']
			end
		end
		
		if string.find(args[2],',') then
			sptable=mw.text.split(args[2],',')
			id = string.gsub(string.lower(mw.text.trim(sptable[1])),' ','_')
			
			if snap['ID'][objtype] then
				if snap['ID'][objtype][id] then
					data = snap
				elseif allowidempty then
					return i18n['Empty']
				else
					return i18n['WrongID'].."'''"..id.."'''"
				end
			else
				if all['ID'][objtype][id] then
					data = all
				elseif allowidempty then
					return i18n['Empty']
				else
					return i18n['WrongID'].."'''"..id.."'''"
				end
			end
			for i,v in ipairs(sptable) do --all['ID'][objtype][id]
				v = string.gsub(string.lower(mw.text.trim(sptable[i])),' ','_')
				if data['ID'][objtype][id] and data['ID'][objtype][v] then
					for i1,v1 in ipairs(data['ID'][objtype][id]) do
						if v1 ~= data['ID'][objtype][v][i1] then
							diff = diff or true
							err = v
						end
					end
				
				end
			end
			if diff then
				return i18n['Different Group'].."'''"..err.."'''"
			end
		end
		
		
		if snap['ID'][objtype] and snap['ID'][objtype][id] then
			data = snap
		else
			if all['ID'][objtype][id] then
				data = all
			elseif allowidempty then
				return i18n['Empty']
			else
				return i18n['WrongID'].."'''"..id.."'''"
			end
		end
		
		
		for i,v in ipairs(data['ID'][objtype][id]) do
			table.insert(outtable,v)
		end
		return prefix..table.concat(outtable,concat_d)..subfix
		
	end
end

return p