Files
ai-images/Source/AIImages/Components/PawnPortraitComp.cs

118 lines
4.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Linq;
using AIImages.Helpers;
using Verse;
namespace AIImages.Components
{
/// <summary>
/// Компонент для хранения данных AI-сгенерированных портретов пешки
/// </summary>
public class PawnPortraitComp : ThingComp
{
/// <summary>
/// Список путей к сохраненным портретам (галерея)
/// </summary>
private List<string> portraitPaths = new List<string>();
/// <summary>
/// Есть ли сохраненные портреты
/// </summary>
public bool HasPortrait => portraitPaths != null && portraitPaths.Count > 0;
/// <summary>
/// Количество портретов в галерее
/// </summary>
public int PortraitCount => portraitPaths?.Count ?? 0;
/// <summary>
/// Получить все пути к портретам
/// </summary>
public List<string> GetAllPortraits() => portraitPaths?.ToList() ?? new List<string>();
/// <summary>
/// Получить последний портрет (для обратной совместимости)
/// </summary>
public string PortraitPath => HasPortrait ? portraitPaths.Last() : null;
/// <summary>
/// Добавить новый портрет в галерею
/// </summary>
public void AddPortrait(string path)
{
if (string.IsNullOrEmpty(path))
return;
if (portraitPaths == null)
portraitPaths = new List<string>();
portraitPaths.Add(path);
DebugLogger.Log($"[AI Images] Added portrait to gallery: {path}");
}
/// <summary>
/// Удалить портрет из галереи
/// </summary>
public bool RemovePortrait(string path)
{
if (portraitPaths == null || string.IsNullOrEmpty(path))
return false;
bool removed = portraitPaths.Remove(path);
if (removed)
{
DebugLogger.Log($"[AI Images] Removed portrait from gallery: {path}");
}
return removed;
}
/// <summary>
/// Очистить все портреты
/// </summary>
public void ClearPortraits()
{
if (portraitPaths != null)
{
int count = portraitPaths.Count;
portraitPaths.Clear();
DebugLogger.Log($"[AI Images] Cleared {count} portraits from gallery");
}
}
/// <summary>
/// Сохранение/загрузка данных
/// </summary>
public override void PostExposeData()
{
base.PostExposeData();
bool isSaving = Scribe.mode == LoadSaveMode.Saving;
bool isLoading = Scribe.mode == LoadSaveMode.LoadingVars;
DebugLogger.Log(
$"[AI Images] PostExposeData for {parent?.LabelShort} - Mode: {Scribe.mode}, Portrait count: {PortraitCount}"
);
// Сохраняем список портретов
Scribe_Collections.Look(ref portraitPaths, "aiPortraitPaths", LookMode.Value);
// Обратная совместимость: если есть старый формат с одним портретом, добавляем его в список
if (isLoading && (portraitPaths == null || portraitPaths.Count == 0))
{
string oldPortraitPath = null;
Scribe_Values.Look(ref oldPortraitPath, "aiPortraitPath", null);
if (!string.IsNullOrEmpty(oldPortraitPath))
{
portraitPaths = new List<string> { oldPortraitPath };
DebugLogger.Log($"[AI Images] Migrated old single portrait to gallery: {oldPortraitPath}");
}
}
DebugLogger.Log(
$"[AI Images] PostExposeData completed for {parent?.LabelShort} - Portrait count: {PortraitCount}, HasPortrait: {HasPortrait}"
);
}
}
}