Add player settings feature and settings API

This commit is contained in:
Holden
2026-06-20 22:58:33 -05:00
parent f4887c3f93
commit e77e479493
17 changed files with 405 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ public class Profile
public DateTimeOffset CreatedAt { get; private set; }
public Avatar Avatar { get; private set; } = Avatar.Empty;
public ICollection<PlayerSetting> Settings { get; } = [];
public static Profile Create(
string name,
@@ -86,6 +87,19 @@ public class Profile
public void SetAvatar(Avatar avatar)
=> Avatar = avatar ?? throw new DomainException("Avatar is required.");
public void SetSetting(string key, string value)
{
var existing = Settings.FirstOrDefault(x => x.Key == key);
if (existing is null)
{
Settings.Add(new PlayerSetting(ProfileId, key, value));
return;
}
existing.UpdateValue(value);
}
private static string RequireValue(string value, string parameterName)
=> !string.IsNullOrWhiteSpace(value) ? value : throw new DomainException($"{parameterName} is required.");
}