Refactor skin tone description logic in AIImages mod to prioritize gene-based descriptions over color fallback. Update ColorDescriptionService to include new methods for gene skin tone extraction. Modify related services and UI components to utilize the updated skin tone logic. Update AIImages.dll to reflect these changes.

This commit is contained in:
Leonid Pershin
2025-10-31 10:07:39 +03:00
parent 51c3ea4bc1
commit 1ec80a01cb
5 changed files with 215 additions and 21 deletions

Binary file not shown.

View File

@@ -79,12 +79,13 @@ namespace AIImages.Services
prompt.Append(", "); prompt.Append(", ");
} }
// 7. Цвет кожи // 7. Цвет кожи (сначала проверяем гены, затем используем цвет как fallback)
string skinTone = ColorDescriptionService.GetSkinToneDescription( string skinTone = GetSkinToneDescription(appearanceData);
appearanceData.SkinColor if (!string.IsNullOrEmpty(skinTone))
); {
prompt.Append(skinTone); prompt.Append(skinTone);
prompt.Append(", "); prompt.Append(", ");
}
// 8. Волосы // 8. Волосы
string hairDescription = GetHairDescription(appearanceData); string hairDescription = GetHairDescription(appearanceData);
@@ -200,6 +201,14 @@ namespace AIImages.Services
}; };
} }
private string GetSkinToneDescription(PawnAppearanceData data)
{
// Этот метод будет использоваться в контексте генерации промптов
// где у нас есть только данные внешности, но не сам Pawn
// Поэтому используем fallback к определению по цвету
return ColorDescriptionService.GetSkinToneDescription(data.SkinColor);
}
private string GetHairDescription(PawnAppearanceData data) private string GetHairDescription(PawnAppearanceData data)
{ {
if (string.IsNullOrEmpty(data.HairDefName)) if (string.IsNullOrEmpty(data.HairDefName))

View File

@@ -1,4 +1,7 @@
using System.Linq;
using RimWorld;
using UnityEngine; using UnityEngine;
using Verse;
namespace AIImages.Services namespace AIImages.Services
{ {
@@ -31,7 +34,23 @@ namespace AIImages.Services
} }
/// <summary> /// <summary>
/// Получает текстовое описание цвета кожи /// Получает текстовое описание цвета кожи, сначала проверяя гены, затем используя цвет как fallback
/// </summary>
public static string GetSkinToneDescription(Pawn pawn)
{
// Сначала проверяем гены цвета кожи
string geneSkinTone = GetSkinToneFromGenes(pawn);
if (!string.IsNullOrEmpty(geneSkinTone))
{
return geneSkinTone;
}
// Fallback к определению по цвету
return GetSkinToneDescription(pawn.story.SkinColor);
}
/// <summary>
/// Получает текстовое описание цвета кожи по RGB цвету (fallback метод)
/// </summary> /// </summary>
public static string GetSkinToneDescription(Color color) public static string GetSkinToneDescription(Color color)
{ {
@@ -59,6 +78,147 @@ namespace AIImages.Services
return "very dark skin"; return "very dark skin";
} }
/// <summary>
/// Получает текстовое описание цвета кожи по генам
/// </summary>
public static string GetSkinToneFromGenes(Pawn pawn)
{
if (pawn?.genes?.GenesListForReading == null)
return null;
// Ищем активные гены цвета кожи
var skinColorGenes = pawn
.genes.GenesListForReading.Where(gene =>
gene.Active && IsSkinColorGene(gene.def.defName)
)
.ToList();
if (!skinColorGenes.Any())
return null;
// Берем первый найденный ген (обычно у персонажа один ген цвета кожи)
var skinGene = skinColorGenes[0];
return GetSkinToneDescriptionFromGene(skinGene.def.defName);
}
/// <summary>
/// Проверяет, является ли ген геном цвета кожи
/// </summary>
private static bool IsSkinColorGene(string geneDefName)
{
return geneDefName.StartsWith("Skin_")
|| geneDefName.Contains("SkinColor")
|| geneDefName.Contains("SkinTone");
}
/// <summary>
/// Получает описание цвета кожи по названию гена
/// </summary>
private static string GetSkinToneDescriptionFromGene(string geneDefName)
{
// Проверяем стандартные гены
string standardGene = GetStandardGeneSkinTone(geneDefName);
if (!string.IsNullOrEmpty(standardGene))
return standardGene;
// Проверяем дополнительные гены
string additionalGene = GetAdditionalGeneSkinTone(geneDefName);
if (!string.IsNullOrEmpty(additionalGene))
return additionalGene;
// Пытаемся извлечь информацию из названия
return ExtractSkinToneFromGeneName(geneDefName);
}
/// <summary>
/// Получает описание для стандартных генов цвета кожи
/// </summary>
private static string GetStandardGeneSkinTone(string geneDefName)
{
switch (geneDefName)
{
case "Skin_InkBlack":
return "ink black skin";
case "Skin_SlateGray":
return "slate gray skin";
case "Skin_LightGray":
return "light gray skin";
case "Skin_SheerWhite":
return "sheer white skin";
case "Skin_Blue":
return "blue skin";
case "Skin_Purple":
return "purple skin";
case "Skin_PaleRed":
return "pale red skin";
case "Skin_DeepRed":
return "deep red skin";
case "Skin_PaleYellow":
return "pale yellow skin";
case "Skin_DeepYellow":
return "deep yellow skin";
case "Skin_Orange":
return "orange skin";
case "Skin_Green":
return "green skin";
default:
return null;
}
}
/// <summary>
/// Получает описание для дополнительных генов цвета кожи
/// </summary>
private static string GetAdditionalGeneSkinTone(string geneDefName)
{
switch (geneDefName)
{
case "Skin_Dark":
return "dark skin";
case "Skin_Light":
return "light skin";
case "Skin_Medium":
return "medium skin";
case "Skin_Fair":
return "fair skin";
case "Skin_Tan":
return "tan skin";
case "Skin_Olive":
return "olive skin";
case "Skin_Brown":
return "brown skin";
default:
return null;
}
}
/// <summary>
/// Извлекает описание цвета кожи из названия гена
/// </summary>
private static string ExtractSkinToneFromGeneName(string geneDefName)
{
if (geneDefName.Contains("Black"))
return "black skin";
if (geneDefName.Contains("White"))
return "white skin";
if (geneDefName.Contains("Gray") || geneDefName.Contains("Grey"))
return "gray skin";
if (geneDefName.Contains("Blue"))
return "blue skin";
if (geneDefName.Contains("Red"))
return "red skin";
if (geneDefName.Contains("Green"))
return "green skin";
if (geneDefName.Contains("Yellow"))
return "yellow skin";
if (geneDefName.Contains("Purple"))
return "purple skin";
if (geneDefName.Contains("Orange"))
return "orange skin";
return null; // Неизвестный ген
}
/// <summary> /// <summary>
/// Получает описание цвета одежды /// Получает описание цвета одежды
/// </summary> /// </summary>

View File

@@ -85,12 +85,10 @@ namespace AIImages.Services
); );
} }
// Цвет кожи (с умным описанием) // Цвет кожи (с умным описанием, сначала проверяем гены)
if (pawn.story.SkinColor != null) string skinDescription = ColorDescriptionService.GetSkinToneDescription(pawn);
if (!string.IsNullOrEmpty(skinDescription))
{ {
string skinDescription = ColorDescriptionService.GetSkinToneDescription(
pawn.story.SkinColor
);
sb.AppendLine("AIImages.Appearance.SkinTone".Translate(skinDescription)); sb.AppendLine("AIImages.Appearance.SkinTone".Translate(skinDescription));
} }

View File

@@ -585,7 +585,7 @@ namespace AIImages
("AIImages.Info.BodyType".Translate(), appearanceData.BodyType), ("AIImages.Info.BodyType".Translate(), appearanceData.BodyType),
( (
"AIImages.Info.SkinTone".Translate(), "AIImages.Info.SkinTone".Translate(),
ColorDescriptionService.GetSkinToneDescription(appearanceData.SkinColor) ColorDescriptionService.GetSkinToneDescription(pawn)
), ),
("AIImages.Info.Hair".Translate(), appearanceData.HairStyle), ("AIImages.Info.Hair".Translate(), appearanceData.HairStyle),
( (
@@ -653,16 +653,29 @@ namespace AIImages
contentY += lineHeight + 2f; contentY += lineHeight + 2f;
Text.Font = GameFont.Tiny; Text.Font = GameFont.Tiny;
var geneLabels = pawn var activeGenes = pawn.genes.GenesListForReading.Where(gene => gene.Active).ToList();
.genes.GenesListForReading.Where(gene => gene.Active) foreach (var gene in activeGenes)
.Select(gene => gene.def.LabelCap);
foreach (var geneLabel in geneLabels)
{ {
// Получаем лейбл гена (предпочитаем Label, если доступен, иначе LabelCap)
string geneLabel = gene.Label ?? gene.def.LabelCap;
// Собираем дополнительную информацию
string geneInfo = geneLabel;
// Добавляем описание, если оно есть и не слишком длинное
if (!string.IsNullOrEmpty(gene.def.description) && gene.def.description.Length < 100)
{
geneInfo += " - " + gene.def.description;
}
// Рассчитываем высоту текста
float textHeight = Text.CalcHeight(geneInfo, parentRect.width - 25f);
Widgets.Label( Widgets.Label(
new Rect(parentRect.x + 15f, contentY, parentRect.width - 20f, lineHeight), new Rect(parentRect.x + 15f, contentY, parentRect.width - 25f, textHeight),
"• " + geneLabel "• " + geneInfo
); );
contentY += lineHeight; contentY += textHeight;
} }
} }
@@ -823,7 +836,21 @@ namespace AIImages
height += 15f; // Отступ height += 15f; // Отступ
height += 22f; // Заголовок "Гены" height += 22f; // Заголовок "Гены"
height += 2f; // Отступ height += 2f; // Отступ
height += pawn.genes.GenesListForReading.Count(gene => gene.Active) * 22f; // Каждый активный ген
// Рассчитываем высоту для каждого гена с учетом описания
Text.Font = GameFont.Tiny;
var activeGenes = pawn.genes.GenesListForReading.Where(gene => gene.Active).ToList();
float labelWidth = parentRect.width - 25f;
foreach (var gene in activeGenes)
{
string geneLabel = gene.Label ?? gene.def.LabelCap;
string geneInfo = geneLabel;
if (!string.IsNullOrEmpty(gene.def.description) && gene.def.description.Length < 100)
{
geneInfo += " - " + gene.def.description;
}
height += Text.CalcHeight("• " + geneInfo, labelWidth);
}
} }
// Хедифы (если есть) // Хедифы (если есть)