此模块的文档可以在模块:Common/doc创建

local p = {}

-- 导入函数
local get_data = require('Module:Common/Utility.lua').get_data
local get_trans_data = require('Module:Common/Utility.lua').get_trans_data
local count_data = require('Module:Common/Utility.lua').count_data
local set_style = require('Module:Common/Utility.lua').set_style
local getArgs = require('Module:Arguments').getArgs
local versions = require('Module:Common/Utility.lua').versions
local floor = require('Module:Common/Utility.lua').floor
local get_category = require('Module:Common/Utility.lua').get_category
-- 导入映射表
p.event_types = require('Module:Common/Utility.lua').event_types
p.building_types = require('Module:Common/Utility.lua').building_types
p.component_templates_types = require('Module:Common/Utility.lua').component_templates_types
p.edicts_types = require('Module:Common/Utility.lua').edicts_types
p.unlock_types = require('Module:Common/Utility.lua').unlock_types


--style
p.tooltip_style = 'background:#222;padding:16px 32px 16px 32px;color:#fff;max-width:400px;list-style: none;font-size: 14px; border: 2px solid #14796c;'
p.tooltip_no_width_style = 'background:#222;padding:16px 32px 16px 32px;color:#fff;list-style: none;font-size: 14px; border: 2px solid #14796c;'
p.default_margin = 'margin-left:14px'
p.divide_line = '<div>--------------</div>'		-- 瑞典蠢驴的分割线

p.info_set = {
	['projection'] = {
		['key'] = 1, 
		['zhcn_name'] = 1,
		['en_name'] = 1,
		['main_category'] = 1,
		['sub_category'] = 1,
		['icon'] = 1,
		['icon_frame'] = 1,
		['blocker'] = 1,
		['important'] = 1,
		['version'] = 1,
		['_index'] = 1
	}
}

-- 可以显示浮层的部分
function p.tooltip(main_category, key, content, style)
	local tt_end = ''
	if style == 'inline' then
		tt_end = '" style="display:inline-block;position:relative">'
	else
		tt_end = '" style="display:inline-block;margin-bottom:12px">'
	end
	local tt_header = '<span class="huiji-tt" data-type="'..main_category..'" data-name="'..key..tt_end
	return tt_header..content..'</span>'
end

-- 文字链接部分
function p.item_tip(data)
	if data.hide_window == 'yes' then
		name = '隐藏事件'
	else
		name = data.zhcn_name
	end
	local link = 'Item:'..data.main_category..'/'..data.key
	local temp_name = set_style(name)
    i, j = string.find(temp_name, '%[%[')
    if i == nil then
    	return '[['..link..'|'..name..']]'
	elseif name == '£minerals30£energy30' then
    	temp_name = '£minerals[['..link..'|30]]£energy[['..link..'|30]]'
    elseif i == 1 then
    	temp_name = string.gsub(temp_name, '^(%[%[.-)|link=.-%]%](.*)', '%1|link='..link..']][['..link..'|%2]]')
    else
    	temp_name = string.gsub(temp_name, '^(.-)(%[%[.-)|link=.-%]%](.*)$', '[['..link..'|%1]]%2|link='..link..']][['..link..'|%3]]')
    end
	return temp_name
end

-- 查询数据
function p.query_data(key, key_type, namespace, sets, hidden_old)
	local result = get_data(key, key_type, namespace, sets, hidden_old)
	return result
end

-- 查询数量
function p.query_count(key, key_type, namespace)
	local result = count_data(key, key_type, namespace)
	return result
end

-- 格式化数据
function p.format_data(result, func)
	local html = mw.html.create()
	if #result ~= 1 then  
		local table_html = html:tag('table'):addClass('wikitable'):cssText("background:#222;padding:16px 32px 16px 32px;color:#fff;max-width:400px;list-style: none;font-size: 14px; border: 2px solid #14796c;")
		for _, data in ipairs(result) do
			table_html:tag('tr'):tag('td'):wikitext(set_style(func(data))):done()
		end
	elseif func == p.refined_common then
		if result[1].main_category == 'planet_classes' or result[1].main_category == 'events' then
			local local_html = html:wikitext(set_style(func(result[1]))):done()
		else
			local local_html = html:tag('div'):cssText("background:#222;padding:16px 32px 16px 32px;color:#fff;width:400px;list-style: none;font-size: 14px; border: 2px solid #14796c;"):wikitext(set_style(func(result[1]))):done()
		end
	else
		local local_html = html:tag('span'):cssText("font-size: 14px"):wikitext(set_style(func(result[1]))):done()
	end
	return tostring(html)
end

-- 图标+名称,Info3
function p.info_table(frame)
	local frame_args = getArgs(frame)
	local hidden_old = frame_args[3] or 'false'
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'building_paradise_dome'
	return p.func_info(key, key_type, 'Data:', p.info_set, hidden_old)
end

-- Info3模块查询
function p.func_info(key, key_type, namespace, sets, hidden_old)
	return p.func_info_result(p.query_data(key, key_type, namespace, sets, hidden_old))
end

function p.func_info_result(result)
	local html = mw.html.create()

	if #result ~= 1 then  
		local table_html = html:tag('table'):addClass('wikitable'):cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
		end
	else
		local local_html = html:wikitext(set_style(p.refined_info(result[1]))):done()
	end
	return tostring(html)
end

-- 详细数据,Item,展示页面
function p.item_detail(frame)
	local result = p.common_query(frame)
	cat = get_category(result)
	if cat  == -1 then
		return '错误:结果不唯一'
	end
	return '<p>相关页面:[['..cat ..']]</p>'..frame:preprocess(p.format_data(result, p.refined_common)..'[[Category:'..cat ..']]')
end

-- 详细数据,Common,鼠标提示
function p.common_detail(frame)
	local result = p.common_query(frame)
	return frame:preprocess(p.format_data(result, p.refined_common))
end

-- common和item的查询部分
function p.common_query(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'building_paradise_dome'
	return p.query_data(key, key_type, 'Data:')
end

-- 数据集合
function p.info_all(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or '2.2.4'
	local events = frame_args[2] or 'false'
	local result = p.query_data(key, 'version', 'Data:', p.info_set, true)
	local html = mw.html.create()

	if #result ~= 1 then
		local table_html = html:tag('table'):addClass('wikitable'):cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			condition = False
			if events == 'false' then
				condition = (data.main_category ~= 'Events')
			else
				condition = (data.main_category == 'Events')
			end
			if condition then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
			end
		end
	else
		local local_html = html:wikitext(set_style(p.refined_info(result[1]))):done()
	end
	return tostring(html)
end

-- 图标,Icon3
function p.icon_table(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'ethic_gestalt_consciousness'
	local result = p.query_data(key, key_type, 'Data:')
	return p.format_data(result, p.set_icon)
end

-- 新Icon3样式
function p.set_icon(data)
	local content = ''
	if data.main_category =='terraform' then
		content = '[[File:'
			..data.from_icon
			..'.png|24px|link=Item:'
			..data.main_category
			..'/'
			..data.key
			..']]→[[File:'
			..data.to_icon
			..'.png|24px|link=Item:'
			..data.main_category
			..'/'
			..data.key
			..']]'
	elseif data.main_category =='agendas' then
		content = p.image_default_link('Agenda', data)
	elseif data.main_category =='edicts' or data.main_category =='policies' then
		content = p.image_default_link('Menu_icon_policies_and_edicts', data)
	elseif data.main_category =='casus_belli' then
		content = p.image_default_link('Diplomacy_status_casus_belli_holder', data)
	elseif data.main_category =='war_goals' then
		content = p.image_default_link('Diplomacy_war', data)
	elseif data.main_category =='governments' then
		content = p.image_default_link('Tech_frontier_commissars', data)
	elseif data.main_category =='subjects' then
		content = p.image_default_link('Diplomacy_isvassal', data)
	elseif data.main_category =='personalities' then
		content = p.image_default_link('Tech_xeno_diplomacy', data)
	elseif data.main_category =='section_templates' then
		content = p.image_default_link('Ship_part_computer_default', data)
	elseif data.main_category =='ship_behaviors' then
		content = p.image_default_link('Ship_part_aura_targeting_grid', data)
	elseif data.main_category =='strategic_resources' then
		content = p.image_default_link((data.icon or data.key), data)
	else
		content = p.image_default_link((data.icon or data.key), data, 24)
		if data.main_category =='planet_modifiers' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('icon_frame_'..(data.icon_frame or '2'), data)
				..'</span>'
		elseif data.main_category =='ascension_perks' then
			content = content
				..'<span style="position:absolute;left:-4px;top:-2px">'
				..p.image_default_link('empire_flag_64_frame', data, 32)
				..'</span>'
		elseif data.main_category =='deposits' and data.blocker == 'yes' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('tile_blocked_frame_clearable', data)
				..'</span>'
		elseif data.main_category =='deposits' and data.important == 'yes' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('rare_frame', data)
				..'</span>'
		end
	end
	newstring = p.tooltip(data.main_category, data.key, content, 'inline')
	return newstring
end


-- 带默认链接的图片
function p.image_default_link(image_name, data, size)
	local default_link = data.main_category..'/'..data.key..'|'..data.zhcn_name
	return p.image_with_link(image_name, default_link, size)
end

-- 带链接的图片
function p.image_with_link(image_name, link, size)
	if not image_name then
		return ''	
	end
	local item_link = ''
	if link == '' then
		item_link = ''
	else
		item_link = 'Item:'..link
	end
	local size_part = ''
	if size then
		size_part = '|'..size..'px'
	else
		size_part = '|24px'
	end
	return '[[File:'
			..image_name
			..'.png'
			..size_part
			..'|link='
			..item_link
			..']]'
end

function p.yes_no(sub_data, yes_desc, no_desc, default_desc)
	if sub_data == 'yes' and yes_desc then
		return p.data_block(yes_desc)
	elseif sub_data == 'no' and no_desc then
		return p.data_block(no_desc)
	else
		return p.data_block(default_desc)
	end
end

function p.data_divide_block(content, title, yellow_value)
	if content and content ~= '' then
		return p.divide_line..p.data_block(content, title, yellow_value)
	else
		return ''
	end
end

function p.data_block_num(content, title, default_value)
	if not default_value then
		default_value = '0'
	end
	return '<div>§L'..title..':§!§Y'..(content or default_value)..'§!</div>'
end

function p.data_block_add(content, title, yellow_value)
	if not content then
		return ''
	end
	return p.data_block('+'..content, title, yellow_value)
end

-- 每一小块内容
function p.data_block(content, title, yellow_value)
	if (not content) or (content == '') then
		return ''
	end
	local formated_block = ''
	if type(content) ~= 'string' and type(content) ~= 'number' then
		content_list = ''
		for _, item in ipairs(content) do
			content_list = content_list..item..'<br />'
		end
		content = content_list
	end
	if yellow_value == 'inlinelist' then
		return '<div>§E'..title..':§!<div style="display: inline-grid">§Y'..content..'§!</div></div>'
	elseif yellow_value == 'inline' or tonumber(content) then
		return '<div>§E'..title..':§!§Y'..content..'§!</div>'
	elseif yellow_value then
		return formated_block..'<div>§E'..title..':§!</div><div style="'..p.default_margin..'">§Y'..content..'§!</div>'
	elseif title then
		return formated_block..'<div>§E'..title..':§!</div><div style="'..p.default_margin..'">'..content..'</div>'
	else
		return '<div>'..content..'</div>'
	end
end

-- 新Info3样式,以及新Common的头部
function p.refined_info(data, size)
	local has_english = size
	local newstring = ''
	local content = ''
	if data.main_category =='events' then
		local event_type = p.event_types[data.sub_category]
		if not event_type and data.sub_category then
			content = '§E'..data.sub_category..':§!'
		elseif not event_type then
			content = '§E事件:§!'
		else
			content = '§E'..event_type..':§!'
		end
	elseif data.main_category == 'agendas' then
		content = p.image_default_link('Agenda', data, size)
			..'<span style="margin-left:12px">§E议程:§!</span>'
	elseif data.main_category =='casus_belli' then
		content = p.image_default_link('Diplomacy_status_casus_belli_holder', data, size)
	elseif data.main_category =='edicts' or data.main_category =='policies' then
		content = p.image_default_link('Menu_icon_policies_and_edicts', data, size)
	elseif data.main_category =='war_goals' then
		content = p.image_default_link('Diplomacy_war', data, size)
	elseif data.main_category =='governments' 
		or data.main_category =='personalities' 
		or data.main_category =='section_templates'
		or data.main_category =='ship_behaviors' 
		or data.main_category =='subjects' 
		or data.main_category =='terraform' then
		-- doing nothing
	elseif data.main_category =='static_modifiers' then
		if data.icon then
			local icon = ''
			if data.icon == 'capital' then
				icon = 'pm_capital'
			else
				icon = (data.icon or data.key)
			end
			content = p.image_default_link(icon, data, size)
			if data.icon_frame then
				content = content
					..'<span style="position:absolute;left:0px;top:0px">'
					..p.image_default_link('icon_frame_'..data.icon_frame, data, size)
					..'</span>'
			end
		else
			size = -4
		end
	elseif data.main_category =='strategic_resources' then
		content = p.image_default_link((data.icon or data.key), data, 17)
	elseif data.main_category =='buildings' then
		local temp_size = size or 24
		content = '<span style="position:relative;left:-'..math.floor(temp_size / 6)..'px;top:0px">'
			..p.image_default_link((data.icon or data.key), data, size)
			..'</span>'
	else
		content = p.image_default_link((data.icon or data.key), data, size)
		if data.main_category =='planet_modifiers' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('icon_frame_'..(data.icon_frame or '2'), data, size)
				..'</span>'
		elseif data.main_category =='ascension_perks' then
			local temp_size = size or 24
			content = content
				..'<span style="position:absolute;left:-'..math.floor(temp_size / 6)..'px;top:-'..math.floor(temp_size / 12)..'px">'
				..p.image_default_link('empire_flag_64_frame', data, math.floor(temp_size * 4.0 / 3 + 0.5))
				..'</span>'
		elseif data.main_category =='deposits' and data.blocker == 'yes' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('tile_blocked_frame_clearable', data, size)
				..'</span>'
		elseif data.main_category =='deposits' and data.important == 'yes' then
			content = content
				..'<span style="position:absolute;left:0px;top:0px">'
				..p.image_default_link('rare_frame', data, size)
				..'</span>'
		end
	end

	if not has_english then	-- 无英文名,Info3
		content = content..p.item_tip(data)
	else	-- 有英文名,Common
		content = content..'<div style="display:inline-grid">'..p.item_tip(data)
		if data.slot and data.slot ~= '' then
			content = content
				..'<div style="display:inline;float:right">[[File:component_slot_'
				..string.lower(data.slot)
				..'.png|'
				..data.slot
				..'槽组件|link=]]</div>'
		end
		content = content..'§L'..data.en_name..'§!</div>'
	end
	newstring = p.tooltip(data.main_category, data.key, content, 'inline')
	return newstring
end

-- 内部查询,不限字段
function p.extend_query(data_query, key, range, title, divide)
	if not divide then
		divide = true
	end
	if not data_query then
		return ''
	end
	local query_range = ''
	if range then
		query_range = 'Data:'..range..'/'
	else
		query_range = 'Data:'
	end
	if type(data_query) == "string" then
		return p.data_block(p.func_info(data_query, key, query_range), title, divide)
	else
		local result_list = ''
		for _, item in ipairs(data_query) do
			result_list = result_list..p.func_info(item, key, query_range)..'<br />'
		end
		return p.data_block(result_list, title, divide)
	end
end

-- 内部查询
function p.intenal_query(data_query, range, title, divide)
	return p.extend_query(data_query, 'key', range, title, divide)
end

-- 前置科技
function p.prerequisite(data_prerequisites)
	return p.intenal_query(data_prerequisites, 'Technology', '前置科技')
end

-- 首字母大写
function p.firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end

-- 科技解锁
function p.unlock_list(data)
	data_list = ''
	if data.unlock then
		for key, value in pairs(data.unlock) do
			if key ~= 'technology' then
				name = p.unlock_types[key]
				if name then
					data_list = data_list..p.intenal_query(value, p.firstToUpper(key), name, 'inlinelist')
				end
			end
		end
	end
	return data_list
end

function p.list_to_div(data_list, title, separator)
	if data_list then
		local sub_data = ''
		for _,item in ipairs(data_list) do
			sub_data = sub_data..item..separator
		end
		return p.data_block(all_cats, title, 'inline')
	end
	return ''
end

--2.2版本的花费,维护,产出三连
function p.resources(data)
	local cost_tip = nil
	if data.cost_detail then
		cost_tip = data.cost_detail
		if data.construction_days then
			cost_tip = cost_tip..'£time'..data.construction_days
		elseif data.base_buildtime then
			cost_tip = cost_tip..'£time'..data.base_buildtime
		elseif data.build_time then
			cost_tip = cost_tip..'£time'..data.build_time
		elseif data.time then
			cost_tip = cost_tip..'£time'..data.time
		end
	end
	return p.data_block(cost_tip, '花费', 'inline')
		..p.data_block(data.upkeep_detail, '维护费', 'inline')
		..p.data_block(data.produces_detail, '产出', 'inline')
end

-- 新Common样式
function p.refined_common(data)
	local newstring = ''
	local has_detail = true
	if data.main_category == 'agendas' then
		newstring = p.refined_info(data, 24)
			..p.data_block(data.zhcn_modifier)
	elseif data.main_category == 'armies' then
		newstring = p.refined_info(data, 34)
			..p.resources(data)
			..p.data_block((data.min_damage or '0.00')..'-'..(data.max_damage or '0.00'), '伤害', 'inline')
		if data.has_morale ~= 'no' then
			newstring = newstring..p.data_block(data.min_morale_damage..'-'..data.max_morale_damage, '士气伤害', 'inline')
		end
		if data.collateral and data.collateral ~= '0' then
			newstring = newstring..p.data_block(data.collateral, '附加伤害', 'inline')
		end
		newstring = newstring..p.data_block(data.max_health, '生命值', 'inline')
		if data.has_morale ~= 'no' then
			newstring = newstring..p.data_block(data.max_morale, '士气', 'inline')
		else
			newstring = newstring..p.data_block('§G这种部队没有士气值且不受士气伤害影响。§!')
		end
		newstring = newstring..p.data_block(data.war_exhaustion, '被击杀获得厌战度', 'inline')
			..p.yes_no(data.defensive, '§G防御部队§!', nil, nil)
			..p.yes_no(data.is_pop_spawned, '§G根据人口由建筑生成的部队§!', nil, nil)
			..p.yes_no(data.has_species, '§G有种族(会受到特质加成)§!', '§R没有种族(不会受到特质影响)§!', nil)
			..p.prerequisite(data.prerequisites)
			..p.yes_no(data.pop_limited, nil, '§G不受人口数量限制§!', nil)
			..p.yes_no(data.rebel, '§G是叛军§!', nil, nil)
			..p.yes_no(data.occupation, '§G是占领军§!', nil, nil)
			..p.data_block(data.on_queued_logic, '建造时')
			..p.data_block(data.on_unqueued_logic, '取消建造时')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'ascension_perks' then
		newstring = p.refined_info(data, 52)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_modifier, '效果')
	elseif data.main_category == 'bombardment_stances' then
		newstring = p.refined_info(data, 44)
			..p.data_block(data.zhcn_desc)
			..p.divide_line
			..p.yes_no(data.default, '§G默认姿态§!', nil, nil)
			..p.yes_no(data.stop_when_armies_dead, '§G陆军死亡时停止轰炸§!', '§R陆军死亡时不停止轰炸§!', nil)
			..p.yes_no(data.abduct_pops, '§G劫掠人口§!', nil, nil)
			..p.data_block(data.planet_damage, '对星球防御伤害修正', 'inline')
			..p.data_block(data.army_damage, '对陆军伤害修正', 'inline')
			..p.data_block(data.kill_pop_chance, '击杀人口概率修正', 'inline')
			..p.data_block(data.min_pops_to_kill_pop, '击杀人口所需最小人口数量', 'inline')
			..p.data_divide_block(data.trigger_logic, '允许开启条件')
	elseif data.main_category == 'buildings' then
		newstring = p.refined_info(data, 98)
			..p.resources(data)
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.data_block(data.zhcn_planet_modifier, '星球修正')
			..p.data_block(data.zhcn_army_modifier, '陆军修正')
			..p.prerequisite(data.prerequisites)
			..p.intenal_query(data.upgrades, 'Buildings', '可用升级')
			..p.data_block(p.building_types[data.category], '建筑分类', 'inline')
			..p.yes_no(data.capital, '§G星球首都建筑§!', nil, nil)
			..p.yes_no(data.branch_office_building, '§G分公司建筑§!', nil, nil)
			..p.data_block(data.base_cap_amount, '基础上限')
			..p.intenal_query(data.convert_to, 'Buildings', '在不支持该建筑的国家转化为')
			..p.yes_no(data.can_build, '§G可建造§!', '§R不可建造§!', nil)
			..p.yes_no(data.can_demolish, '§G可拆除§!', '§R不可拆除§!', nil)
			..p.yes_no(data.can_be_ruined, nil, '§R不可被摧毁§!', '§G可被摧毁§!')
			..p.yes_no(data.can_be_disabled, nil, '§R不可禁用§!', '§G可禁用§!')
			..p.yes_no(data.add_to_first_building_slot, '§G添加至第一建筑槽位§!', nil, nil)
			..p.yes_no(data.planetary_ftl_inhibitor, '§G提供超光速屏蔽§!', nil, nil)
			..p.yes_no(data.is_capped_by_modifier, '§G数量上限由星球特征决定§!', nil, nil)
			..p.data_block(data.resources_logic, '额外资源产出')
			..p.data_block(data.triggered_planet_modifier_logic, '额外星球修正')
			..p.data_block(data.triggered_desc_logic, '额外描述')
			..p.data_block(data.ai_resource_production_logic, 'AI资源产出')
			..p.data_block(data.on_queued_logic, '加入建造队列时')
			..p.data_block(data.on_unqueued_logic, '从建造队列种移除时')
			..p.data_block(data.on_built_logic, '建造时')
			..p.data_block(data.on_destroy_logic, '摧毁时')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'casus_belli' then
		newstring = p.refined_info(data, 44)
			..data.zhcn_desc
			..p.divide_line
			..p.intenal_query(data.war_goals, 'War_goals', '战争目标')
			..p.yes_no(data.show_in_diplomacy, '§G在外交中显示§!', '§R在外交中不显示§!', nil)
			..p.yes_no(data.show_notification, '§G显示通知§!', '§R不显示通知§!', nil)
	elseif data.main_category == 'component_templates' then
		newstring = p.refined_info(data, 58)
			..p.data_divide_block(data.zhcn_desc)
			..'<br />'
		if data.power > 0 then
			newstring = newstring..p.data_block(data.power, '能源产出', 'inline')
		elseif data.power < 0 then
			newstring = newstring..p.data_block(data.power, '能源消耗', 'inline')
		end
		newstring = newstring..p.resources(data)
			..p.data_block(p.component_templates_types[data.category], '组件分类', 'inline')
		if data.weapon_type then
			if data.weapon_type == 'instant' then
				newstring = newstring..p.data_block('§G即时§!', '类型', 'inline')
			elseif data.weapon_type == 'point_defence' then
				newstring = newstring..p.data_block('§G点防御§!', '类型', 'inline')
			end
		end
		if data.type then
			if data.type == 'instant' then
				newstring = newstring..p.data_block('§G即时§!', '类型', 'inline')
			elseif data.type == 'missile' then
				newstring = newstring..p.data_block('§G导弹§!', '类型', 'inline')
			elseif data.type == 'planet_killer' then
				newstring = newstring..p.data_block('§G行星终结者§!', '类型', 'inline')
			elseif data.type == 'point_defence' then
				newstring = newstring..p.data_block('§G点防御§!', '类型', 'inline')
			end
		end
		if data.category == 'weapon' then
			cooldown = 0.0
			newstring = newstring..p.data_block(data.zhcn_instruction, '类型', 'inline')
				..p.data_block(data.min_damage..'-'..data.max_damage, '伤害', 'inline')
			if data.count then
				newstring = newstring..p.data_block('('..data.regeneration_per_day..'/ £resource_time )', '数量', 'inline')
			end
			if data.max_windup then
				if data.max_windup == 0 and data.min_windup ~=0 then
					cooldown = data.cooldown + data.min_windup
					newstring = newstring
						..p.data_block(data.min_windup..'£time ', '充能时间', 'inline')
						..p.data_block(data.cooldown..'£time ', '开火时间', 'inline')
						..p.data_block(cooldown..'£time ', '总时间', 'inline')
				else
					cooldown = (data.cooldown + (data.min_windup + data.max_windup) / 2.0) / 10
					newstring = newstring
						..p.data_block((data.cooldown / 10.0)..'£time ', '基础冷却', 'inline')
						..p.data_block((data.min_windup/ 10.0)..'-'..(data.max_windup/ 10.0)..'£time ', '准备时间', 'inline')
						..p.data_block(cooldown..'£time ', '平均冷却时间', 'inline')
				end
			end
			if data.max_damage and data.max_damage ~= 0 then
				if data.accuracy then
					newstring = newstring..p.data_block((data.accuracy * 100)..'%', '命中', 'inline')
				end
				if data.tracking then
					newstring = newstring..p.data_block((data.tracking * 100)..'%', '索敌', 'inline')
				end
				if data.range then
					newstring = newstring..p.data_block(data.range, '射程', 'inline')
				end
			end
			newstring = newstring..p.data_block(data.health, '船体值', 'inline')
				..p.data_block(data.shield, '护盾', 'inline')
				..p.data_block(data.armor, '护甲', 'inline')
				..p.data_block(data.evasion, '闪避', 'inline')
				..p.data_block(data.speed, '速度', 'inline')
				..p.data_block(data.attack_range, '舰载机起飞距离', 'inline')
				..p.data_block(data.launch_time, '舰载机发射时间', 'inline')
				..p.data_block(data.rotation_speed, '舰载机转身速度', 'inline')
				..p.data_block(data.acceleration, '舰载机加速度', 'inline')
			if data.max_damage then
				if data.max_windup >= data.min_windup then
					newstring = newstring..p.data_block(((data.min_damage + data.max_damage) / 2.0 / cooldown * data.accuracy)..'£time ', '平均伤害', 'inline')
				end
			end
			newstring = newstring
				..p.data_block(data.min_range, '最小距离', 'inline')
				..p.data_block(data.firing_arc, '开火角度', 'inline')
			if data.missile_health and data.missile_health ~=0 then
				newstring = newstring..p.data_block(
						p.data_block(data.missile_health, '船体值', 'inline')
						..p.data_block(data.missile_shield, '护盾', 'inline')
						..p.data_block(data.missile_armor, '护甲', 'inline')
						..p.data_block(data.missile_evasion, '闪避', 'inline')
						..p.data_block(data.missile_speed, '速度', 'inline')
						..p.data_block(data.missile_retarget_range, '重定向范围', 'inline')
					, '导弹')
			end
			if data.max_damage and data.max_damage ~= 0 then
				newstring = newstring..'<br />'
				if data.shield_penetration and data.shield_penetration ~= 0 then
					newstring = newstring..p.data_block('§G+'..(data.shield_penetration * 100)..'%护盾穿透§!')
				end
				if data.shield_damage then
					if data.shield_damage > 1 then
						newstring = newstring..p.data_block('§G+'..((data.shield_damage - 1) * 100)..'%护盾伤害§!')
					elseif data.shield_damage < 1 then
						newstring = newstring..p.data_block('§R-'..((1 - data.shield_damage) * 100)..'%护盾伤害§!')
					end
				end
				if data.armor_penetration and data.armor_penetration ~= 0 then
					newstring = newstring..p.data_block('§G+'..(data.armor_penetration * 100)..'%护甲穿透§!')
				end
				if data.armor_damage then
					if data.armor_damage > 1 then
						newstring = newstring..p.data_block('§G+'..((data.armor_damage - 1) * 100)..'%护甲伤害§!')
					elseif data.armor_damage < 1 then
						newstring = newstring..p.data_block('§R-'..((1 - data.armor_damage) * 100)..'%护甲伤害§!')
					end
				end
				if data.hull_damage then
					if data.hull_damage > 1 then
						newstring = newstring..p.data_block('§G+'..((data.hull_damage - 1) * 100)..'%船体伤害§!')
					elseif data.hull_damage < 1 then
						newstring = newstring..p.data_block('§R-'..((1 - data.hull_damage) * 100)..'%船体伤害§!')
					end
				end
			end
			newstring = newstring..'<br />'
				..p.yes_no(data.static_rotation, '§R不能自行转向,只能随船体转向§!', nil, nil)
				..p.yes_no(data.prio_projectile, '§G高优先级弹道§!', nil, nil)
				..p.data_block(data.ai_task, 'AI任务', 'inline')
				..p.data_block(data.entity, '炮台模型', 'inline')
				..p.data_block(data.projectile_gfx, '弹道模型', 'inline')
				..p.data_block(data.planet_destruction_gfx, '星球摧毁动画', 'inline')
				..p.data_block(data.ai_tag_weight, 'AI分类权重', 'inline')
				..'<br />'
		else
			newstring = newstring..p.data_block(data.zhcn_ship_modifier)
				..p.data_block(data.zhcn_modifier)
				..p.data_block(data.sensor_range, '探测距离', 'inline')
				..p.data_block(data.hyperlane_range, '超空间探测距离', 'inline')
				..p.yes_no(data.ftl, '§G超光速组件§!', nil, nil)
				..p.yes_no(data.jumpdrive, '§G跃迁引擎组件§!', nil, nil)
				..p.yes_no(data.should_ai_use, nil, '§GAI不会选择该组件§!', nil)
				..p.yes_no(data.ftl_inhibitor, '§G超光速抑制装置§!', nil, nil)
			if data.friendly_aura == 'yes' then
				newstring = newstring..p.data_block(data.friendly_aura.zhcn_modifier, data.friendly_aura.zhcn_name)
			end
			if data.hostile_aura == 'yes' then
				newstring = newstring..p.data_block(data.hostile_aura.zhcn_modifier, data.hostile_aura.zhcn_name)
			end
		end
		local behaviour = nil
		if data.ship_behavior then
			behaviour = 'ship_behavior_'..data.ship_behavior
		end
		newstring = newstring..p.prerequisite(data.prerequisites)
			..p.data_block(data.zhcn_class_restriction, '舰船类型限制', 'inline')
			..p.intenal_query(data.size_restriction, 'Ship_sizes', '舰船限制')
			..p.intenal_query(data.upgrades_to, 'Component_templates', '可用升级')
			..p.intenal_query(behaviour, 'Ship_behaviors', '舰船行为')
			..p.yes_no(data.hidden, '§R隐藏组件(无法在舰船设计器中使用)§!', nil, nil)
	elseif data.main_category == 'deposits' then	
		local type_desc = nil
		if data.blocker == 'yes' then
			type_desc = '§Y障碍§!'
		end
		newstring = p.refined_info(data, 98)
			..p.data_block(type_desc)
			..p.resources(data)
			..p.data_block(data.zhcn_planet_modifier)
			..p.data_block(data.triggered_planet_modifier_logic, '额外星球修正')
			..p.intenal_query(data.blocker_swap_types, 'Deposits', '清除后替换为')
			..p.intenal_query(data.terraforming_swap_types, 'Deposits', '环境改造后替换为')
			..p.intenal_query(data.prerequisites, 'Technology', '清除障碍所需前置科技')
			..p.extend_query(data.station, 'class', 'Ship_sizes', '采集资源所需轨道站')
			..p.yes_no(data.should_swap_deposit_on_terraforming, '§G环境改造后会替换矿脉§!', nil, nil)
			..p.yes_no(data.use_weights_for_terraforming_swap_types, '§G环境改造后使用矿脉替换权重§!', nil, nil)
			..p.yes_no(data.is_null, '§R空矿脉(仅用于计算,不生成实体)§!', nil, nil)
			..p.yes_no(data.is_for_colonizeable, '§G可在宜居星球上生成§!', nil, nil)
			..p.yes_no(data.important, '§G是重要矿脉§!', nil, nil)
			..p.yes_no(data.use_for_min_max_adjustments, '§G用于调整区划上限数量§!', nil, nil)
			..p.yes_no(data.all_blocker_swap_types, '§R是障碍替换类型§!', nil, nil)
			..p.yes_no(data.use_weights_for_blocker_swap_types, '§R使用障碍替换权重§!', nil, nil)
			..p.data_divide_block(data.zhcn_desc)
			..p.data_block(data.on_cleared_logic, '障碍清除之后')
			..p.data_divide_block(can_be_cleared_logic, '满足条件后可清除')
			..p.data_divide_block(data.drop_weight_logic, '生成权重')
	elseif data.main_category == 'districts' then
		newstring = p.refined_info(data, 77)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_modifier, '效果')
			..p.resources(data)
			..p.data_block(data.min_for_deposits_on_planet , '星球最小矿脉数', 'inline')
			..p.data_block(data.max_for_deposits_on_planet , '星球最大矿脉数', 'inline')
			..p.prerequisite(data.prerequisites)
			..p.intenal_query(data.convert_to, 'Districts', '在不支持该区划的星球上转化为')
			..p.data_block(data.conversion_ratio , '转化率', 'inline')
			..p.yes_no(data.is_capped_by_modifier, nil, '§G区划数量不受修正影响§!', '§R区划数量受修正影响§!')
			..p.data_block(data.show_on_uncolonized_logic, '未殖民显示条件')
			..p.data_block(data.triggered_planet_modifier_logic, '额外星球修正')
			..p.data_block(data.ai_resource_production_logic, 'AI资源产出')
	elseif data.main_category == 'edicts' then
		local duration = ''
		if data.length ~= '0' then
			day = tonumber(data.length)
			month, day = math.modf(day/30)
			year, month = math.modf(month/12)
			duration = '持续'
			if year ~= 0 then
				duration = duration..'§H'..tostring(year)..'§!年'
			end
			if month ~= 0 then
				duration = duration..'§H'..tostring(month)..'§!月'
			end
			if day ~= 0 then
				duration = duration..'§H'..tostring(day)..'§!日'
			end
			duration = duration
		end
		newstring = p.refined_info(data, 33)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_modifier, '效果', true)
			..p.data_block(duration)
			..p.data_block(data.zhcn_cost)
			..p.data_block(p.edicts_types[data.category])
			..p.yes_no(data.is_ambition, '§G野望法案§!', nil, nil)
			..p.prerequisite(data.prerequisites)
	elseif data.main_category == 'ethics' then
		newstring = p.refined_info(data, 29)
			..p.data_block(data.instruction)
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.data_block(data.cost, '花费', 'inline')
			..p.data_divide_block(data.pop_attraction_tag_logic, '人口吸引修正描述')
			..p.data_divide_block(data.pop_attraction_logic, '人口吸引修正')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'governments' then
		newstring = p.refined_info(data, -4)
			..p.data_block(data.zhcn_desc)
			..p.divide_line
		if data.ruler_title_desc then
			if data.ruler_title_female_desc then
				newstring = newstring..p.data_block(data.ruler_title_desc, '统治者头衔(♂)', 'inline')
			else
				newstring = newstring..p.data_block(data.ruler_title_desc, '统治者头衔', 'inline')
			end
		end
		newstring = newstring..p.data_block(data.ruler_title_female_desc, '统治者头衔(♀)', 'inline')
		if data.heir_title_desc then
			if data.ruler_title_female_desc then
				newstring = newstring..p.data_block(data.heir_title_desc, '继承人头衔(♂)', 'inline')
			else
				newstring = newstring..p.data_block(data.heir_title_desc, '继承人头衔', 'inline')
			end
		end
		newstring = newstring..p.data_block(data.heir_title_female_desc, '继承人头衔(♀)', 'inline')
			..p.data_block(data.leader_class_desc, '统治者阶级', 'inline')
			..p.yes_no(data.use_regnal_names, '§G使用帝王名字§!', nil, nil)
			..p.yes_no(data.dynastic_last_names, '§G使用王朝姓氏§!', nil, nil)
			..p.yes_no(data.should_force_rename, '§G系统强制改名§!', nil, nil)
			..p.data_divide_block(data.election_candidates_logic, '参选权重')
	elseif data.main_category == 'authorities' then
		local sub_trait = nil
		if data.traits and data.traits.trait then
			sub_trait = data.traits.trait
		end
		newstring = p.refined_info(data, 44)
			..p.data_block(data.instruction)
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.intenal_query(sub_trait, 'Traits', '对应特质')
			..p.data_divide_block(data.desc_detail, '效果')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'civics' then
		local sub_trait = nil
		if data.traits and data.traits.trait then
			sub_trait = data.traits.trait
		end
		newstring = p.refined_info(data, 29)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_modifier, '效果')
			..p.intenal_query(sub_trait, 'Traits', '对应特质')
			..p.intenal_query(data.homeworld, 'Planet_classes', '母星类型')
			..p.yes_no(data.modification, nil, '§R这个国家理念在游戏开始后不能被添加。§!', nil)
			..p.yes_no(data.moddable, nil, '§R这个国家理念在游戏开始后不能被删除。§!', nil)
	elseif data.main_category == 'megastructures' then
		newstring = p.refined_info(data, 52)--要不要做个蠢驴UI?
			..p.data_block(data.zhcn_desc)
			..p.resources(data)
			..p.data_block(data.megastructure_details, '建造提示')
			..p.data_block(data.construction_info_delayed, '建造信息')
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.data_block(data.sensor_range, '传感距离', 'inline')
			..p.data_block(data.hyperlane_range, '超空间探测距离', 'inline')
		if data.upgrade_desc == 'hide' then
			newstring = newstring..p.data_block('§G隐藏升级提示(系统对其升级进行特殊处理)§!')
		end
		newstring = newstring..p.intenal_query(data.upgrade, 'Megastructures', '可用升级')
			..p.intenal_query(data.upgrade_from, 'Megastructures', '升级自')
			..p.data_block(data.construction_entity, '建造时的模型')
			..p.data_block(data.zhcn_offset, '模型偏移量')
			..p.data_block(data.entity, '模型')
			..p.yes_no(data.place_entity_on_planet_plane, '§G模型放在星球平面上§!', '§R模型不放在星球平面上§!', nil)
			..p.yes_no(data.place_entity_on_planet_plane, '§G模型放在星球平面上§!', nil, nil)
			..p.yes_no(data.build_outside_gravity_well, '§R不能建造在星系的重力井内§!', nil, nil)
			..p.yes_no(data.show_galactic_map_icon, nil, '§R不显示银河地图图标§!', nil)
			..p.yes_no(data.construction_blocks_others, nil, '§G建造时不影响建造或升级其他巨型建筑§!', nil)
		if data.bypass_type == 'gateway' then
			newstring = newstring..p.data_block('星门', '通行方式')
		elseif data.bypass_type == 'lgate' then
			newstring = newstring..p.data_block('L星门', '通行方式')
		end
		newstring = newstring..p.divide_line
			..p.data_block(data.placement_rules_logic, '放置规则')
			..p.data_block(data.on_build_start_logic, '开始建造事件')
			..p.data_block(data.on_build_cancel_logic, '取消建造事件')
			..p.data_block(data.on_build_complete_logic, '建造完毕事件')
	elseif data.main_category == 'personalities' then
		local attr_modifier = p.data_block_num(data.aggressiveness, '侵略性')
			..p.data_block_num(data.trade_willingness, '贸易意愿')
			..p.data_block_num(data.bravery, '勇气')
			..p.data_block_num(data.combat_bravery, '战斗勇气')
			..p.data_block_num(data.military_spending, '军事开销')
			..p.data_block_num(data.colony_spending, '殖民开销')
			..p.data_block_num(data.threat_modifier, '威胁修正')
			..p.data_block_num(data.threat_others_modifier, '威胁其他人修正')
			..p.data_block_num(data.friction_modifier, '边境摩擦修正')
			..p.data_block_num(data.claims_modifier, '宣称修正')
			..p.data_block_num(data.advanced_start_chance, '优势开局几率')
		local diplo_modifier = p.data_block_num(data.nap_acceptance, '互不侵犯条约接受度')
			..p.data_block_num(data.commercial_pact_acceptance, '商业协议接受度')
			..p.data_block_num(data.research_agreement_acceptance, '科研协议接受度')
			..p.data_block_num(data.defensive_pact_acceptance, '共同防御条约接受度')
			..p.data_block_num(data.federation_acceptance, '联邦接受度')
			..p.data_block_num(data.migration_pact_acceptance, '移民条约接受度')
		local choice_modifier = ''
		if data.zhcn_weapon then
			choice_modifier = p.data_block_num(data.zhcn_weapon, '武器偏好', '采用特殊设计')
				..p.data_block_num(data.shields_ratio, '护盾比重')
				..p.data_block_num(data.armor_ratio, '装甲比重')
				..p.data_block_num(data.hull_ratio, '船体比重')
		else
			choice_modifier = '<div>采用特殊全局舰船设计(§GGlobal Ship Design§!)</div>'
		end
		newstring = p.refined_info(data, -4)
			..p.data_block(data.zhcn_desc)
			..'§L'..p.data_block(data.zhcn_behaviour, '行为模式')..'§!'
			..p.data_divide_block(attr_modifier, '属性修正')
			..p.data_divide_block(diplo_modifier, '外交修正')
			..p.data_divide_block(choice_modifier, '舰船选择修正')
	elseif data.main_category == 'planet_classes' then
		has_detail = false
		newstring = p.refined_info(data, 24)
			..p.data_block('数据重新处理中')
		-- 	'<div style="padding:0px 0px 0px 0px;color:#fff;width:566px;height:620px;list-style: none;font-size: 14px; border: 0px solid #14796c;position:relative;overflow:hidden">'
		-- 	..'<div style="position:absolute;left:0px;top:-46px;display:inline">[[文件:'
		-- 	..(data.picture or data.key)
		-- 	..'_sky_view.png|link=Item:'
		-- 	..data.main_category
		-- 	..'/'
		-- 	..data.key
		-- 	..']]</div><div style="position:absolute;left:0px;top:-46px;display:inline">[[文件:planet_view_box.png|link=Item:'
		-- 	..data.main_category
		-- 	..'/'
		-- 	..data.key
		-- 	..']]'
		-- 	..'<div style="position:absolute;left:23px;top:50px">'
		-- 	..'<div class="huiji-tt" data-type="planet_classes" data-name="'
		-- 	..data.key
		-- 	..'" style="display:inline">[[文件:'
		-- 	..(data.icon or data.key)
		-- 	..'.png|'
		-- 	..data.zhcn_name
		-- 	..'|29px|link=Item:'
		-- 	..data.main_category
		-- 	..'/'
		-- 	..data.key
		-- 	..']]<span style="margin-left:12px">'
		-- 	..p.item_tip(data)
		-- 	..'('
		-- 	..data.en_name
		-- 	..')</span></div>'
		-- 	..'<div style="position:absolute;left:-10px;top:240px;display:inline;height:35px;width:190px">'
		-- 	..'<div style="text-align:center">'
		-- if data.star == 'yes' then
		-- 	newstring = newstring..'恒星'
		-- elseif data.colonizable == 'yes' then
		-- 	if data.ideal == 'yes' then
		-- 		if data.ringworld == 'yes' then
		-- 			newstring = newstring..'§B理想宜居环世界§!'
		-- 		elseif data.habitat == 'yes' then
		-- 			newstring = newstring..'§B理想宜居栖息地§!'
		-- 		else
		-- 			newstring = newstring..'§B理想可宜居星球§!'
		-- 		end
		-- 	else
		-- 		newstring = newstring..'§G可宜居星球§!'
		-- 		if data.climate_desc then
		-- 			newstring = newstring..data.climate_desc
		-- 		end
		-- 	end
		-- else
		-- 	if data.ringworld == 'yes' then
		-- 		newstring = newstring..'§H不可居住环世界§!'
		-- 	elseif data.habitat == 'yes' then
		-- 		newstring = newstring..'§H不可居住栖息地§!'
		-- 	else
		-- 		newstring = newstring..'§H不可居住星球§!'
		-- 	end
		-- end
		-- newstring = newstring..'</div></div>'
		-- if data.atmosphere_color then
		-- 	newstring = newstring
		-- 	..'<div style="position:absolute;left:-10px;top:282px;display:inline;height:35px;width:190px">'
		-- 	..'<div style="text-align:center">大气颜色:#'
		-- 	..data.atmosphere_color
		-- 	..'</div></div>'
		-- end
		-- if data.habitable_odds then
		-- 	newstring = newstring
		-- 	..'<div style="position:absolute;left:-10px;top:324px;display:inline;height:35px;width:190px">'
		-- 	..'<div style="text-align:center">'
		-- 	..data.habitable_odds
		-- 	..'</div></div>'
		-- end
		-- newstring = newstring
		-- 	..'<div style="position:absolute;left:349px;top:240px;width:170px">'
		-- 	..data.desc_detail
		-- 	..'</div><div style="position:absolute;left:24px;top:370px;width:470px">'
		-- 	..data.zhcn_desc
	 
		-- newstring = newstring..'</div></div></div>'
	elseif data.main_category == 'planet_modifiers' or data.main_category == 'static_modifiers' then
		newstring = p.refined_info(data, 60)
			..p.data_block(data.zhcn_modifier)
			..p.data_divide_block(data.zhcn_desc)
			..p.data_divide_block(data.spawn_chance_logic, '出现概率')
			..p.intenal_query(data.apply_modifier_to_other_planets, 'Static_modifiers', '其他星球获得效果')
	elseif data.main_category == 'policies' then
		newstring = p.refined_info(data, 33)
			..p.data_block(data.zhcn_desc)
		if data.option then
			for _,options in ipairs(data.option) do
				newstring = newstring
					..p.divide_line
					..'<div>[[File:Radio_button_normal.png|选项|28px|link=]]'
					..'§E'
					..options.zhcn_name
					..'§!<div style="padding:0px 0px 0px 32px">§L'
					..options.en_name
					..'§!</div>'
					..options.zhcn_desc
					..'</div>'
					..p.data_block(options.zhcn_modifier)
					..p.data_block(options.policy_flags, '政策标识')
					..p.data_block(options.valid_logic, '条件')
					..p.data_block(options.AI_weight_logic, 'AI权重')
					..p.prerequisite(options.prerequisites)
					..p.data_block(options.on_enabled_logic, '开启条件')
					..p.data_block(options.on_disabled_logic, '禁用条件')
					..p.data_block(options.potential_logic, '基础要求')
			end
		end
	elseif data.main_category =='pop_categories' then
		local allow_resettlements = data.allow_resettlement
		if allow_resettlements then
			allow_resettlements = allow_resettlements.always
		end
		display_cat = data.display_category
		if display_cat then
			display_cat	= 'pop_cat_'..display_cat
		end
		newstring = p.refined_info(data, 28)
			..p.resources(data)
			..p.data_block(data.zhcn_pop_modifier, '人口修正')
			..p.data_block(data.rank, '阶级', 'inline')
			..p.intenal_query(display_cat, 'Pop_categories', '显示分类', 'inline')
			..p.data_block(data.demotion_time, '人口降级时间', 'inline')
			..p.data_block(data.clothes_texture_index, '服装序号', 'inline')
			..p.data_block(data.change_job_threshold, '岗位权重值', 'inline') -- 驴:A job must have this much higher weight in order for a pop to switch to it from their current job
			..p.yes_no(data.keep_from_former_job, '§G离开原岗位§!', nil, nil)
			..p.yes_no(allow_resettlements, '§G始终可以强制迁移§!', '§G始终不能强制迁移§!', nil)
			..p.data_block(data.resettlement_detail, '强制迁移花费', 'inline')
			..p.data_block(data.purge, '净化类型', 'inline') -- TODO: 加入species_rights后删除本行
			..p.intenal_query(data.purge, 'Species_rights', '净化类型', 'inline')
			..p.data_block(data.should_apply_unemployment_penalties_logic, '应用惩罚的条件')
			..p.data_block(data.zhcn_unemployment_penalties, '失业惩罚')
			..p.data_block(data.unemployment_resources_logic, '失业资源')
			..p.data_block(data.triggered_planet_modifier_logic, '额外星球修正')
			..p.data_block(data.resources_logic, '额外资源产出')
			..p.data_block(data.assign_to_pop_logic, '分类存在的条件')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'pop_faction_types' then
		newstring = p.refined_info(data, 64)
			..p.data_block(data.zhcn_desc)
			..p.intenal_query(data.guiding_ethic, 'Ethics', '指引思潮', 'inline')
			..p.data_block(data.support_multiplier, '支持率系数', 'inline')
			..p.resources(data)
			..p.yes_no(data.unique, '§G派系唯一§!', nil, nil)
		if data.demand then
			local all_demands = ''
			for _, demand in ipairs(data.demand) do
				all_demands = all_demands
				local demand_data = p.data_block(demand.zhcn_name, '满足诉求时的名称', 'inline')
					..p.data_block(demand.un_name, '不满足诉求时的名称', 'inline')
					..p.data_block(demand.desc)
					..p.data_block('§G+'..(demand.fulfilled_effect or '0')..'%§!', '满足要求时派系幸福度', 'inline')
					..p.data_block('§R'..(demand.unfulfilled_effect or '0')..'%§!', '不满足要求时派系幸福度', 'inline')
					..p.data_block(demand.potential_logic, '基础要求')
					..p.data_block(demand.trigger_logic, '允许开启条件')
				all_demands = all_demands..p.data_block(demand_data)..p.divide_line
			end
			if string.len(all_demands) > string.len(p.divide_line) then 
				all_demands = string.sub(all_demands, 0, -1-string.len(p.divide_line))
			end
			newstring = newstring..p.data_divide_block(all_demands, '派系诉求')
		end
		if data.actions then
			local all_actions = ''
			for _, actions in ipairs(data.actions) do
				local action_data = p.data_block(actions.zhcn_cost, '消耗')
					..p.data_block(actions.potential_logic, '基础要求')
					..p.data_block(actions.valid_logic, '条件')
					..p.data_block(actions.effect_logic, '效果')
					..p.data_block(actions.ai_weight_logic, 'AI权重')
				all_actions = all_actions..p.data_block(action_data, actions.zhcn_name)..p.divide_line
			end
			if string.len(all_actions) > string.len(p.divide_line) then 
				all_actions = string.sub(all_actions, 0, -1-string.len(p.divide_line))
			end
			newstring = newstring..p.data_divide_block(all_actions, '管理派系') -- TODO:问题在哪?
		end
		newstring = newstring..p.data_divide_block(data.is_potential_logic, '允许开启条件')
			..p.data_divide_block(data.can_join_faction_logic, '加入派系要求')
			..p.data_divide_block(data.attraction_logic, '吸引力修正')
			..p.data_divide_block(data.leader_logic, '派系领导人判定修正')
			..p.data_divide_block(data.on_create_logic, '建立派系时')
			..p.data_divide_block(data.on_destroy_logic, '派系解散时')
	elseif data.main_category == 'pop_jobs' then
		display_cat = data.category
		if display_cat then
			display_cat	= 'pop_cat_'..display_cat
		end
		newstring = p.refined_info(data, 30)
			..p.resources(data)
			..p.data_block(data.zhcn_condition_string)
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.data_block(data.zhcn_planet_modifier, '星球修正')
			..p.data_block(data.zhcn_pop_modifier, '人口修正')
			..p.data_block(data.clothes_texture_index, '服装序号', 'inline')
			..p.intenal_query(display_cat, 'Pop_categories', '人口分类', 'inline')
			..p.data_block(p.image_with_link(data.building_icon, '', 98), '背景建筑图标')
			..p.yes_no(data.is_capped_by_modifier, '§G数量受修正影响§!', '§G数量不受修正影响§!', nil)
			..p.data_block(data.resources_logic, '额外资源产出')
			..p.yes_no(data.can_set_priority, nil, '§R不可设置优先级§!', nil)
			..p.yes_no(data.is_pre_sapient, '§G需要未开智物种§!', nil, nil)
			..p.data_block(data.purge, '净化类型', 'inline') -- TODO: 加入species_rights后删除本行
			..p.intenal_query(data.purge, 'Species_rights', '净化类型', 'inline')
			..p.data_block(data.triggered_country_modifier_logic, '额外国家修正')
			..p.data_block(data.triggered_planet_modifier_logic, '额外星球修正')
			..p.data_block(data.triggered_pop_modifier_logic, '额外人口修正')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'section_templates' then
		local slots = ''
		local u_slots = ''
		-- 武器
		if data.slot_count.P ~= 0 then
			slots = slots..'[[File:component_slot_p.png|点防|25px|link=]]'..data.slot_count.P
		end
		if data.slot_count.S ~= 0 then
			slots = slots..'[[File:component_slot_s.png|小型|25px|link=]]'..data.slot_count.S
		end
		if data.slot_count.G ~= 0 then
			slots = slots..'[[File:component_slot_g.png|制导|25px|link=]]'..data.slot_count.G
		end
		if data.slot_count.M ~= 0 then
			slots = slots..'[[File:component_slot_m.png|中型|25px|link=]]'..data.slot_count.M
		end
		if data.slot_count.L ~= 0 then
			slots = slots..'[[File:component_slot_l.png|大型|25px|link=]]'..data.slot_count.L
		end
		if data.slot_count.H ~= 0 then
			slots = slots..'[[File:component_slot_h.png|机库|25px|link=]]'..data.slot_count.H
		end
		if data.slot_count.X ~= 0 then
			slots = slots..'[[File:component_slot_x.png|巨型|25px|link=]]'..data.slot_count.X
		end
		if data.slot_count.T ~= 0 then
			slots = slots..'[[File:component_slot_t.png|泰坦|25px|link=]]'..data.slot_count.T
		end
		if data.slot_count.W ~= 0 then
			slots = slots..'[[File:component_slot_w.png|歼星|25px|link=]]'..data.slot_count.W
		end
		-- 通用
		if data.small_utility_slots and data.small_utility_slots ~= 0 then
			u_slots = u_slots..'[[文件:component_slot_s.png|小型|25px|link=]]'..data.small_utility_slots
		end
		if data.medium_utility_slots and data.medium_utility_slots ~= 0 then
			u_slots = u_slots..'[[文件:component_slot_m.png|中型|25px|link=]]'..data.medium_utility_slots
		end
		if data.large_utility_slots and data.large_utility_slots ~= 0 then
			u_slots = u_slots..'[[文件:component_slot_l.png|大型|25px|link=]]'..data.large_utility_slots
		end
		if data.aux_utility_slots and data.aux_utility_slots ~= 0 then
			u_slots = u_slots..'[[文件:component_slot_a.png|辅助|25px|link=]]'..data.aux_utility_slots
		end
		newstring = p.refined_info(data, -4)
			..p.data_block(slots, '武器槽位', 'inline')
			..p.data_block(u_slots, '通用槽位', 'inline')
			..p.intenal_query(data.ship_size, 'Ship_sizes', '适用舰船类型', 'inline')
			..p.list_to_div(data.fits_on_slot, '适用槽位', ' ')
			..p.resources(data)
			..p.prerequisite(data.prerequisites)
			..p.data_block(data.entity, '模型', 'inline')
			..p.yes_no(data.should_draw_components, '§G会显示模型§!', nil, nil)
	elseif data.main_category == 'ship_behaviors' then
		newstring = p.refined_info(data, -4)
			..p.data_block(data.zhcn_desc)
		if data.preferred_attack_range then
			local prefer_range = ''
			if data.preferred_attack_range == 'max' then
				prefer_range = '最大射程'
			elseif data.preferred_attack_range == 'median' then
				prefer_range = '中位射程'
			else
				prefer_range = data.preferred_attack_range
			end
			newstring = newstring..p.data_block(prefer_range, '最佳攻击距离', 'inline')
		end
		newstring = newstring..p.data_block(data.formation_distance, '编队距离', 'inline')
			..p.data_block(data.return_to_formation_distance, '返回编队距离', 'inline')
			..p.data_block(data.collision_radius, '碰撞半径', 'inline')
			..p.data_block(data.collision_strafe, '碰撞惩罚', 'inline')
			..p.data_block(data.collision_awareness, '碰撞意识', 'inline')
		if data.attack_move_pattern then
			local attack_pattern = ''
			if data.attack_move_pattern == 'none' then
				attack_pattern = '无'
			elseif data.attack_move_pattern == 'charge' then
				attack_pattern = '冲锋'
			elseif data.attack_move_pattern == 'orbit' then
				attack_pattern = '环绕'
			elseif data.attack_move_pattern == 'stay_at_range' then
				attack_pattern = '远程狙击'
			elseif data.attack_move_pattern == 'stationary' then
				attack_pattern = '固定'
			elseif data.attack_move_pattern == 'flee' then
				attack_pattern = '逃跑'
			else
				attack_pattern = data.attack_move_pattern
			end
			newstring = newstring..p.data_block(attack_pattern, '主动模式', 'inline')
		end
		if data.passive_move_pattern then
			local passive_pattern = ''
			if data.passive_move_pattern == 'none' then
				passive_pattern = '无'
			elseif data.passive_move_pattern == 'charge' then
				passive_pattern = '冲锋'
			elseif data.passive_move_pattern == 'orbit' then
				passive_pattern = '在轨'
			elseif data.passive_move_pattern == 'stay_at_range' then
				passive_pattern = '远程狙击'
			elseif data.passive_move_pattern == 'stationary' then
				passive_pattern = '固定'
			elseif data.passive_move_pattern == 'flee' then
				passive_pattern = '逃跑'
			else
				passive_pattern = data.passive_move_pattern
			end
			newstring = newstring..p.data_block(passive_pattern, '被动模式', 'inline')
		end
		if data.combat_target_anchor == 'root' then
			newstring = newstring..p.data_block('舰队旗舰', '战斗位置计算点', 'inline')
		end
		newstring = newstring..p.data_block(data.source_target_anchor_factor, '战斗距离系数', 'inline')
			..p.yes_no(data.ignore_combat_movement, '§G该模式将忽视战斗,继续之前的指令§!', nil, nil)
	elseif data.main_category == 'ship_sizes' then
		newstring = p.refined_info(data, 44)
			..p.data_block(data.zhcn_class, '分类', 'inline')
			..p.resources(data)
			..p.data_block(data.zhcn_desc)
		if data.class == 'shipclass_military' or data.class == 'shipclass_military_special' then
			newstring = newstring..p.data_block(data.size_multiplier, '[[File:fleet_size_icon.png|舰船大小|20px|link=]]舰船大小', 'inline')
		end
		local evasion = ''
		if data.modifier.ship_evasion_add then
			if data.modifier.ship_evasion_mult and data.modifier.ship_evasion_mult == -1 then
				evasion = '0%'
			else
				evasion = data.modifier.ship_evasion_add..'%'
			end
		end
		local modifier_dict = {}
		if data.modifier then
			modifier_dict = data.modifier
		end
		newstring = newstring
			..p.data_block(data.max_hitpoints, '[[File:hit_points.png|船体值|20px|link=]]基础船体值', 'inline')
			..p.data_block((modifier_dict.ship_armor_add or '0'), '[[File:armor.png|装甲|20px|link=]]基础装甲', 'inline')
			..p.data_block((modifier_dict.ship_shield_add or '0'), '[[File:shield.png|护盾|20px|link=]]基础护盾', 'inline')
			..p.data_block(data.max_speed, '[[File:speed.png|速度|20px|link=]]基础速度', 'inline')
			..p.data_block(evasion, '[[File:evasion.png|闪避|20px|link=]]基础闪避', 'inline')
			..p.data_block((data.acceleration or 0), '加速度', 'inline')
			..p.data_block((data.rotation_speed or 0), '转身速率', 'inline')
			..p.data_block((data.collision_radius or 0), '碰撞半径', 'inline')
			..p.data_block((data.zhcn_construction_type or '其他'), '建造类型', 'inline')
		local modifier_block = p.data_block('+'..(modifier_dict.ship_hull_regen_add_perc or '0')..'%', '每日船体再生', 'inline')
			..p.data_block('+'..(modifier_dict.ship_armor_regen_add_perc or '0')..'%', '每日护盾再生', 'inline')
			..p.data_block('+'..(modifier_dict.ship_shield_regen_add_static or '0')..'%', '碰撞半径', 'inline')
			..p.data_block('+'..(modifier_dict.ship_piracy_suppression_add or '0'), '对海盗的压制', 'inline')
			..p.data_block_add(modifier_dict.starbase_module_capacity_add, '恒星基地模组', 'inline')
			..p.data_block_add(modifier_dict.starbase_building_capacity_add, '恒星基地建筑', 'inline')
			..p.data_block_add(modifier_dict.starbase_defense_platform_capacity_add, '防御平台', 'inline')
			..p.data_block_add(modifier_dict.ship_shield_mult, '护盾承受值', 'inline')
			..p.data_block_add(modifier_dict.ship_weapon_damage, '武器伤害', 'inline')
			..p.data_block(((data.combat_disengage_chance or 0) * 100)..'%', '战斗逃脱几率修正', 'inline')
		local behaviour = nil
		if data.default_behavior then
			behaviour = 'ship_behavior_'..data.default_behavior
		end
		newstring = newstring..p.data_block(modifier_block, '修正')
			..p.data_block(data.zhcn_ship_modifier)
			..p.data_block(data.zhcn_section, '舰船区块')
			..p.data_block(data.zhcn_required_component_set, '需要组件')
			..p.prerequisite(data.prerequisites)
			..p.intenal_query(behaviour, 'Ship_behaviors', '默认行为', 'inline')
			..p.data_block(data.fleet_slot_size, '舰队槽位大小', 'inline')
			..p.data_block(data.num_target_locators, '目标定位数量', 'inline')
			..p.data_block(data.formation_priority, '编队优先级', 'inline')
			..p.data_block(data.combat_size_multiplier, '战斗尺寸', 'inline')
			..p.data_block(data.zhcn_limit, '建造上限')
			..p.data_block(data.possible_starbase_logic, '允许建造该型号舰船的恒星基地')
		if data.build_block_radius and data.build_block_radius ~= 0 then
			newstring = newstring..p.data_block('§Y'..data.build_block_radius..'§!半径内禁止建造其他建筑')
		end
		newstring = newstring..p.yes_no(data.can_disable, '§G常规战斗中,船体值为0时不会被摧毁而是陷入瘫痪状态§!', nil, nil)
			..p.yes_no(data.flip_control_on_disable, '§G瘫痪后转移所属权§!', nil, nil)
			..p.yes_no(data.is_space_station, '§G空间站类型§!', nil, nil)
			..p.yes_no(data.is_civilian, '§G民用舰船§!', nil, nil)
			..p.yes_no(data.is_designable, nil, '§R不可设计§!', nil)
			..p.yes_no(data.is_designable, nil, '§G组件不增加建造费用§!', nil)
			..p.yes_no(data.valid_target_aggressive_stance, nil, '§R无主动进攻模式§!', nil)
			..p.yes_no(data.auto_upgrade, '§G自动升级§!', nil, nil)
			..p.yes_no(data.can_have_federation_design, '§G有联邦设计§!', nil, nil)
			..p.yes_no(data.enable_default_design, '§G有默认设计§!', nil, nil)
			..p.yes_no(data.uses_name_prefix, nil, '§R不使用前缀§!', nil)
			..p.yes_no(data.takes_name_from_ship_design, '§G使用舰船设计名§!', nil, nil)
			..p.yes_no(data.is_listed, nil, '§R不可建造§!', nil)
			..p.yes_no(data.can_be_inspected, nil, '§R不可查看细节(我们的科学家完全搞不懂这些东西的原理。)§!', nil)
			..p.yes_no(data.is_space_object, '§G是太空物体§!', nil, nil)
		if data.graphical_culture and data.graphical_culture ~= 'no' then
			newstring = newstring..p.list_to_div(data.graphical_culture, '画面风格', '<br />')
		end
		newstring = newstring..p.data_block(data.entity, '模型')
			..p.data_block(data.pre_communications_name, '建立联系前的名称')
			..p.data_block(data.zhcn_min_upgrade_cost, '升级所需最低花费', 'inline')
			..p.data_block(data.potential_country_logic, '国家要求')
	elseif data.main_category == 'starbase_buildings' or data.main_category == 'starbase_modules' then
		newstring = p.refined_info(data, 58)
			..p.data_block(data.zhcn_desc)
			..p.resources(data)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_country_modifier, '帝国修正')
			..p.data_block(data.zhcn_system_modifier, '星系修正')
			..p.data_block(data.zhcn_orbit_modifier, '轨道修正')
			..p.data_block(data.zhcn_station_modifier, '恒星基地修正')
			..p.data_block(data.zhcn_ship_modifier, '舰船修正')
			..p.data_block(data.zhcn_tip)
			..p.intenal_query(data.equipped_component, 'Component_templates', '装备组件')
			..p.intenal_query(data.section, 'Data:Section_templates', '对应区块')
			..p.prerequisite(data.prerequisites)
			..p.intenal_query(data.show_in_tech, 'Data:Technology', '拥有以下科技才会显示')
			..p.yes_no(data.initial, '§G起始恒星基地自带§!', nil, nil)
			..p.yes_no(data.ai_build_at_chokepoint, '§GAI会在路口星系的恒星基地安装此建筑§!', '§RAI不会在路口星系的恒星基地安装此建筑§!', nil)
			..p.yes_no(data.ai_build_outside_chokepoint, '§GAI会在非路口星系的恒星基地安装此建筑§!', '§RAI不会在非路口星系的恒星基地安装此建筑§!', nil)
			..p.data_divide_block(data.triggered_country_modifier_logic, '额外国家修正')
			..p.data_divide_block(data.triggered_station_modifier_logic, '修正')
	elseif data.main_category == 'starbase_levels' then
		newstring = p.refined_info(data, 33)
			..p.intenal_query(data.ship_size, 'Ship_sizes', '舰船大小', 'inline')
			..p.intenal_query(data.next_level, 'Starbase_levels', '可用升级', 'inline')
			..p.data_block(data.level_weight, '等级', 'inline')
			..p.data_block(data.ai_weight_logic, 'AI权重')
			..p.yes_no(data.display_map_icon, nil, '§R在星系地图中默认不显示§!', nil)
			..p.yes_no(data.show_in_outliner, nil, '§R在右侧概览表中默认不显示§!', nil)
	elseif data.main_category == 'star_classes' then
		local planets = data.planet
		local count_planets = ''
		if data.num_planets then
			if data.num_planets.min and data.num_planets.max then
				count_planets = data.num_planets.min..'~'..data.num_planets.max
			else
				count_planets = data.num_planets
			end
		end
		newstring = p.refined_info(data, 29)
			..p.data_block(data.spawn_odds, '生成概率系数', 'inline')
			..p.intenal_query(planets.key, 'Planet_classes', '恒星类型', 'inline')
			..p.data_block(count_planets, '星系内星球数量', 'inline')
			..p.data_block(data.habitable, '宜居星球生成概率系数', 'inline')
			..p.data_block(data.pc_gas_giant_odds, '气态巨行星生成概率系数', 'inline')
			..p.data_block(data.pc_gaia_odds, '盖亚星球生成概率系数', 'inline')
			..p.data_block(data.zhcn_modifier)
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'strategic_resources' then
		local base_price = nil
		if data.market_amount and data.market_price then
			base_price = data.market_price / data.market_amount
		end
		newstring = p.refined_info(data, 17)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.max, '初始上限', 'inline')
			..p.prerequisite(data.prerequisites)
			..p.data_block(data.visibility_logic, '以下情况才会显示')
			..p.data_block(data.market_amount, '交易区最小单位', 'inline')
			..p.data_block(base_price, '单价', 'inline')
			..p.data_block(data.tooltip_decimals, '文本精确到', 'inline')
			..p.data_block(data.zhcn_deficit_modifier, '亏空时的提示', 'inline')
			..p.yes_no(data.fixed_max_amount, '§R上限不会变§!', nil, nil)
			..p.yes_no(data.tradable, '§G可交易§!', nil, '§R不可交易§!')
			..p.data_block(ai_wants_logic, 'AI保证最低库存量')
	elseif data.main_category == 'subjects' then
		newstring = p.refined_info(data, -4)
			..p.data_block(data.zhcn_desc)
			..p.divide_line
			..p.data_block(data.zhcn_tax_rate, '为宗主国纳贡', 'inline')
			..p.data_block(data.diplo_threat, '外交威胁度系数', 'inline')
			..p.intenal_query(data.can_switch_to, 'Subjects', '可转变为')
			..p.yes_no(data.can_expand, '§G可以扩张§!', '§R不能扩张§!', nil)
			..p.yes_no(data.can_be_integrated, '§G可被§!§Y合并附庸§!', '§R不能被合并§!', nil)
			..p.yes_no(data.joins_overlord_wars, '§R必须加入宗主国的战争§!', '§G可以不加入宗主国的战争§!', nil)
			..p.yes_no(data.calls_overlord_to_war, '§G召唤宗主国加入战争§!', '§R不召唤宗主国加入战争§!', nil)
			..p.yes_no(data.can_do_diplomacy, '§G极大的外交权§!', '§R有限的外交权§!', nil)
			..p.yes_no(data.research_agreement, nil, '§G不可签署科研协议§!', '§R可签署科研协议§!')
			..p.yes_no(data.research_sharing, '§G与宗主国分享科研§!', nil, nil)
			..p.data_block(data.tech_cost, '研究宗主国已有科技时减少消耗')
			..p.data_block(data.tax_rate, '附庸想宗主国字符资源', 'inline')
			..p.data_block(data.overlord_produces, '宗主国获得资源', 'inline')
			..p.data_block(data.effect_logic, '效果')
			..p.data_block(data.become_vassal_logic, '成为附庸的条件')
	elseif data.main_category == 'technology' then
		local tech_area = nil
		if data.area then
			if data.area == 'physics' then
				tech_area = '§E物理学§!'
			elseif data.area == 'society' then
				tech_area = '§G社会学§!'
			elseif data.area == 'engineering' then
				tech_area = '§H工程学§!'
			end
		end
		local tech_cat = nil
		if data.zhcn_category then
			tech_cat = '[[File:leader_trait_expertise_'
				..data.category
				..'.png|20px|link=]]'
				..data.zhcn_category
		end
		local tech_group = ''
		if data.weight_groups then
			for _, item in ipairs(data.weight_groups) do
				if item == 'repeatable' then
					tech_group = tech_group..'循环科技,'
				elseif item == 'deposit_blockers' then
					tech_group = tech_group..'障碍清理,'
				else
					tech_group = tech_group..data.weight_groups..','
				end
			end
		end
		if #tech_group > 2 then
			tech_group = string.sub(tech_group, 0, -1-string.len('<br />'))
		else
			tech_group = nil
		end
		local tech_tier = nil
		if data.tier == '0' then
			tech_tier = '§G无花费§!'
		elseif data.cost then
			tech_tier = '§G'..data.cost..'§!'
			if data.cost_per_level then
				tech_tier = tech_tier..' + §H'..data.cost_per_level..'§!(每级)'
			end
		end
		local tech_limit = nil
		if data.levels == '-1' or ((not data.levels) and data.weight_groups == 'repeatable') then
			tech_limit = '∞'
		elseif data.levels then
			tech_limit = data.levels
		end
		local tech_ai_update = nil
		if data.ai_update_type == 'all' then
			tech_ai_update = '全部'
		elseif data.ai_update_type == 'military' then
			tech_ai_update = '军事舰船'
		elseif data.ai_update_type then
			tech_ai_update = data.ai_update_type
		end
		local mod_weight_ifs = data.mod_weight_if_group_picked
		if not mod_weight_ifs then
			mod_weight_ifs = {}
		end
		newstring = p.refined_info(data, 52)
			..p.data_block(data.zhcn_modifier)
			..p.unlock_list(data)
			..p.data_block(tech_area, '领域', 'inline')
			..p.data_block(tech_cat, '分类', 'inline')
			..p.data_block(tech_group, '分组', 'inline')
			..p.data_block(data.tier, '科技等级', 'inline')
			..p.data_block(tech_tier, '花费', 'inline')
			..p.data_block(tech_limit, '循环上限', 'inline')
			..p.yes_no(data.start_tech, '§G起始科技§!', nil, nil)
			..p.yes_no(data.is_dangerous, '§R危险科技§!', nil, nil)
			..p.yes_no(data.is_rare, '§M稀有科技§!', nil, nil)
			..p.yes_no(data.is_reverse_engineerable, '§G可逆向科技§!', '§R不可逆向科技§!', nil)
			..p.prerequisite(data.prerequisites)
			..p.data_block(zhcn_feature_flags, '解锁特性', 'inline')
			..p.data_block(zhcn_gateway, '科技路线', 'inline')
			..p.data_block(tech_ai_update, '升级类型', 'inline')
			..p.data_block(mod_weight_ifs.repeatable, '循环科技已选取时权重系数', 'inline')
			..p.data_block(mod_weight_ifs.deposit_blockers, '地块障碍科技已选取时权重系数', 'inline')
			..p.data_divide_block(data.zhcn_desc)
	elseif data.main_category == 'terraform' then
		local tf_cost = ''
		if data.energy then
			tf_cost = data.energy
		end
		if data.duration then
			tf_cost = tf_cost..'£time'..data.duration
		end
		if tf_cost == '' then
			tf_cost = nil
		end
		local tf_effect = nil
		if data.effect and data.effect.from and data.effect.from.remove_modifier == 'terraforming_candidate' then
			tf_effect = p.data_block('§H改造完成后会移除"地貌改造候选"星球修正§!')
		end
		local tf_option = p.func_info(data.from, 'key', 'Data:Planet_classes/')
			..'→'
			..p.func_info(data.to, 'key', 'Data:Planet_classes/')
		newstring = p.refined_info(data, 24)
			..p.data_block(tf_option, '改造选项', 'inline')
			..p.data_block(tf_cost, '花费', 'inline')
			..p.data_divide_block(data.condition_logic, '条件')
	elseif data.main_category == 'traditions' then
		newstring = p.refined_info(data, 45)
			..p.data_block(data.zhcn_category, '分类')
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.zhcn_modifier)
		if data.tradition_swap then
			all_swap = ''
			for _, item in ipairs(data.tradition_swap) do
				local tr_swap = p.refined_info(item, 24)
					..p.yes_no(item.inherit_effects, '§G继承原来传统的效果§!', nil, nil)
					..p.data_block(item.zhcn_modifier)
					..p.data_block(item.trigger_logic, '允许开启条件')
					..p.data_block(item.weight_logic, '权重')
				all_swap = all_swap..tr_swap..p.divide_line
			end
			if all_swap ~= '' then
				all_swap = string.sub(all_swap, 0, -1-string.len(p.divide_line))
			end
			newstring = newstring..p.divide_line..p.data_block(all_swap, '替换传统')
		end
	elseif data.main_category == 'traits' then
		newstring = p.refined_info(data, 29)
			..p.data_block(data.zhcn_modifier)
			..p.yes_no(data.immortal_leaders, '§G不朽§!', nil, nil)
			..p.data_divide_block(data.zhcn_desc)
			..p.data_divide_block(data.cost or '0', '点数', 'inline')
			..p.intenal_query(data.opposites, 'Traits', '互斥特性')
			..p.prerequisite(data.prerequisites)
			..p.yes_no(data.initial, nil, '§R非初始特性§!', '§G可成为初始特性§!')
			..p.yes_no(data.randomized, nil, '§R非随机出现的特性§!', '§G可随机出现特性§!')
			..p.yes_no(data.modification, '§G可通过基因修饰删除该特质§!', '§R不可通过基因修饰删除该特质§!', nil)
		if data.leader_trait then
			newstring = newstring..p.list_to_div(data.zhcn_leader_class, '所属领袖类型', ' ')
				..p.list_to_div(data.ai_categories, '特性分类', ' ')
				..p.yes_no(data.hide_age, '§G不显示年龄§!(因为不朽)', nil, nil)
				..p.data_divide_block(data.leader_potential_add_logic, '可能性加成')
		else
			newstring = newstring..p.yes_no(data.improves_leaders, '§G来自这个种族的领袖能够获得额外的特质和加成§!', nil, nil)
				..p.list_to_div(data.zhcn_archetypes, '允许的种族类型', ' ')
				..p.yes_no(data.forced_happiness, '§G不受幸福度影响§!', nil, nil)
			if data.potential_crossbreeding_chance then
				newstring = newstring..p.data_block((data.potential_crossbreeding_chance * 100)..'%', '杂交概率修正', 'inline')
			end
			newstring = newstring..p.yes_no(data.sapient, nil, '§G未开智物种特性§!', nil)
				..p.yes_no(data.advanced_trait, '§G高级特性§!', nil, nil)
				..p.data_block(data.leader_age_min, '领袖最小初始年龄', 'inline')
				..p.data_block(data.leader_age_max, '领袖最大初始年龄', 'inline')
				..p.data_block(data.slave_cost_detail, '奴役消耗', 'inline')
				..p.data_block(data.sorting_priority, '图标排列优先级', 'inline')
				..p.data_divide_block(data.species_potential_add_logic, '可能性加成')
				..p.data_divide_block(data.zhcn_assembling_modifier, '组装时修正')
		end
	elseif data.main_category == 'war_goals' then
		newstring = p.refined_info(data, 44)
			..p.data_block(data.zhcn_desc)
			..p.intenal_query(data.casus_belli, 'Casus_belli', '对应的宣战借口')
			..p.intenal_query(data.set_defender_wargoal, 'War_goals', '防御方可用战争目标')
			..p.yes_no(data.hide_if_no_cb, '§G无对应宣战借口时隐藏§!', '§G无对应宣战借口时依然显示§!', nil)
			..p.yes_no(data.total_war, '§G全面战争§!', nil, nil)
			..p.data_block(data.surrender_acceptance, '被宣战方投降接受度修正', 'inline')
			..p.data_block(data.war_exhaustion, '厌战度修正', 'inline')
			..p.data_block(data.threat_multiplier, '威胁度修正', 'inline')
			..p.yes_no(data.defender_default, '§G防御方默认战争目标§!', nil, nil)
		if data.cede_claims == 'occupied_only' then
			newstring = newstring..p.data_block('§G仅占领§!')
		end
		newstring = newstring..p.data_divide_block(data.on_accept_logic, '达成战争目标时')
			..p.data_block(data.on_status_quo_logic, '维持现状时')
			..p.data_block(data.on_wargoal_set_logic, '设定战争目标时')
			..p.yes_no(data.release_occupied_systems_on_status_quo, '§G维持现状时释放占领的恒星系§!', '§R维持现状时不释放占领的恒星系§!', nil)
	elseif data.main_category == 'achievements' then
		newstring = p.refined_info(data, 64)
			..p.data_block(data.zhcn_desc)
			..p.data_block(data.id, '序号', 'inline')
			..p.data_block(data.happened_logic, '解锁成就条件')
	elseif data.main_category == 'events' then
		has_detail = false
		if data.hide_window == 'yes' then
			hide = '隐藏事件,'	
		else
			hide = ''
		end
		if data.picture then
			if type(data.picture) == 'list' then
				pic = data.picture[1]
				icon = pic.picture
			elseif type(data.picture) == 'string' then
				icon = data.picture
			else
				icon = 'no_video_feed_room'
			end
		else
				icon = 'no_video_feed_room'
		end
		if type(data.zhcn_desc) == 'table' then
			desc = data.zhcn_desc[1]
		else
			desc = data.zhcn_desc
		end
		if string.len(desc) == 0 then
			all_desc = ''
		else
			all_desc = '<table style="border: 2px solid #14796c;background:rgba(41,55,50,0.5);width:100%"><tr><td style="padding: 5px">§E'
			..hide
			..desc
			..'§!</td></tr></table>'
		end
		icon = 'event_'..icon..'.png'
		newstring='<div style="padding:0px 0px 0px 0px;color:#fff;width:490px;list-style: none;font-size: 14px; border: 0px solid #14796c;position:relative;overflow:hidden">'
			..'<table style="width:490px;border:0">'
			..'<tr><td class="event-top">'
			..'<div style="position:absolute;left:19px;top:55px">[[文件:'
			..icon
			..'|link=]]</div><div style="position:absolute;left:23px;top:0px" class="huiji-tt" data-type="events" data-name="'
			..data.key
			..'" style="display:inline;position:absolute;left:14px;top:10px">'
			..hide
			..p.item_tip(data)
			..'</div></td></tr><tr><td class="event-body">'
			..all_desc
		if data.option then
			for _, ops in ipairs(data.option) do
				if ops.zhcn_name then
					newstring = newstring..'<table style="margin-top:5px;width:100%"><tr><td class="event-button">'..ops.zhcn_name..'</td></tr></table>'
				end
			end
		end
		newstring = newstring
			..'</td></tr><tr><td class="event-bottom"></td></tr>'
			..'</table></div>'
	else
		has_detail = false
		newstring = '<div>错误:该模板尚不支持'..data.key..'(主分类为:'..data.main_category..')</div>'
	end
	if has_detail then
		local more_details = p.data_block(data.playable_logic, '前置条件')
			..p.data_block(data.show_tech_unlock_if_logic, '显示其科技所需条件')
			..p.data_block(data.potential_logic, '基础要求')
			..p.data_block(data.allow_logic, '要求')
			..p.data_block(data.possible_desc, '条件')
			..p.data_block(data.possible_logic, '条件')
			..p.data_block(data.is_valid_logic, '条件')
			..p.data_block(data.weight_logic, '权重')
			..p.data_block(data.weight_modifier_logic, '权重修正')
			..p.data_block(data.random_weight_logic, '随机权重')
			..p.data_block(data.ai_weight_logic, 'AI权重')
		if more_details ~= '' then
			more_details = p.divide_line..more_details
		end
		newstring = newstring..more_details
	end
	local ver = versions()
	if data.version ~=  ver[1] then
		newstring = newstring..p.divide_line..'§R该项目已经被移除游戏或未被更新<br />最后更新的版本为:'..data.version..'§!<br />(§G当前最新版本:'..ver[1]..'§!)'
	end
	return newstring
end

-- 星球和地块,Tiles
function p.tile_detail(frame)
	local frame_args = getArgs(frame)
	local tile_html = mw.html.create()
	if #frame_args ~= 1 then
		local tile_table_html = tile_html:tag('table'):addClass('wikitable')
			:cssText('background:#222;color:#fff;list-style: none;font-size: 14px; border: 2px solid #14796c;')
		tile_table_html:tag('tr')
		tile_table_html:tag('td'):wikitext('星球类型'):cssText('width: 160px')
		tile_table_html:tag('td'):wikitext('地块样式'):cssText('width: 520px')
		for _, name in ipairs(frame_args) do
			result = p.query_data(name, 'key', 'Data:Planet_classes/')
			if #result == 1 then
				local tile = {}
				tile_table_html:tag('tr')
				tile_table_html:tag('td'):wikitext(p.func_info_result(result))
				for i =1,4,1 do
					tile[i] = '[[File:'..(result[1].tile_set or name)..'_'..i..'.png|link=]]'
				end
				tile_queue = tile[4]..tile[1]..tile[2]..tile[3]..tile[3]..'<br/>'
					..tile[2]..tile[4]..tile[2]..tile[2]..tile[2]..'<br/>'
					..tile[1]..tile[3]..tile[4]..tile[4]..tile[3]..'<br/>'
					..tile[2]..tile[1]..tile[3]..tile[4]..tile[4]..'<br/>'
					..tile[1]..tile[1]..tile[2]..tile[1]..tile[3]
				tile_table_html:tag('td'):wikitext(tile_queue)
			end
		end
		tile_table_html:done()
	end
	return tostring(tile_html)
end

function p.valid_value(value)
	trigger_yes = '[[文件:Trigger_yes.png|link=]]'
	trigger_no = '[[文件:Trigger_no.png|link=]]'
	return (value == 'yes' and trigger_yes or (value and trigger_no or nil))
end

-- AI性格表
function p.personality_table(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'modifiers'
	local result = p.query_data('personalities', 'main_category', 'Data:Personalities/')
	local html = mw.html.create()

	local table_html = html:tag('table'):addClass('wikitable sortable'):cssText(tooltip_style)
	if key == 'modifiers' then
		table_headers = {
			'{{tooltip|AG|侵略性}}',
			'{{tooltip|TW|贸易意愿}}',
			'{{tooltip|BR|勇气}}',
			'{{tooltip|CB|战斗勇气}}',
			'{{tooltip|MS|军事开销}}',
			'{{tooltip|CS|殖民开销}}',
			'{{tooltip|TM|威胁修正}}',
			'{{tooltip|TO|威胁其他人修正}}',
			'{{tooltip|FM|边境摩擦修正}}',
			'{{tooltip|CM|宣称修正}}',
			'{{tooltip|AS|优势开局几率}}',
			'{{tooltip|FA|联邦接受度}}',
			'{{tooltip|NA|互不侵犯条约接受度}}',
			'{{tooltip|DP|移民条约接受度}}',
			'{{tooltip|MP|共同防御条约接受度}}',
			'[[文件:damage.png|武器偏好|20px|link=]]',
			'[[文件:armor.png|装甲比重|20px|link=]]',
			'[[文件:shield.png|护盾比重|20px|link=]]',
			'[[文件:hit_points.png|船体比重|20px|link=]]',
		}
		table_html:tag('tr')
			
		table_html:tag('th'):wikitext(''):cssText('width: 80px'):done()
		for _, header_name in ipairs(table_headers) do
			table_html:tag('th'):wikitext(header_name):done()
		end
		for _, data in ipairs(result) do
			if data.weapon_preferences == 'weapon_type_energy' then
				wp = '[[文件:combat_stat_damage_energy.png|能量|28px|link=]]'
			elseif data.weapon_preferences == 'weapon_type_kinetic' then
				wp = '[[文件:combat_stat_damage_kinetic.png|动能|28px|link=]]'
			elseif data.weapon_preferences == 'weapon_type_explosive' then
				wp = '[[文件:combat_stat_damage_explosive.png|炸药|28px|link=]]'
			elseif data.weapon_preferences == 'weapon_type_strike_craft' then
				wp = '[[文件:combat_stat_damage_strike_craft.png|舰载机|28px|link=]]'
			else
				wp = '[[文件:combat_stat_damage_shields.png|定制|28px|link=]]'
			end
			table_column = {
				'aggressiveness', 
				'trade_willingness', 
				'bravery', 
				'combat_bravery', 
				'military_spending', 
				'colony_spending', 
				'threat_modifier', 
				'threat_others_modifier', 
				'friction_modifier', 
				'claims_modifier', 
				'advanced_start_chance', 
				'federation_acceptance', 
				'nap_acceptance', 
				'defensive_pact_acceptance', 
				'migration_pact_acceptance',
				'wp',
				'armor_ratio', 
				'shields_ratio',
				'hull_ratio'
			}
			table_html:tag('tr')
			table_html:tag('td'):wikitext(p.refined_info(data)):done()
			for _, column_name in ipairs(table_column) do
				if column_name == 'wp' then
					table_html:tag('td'):wikitext(wp):done()
				else
					table_html:tag('td'):wikitext(data[column_name] or 0):done()
				end
			end
		end
	elseif key == 'behaviour' then 
		table_html:tag('tr')
		table_headers = {
 			'CQ|征服者', 
 			'SJ|四海臣服', 
 			'LB|解放者', 
 			'OP|机会主义者', 
 			'SL|奴隶主', 
 			'CS|阶序制度', 
 			'UL|提升者', 
 			'PG|灭绝者', 
 			'DP|迁移者', 
 			'IF|渗透者', 
 			'DM|主宰', 
 			'RE|机械奴役者', 
 			'RL|机械解放者', 
 			'PP|传播者', 
 			'MS|多种族者', 
 			'CF|危机斗士', 
 			'CL|危机斗士领导者', 
 			'WT|想要贸易', 
 			'AN|攻击中立势力', 
 			'DC|颓败', 
			-- 'IS|孤立主义', 
			-- 'HP|重视圣地', 
			-- 'DB|需要边界缓冲区', 
			-- 'EN|神秘态度', 
			-- 'CT|监护者', 
			-- 'LM|限制', 
			-- 'BS|狂暴', 
		}
		table_html:tag('th'):wikitext(''):cssText('width: 80px'):done()
		for _, header_name in ipairs(table_headers) do
			table_html:tag('th'):wikitext('{{tooltip|'..header_name..'}}'):done()
		end
		for _, data in ipairs(result) do
			table_column = {
				'conqueror', 
				'subjugator', 
				'liberator', 
				'opportunist', 
				'slaver', 
				'caste_system', 
				'uplifter', 
				'purger', 
				'displacer', 
				'infiltrator', 
				'dominator', 
				'robot_exploiter', 
				'robot_liberator', 
				'propagator', 
				'multispecies', 
				'crisis_fighter', 
				'crisis_leader', 
				'wants_tribute', 
				'attack_neutrals', 
				'decadent', 
				-- 'isolationist', 
				-- 'holy_planets', 
				-- 'demands_clear_borders', 
				-- 'enigmatic', 
				-- 'custodian', 
				-- 'limited', 
				-- 'berserker', 
			}
			table_html:tag('tr')
			table_html:tag('td'):wikitext(p.refined_info(data)):done()
			for _, column_name in ipairs(table_column) do
				table_html:tag('td'):wikitext(p.valid_value(data.behaviour[column_name])):done()
			end
		end
	end
	table_html:done()
	return frame:preprocess(tostring(html))
end

-- 建筑图标,Building_icon
function p.output_building_icon(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'building_paradise_dome'
	local result = p.query_data(key, key_type, 'Data:Buildings/')
	local html = mw.html.create()

	if #result ~= 1 then  
		local table_html = html:tag('table')
			:addClass('wikitable')
			:cssText('background:#222;padding:0px 0px 0px 0px;color:#fff;max-width:400px;list-style: none;font-size: 12px;')
		for _, data in ipairs(result) do
			table_html:tag('tr'):tag('td'):wikitext(set_style(p.set_building_str(data))):done()
		end
	else
		local local_html = html:wikitext(set_style(p.set_building_str(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 领袖分类
function p.leader_traits_flag(data, addtion)
	flag = true
	if addtion == 'all' then
		flag = (data.leader_trait == 'yes') and ((not data.leader_class) or #data.leader_class > 1)
	elseif addtion ~= nil then
		flag = data.leader_class and (#data.leader_class == 1) and (data.leader_class[1] == addtion)
	end
	return flag
end

-- 控制台码,Console
function p.output_console_table(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'Strategic_resources'
	local command = frame_args[2]
	local addtion = frame_args[3] or nil
	local result = p.query_data(key, 'main_category', 'Data:')
	local html = mw.html.create()
	
		
	local table_html = html:tag('table')
		:addClass('wikitable sortable')
		:cssText(p.tooltip_no_width_style)
		:tag('th'):wikitext('名称'):done() 
		:tag('th'):wikitext('代码'):done() 
	local content = ''

	for _, data in ipairs(result) do
		if command == 'add_modifier' then
			content = 'effect add_modifier = { modifier = '..(data.key or '')..' days = -1 }'
		else
			content = command..' '..data.key or ''
		end
		if p.leader_traits_flag(data, addtion) then
			table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
					:tag('td'):wikitext(content):done()
		end
	end
	return frame:preprocess(tostring(html))
end

-- 建筑分类,Normal_buildings
function p.output_building_cat_table(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'normal'
	local result = p.query_data('buildings', 'main_category', 'Data:Buildings/')
	local html = mw.html.create()
 
	if #result ~= 1 then  
		local table_html = html:tag('table')
			:addClass('wikitable')
			:cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			if key == 'normal' then
				condition = (not (data.potential and data.potential.owner and (
						data.potential.owner.has_authority == 'auth_machine_intelligence' or data.potential.owner.has_non_swapped_tradition 
						or data.potential.owner.has_swapped_tradition or data.potential.owner.has_ascension_perk))) 
					and (not (data.potential and data.potential.planet and data.potential.planet.is_planet_class == 'pc_habitat'))
					and (not (data.event_building == 'yes'))
			elseif key == 'machine_intelligence' then
				condition = data.potential and data.potential.owner and data.potential.owner.has_authority == 'auth_machine_intelligence'
			elseif key == 'habitat_building' then
				condition = data.potential and data.potential.planet and data.potential.planet.is_planet_class == 'pc_habitat'
			elseif key == 'event_building' then 
				condition = data.event_building == 'yes'
			elseif key == 'tradition_building' then
				condition = data.potential and data.potential.owner and (data.potential.owner.has_non_swapped_tradition or data.potential.owner.has_swapped_tradition)
			elseif key == 'ascension_building' then
				condition = data.potential and data.potential.owner and data.potential.owner.has_ascension_perk
			end
			if condition then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.set_building_str(data))):done()
			end
		end
	else
		local local_html = html:wikitext(set_style(p.set_building_str(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 宜居星球,Planet_info
function p.planet_table(frame)
	local frame_args = getArgs(frame)
	local colonizable = frame_args[1] or 'yes'
	local result = p.query_data('no', 'star', 'Data:Planet_classes/')
	local html = mw.html.create()

	if #result ~= 1 then  
		local table_html = html:tag('table'):addClass('wikitable'):cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			if data.colonizable == colonizable then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
			end
		end
	else
		local local_html = html:wikitext(set_style(p.refined_info(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 国家理念,Normal_civics
function p.output_civics_table(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'normal'
	local result = p.query_data('civics', 'main_category', 'Data:Civics/')
	local html = mw.html.create()
 
	if #result ~= 1 then  
		local table_html = html:tag('table')
			:addClass('wikitable')
			:cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			if key == 'normal' then
				condition = (not data.potential.country_type) 
					and ((data.potential.authority and data.potential.authority.value ~= 'auth_hive_mind' 
					and data.potential.authority.value ~= 'auth_machine_intelligence') or (not data.potential.authority))
					and ((not data.potential.always) or data.potential.always ~='no')
			elseif key == 'hive_mind' then
				condition = data.potential.authority and data.potential.authority.value == 'auth_hive_mind'
			elseif key == 'machine_intelligence' then
				condition = (not data.potential.country_type) and data.potential.authority and data.potential.authority.value == 'auth_machine_intelligence'
			elseif key == 'fallen_empire' then
				condition = data.potential.country_type and data.potential.country_type.value == 'fallen_empire'
			elseif key == 'awakened_fallen_empire' then 
				condition = data.potential.country_type and data.potential.country_type.value == 'awakened_fallen_empire'
			elseif key == 'primitive' then
				condition = data.potential.country_type and data.potential.country_type.value == 'primitive'
			elseif key == 'special' then
				condition = data.potential.always and data.potential.always =='no'
			end
			if condition then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
			end
		end
	else
		local local_html = html:tag('span'):wikitext(set_style(p.refined_info(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 科技
function p.tech_category(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'rare'
	local result = p.query_data('technology', 'main_category', 'Data:Technology/')
	local html = mw.html.create()
 
	if #result ~= 1 then  
		local table_html = html:tag('table')
			:addClass('wikitable')
			:cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			if key == 'physics' then
				condition = (data.area == 'physics')
			elseif key == 'society' then
				condition = (data.area == 'society')
			elseif key == 'engineering' then
				condition = (data.area == 'engineering')
			elseif key == 'rare' then
				condition = (data.is_rare == 'yes')
			elseif key == 'dangerous' then
				condition = (data.is_dangerous == 'yes')
			end
			if condition then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.set_tech_card(data))):done()
			end
		end
	else
		local local_html = html:tag('span'):wikitext(set_style(p.set_tech_card(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 战略资源,Normal_resources
function p.output_resources_table(frame)
	local frame_args = getArgs(frame)
	local key = frame_args[1] or 'normal'
	local result = p.query_data('strategic_resources', 'main_category', 'Data:Strategic_resources/')
	local html = mw.html.create()
 
	if #result ~= 1 then  
		local table_html = html:tag('table')
			:addClass('wikitable')
			:cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			if key == 'normal' then
				condition = data.AI_category ~='strategic_resource' or data.is_planet_local == 'yes'
			elseif key == 'strategic_resource' then
				condition = data.AI_category =='strategic_resource' and data.is_planet_local ~= 'yes'
			end
			if condition then
				table_html:tag('tr'):tag('td'):wikitext(set_style(p.refined_info(data))):done()
			end
		end
	else
		local local_html = html:tag('span'):wikitext(set_style(p.refined_info(result[1]))):done()
	end
	return frame:preprocess(tostring(html))
end

-- 科技卡片
function p.tech_card(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'tech_jump_drive_1'
	local result = p.query_data(key, key_type, 'Data:Technology')
	return frame:preprocess(p.format_data(result, p.set_tech_card))
end

-- 科技数量
function p.tech_count(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'area'
	local key = frame_args[1] or 'engineering'
	local result = p.query_count(key, key_type, 'Data:Technology')
	return tostring(result)
end

-- 政策列表
function p.policies_table(frame)
	local frame_args = getArgs(frame)
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'war_doctrine'
	local result = p.query_data(key, key_type, 'Data:Policies')
	return p.format_data(result, p.set_policies_list)
end

-- 替换传统,Info3版本
function p.swap_tradition_table(frame)
	local frame_args = getArgs(frame)
	local swap_type = frame_args[2] or 'none'
	local key_type = frame_args[3] or 'key'
	local key = frame_args[1] or 'tr_diplomacy_alien_tourism'
	local result = p.query_data(key, key_type, 'Data:Traditions/')
	local html = mw.html.create()

	if #result ~= 1 then  
		local table_html = html:tag('table'):addClass('wikitable'):cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			table_html:tag('tr'):tag('td'):wikitext(set_style(p.set_swap_tradition(data, swap_type))):done()
		end
	else
		local local_html = html:wikitext(set_style(p.set_swap_tradition(result[1], swap_type))):done()
	end
	return tostring(html)
end

-- 替换传统Info样式
function p.set_swap_tradition(data, swap_type)
	local name = data.zhcn_name
	local icon = (data.icon or data.key)
	if swap_type ~= 'none' then
		if data.tradition_swap then
			for _, item in ipairs(data.tradition_swap) do
				if item.trigger and (
					item.trigger.has_authority == swap_type 
					or item.trigger.has_valid_civic == swap_type 
					or (item.trigger.OR 
						and (item.trigger.OR.has_valid_civic == swap_type 
							or item.trigger.OR.has_authority == swap_type ))
				)then
					name = item.zhcn_name
					if item.inherit_icon == 'yes' then
						icon = (data.icon or data.key)
					else
						icon = (item.icon or (data.icon or data.key))
					end
				elseif item.trigger and item.trigger.OR and item.trigger.OR.has_valid_civic then
					for _, civic in ipairs(item.trigger.OR.has_valid_civic) do
						if swap_type == civic then
							name = item.zhcn_name
							if item.inherit_icon == 'yes' then
								icon = (data.icon or data.key)
							else
								icon = (item.icon or (data.icon or data.key))
							end
						end
					end
				elseif item.trigger and item.trigger.OR and item.trigger.OR.has_authority then
					for _, civic in ipairs(item.trigger.OR.has_authority) do
						if swap_type == civic then
							name = item.zhcn_name
							if item.inherit_icon == 'yes' then
								icon = (data.icon or data.key)
							else
								icon = (item.icon or (data.icon or data.key))
							end
						end
					end
				end
			end
		end
	end
	local newstring = '<span class="huiji-tt" data-type="'
			..data.main_category
			..'" data-name="'
			..data.key
			..'" style="display:inline-block;position:relative">'
			..'[[文件:'
			..icon
			..'.png|'
			..name
			..'|29px|link=Item:'
			..data.main_category
			..'/'
			..data.key
			..']]'
			..'<span style="padding:8px 0px 0px 6px">'
			..'[[Item:'
			..data.main_category
			..'/'
			..data.key
			..'|'
			..name
			..']]'
			..'</span></span>'
	return newstring
end

-- 科技卡片样式
function p.set_tech_card(data)
	local tech_card_style = 'background:#222;padding:0px 0px 0px 0px;color:#fff;width:452px;height:85px;list-style: none;font-size:12px; border: 0px solid #14796c;position:relative;overflow:hidden'
	local tech_card_back = ''
	if data.is_dangerous == 'yes' then
		tech_card_back = 'tech_bg_dangerous'
	elseif data.is_rare == 'yes' then
		tech_card_back = 'tech_bg_rare'
	elseif data.area == 'physics' then
		tech_card_back = 'tech_bg_physics'
	elseif data.area == 'society' then
		tech_card_back = 'tech_bg_society'
	elseif data.area == 'engineering' then
		tech_card_back = 'tech_bg_engineering'
	end
	if tech_card_back ~= '' then
		tech_card_back = p.image_default_link(tech_card_back, data, 452)
	end
	local card_desc = ''
	if data.prereqfor_desc then
		card_desc = data.zhcn_modifier
	else
		card_desc = (data.zhcn_modifier or '')..p.unlock_list(data)
	end
	newstring='<div class="huiji-tt" data-type="technology" data-name="'
		..data.key
		..'" style="'..tech_card_style..'">'
		..'<div class="link-block">'
		..tech_card_back
		..'<div style="position:absolute;width:452px;top:0px;text-align:right;color:#00ff00">'
		..(data.start_tech == 'yes' and '起始科技' or data.cost)
		..'</div>'
		..'<div style="position:absolute;left:7px;top:4px;color:#fff">'
		..data.zhcn_name
		..' ('
		..data.en_name
		..')</div>'
		..'<div style="position:absolute;background:#3a6656;left:4px;top:28px;width:54px;height:54px;border: 1px solid #3a6656">'
		..p.image_default_link((data.icon or data.key), data, 52)
		..'</div><div style="position:absolute;left:70px;top:30px;color:#fff;width:340px;height:50px;list-style: none;font-size:12px; border: 0px solid #14796c">'
		..card_desc
		..'</div><div style="position:absolute;left:415px;top:30px;width:29px;height:29px;border: 0px solid #3a6656">'
		..p.image_with_link('leader_trait_expertise_'..data.category, '', 29)
		..'</div></div></div>'
	return newstring
end

-- Normal_buildings样式
function p.set_building_str(data)
	newstring ='<div style="background:#222;padding:0px 0px 0px 0px;border: 2px solid #14796c;width:98px;font-size: 12px"><span class="huiji-tt" data-type="'
		   ..data.main_category
		..'" data-name="'
		..data.key
		..'" style="display:inline-block;position:relative">'
		..p.image_default_link('building_bg', data, 98)
		..'<span style="position:absolute;left:-20px;top:-7px">'
		..p.image_default_link((data.icon or data.key), data, 98)
		..'</span></span></div>'
	return newstring
end

-- Policies样式
function p.set_policies_list(data)
	newstring='<span class="huiji-tt" data-type="'
		   ..data.main_category
		   ..'" data-name="'
		..data.key
		..'" style="display:inline-block;margin-bottom:12px">[[文件:Menu_icon_policies_and_edicts.png|'
		..data.zhcn_name
		..'|29px|link=Item:'
		..data.main_category
		..'/'
		..data.key
		..']]<span style="margin-left:12px">[[Item:'
		..data.main_category
		..'/'
		..data.key
		..'|'
		..data.zhcn_name
		..']]</span>'
		if data.option then
			for _,options in ipairs(data.option) do
				newstring = newstring
					..'<div style="margin-left:12px">[[文件:Radio_button_normal.png|选项|29px|link=]]§E'
					..options.zhcn_name
					..'§!</div>'
			end
		end
		newstring = newstring..'</span>'
	return newstring
end

-- 单独字段显示
function p.logics_table(frame)
	local frame_args = getArgs(frame)
	local segment = frame_args[3] or 'possible_logic'
	local key_type = frame_args[2] or 'key'
	local key = frame_args[1] or 'building_paradise_dome'
	return p.func_logics(key, key_type, 'Data:', segment)
end

function p.func_logics(key, key_type, namespace, segment)
	return p.func_logics_result(p.query_data(key, key_type, namespace), segment)
end

function p.func_logics_result(result, segment)
	local html = mw.html.create()

	if #result ~= 1 then  
		local table_html = html:tag('table'):addClass('wikitable'):cssText(p.tooltip_style)
		for _, data in ipairs(result) do
			table_html:tag('tr'):tag('td'):wikitext(set_style(p.data_block(data[segment]))):done()
		end
	else
		local local_html = html:wikitext(set_style(p.data_block(result[1][segment]))):done()
	end
	return tostring(html)
end

-- 译名表
function p.translation_all(frame)
	local result = get_trans_data(p.info_set)
	local html = mw.html.create()

	local table_html = html:tag('table'):addClass('wikitable sortable'):cssText(p.tooltip_style)
		table_html:tag('tr')
			:tag('th'):wikitext('ID'):done()
			:tag('th'):wikitext('英文'):done()
			:tag('th'):wikitext('中文'):done()
			:tag('th'):wikitext('链接'):done()
	for _, data in ipairs(result) do
		if data.en_name 
				and data.en_name~='没有议程' 
				and data.en_name~='No Title' 
				and data.main_category ~= 'deposits' 
				and data.main_category ~= 'terraform' 
				and data.en_name~= 'core' then
			table_html:tag('tr')
				:tag('td'):wikitext(data.key):done()
				:tag('td'):wikitext(data.en_name):done()
				:tag('td'):wikitext(data.zhcn_name):done()
				:tag('td'):wikitext(set_style(p.refined_info(data))):done()
		end
	end
	return tostring(html)
end

-- 直接dump数据
function p.output_query(frame)
	return mw.dumpObject(p.query_data(frame, 'Data:'))
end

return p
0.0
0人评价
avatar