local ModularTextureHandler = dwarf_characters.ModularTextureHandler

ModularTextureHandler("skin")
ModularTextureHandler("beard")
ModularTextureHandler("hair")
ModularTextureHandler("armor")
ModularTextureHandler("helmet")


do --Skins
	local apply_color = function(self, mod)
		return self[1] .. mod
	end
	local normal_skin = {"dwarf_chreator_skin.png", process = apply_color}
	dwarf_characters.register_skin("normal",
	{
		arm_skin_left = normal_skin,
		arm_skin_right = normal_skin,
		leg_skin_left = normal_skin,
		leg_skin_right = normal_skin,
		head =
		{
			"dwarf_chreator_skin.png",
			process =
				function(self, colormod)
					return "(" .. self[1]..colormod .. ")^dwarf_chreator_eyes.png"
				end
		},
		torso_skin =
		{
			"dwarf_chreator_skin.png^dwarf_chreator_torso_defined.png",
			process = apply_color
		},
	})
end




do --Beards
	
	
	--[[
		For dwarves, female beards are softer and don't grow as big as
		male beards so we need a distinction.
	]]
	local oldregb = dwarf_characters.register_beard
	local oldgetrb = dwarf_characters.get_random_beard
	
	local masculinebeards = {}
	local femininebeards = {}
	
	function dwarf_characters.register_beard(name, def)
		local sex = def.sex
		
		if sex == "m"
		then
			table.insert(masculinebeards, name)
		elseif sex == "f"
		then
			table.insert(femininebeards, name)
		else
			table.insert(masculinebeards, name)
			table.insert(femininebeards, name)
		end
		def.sex = nil --save a little memory
		oldregb(name, def)
	end
	
	function dwarf_characters.get_random_beard(appearance)
		local sex = appearance.sex
		if sex == "m"
		then
			return masculinebeards[math.random(#masculinebeards)]
		elseif sex == "f"
		then
			return femininebeards[math.random(#femininebeards)]
		else
			return oldgetrb()
		end
	end
	
	function dwarf_characters.get_beard_list(appearance)
		local sex = appearance.sex
		if sex == "m"
		then
			return masculinebeards
		elseif sex == "f"
		then
			return femininebeards
		end
	end
	
	dwarf_characters.register_beard("masc_long",
	{
		hair = {"dwarf_chreator_beard.png"},
		sex = "m",
		preview = "dwarf_chreator_beard_preview.png",
	})
	dwarf_characters.register_beard("gerold",
	{
		hair = {"dwarf_chreator_gerold_beard.png"},
		sex = "m",
		preview = "dwarf_chreator_gerold_beard_preview.png",
	})
	dwarf_characters.register_beard("floofy",
	{
		hair = {"dwarf_chreator_floofy_beard.png"},
		sex = "f",
		preview = "dwarf_chreator_floofy_beard_preview.png",
	})
	dwarf_characters.register_beard("cheeky",
	{
		hair = {"dwarf_chreator_cheeky_beard.png"},
		sex = "f",
		preview = "dwarf_chreator_cheeky_beard_preview.png",
	})
end

do --Hair
	dwarf_characters.register_hair("short_ponytail",
	{
		hair = {"dwarf_chreator_hair_short_ponytail.png"},
		preview = "dwarf_chreator_hair_short_ponytail_preview.png"
	})
	dwarf_characters.register_hair("long",
	{
		hair = {"dwarf_chreator_hair_long.png"},
		preview = "dwarf_chreator_hair_long_preview.png"
	})
end






do --Armors
	dwarf_characters.register_armor("berserker_pants",
	{
		leg_armor_left = {"dwarf_chreator_armor_legs.png"},
		leg_armor_right = {"dwarf_chreator_armor_legs.png"},
		torso_armor = {"dwarf_chreator_armor.png"},
		preview = "dwarf_chreator_berserker_pants_preview.png",
	})
	dwarf_characters.register_armor("chest",
	{
		leg_armor_left = {"dwarf_chreator_chest_armor_legs.png"},
		leg_armor_right = {"dwarf_chreator_chest_armor_legs.png"},
		arm_armor_left={"dwarf_chreator_chest_armor_arms.png"},
		arm_armor_right={"dwarf_chreator_chest_armor_arms.png"},
		torso_armor = {"dwarf_chreator_chest_armor.png"},
		preview = "dwarf_chreator_chest_armor_preview.png",
	})
end

do --Helmets
	dwarf_characters.register_helmet("cockatoo_helmet",
	{
		helmet = {"dwarf_chreator_helmet.png"},
		preview = "dwarf_chreator_helmet_preview.png",
	})
	dwarf_characters.register_helmet("nothing",
	{
		helmet = {"blank.png"},
		preview = "blank.png",
	})
end

do --Models
	
	dwarf_characters.register_model(
		"dwarf_chreator_masc.b3d", "Masculine Dwarf", "m")
	dwarf_characters.register_model(
		"dwarf_chreator_fem.b3d", "Feminine Dwarf", "f")
end
