diff --git a/TaikoLocalServer/Controllers/Api/UserSettingsController.cs b/TaikoLocalServer/Controllers/Api/UserSettingsController.cs index ca790de..8ae4dab 100644 --- a/TaikoLocalServer/Controllers/Api/UserSettingsController.cs +++ b/TaikoLocalServer/Controllers/Api/UserSettingsController.cs @@ -1,6 +1,7 @@ using SharedProject.Models; using SharedProject.Utils; using System.Text.Json; +using Throw; namespace TaikoLocalServer.Controllers.Api; @@ -123,6 +124,21 @@ public class UserSettingsController : BaseController user.ColorLimb = userSetting.LimbColor; user.CostumeData = JsonSerializer.Serialize(costumes); + // If a locked tone is selected, unlock it + uint[] toneFlg = { 0u }; + try + { + toneFlg = JsonSerializer.Deserialize(user.ToneFlgArray)!; + } + catch (JsonException e) + { + Logger.LogError(e, "Parsing tone flg json data failed"); + } + toneFlg.ThrowIfNull("Tone flg should never be null!"); + toneFlg = toneFlg.Append(0u).Append(userSetting.ToneId).Distinct().ToArray(); + + user.ToneFlgArray = JsonSerializer.Serialize(toneFlg); + await userDatumService.UpdateUserDatum(user); return NoContent();