Add user setting UI and api
Use more user settings
This commit is contained in:
parent
3a0edd3e1e
commit
524ae10439
8
SharedProject/Enums/RandomType.cs
Normal file
8
SharedProject/Enums/RandomType.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace SharedProject.Enums;
|
||||
|
||||
public enum RandomType
|
||||
{
|
||||
None = 0,
|
||||
Whimsical = 1,
|
||||
Messy = 2
|
||||
}
|
14
SharedProject/Models/PlaySetting.cs
Normal file
14
SharedProject/Models/PlaySetting.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace SharedProject.Models;
|
||||
|
||||
public class PlaySetting
|
||||
{
|
||||
public uint Speed { get; set; }
|
||||
|
||||
public bool IsVanishOn { get; set; }
|
||||
|
||||
public bool IsInverseOn { get; set; }
|
||||
|
||||
public RandomType RandomType { get; set; }
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace SharedProject.Models.Responses;
|
||||
|
||||
public class UserSettingResponse
|
||||
{
|
||||
public uint Baid { get; set; }
|
||||
|
||||
|
||||
}
|
22
SharedProject/Models/UserSetting.cs
Normal file
22
SharedProject/Models/UserSetting.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace SharedProject.Models;
|
||||
|
||||
public class UserSetting
|
||||
{
|
||||
public uint ToneId { get; set; }
|
||||
|
||||
public bool IsDisplayAchievement { get; set; }
|
||||
|
||||
public bool IsDisplayDanOnNamePlate { get; set; }
|
||||
|
||||
public bool IsVoiceOn { get; set; }
|
||||
|
||||
public bool IsSkipOn { get; set; }
|
||||
|
||||
public Difficulty AchievementDisplayDifficulty { get; set; }
|
||||
|
||||
public PlaySetting PlaySetting { get; set; } = new();
|
||||
|
||||
public int NotesPosition { get; set; }
|
||||
}
|
@ -10,4 +10,8 @@
|
||||
<Folder Include="Models\Requests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Throw" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
48
SharedProject/Utils/PlaySettingConverter.cs
Normal file
48
SharedProject/Utils/PlaySettingConverter.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Models;
|
||||
using Throw;
|
||||
|
||||
namespace SharedProject.Utils;
|
||||
|
||||
public static class PlaySettingConverter
|
||||
{
|
||||
public static PlaySetting ShortToPlaySetting(short input)
|
||||
{
|
||||
var bits = new BitVector32(input);
|
||||
var speedSection = BitVector32.CreateSection(15);
|
||||
var vanishSection = BitVector32.CreateSection(1, speedSection);
|
||||
var inverseSection = BitVector32.CreateSection(1, vanishSection);
|
||||
var randomSection = BitVector32.CreateSection(2, inverseSection);
|
||||
|
||||
var randomType = (RandomType)bits[randomSection];
|
||||
randomType.Throw().IfOutOfRange();
|
||||
var result = new PlaySetting
|
||||
{
|
||||
Speed = (uint)bits[speedSection],
|
||||
IsVanishOn = bits[vanishSection] == 1,
|
||||
IsInverseOn = bits[inverseSection] == 1,
|
||||
RandomType = randomType
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static short PlaySettingToShort(PlaySetting setting)
|
||||
{
|
||||
var bits = new BitVector32();
|
||||
var speedSection = BitVector32.CreateSection(15);
|
||||
var vanishSection = BitVector32.CreateSection(1, speedSection);
|
||||
var inverseSection = BitVector32.CreateSection(1, vanishSection);
|
||||
var randomSection = BitVector32.CreateSection(2, inverseSection);
|
||||
|
||||
bits[speedSection] = (int)setting.Speed;
|
||||
bits[vanishSection] = setting.IsVanishOn ? 1 : 0;
|
||||
bits[inverseSection] = setting.IsInverseOn ? 1 : 0;
|
||||
bits[randomSection] = (int)setting.RandomType;
|
||||
|
||||
return (short)bits.Data;
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using SharedProject.Models.Responses;
|
||||
using System.Buffers.Binary;
|
||||
using SharedProject.Models;
|
||||
using SharedProject.Models.Responses;
|
||||
using SharedProject.Utils;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/[controller]")]
|
||||
[Route("/api/[controller]/{baid}")]
|
||||
public class UserSettingsController : BaseController<UserSettingsController>
|
||||
{
|
||||
private readonly TaikoDbContext context;
|
||||
@ -13,8 +16,8 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
[HttpGet("{baid}")]
|
||||
public async Task<ActionResult<UserSettingResponse>> GetUserSettingResponse(uint baid)
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
|
||||
{
|
||||
var user = await context.UserData.FirstOrDefaultAsync(datum => datum.Baid == baid);
|
||||
|
||||
@ -23,11 +26,43 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var response = new UserSettingResponse
|
||||
var response = new UserSetting
|
||||
{
|
||||
|
||||
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
|
||||
IsDisplayAchievement = user.DisplayAchievement,
|
||||
IsDisplayDanOnNamePlate = user.DisplayDan,
|
||||
IsVoiceOn = user.IsVoiceOn,
|
||||
IsSkipOn = user.IsSkipOn,
|
||||
NotesPosition = user.NotesPosition,
|
||||
PlaySetting = PlaySettingConverter.ShortToPlaySetting(user.OptionSetting),
|
||||
ToneId = user.SelectedToneId
|
||||
};
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
|
||||
{
|
||||
var user = await context.UserData.FirstOrDefaultAsync(datum => datum.Baid == baid);
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
user.IsSkipOn = userSetting.IsSkipOn;
|
||||
user.IsVoiceOn = userSetting.IsVoiceOn;
|
||||
user.DisplayAchievement = userSetting.IsDisplayAchievement;
|
||||
user.DisplayDan = userSetting.IsDisplayDanOnNamePlate;
|
||||
user.NotesPosition = userSetting.NotesPosition;
|
||||
user.SelectedToneId = userSetting.ToneId;
|
||||
user.AchievementDisplayDifficulty = userSetting.AchievementDisplayDifficulty;
|
||||
user.OptionSetting = PlaySettingConverter.PlaySettingToShort(userSetting.PlaySetting);
|
||||
|
||||
context.Update(user);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
@ -146,7 +146,7 @@ public class BaidController : BaseController<BaidController>
|
||||
CostumeFlg4 = costumeFlag,
|
||||
CostumeFlg5 = costumeFlag,
|
||||
LastPlayDatetime = userData.LastPlayDatetime.ToString(Constants.DATE_TIME_FORMAT),
|
||||
IsDispDanOn = /*userData.DisplayDan*/ true,
|
||||
IsDispDanOn = userData.DisplayDan,
|
||||
GotDanMax = maxDan,
|
||||
GotDanFlg = gotDanFlagArray,
|
||||
GotDanextraFlg = new byte[20],
|
||||
|
@ -83,7 +83,7 @@ public class UserDataController : BaseController<UserDataController>
|
||||
// TitleFlg = GZipBytesUtil.GetGZipBytes(new byte[100]),
|
||||
ReleaseSongFlg = releaseSongArray,
|
||||
UraReleaseSongFlg = uraSongArray,
|
||||
DefaultOptionSetting = new byte[] {0},
|
||||
DefaultOptionSetting = defaultOptions,
|
||||
IsVoiceOn = userData.IsVoiceOn,
|
||||
IsSkipOn = userData.IsSkipOn,
|
||||
IsChallengecompe = false,
|
||||
|
@ -23,7 +23,7 @@
|
||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Throw" Version="1.2.0" />
|
||||
<PackageReference Include="Throw" Version="1.3.0" />
|
||||
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="0.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,8 +1,115 @@
|
||||
@page "/Card/{baid}"
|
||||
@using SharedProject.Models.Responses
|
||||
@using SharedProject.Enums
|
||||
@using SharedProject.Models
|
||||
@inject HttpClient Client
|
||||
|
||||
<h1>Card: @Baid</h1>
|
||||
|
||||
@if (response is not null)
|
||||
{
|
||||
<MudStack>
|
||||
<MudSelect @bind-Value="@response.IsDisplayAchievement"
|
||||
Label="Is Display Achievement Panel">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.IsSkipOn"
|
||||
Label="Is Skip On">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.IsVoiceOn"
|
||||
Label="Is Voice On">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.IsDisplayDanOnNamePlate"
|
||||
Label="Should Dan be Displayed On Name Plate">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.AchievementDisplayDifficulty"
|
||||
Label="Difficulty Used on Achievement Panel">
|
||||
@foreach (var item in Enum.GetValues<Difficulty>())
|
||||
{
|
||||
<MudSelectItem Value="@item"/>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.NotesPosition"
|
||||
Label="Notes Position">
|
||||
@for (var i = -5; i <= 5; i++)
|
||||
{
|
||||
<MudSelectItem Value="@i"/>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.PlaySetting.RandomType"
|
||||
Label="Random">
|
||||
@foreach (var item in Enum.GetValues<RandomType>())
|
||||
{
|
||||
<MudSelectItem Value="@item"/>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.PlaySetting.Speed"
|
||||
Label="Speed">
|
||||
@for (uint i = 0; i < 15; i++)
|
||||
{
|
||||
var index= i;
|
||||
<MudSelectItem Value="@i">@speedStrings[index]</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.PlaySetting.IsInverseOn"
|
||||
Label="Inverse">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.PlaySetting.IsVanishOn"
|
||||
Label="Vanish">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudButton Disabled="@isSavingOptions"
|
||||
OnClick="SaveOptions"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Info">
|
||||
@if (isSavingOptions)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true"/>
|
||||
<MudText Class="ms-2">Saving...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudIcon Icon="@Icons.Filled.Save"></MudIcon>
|
||||
<MudText>Save</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string? Baid { get; set; }
|
||||
|
||||
private UserSetting? response;
|
||||
|
||||
private bool isSavingOptions;
|
||||
|
||||
private readonly string[] speedStrings = { "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9",
|
||||
"2.0", "2.5", "3.0", "3.5", "4.0"};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
isSavingOptions = false;
|
||||
response = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
||||
}
|
||||
|
||||
private async Task SaveOptions()
|
||||
{
|
||||
isSavingOptions = true;
|
||||
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
||||
isSavingOptions = false;
|
||||
}
|
||||
|
||||
}
|
@ -45,7 +45,7 @@
|
||||
}
|
||||
|
||||
|
||||
void NavigateToProfile(uint baid)
|
||||
private void NavigateToProfile(uint baid)
|
||||
{
|
||||
UriHelper.NavigateTo($"/Card/{baid}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user