Add DifficultySettingArray handle and WebUI
This commit is contained in:
parent
05cdeb0dec
commit
4fedead174
@ -10,6 +10,12 @@ public class UserSetting
|
|||||||
|
|
||||||
public bool IsDisplayDanOnNamePlate { get; set; }
|
public bool IsDisplayDanOnNamePlate { get; set; }
|
||||||
|
|
||||||
|
public uint DifficultySettingCourse { get; set; }
|
||||||
|
|
||||||
|
public uint DifficultySettingStar { get; set; }
|
||||||
|
|
||||||
|
public uint DifficultySettingSort { get; set; }
|
||||||
|
|
||||||
public bool IsVoiceOn { get; set; }
|
public bool IsVoiceOn { get; set; }
|
||||||
|
|
||||||
public bool IsSkipOn { get; set; }
|
public bool IsSkipOn { get; set; }
|
||||||
|
@ -1,10 +1,33 @@
|
|||||||
using System.Text.Json;
|
using GameDatabase.Entities;
|
||||||
using GameDatabase.Entities;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace TaikoLocalServer.Common.Utils;
|
namespace TaikoLocalServer.Common.Utils;
|
||||||
|
|
||||||
public static class JsonHelper
|
public static class JsonHelper
|
||||||
{
|
{
|
||||||
|
public static uint[] GetUIntArrayFromJson(string data, int length, ILogger logger, string fieldName)
|
||||||
|
{
|
||||||
|
var array = new uint[length];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
array = JsonSerializer.Deserialize<uint[]>(data);
|
||||||
|
}
|
||||||
|
catch (JsonException e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "Parsing {FieldName} json data failed", fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array != null && array.Length >= length)
|
||||||
|
{
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogWarning($"{fieldName} is null or length less than {length}!");
|
||||||
|
array = new uint[length];
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<uint> GetCostumeDataFromUserData(UserDatum userData, ILogger logger)
|
public static List<uint> GetCostumeDataFromUserData(UserDatum userData, ILogger logger)
|
||||||
{
|
{
|
||||||
var costumeData = new List<uint> { 0, 0, 0, 0, 0 };
|
var costumeData = new List<uint> { 0, 0, 0, 0, 0 };
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Text.Json;
|
using SharedProject.Models;
|
||||||
using SharedProject.Models;
|
|
||||||
using SharedProject.Utils;
|
using SharedProject.Utils;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace TaikoLocalServer.Controllers.Api;
|
namespace TaikoLocalServer.Controllers.Api;
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var difficultySettingArray = JsonHelper.GetUIntArrayFromJson(user.DifficultySettingArray, 3, Logger, nameof(user.DifficultySettingArray));
|
||||||
|
|
||||||
var costumeData = JsonHelper.GetCostumeDataFromUserData(user, Logger);
|
var costumeData = JsonHelper.GetCostumeDataFromUserData(user, Logger);
|
||||||
|
|
||||||
var costumeUnlockData = JsonHelper.GetCostumeUnlockDataFromUserData(user, Logger);
|
var costumeUnlockData = JsonHelper.GetCostumeUnlockDataFromUserData(user, Logger);
|
||||||
@ -34,6 +36,9 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
|||||||
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
|
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
|
||||||
IsDisplayAchievement = user.DisplayAchievement,
|
IsDisplayAchievement = user.DisplayAchievement,
|
||||||
IsDisplayDanOnNamePlate = user.DisplayDan,
|
IsDisplayDanOnNamePlate = user.DisplayDan,
|
||||||
|
DifficultySettingCourse = difficultySettingArray[0],
|
||||||
|
DifficultySettingStar = difficultySettingArray[1],
|
||||||
|
DifficultySettingSort = difficultySettingArray[2],
|
||||||
IsVoiceOn = user.IsVoiceOn,
|
IsVoiceOn = user.IsVoiceOn,
|
||||||
IsSkipOn = user.IsSkipOn,
|
IsSkipOn = user.IsSkipOn,
|
||||||
NotesPosition = user.NotesPosition,
|
NotesPosition = user.NotesPosition,
|
||||||
@ -78,10 +83,18 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
|||||||
userSetting.Puchi,
|
userSetting.Puchi,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var difficultySettings = new List<uint>
|
||||||
|
{
|
||||||
|
userSetting.DifficultySettingCourse,
|
||||||
|
userSetting.DifficultySettingStar,
|
||||||
|
userSetting.DifficultySettingSort
|
||||||
|
};
|
||||||
|
|
||||||
user.IsSkipOn = userSetting.IsSkipOn;
|
user.IsSkipOn = userSetting.IsSkipOn;
|
||||||
user.IsVoiceOn = userSetting.IsVoiceOn;
|
user.IsVoiceOn = userSetting.IsVoiceOn;
|
||||||
user.DisplayAchievement = userSetting.IsDisplayAchievement;
|
user.DisplayAchievement = userSetting.IsDisplayAchievement;
|
||||||
user.DisplayDan = userSetting.IsDisplayDanOnNamePlate;
|
user.DisplayDan = userSetting.IsDisplayDanOnNamePlate;
|
||||||
|
user.DifficultySettingArray = JsonSerializer.Serialize(difficultySettings);
|
||||||
user.NotesPosition = userSetting.NotesPosition;
|
user.NotesPosition = userSetting.NotesPosition;
|
||||||
user.SelectedToneId = userSetting.ToneId;
|
user.SelectedToneId = userSetting.ToneId;
|
||||||
user.AchievementDisplayDifficulty = userSetting.AchievementDisplayDifficulty;
|
user.AchievementDisplayDifficulty = userSetting.AchievementDisplayDifficulty;
|
||||||
@ -94,7 +107,6 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
|||||||
user.ColorLimb = userSetting.LimbColor;
|
user.ColorLimb = userSetting.LimbColor;
|
||||||
user.CostumeData = JsonSerializer.Serialize(costumes);
|
user.CostumeData = JsonSerializer.Serialize(costumes);
|
||||||
|
|
||||||
|
|
||||||
await userDatumService.UpdateUserDatum(user);
|
await userDatumService.UpdateUserDatum(user);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Buffers.Binary;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System.Buffers.Binary;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using TaikoLocalServer.Settings;
|
using TaikoLocalServer.Settings;
|
||||||
using Throw;
|
using Throw;
|
||||||
|
|
||||||
@ -111,25 +111,16 @@ public class UserDataController : BaseController<UserDataController>
|
|||||||
var defaultOptions = new byte[2];
|
var defaultOptions = new byte[2];
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(defaultOptions, userData.OptionSetting);
|
BinaryPrimitives.WriteInt16LittleEndian(defaultOptions, userData.OptionSetting);
|
||||||
|
|
||||||
var difficultyPlayedArray = Array.Empty<uint>();
|
var difficultySettingArray = JsonHelper.GetUIntArrayFromJson(userData.DifficultySettingArray, 3, Logger, nameof(userData.DifficultySettingArray));
|
||||||
try
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
difficultyPlayedArray = JsonSerializer.Deserialize<uint[]>(userData.DifficultyPlayedArray);
|
if (difficultySettingArray[i] >= 2)
|
||||||
|
{
|
||||||
|
difficultySettingArray[i] -= 1;
|
||||||
}
|
}
|
||||||
catch (JsonException e)
|
|
||||||
{
|
|
||||||
Logger.LogError(e, "Parsing difficulty played json data failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var difficultySettingArray = Array.Empty<uint>();
|
var difficultyPlayedArray = JsonHelper.GetUIntArrayFromJson(userData.DifficultyPlayedArray, 3, Logger, nameof(userData.DifficultyPlayedArray));
|
||||||
try
|
|
||||||
{
|
|
||||||
difficultySettingArray = JsonSerializer.Deserialize<uint[]>(userData.DifficultySettingArray);
|
|
||||||
}
|
|
||||||
catch (JsonException e)
|
|
||||||
{
|
|
||||||
Logger.LogError(e, "Parsing difficulty setting json data failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = new UserDataResponse
|
var response = new UserDataResponse
|
||||||
{
|
{
|
||||||
@ -144,24 +135,16 @@ public class UserDataController : BaseController<UserDataController>
|
|||||||
NotesPosition = userData.NotesPosition,
|
NotesPosition = userData.NotesPosition,
|
||||||
IsVoiceOn = userData.IsVoiceOn,
|
IsVoiceOn = userData.IsVoiceOn,
|
||||||
IsSkipOn = userData.IsSkipOn,
|
IsSkipOn = userData.IsSkipOn,
|
||||||
|
DifficultySettingCourse = difficultySettingArray[0],
|
||||||
|
DifficultySettingStar = difficultySettingArray[1],
|
||||||
|
DifficultySettingSort = difficultySettingArray[2],
|
||||||
|
DifficultyPlayedCourse = difficultyPlayedArray[0],
|
||||||
|
DifficultyPlayedStar = difficultyPlayedArray[1],
|
||||||
|
DifficultyPlayedSort = difficultyPlayedArray[2],
|
||||||
IsChallengecompe = false,
|
IsChallengecompe = false,
|
||||||
SongRecentCnt = (uint)recentSongs.Length
|
SongRecentCnt = (uint)recentSongs.Length
|
||||||
};
|
};
|
||||||
|
|
||||||
if (difficultyPlayedArray is { Length: >= 3 })
|
|
||||||
{
|
|
||||||
response.DifficultyPlayedCourse = difficultyPlayedArray[0];
|
|
||||||
response.DifficultyPlayedStar = difficultyPlayedArray[1];
|
|
||||||
response.DifficultyPlayedSort = difficultyPlayedArray[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (difficultySettingArray is { Length: >= 3 })
|
|
||||||
{
|
|
||||||
response.DifficultySettingCourse = difficultySettingArray[0];
|
|
||||||
response.DifficultySettingStar = difficultySettingArray[1];
|
|
||||||
response.DifficultySettingSort = difficultySettingArray[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,9 +46,42 @@
|
|||||||
}
|
}
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudStack Spacing="4">
|
||||||
<MudSwitch @bind-Checked="@response.IsDisplayAchievement" Label="Display Achievement Panel" Color="Color.Primary" />
|
<MudSwitch @bind-Checked="@response.IsDisplayAchievement" Label="Display Achievement Panel" Color="Color.Primary" />
|
||||||
<MudSwitch @bind-Checked="@response.IsDisplayDanOnNamePlate" Label="Display Dan Rank on Name Plate" Color="Color.Primary" />
|
<MudSwitch @bind-Checked="@response.IsDisplayDanOnNamePlate" Label="Display Dan Rank on Name Plate" Color="Color.Primary" />
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="8">
|
||||||
|
<MudStack Spacing="4">
|
||||||
|
<MudSelect @bind-Value="@response.DifficultySettingCourse" Label="Difficulty Setting Course">
|
||||||
|
@for (uint i = 0; i < DifficultySettingCourseStrings.Length; i++)
|
||||||
|
{
|
||||||
|
var index = i;
|
||||||
|
<MudSelectItem Value="@i">@DifficultySettingCourseStrings[index]</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudSelect @bind-Value="@response.DifficultySettingStar" Label="Difficulty Setting Star">
|
||||||
|
@for (uint i = 0; i < DifficultySettingStarStrings.Length; i++)
|
||||||
|
{
|
||||||
|
var index = i;
|
||||||
|
<MudSelectItem Value="@i">@DifficultySettingStarStrings[index]</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudSelect @bind-Value="@response.DifficultySettingSort" Label="Difficulty Setting Sort">
|
||||||
|
@for (uint i = 0; i < DifficultySettingSortStrings.Length; i++)
|
||||||
|
{
|
||||||
|
var index = i;
|
||||||
|
<MudSelectItem Value="@i">@DifficultySettingSortStrings[index]</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
</MudStack>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudStack>
|
||||||
</MudTabPanel>
|
</MudTabPanel>
|
||||||
|
|
||||||
<MudTabPanel Text="Costume">
|
<MudTabPanel Text="Costume">
|
||||||
|
@ -50,6 +50,24 @@ public partial class Profile
|
|||||||
"AI 1", "AI 2", "AI 3", "AI 4"
|
"AI 1", "AI 2", "AI 3", "AI 4"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly string[] DifficultySettingCourseStrings =
|
||||||
|
{
|
||||||
|
"None", "Set up each time",
|
||||||
|
"Easy", "Normal", "Hard", "Oni", "Ura Oni"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly string[] DifficultySettingStarStrings =
|
||||||
|
{
|
||||||
|
"None", "Set up each time",
|
||||||
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly string[] DifficultySettingSortStrings =
|
||||||
|
{
|
||||||
|
"None", "Set up each time", "Default",
|
||||||
|
"Not cleared", "Not Full Combo", "Not Donderful Combo"
|
||||||
|
};
|
||||||
|
|
||||||
private readonly List<BreadcrumbItem> breadcrumbs = new()
|
private readonly List<BreadcrumbItem> breadcrumbs = new()
|
||||||
{
|
{
|
||||||
new BreadcrumbItem("Cards", href: "/Cards"),
|
new BreadcrumbItem("Cards", href: "/Cards"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user