diff --git a/TaikoLocalServer/Controllers/Game/BaidController.cs b/TaikoLocalServer/Controllers/Game/BaidController.cs index 32b98bd..934d53e 100644 --- a/TaikoLocalServer/Controllers/Game/BaidController.cs +++ b/TaikoLocalServer/Controllers/Game/BaidController.cs @@ -1,4 +1,6 @@ -using TaikoLocalServer.Services.Interfaces; +using System.Text.Json; +using TaikoLocalServer.Services.Interfaces; +using Throw; namespace TaikoLocalServer.Controllers.Game; @@ -93,6 +95,23 @@ public class BaidController : BaseController .Max(); var gotDanFlagArray = FlagCalculator.ComputeGotDanFlags(danData); + var genericInfoFlg = Array.Empty(); + try + { + genericInfoFlg = JsonSerializer.Deserialize(userData.GenericInfoFlgArray); + } + catch (JsonException e) + { + Logger.LogError(e, "Parsing genericinfo flg json data failed"); + } + + // The only way to get a null is provide string "null" as input, + // which means database content need to be fixed, so better throw + genericInfoFlg.ThrowIfNull("Genericinfo flg should never be null!"); + + var genericInfoFlgLength = genericInfoFlg.Any()? genericInfoFlg.Max() + 1 : 0; + var genericInfoFlgArray = FlagCalculator.GetBitArrayFromIds(genericInfoFlg, (int)genericInfoFlgLength, Logger); + response = new BAIDResponse { Result = 1, @@ -131,7 +150,7 @@ public class BaidController : BaseController GotDanFlg = gotDanFlagArray, GotDanextraFlg = new byte[20], DefaultToneSetting = userData.SelectedToneId, - GenericInfoFlg = new byte[10], + GenericInfoFlg = genericInfoFlgArray, AryCrownCounts = crownCount, AryScoreRankCounts = scoreRankCount, IsDispAchievementOn = userData.DisplayAchievement, diff --git a/TaikoLocalServer/Controllers/Game/MyDonEntryController.cs b/TaikoLocalServer/Controllers/Game/MyDonEntryController.cs index 9fd7e23..2764a97 100644 --- a/TaikoLocalServer/Controllers/Game/MyDonEntryController.cs +++ b/TaikoLocalServer/Controllers/Game/MyDonEntryController.cs @@ -43,7 +43,8 @@ public class MyDonEntryController : BaseController FavoriteSongsArray = "[]", ToneFlgArray = "[]", TitleFlgArray = "[]", - CostumeFlgArray = "[[],[],[],[],[]]" + CostumeFlgArray = "[[],[],[],[],[]]", + GenericInfoFlgArray = "[]" }; await userDatumService.InsertUserDatum(newUser); diff --git a/TaikoLocalServer/Controllers/Game/PlayResultController.cs b/TaikoLocalServer/Controllers/Game/PlayResultController.cs index bc1cbed..43e5ea2 100644 --- a/TaikoLocalServer/Controllers/Game/PlayResultController.cs +++ b/TaikoLocalServer/Controllers/Game/PlayResultController.cs @@ -196,8 +196,7 @@ public class PlayResultController : BaseController UpdateJsonUintFlagArray(userdata.ToneFlgArray, playResultData.GetToneNoes, nameof(userdata.ToneFlgArray)); userdata.TitleFlgArray = - UpdateJsonUintFlagArray(userdata.TitleFlgArray, playResultData.GetTitleNoes, - nameof(userdata.TitleFlgArray)); + UpdateJsonUintFlagArray(userdata.TitleFlgArray, playResultData.GetTitleNoes, nameof(userdata.TitleFlgArray)); userdata.CostumeFlgArray = UpdateJsonCostumeFlagArray(userdata.CostumeFlgArray, new[] @@ -209,6 +208,9 @@ public class PlayResultController : BaseController playResultData.GetCostumeNo5s }); + userdata.GenericInfoFlgArray = + UpdateJsonUintFlagArray(userdata.GenericInfoFlgArray, playResultData.GetGenericInfoNoes, nameof(userdata.GenericInfoFlgArray)); + await userDatumService.UpdateUserDatum(userdata); } diff --git a/TaikoLocalServer/Entities/UserDatum.cs b/TaikoLocalServer/Entities/UserDatum.cs index cfd98b6..21d0653 100644 --- a/TaikoLocalServer/Entities/UserDatum.cs +++ b/TaikoLocalServer/Entities/UserDatum.cs @@ -9,7 +9,8 @@ public string FavoriteSongsArray { get; set; } = "[]"; public string ToneFlgArray { get; set; } = "[]"; public string TitleFlgArray { get; set; } = "[]"; - public string CostumeFlgArray { get; set; } = "[]"; + public string CostumeFlgArray { get; set; } = "[[],[],[],[],[]]"; + public string GenericInfoFlgArray { get; set; } = "[]"; public short OptionSetting { get; set; } public int NotesPosition { get; set; } public bool IsVoiceOn { get; set; } diff --git a/TaikoLocalServer/Migrations/20220916121143_AddGenericInfoFlg.Designer.cs b/TaikoLocalServer/Migrations/20220916121143_AddGenericInfoFlg.Designer.cs new file mode 100644 index 0000000..60e6607 --- /dev/null +++ b/TaikoLocalServer/Migrations/20220916121143_AddGenericInfoFlg.Designer.cs @@ -0,0 +1,345 @@ +// +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("20220916121143_AddGenericInfoFlg")] + partial class AddGenericInfoFlg + { + /// + 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("DrumrollCount") + .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("CostumeFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DisplayAchievement") + .HasColumnType("INTEGER"); + + b.Property("DisplayDan") + .HasColumnType("INTEGER"); + + b.Property("FavoriteSongsArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("GenericInfoFlgArray") + .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("TitleFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TitlePlateId") + .HasColumnType("INTEGER"); + + b.Property("ToneFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + + 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/20220916121143_AddGenericInfoFlg.cs b/TaikoLocalServer/Migrations/20220916121143_AddGenericInfoFlg.cs new file mode 100644 index 0000000..638183a --- /dev/null +++ b/TaikoLocalServer/Migrations/20220916121143_AddGenericInfoFlg.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TaikoLocalServer.Migrations +{ + /// + public partial class AddGenericInfoFlg : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "GenericInfoFlgArray", + table: "UserData", + type: "TEXT", + nullable: false, + defaultValue: "[]"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "GenericInfoFlgArray", + table: "UserData"); + } + } +} diff --git a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs index 2dba260..90b5110 100644 --- a/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs +++ b/TaikoLocalServer/Migrations/TaikoDbContextModelSnapshot.cs @@ -224,6 +224,10 @@ namespace TaikoLocalServer.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("GenericInfoFlgArray") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("IsSkipOn") .HasColumnType("INTEGER");