From 9f9abcc17049801c83d207ffa8ff160ffd87041b Mon Sep 17 00:00:00 2001 From: Yuchen Ji Date: Wed, 29 Nov 2023 03:28:29 +0800 Subject: [PATCH 1/2] Unlock tone when selected --- .../Controllers/Api/UserSettingsController.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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(); From b0b3ba7fd771a5fc882ad24d004231decc090a3d Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Wed, 29 Nov 2023 03:28:29 +0800 Subject: [PATCH 2/2] Unlock tone when selected --- .../Controllers/Api/UserSettingsController.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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();