Add player settings feature and settings API
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user