From 3a0edd3e1e2f8f7f60b497df17d715ba985814b0 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Mon, 5 Sep 2022 21:28:15 +0800 Subject: [PATCH] Add more options, prepare for options page --- .../Models/Responses/UserSettingResponse.cs | 8 + .../Controllers/Api/DashboardController.cs | 6 +- .../Controllers/Api/UserSettingsController.cs | 33 ++ .../Controllers/Game/BaidController.cs | 4 +- .../Controllers/Game/PlayResultController.cs | 11 +- .../Controllers/Game/UserDataController.cs | 11 +- TaikoLocalServer/Entities/UserDatum.cs | 6 +- .../20220905132703_AddMoreOptions.Designer.cs | 326 ++++++++++++++++++ .../20220905132703_AddMoreOptions.cs | 40 +++ .../Migrations/TaikoDbContextModelSnapshot.cs | 10 +- 10 files changed, 440 insertions(+), 15 deletions(-) create mode 100644 SharedProject/Models/Responses/UserSettingResponse.cs create mode 100644 TaikoLocalServer/Controllers/Api/UserSettingsController.cs create mode 100644 TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.Designer.cs create mode 100644 TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.cs diff --git a/SharedProject/Models/Responses/UserSettingResponse.cs b/SharedProject/Models/Responses/UserSettingResponse.cs new file mode 100644 index 0000000..c6e484d --- /dev/null +++ b/SharedProject/Models/Responses/UserSettingResponse.cs @@ -0,0 +1,8 @@ +namespace SharedProject.Models.Responses; + +public class UserSettingResponse +{ + public uint Baid { get; set; } + + +} \ No newline at end of file diff --git a/TaikoLocalServer/Controllers/Api/DashboardController.cs b/TaikoLocalServer/Controllers/Api/DashboardController.cs index de56d60..1dddd88 100644 --- a/TaikoLocalServer/Controllers/Api/DashboardController.cs +++ b/TaikoLocalServer/Controllers/Api/DashboardController.cs @@ -19,11 +19,7 @@ public class DashboardController : BaseController public DashboardResponse GetDashboard() { var cards = context.Cards.AsEnumerable(); - var users = cards.Select(card => new User - { - AccessCode = card.AccessCode, - Baid = card.Baid - }).ToList(); + var users = cards.Select(card => card.CopyPropertiesToNew()).ToList(); return new DashboardResponse { Users = users diff --git a/TaikoLocalServer/Controllers/Api/UserSettingsController.cs b/TaikoLocalServer/Controllers/Api/UserSettingsController.cs new file mode 100644 index 0000000..f7e6c15 --- /dev/null +++ b/TaikoLocalServer/Controllers/Api/UserSettingsController.cs @@ -0,0 +1,33 @@ +using SharedProject.Models.Responses; + +namespace TaikoLocalServer.Controllers.Api; + +[ApiController] +[Route("/api/[controller]")] +public class UserSettingsController : BaseController +{ + private readonly TaikoDbContext context; + + public UserSettingsController(TaikoDbContext context) + { + this.context = context; + } + + [HttpGet("{baid}")] + public async Task> GetUserSettingResponse(uint baid) + { + var user = await context.UserData.FirstOrDefaultAsync(datum => datum.Baid == baid); + + if (user is null) + { + return NotFound(); + } + + var response = new UserSettingResponse + { + + }; + return Ok(response); + } + +} \ No newline at end of file diff --git a/TaikoLocalServer/Controllers/Game/BaidController.cs b/TaikoLocalServer/Controllers/Game/BaidController.cs index 540ab96..0039832 100644 --- a/TaikoLocalServer/Controllers/Game/BaidController.cs +++ b/TaikoLocalServer/Controllers/Game/BaidController.cs @@ -150,14 +150,14 @@ public class BaidController : BaseController GotDanMax = maxDan, GotDanFlg = gotDanFlagArray, GotDanextraFlg = new byte[20], - DefaultToneSetting = 0, + DefaultToneSetting = userData.SelectedToneId, GenericInfoFlg = new byte[10], AryCrownCounts = crownCount, AryScoreRankCounts = scoreRankCount, IsDispAchievementOn = userData.DisplayAchievement, DispAchievementType = (uint)achievementDisplayDifficulty, IsDispAchievementTypeSet = true, - LastPlayMode = 0, + LastPlayMode = userData.LastPlayMode, IsDispSouuchiOn = true, AiRank = 0, AiTotalWin = 0, diff --git a/TaikoLocalServer/Controllers/Game/PlayResultController.cs b/TaikoLocalServer/Controllers/Game/PlayResultController.cs index b5e80e1..9cee3dd 100644 --- a/TaikoLocalServer/Controllers/Game/PlayResultController.cs +++ b/TaikoLocalServer/Controllers/Game/PlayResultController.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Buffers.Binary; +using System.Globalization; using System.Text.Json; namespace TaikoLocalServer.Controllers.Game; @@ -176,7 +177,15 @@ public class PlayResultController : BaseController }; userdata.CostumeData = JsonSerializer.Serialize(costumeData); + var lastStage = playResultData.AryStageInfoes.Last(); + var option = BinaryPrimitives.ReadInt16LittleEndian(lastStage.OptionFlg); + userdata.OptionSetting = option; + userdata.IsSkipOn = lastStage.IsSkipOn; + userdata.IsVoiceOn = lastStage.IsVoiceOn; + userdata.NotesPosition = lastStage.NotesPosition; + userdata.LastPlayDatetime = lastPlayDatetime; + userdata.LastPlayMode = playResultData.PlayMode; context.UserData.Update(userdata); } diff --git a/TaikoLocalServer/Controllers/Game/UserDataController.cs b/TaikoLocalServer/Controllers/Game/UserDataController.cs index faa5588..e7d1710 100644 --- a/TaikoLocalServer/Controllers/Game/UserDataController.cs +++ b/TaikoLocalServer/Controllers/Game/UserDataController.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System.Buffers.Binary; +using System.Collections; using System.Text.Json; using Throw; @@ -39,7 +40,7 @@ public class UserDataController : BaseController } bitSet.CopyTo(uraSongArray, 0); - var toneArray = new byte[5]; + var toneArray = new byte[16]; Array.Fill(toneArray, byte.MaxValue); var recentSongs = context.SongPlayData @@ -72,6 +73,9 @@ public class UserDataController : BaseController // which means database content need to be fixed, so better throw favoriteSongs.ThrowIfNull("Favorite song should never be null!"); + var defaultOptions = new byte[2]; + BinaryPrimitives.WriteInt16LittleEndian(defaultOptions, userData.OptionSetting); + var response = new UserDataResponse { Result = 1, @@ -85,7 +89,8 @@ public class UserDataController : BaseController IsChallengecompe = false, SongRecentCnt = (uint)recentSongs.Length, AryFavoriteSongNoes = favoriteSongs, - AryRecentSongNoes = recentSongs + AryRecentSongNoes = recentSongs, + NotesPosition = userData.NotesPosition }; diff --git a/TaikoLocalServer/Entities/UserDatum.cs b/TaikoLocalServer/Entities/UserDatum.cs index b5ee0f7..c37d2fd 100644 --- a/TaikoLocalServer/Entities/UserDatum.cs +++ b/TaikoLocalServer/Entities/UserDatum.cs @@ -7,11 +7,13 @@ public string Title { get; set; } = string.Empty; public uint TitlePlateId { get; set; } public string FavoriteSongsArray { get; set; } = string.Empty; - public int OptionSetting { get; set; } + public short OptionSetting { get; set; } + public int NotesPosition { get; set; } public bool IsVoiceOn { get; set; } public bool IsSkipOn { get; set; } + public uint SelectedToneId { get; set; } public DateTime LastPlayDatetime { get; set; } - public long LastPlayMode { get; set; } + public uint LastPlayMode { get; set; } public uint ColorBody { get; set; } public uint ColorFace { get; set; } public uint ColorLimb { get; set; } diff --git a/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.Designer.cs b/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.Designer.cs new file mode 100644 index 0000000..7e0cc2d --- /dev/null +++ b/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.Designer.cs @@ -0,0 +1,326 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TaikoLocalServer.Context; + +#nullable disable + +namespace TaikoLocalServer.Migrations +{ + [DbContext(typeof(TaikoDbContext))] + [Migration("20220905132703_AddMoreOptions")] + partial class AddMoreOptions + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.0-preview.7.22376.2"); + + modelBuilder.Entity("TaikoLocalServer.Entities.Card", b => + { + b.Property("AccessCode") + .HasColumnType("TEXT"); + + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.HasKey("AccessCode"); + + b.HasIndex(new[] { "Baid" }, "IX_Card_Baid") + .IsUnique(); + + b.ToTable("Card", (string)null); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("DanId") + .HasColumnType("INTEGER"); + + b.Property("ArrivalSongCount") + .HasColumnType("INTEGER"); + + b.Property("ClearState") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(0u); + + b.Property("ComboCountTotal") + .HasColumnType("INTEGER"); + + b.Property("SoulGaugeTotal") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "DanId"); + + b.ToTable("DanScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanStageScoreDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("DanId") + .HasColumnType("INTEGER"); + + b.Property("SongNumber") + .HasColumnType("INTEGER"); + + b.Property("BadCount") + .HasColumnType("INTEGER"); + + b.Property("ComboCount") + .HasColumnType("INTEGER"); + + b.Property("DrumrollCount") + .HasColumnType("INTEGER"); + + b.Property("GoodCount") + .HasColumnType("INTEGER"); + + b.Property("HighScore") + .HasColumnType("INTEGER"); + + b.Property("OkCount") + .HasColumnType("INTEGER"); + + b.Property("PlayScore") + .HasColumnType("INTEGER"); + + b.Property("TotalHitCount") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "DanId", "SongNumber"); + + b.ToTable("DanStageScoreData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongBestDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("BestCrown") + .HasColumnType("INTEGER"); + + b.Property("BestRate") + .HasColumnType("INTEGER"); + + b.Property("BestScore") + .HasColumnType("INTEGER"); + + b.Property("BestScoreRank") + .HasColumnType("INTEGER"); + + b.HasKey("Baid", "SongId", "Difficulty"); + + b.ToTable("SongBestData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongPlayDatum", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("ComboCount") + .HasColumnType("INTEGER"); + + b.Property("Crown") + .HasColumnType("INTEGER"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("GoodCount") + .HasColumnType("INTEGER"); + + b.Property("HitCount") + .HasColumnType("INTEGER"); + + b.Property("MissCount") + .HasColumnType("INTEGER"); + + b.Property("OkCount") + .HasColumnType("INTEGER"); + + b.Property("PlayTime") + .HasColumnType("datetime"); + + b.Property("Score") + .HasColumnType("INTEGER"); + + b.Property("ScoreRank") + .HasColumnType("INTEGER"); + + b.Property("ScoreRate") + .HasColumnType("INTEGER"); + + b.Property("Skipped") + .HasColumnType("INTEGER"); + + b.Property("SongId") + .HasColumnType("INTEGER"); + + b.Property("SongNumber") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Baid"); + + b.ToTable("SongPlayData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.UserDatum", b => + { + b.Property("Baid") + .HasColumnType("INTEGER"); + + b.Property("AchievementDisplayDifficulty") + .HasColumnType("INTEGER"); + + b.Property("ColorBody") + .HasColumnType("INTEGER"); + + b.Property("ColorFace") + .HasColumnType("INTEGER"); + + b.Property("ColorLimb") + .HasColumnType("INTEGER"); + + b.Property("CostumeData") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DisplayAchievement") + .HasColumnType("INTEGER"); + + b.Property("DisplayDan") + .HasColumnType("INTEGER"); + + b.Property("FavoriteSongsArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsSkipOn") + .HasColumnType("INTEGER"); + + b.Property("IsVoiceOn") + .HasColumnType("INTEGER"); + + b.Property("LastPlayDatetime") + .HasColumnType("datetime"); + + b.Property("LastPlayMode") + .HasColumnType("INTEGER"); + + b.Property("MyDonName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NotesPosition") + .HasColumnType("INTEGER"); + + b.Property("OptionSetting") + .HasColumnType("INTEGER"); + + b.Property("SelectedToneId") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TitlePlateId") + .HasColumnType("INTEGER"); + + b.HasKey("Baid"); + + b.ToTable("UserData"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanStageScoreDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.DanScoreDatum", "Parent") + .WithMany("DanStageScoreData") + .HasForeignKey("Baid", "DanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongBestDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.SongPlayDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.UserDatum", b => + { + b.HasOne("TaikoLocalServer.Entities.Card", "Ba") + .WithMany() + .HasForeignKey("Baid") + .HasPrincipalKey("Baid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ba"); + }); + + modelBuilder.Entity("TaikoLocalServer.Entities.DanScoreDatum", b => + { + b.Navigation("DanStageScoreData"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.cs b/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.cs new file mode 100644 index 0000000..1ebcadc --- /dev/null +++ b/TaikoLocalServer/Migrations/20220905132703_AddMoreOptions.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TaikoLocalServer.Migrations +{ + /// + public partial class AddMoreOptions : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NotesPosition", + table: "UserData", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "SelectedToneId", + table: "UserData", + type: "INTEGER", + nullable: false, + defaultValue: 0u); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "NotesPosition", + table: "UserData"); + + migrationBuilder.DropColumn( + name: "SelectedToneId", + table: "UserData"); + } + } +} diff --git a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs index 395887c..2562bd1 100644 --- a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs +++ b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs @@ -226,14 +226,20 @@ namespace TaikoLocalServer.Migrations b.Property("LastPlayDatetime") .HasColumnType("datetime"); - b.Property("LastPlayMode") + b.Property("LastPlayMode") .HasColumnType("INTEGER"); b.Property("MyDonName") .IsRequired() .HasColumnType("TEXT"); - b.Property("OptionSetting") + b.Property("NotesPosition") + .HasColumnType("INTEGER"); + + b.Property("OptionSetting") + .HasColumnType("INTEGER"); + + b.Property("SelectedToneId") .HasColumnType("INTEGER"); b.Property("Title")