Add SwarmUI settings management and portrait generation enhancements

- Introduced new API endpoints for managing SwarmUI settings, including fetching and saving presets and age rules.
- Updated the portrait generation logic to utilize the new settings structure, allowing for dynamic preset selection based on age.
- Enhanced UI components to support SwarmUI settings, including localization for new strings and improved styling for settings sections.
- Added tests to verify the functionality of new settings endpoints and portrait generation behavior.

This commit lays the groundwork for more flexible and user-friendly portrait generation options.
This commit is contained in:
Leonid Pershin
2026-08-20 06:06:45 +03:00
parent e0b7122f3b
commit 5a400be792
32 changed files with 2178 additions and 184 deletions
@@ -0,0 +1,43 @@
using HSchool.Server.Game;
namespace HSchool.Server.Tests;
public class SwarmUiSettingsStoreTests
{
[Fact]
public void Resolve_UsesAgeRulePreset()
{
var config = SwarmUiConfigFile.CreateDefault();
var profile = config.Resolve(8, PortraitKind.Avatar);
Assert.Equal("child", profile.PresetId);
}
[Fact]
public void Resolve_FallsBackToActivePresetForAdults()
{
var config = SwarmUiConfigFile.CreateDefault();
var profile = config.Resolve(34, PortraitKind.Full);
Assert.Equal("default", profile.PresetId);
}
[Fact]
public void NormalizeAfterLoad_MigratesLegacyFlatFile()
{
var config = new SwarmUiConfigFile
{
Model = "legacy.safetensors",
Steps = 12,
Positive = "legacy prompt",
Avatar = new SwarmUiKindPreset { Width = 640, Height = 640 },
};
config.NormalizeAfterLoad();
Assert.Single(config.Presets);
Assert.Equal("default", config.Presets[0].Id);
Assert.Equal("legacy.safetensors", config.Presets[0].Model);
Assert.Equal(12, config.Presets[0].Steps);
}
}