模块:CharacterInfo

来自异世界百科

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

local p = {}

function p.create(frame)
	-- 信息项
	local name = frame.args.name
	local originalName = frame.args.original_name
	local age = frame.args.age
	local gender = frame.args.gender or frame.args.custom_gender
	local hairColor = frame.args.hair_color
	local eyesColor = frame.args.eyes_color
	local height = frame.args.height
	local weight = frame.args.weight
	local ethnic = frame.args.ethnic
	local parentSetting = frame.args.parent_setting or tostring(frame:getTitle())
	
	-- 配置项
	local picture = frame.args.picture
	local displayType = frame.args.display_type
	local float = frame.args.float
	local content = frame.args.content or ""
	
	local dataAge = age
	-- 年龄不是数字,则不进入数据表
	if not dataAge:match("^%-?%d+$") then
		dataAge = nil
	end
	
	local dataTable = {
		["parent_setting"] = parentSetting
	}
	local infoTable = {
		["title_key"] = "名字"
	}
	if name then
		infoTable["名字"] = name
		dataTable["name"] = name
	end
	-- 原语言名字显示为上标
	if originalName then
		infoTable["名字"] = "{{上标|" .. name .. "|" .. originalName .. "}}"
		dataTable["original_name"] = originalName
	end
	if gender then
		infoTable["性别"] = gender
		dataTable["gender"] = gender
	end
	if age then
		infoTable["年龄"] = age
	end
	if dataAge then
		dataTable["age"] = dataAge
	end
	if hairColor then
		infoTable["发色"] = hairColor .. "色"
		dataTable["hair_color"] = hairColor
	end
	if eyesColor then
		infoTable["瞳色"] = eyesColor .. "色"
		dataTable["eyes_color"] = eyesColor
	end
	if height then
		infoTable["身高"] = height .. "cm"
		dataTable["height"] = height
	end
	if weight then
		infoTable["体重"] = weight .. "kg"
		dataTable["weight"] = weight
	end
	if ethnic then
		infoTable["种族"] = ethnic
		dataTable["ethnic"] = ethnic
	end
	
	if picture then
		infoTable["picture"] = picture
		dataTable["picture"] = picture
	end
	if displayType then
		infoTable["type"] = displayType
	else
		infoTable["type"] = "hidden"
	end
	if float then
		infoTable["float"] = float
	end
	
	local finalHtml = frame:expandTemplate{ title = "信息/角色", args = dataTable }
	
	-- 自动生成内容
	if displayType ~= "hidden" then
		finalHtml = finalHtml .. frame:extensionTag("information", content, infoTable)
	end
	
	return finalHtml
end

return p