diff --git a/GC-local-server-rewrite/common/Configs.cs b/GC-local-server-rewrite/common/Configs.cs index 66f30a8..3ca1c3b 100644 --- a/GC-local-server-rewrite/common/Configs.cs +++ b/GC-local-server-rewrite/common/Configs.cs @@ -22,6 +22,8 @@ public static class Configs public const string STATIC_FOLDER = "static"; + public const string WWWROOT = "wwwroot"; + public const string API_BASE_ROUTE = "/api"; public const string OPTION_SERVICE_BASE_ROUTE = "/service/option"; @@ -154,4 +156,11 @@ public static class Configs public const string DEFAULT_SERVER_IP = "127.0.0.1"; public const string DEFAULT_RELAY_SERVER = "127.0.0.1"; public const int DEFAULT_RELAY_PORT = 54321; + + public static readonly IReadOnlyList DEFAULT_UNLOCKABLE_SONGS = new[] + { + 11, 13, 149, 273, 291, 320, 321, 371, 378, 384, 464, 471, 474, 475, 492, 494, 498, 520, + 548, 551, 558, 561, 565, 570, 577, 583, 612, 615, 622, 632, 659, 666, 668, 670, 672, 676, + 680, 682, 685, 686, 697, 700, 701, 711, 720, 749, 875, 876, 877 + }; } \ No newline at end of file diff --git a/GC-local-server-rewrite/common/IAppSettings.cs b/GC-local-server-rewrite/common/IAppSettings.cs index 41771cd..2e3f671 100644 --- a/GC-local-server-rewrite/common/IAppSettings.cs +++ b/GC-local-server-rewrite/common/IAppSettings.cs @@ -36,6 +36,9 @@ public interface IAppSettings [Option(DefaultValue = Configs.DEFAULT_RELAY_PORT)] int RelayPort { get; } + + [Option(DefaultValue = null)] + IEnumerable? UnlockableSongIds { get; } - IEnumerable ResponseData { get; } + IEnumerable ResponseData { get; } } \ No newline at end of file diff --git a/GC-local-server-rewrite/common/IDataResponse.cs b/GC-local-server-rewrite/common/IOptionServiceResponse.cs similarity index 83% rename from GC-local-server-rewrite/common/IDataResponse.cs rename to GC-local-server-rewrite/common/IOptionServiceResponse.cs index 778348c..b418772 100644 --- a/GC-local-server-rewrite/common/IDataResponse.cs +++ b/GC-local-server-rewrite/common/IOptionServiceResponse.cs @@ -1,6 +1,6 @@ namespace GCLocalServerRewrite.common; -public interface IDataResponse +public interface IOptionServiceResponse { string FileName { get; } diff --git a/GC-local-server-rewrite/common/PathHelper.cs b/GC-local-server-rewrite/common/PathHelper.cs index 0fbdf21..3e76097 100644 --- a/GC-local-server-rewrite/common/PathHelper.cs +++ b/GC-local-server-rewrite/common/PathHelper.cs @@ -8,7 +8,7 @@ public static class PathHelper /// /// Gets the local path of html/static files. /// - public static string HtmlRootPath => Path.Combine(BasePath, Configs.STATIC_FOLDER); + public static string HtmlRootPath => Path.Combine(BasePath, Configs.STATIC_FOLDER, Configs.WWWROOT); /// /// Root path for database, when debug, it's under source root, when release, it's the exe dir diff --git a/GC-local-server-rewrite/config.json b/GC-local-server-rewrite/config.json index 8d87f9b..cd11d2b 100644 --- a/GC-local-server-rewrite/config.json +++ b/GC-local-server-rewrite/config.json @@ -10,6 +10,11 @@ "ServerIp": "127.0.0.1", "RelayServer": "26.56.10.224", "RelayPort": 54321, + "UnlockableSongIds": [ + 11, 13, 149, 273, 291, 320, 321, 371, 378, 384, 464, 471, 474, 475, 492, 494, 498, 520, + 548, 551, 558, 561, 565, 570, 577, 583, 612, 615, 622, 632, 659, 666, 668, 670, 672, 676, + 680, 682, 685, 686, 697, 700, 701, 711, 720, 749, 875, 876, 877 + ], "ResponseData": [ { "FileName": "/event_103_20201125.evt", diff --git a/GC-local-server-rewrite/controllers/ApiController.cs b/GC-local-server-rewrite/controllers/ApiController.cs index 2a13769..5186ca0 100644 --- a/GC-local-server-rewrite/controllers/ApiController.cs +++ b/GC-local-server-rewrite/controllers/ApiController.cs @@ -3,6 +3,7 @@ using EmbedIO.Routing; using EmbedIO.WebApi; using GCLocalServerRewrite.common; using GCLocalServerRewrite.models; +using SharedProject.common; using SharedProject.enums; using SharedProject.models; using SQLite.Net2; @@ -125,14 +126,18 @@ public class ApiController : WebApiController private void ProcessCardDetail(UserDetail userDetail, IDictionary songPlayDataDict) { var option = cardSqLiteConnection.Table() - .FirstOrDefault(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == 0, new CardDetail + .FirstOrDefault(detail => detail.CardId == userDetail.CardId + && detail.Pcol1 == Configs.CONFIG_PCOL1 + && detail.Pcol2 == Configs.CONFIG_PCOL2 + && detail.Pcol3 == Configs.CONFIG_PCOL3 + , new CardDetail { CardId = userDetail.CardId }); SetOptions(option, userDetail); var songCounts = cardSqLiteConnection.Table() - .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == 20); + .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == Configs.COUNT_PCOL1); foreach (var detail in songCounts) { @@ -140,7 +145,7 @@ public class ApiController : WebApiController } var songScores = cardSqLiteConnection.Table() - .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == 21); + .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == Configs.SCORE_PCOL1); foreach (var detail in songScores) { @@ -148,7 +153,7 @@ public class ApiController : WebApiController } var favorites = cardSqLiteConnection.Table() - .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == 10) + .Where(detail => detail.CardId == userDetail.CardId && detail.Pcol1 == Configs.FAVORITE_PCOL1) .ToDictionary(detail => detail.Pcol2); foreach (var (musicId, songPlayData) in songPlayDataDict) @@ -186,7 +191,7 @@ public class ApiController : WebApiController AddSongPlayDataIfNotExist(songPlayDataDict, musicId); - for (var i = 0; i < 4; i++) + for (var i = 0; i < SharedConstants.DIFFICULTY_COUNT; i++) { var songPlayDetailData = songPlayDataDict[musicId].SongPlaySubDataList[i]; songPlayDetailData.Difficulty = (Difficulty)i; @@ -201,17 +206,17 @@ public class ApiController : WebApiController userDetail.TotalScore += cardDetail.ScoreUi1; - if (cardDetail.ScoreUi1 >= 900000) + if (cardDetail.ScoreUi1 >= SharedConstants.S_SCORE_THRESHOLD) { userDetail.SAboveStageCount++; } - if (cardDetail.ScoreUi1 >= 950000) + if (cardDetail.ScoreUi1 >= SharedConstants.S_PLUS_SCORE_THRESHOLD) { userDetail.SPlusAboveStageCount++; } - if (cardDetail.ScoreUi1 >= 990000) + if (cardDetail.ScoreUi1 >= SharedConstants.S_PLUS_PLUS_SCORE_THRESHOLD) { userDetail.SPlusPlusAboveStageCount++; } @@ -224,7 +229,7 @@ public class ApiController : WebApiController AddSongPlayDataIfNotExist(songPlayDataDict, musicId); - for (var i = 0; i < 4; i++) + for (var i = 0; i < SharedConstants.DIFFICULTY_COUNT; i++) { var songPlayDetailData = songPlayDataDict[musicId].SongPlaySubDataList[i]; @@ -278,10 +283,10 @@ public class ApiController : WebApiController Artist = musicData.Artist ?? string.Empty, Title = musicData.Title ?? string.Empty, MusicId = musicId, - SongPlaySubDataList = new SongPlayDetailData[4] + SongPlaySubDataList = new SongPlayDetailData[SharedConstants.DIFFICULTY_COUNT] }; - for (var i = 0; i < 4; i++) + for (var i = 0; i < SharedConstants.DIFFICULTY_COUNT; i++) { songPlayData.SongPlaySubDataList[i] = new SongPlayDetailData(); } diff --git a/GC-local-server-rewrite/controllers/CardServiceController.cs b/GC-local-server-rewrite/controllers/CardServiceController.cs index 03b66f7..a7fdb42 100644 --- a/GC-local-server-rewrite/controllers/CardServiceController.cs +++ b/GC-local-server-rewrite/controllers/CardServiceController.cs @@ -1,4 +1,5 @@ -using System.Net.Mime; +using System.Diagnostics; +using System.Net.Mime; using System.Text; using System.Xml.Linq; using ChoETL; @@ -539,21 +540,26 @@ public class CardServiceController : WebApiController var result = cardSqLiteConnection.Table() .Where(detail => detail.CardId == cardId); - // Populate song unlocks in card details table when write for the first time + // Unlock all unlockable songs in card details table when write for the first time if (!result.Any()) { - var musics = musicSqLiteConnection.Table().ToList(); - var detailList = musics.Select(music => new CardDetail + var unlockableSongIds = Configs.SETTINGS.UnlockableSongIds; + + if (unlockableSongIds is null) + { + unlockableSongIds = Configs.DEFAULT_UNLOCKABLE_SONGS; + } + var detailList = unlockableSongIds!.Select(id => new CardDetail { CardId = cardId, Pcol1 = 10, - Pcol2 = music.MusicId, + Pcol2 = id, Pcol3 = 0, ScoreUi2 = 1, ScoreUi6 = 1 }) .ToList(); - + cardSqLiteConnection.InsertOrIgnoreAll(detailList); } diff --git a/MudAdmin/MudAdmin.csproj b/MudAdmin/MudAdmin.csproj index 4a0e5b7..8161d5f 100644 --- a/MudAdmin/MudAdmin.csproj +++ b/MudAdmin/MudAdmin.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,6 +6,14 @@ enable + + False + + + + False + + @@ -17,5 +25,12 @@ + + + PreserveNewest + true + + + \ No newline at end of file diff --git a/MudAdmin/Pages/User.razor b/MudAdmin/Pages/User.razor index a109dd5..30e1c09 100644 --- a/MudAdmin/Pages/User.razor +++ b/MudAdmin/Pages/User.razor @@ -1,6 +1,7 @@ @page "/user/{CardId:long}" @using SharedProject.models @using SharedProject.enums +@using SharedProject.common @inject HttpClient Client @inject IDialogService DialogService @inject ILogger Logger @@ -147,18 +148,6 @@ else private bool isSavingOptions; - private static readonly ScoreGradeMap[] GRADES = - { - new(0, "E"), - new(300000, "D"), - new(500000, "C"), - new(700000, "B"), - new(800000, "A"), - new(900000, "S"), - new(950000, "S+"), - new(990000, "S++"), - }; - protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -186,17 +175,9 @@ else isSavingOptions = false; } - public record ScoreGradeMap(int Score, string Grade) - { - public override string ToString() - { - return $"{{ Score = {Score}, Grade = {Grade} }}"; - } - } - private static string CalculateRating(int score) { - var grade = GRADES.Where(g => g.Score <= score).Select(g => g.Grade).Last(); + var grade = SharedConstants.GRADES.Where(g => g.Score <= score).Select(g => g.Grade).Last(); return grade; } diff --git a/SharedProject/SharedProject.csproj b/SharedProject/SharedProject.csproj index c647bae..52b24a0 100644 --- a/SharedProject/SharedProject.csproj +++ b/SharedProject/SharedProject.csproj @@ -7,10 +7,4 @@ SharedProject - - - - - - diff --git a/SharedProject/common/ScoreGradeMap.cs b/SharedProject/common/ScoreGradeMap.cs new file mode 100644 index 0000000..58c0786 --- /dev/null +++ b/SharedProject/common/ScoreGradeMap.cs @@ -0,0 +1,9 @@ +namespace SharedProject.common; + +public record ScoreGradeMap(int Score, string Grade) +{ + public override string ToString() + { + return $"{{ Score = {Score}, Grade = {Grade} }}"; + } +} \ No newline at end of file diff --git a/SharedProject/common/SharedConstants.cs b/SharedProject/common/SharedConstants.cs new file mode 100644 index 0000000..e960722 --- /dev/null +++ b/SharedProject/common/SharedConstants.cs @@ -0,0 +1,34 @@ +namespace SharedProject.common; + +public static class SharedConstants +{ + public const int DIFFICULTY_COUNT = 4; + + public const int E_SCORE_THRESHOLD = 0; + + public const int D_SCORE_THRESHOLD = 300000; + + public const int C_SCORE_THRESHOLD = 500000; + + public const int B_SCORE_THRESHOLD = 700000; + + public const int A_SCORE_THRESHOLD = 800000; + + public const int S_SCORE_THRESHOLD = 900000; + + public const int S_PLUS_SCORE_THRESHOLD = 950000; + + public const int S_PLUS_PLUS_SCORE_THRESHOLD = 990000; + + public static readonly ScoreGradeMap[] GRADES = + { + new(E_SCORE_THRESHOLD, "E"), + new(D_SCORE_THRESHOLD, "D"), + new(C_SCORE_THRESHOLD, "C"), + new(B_SCORE_THRESHOLD, "B"), + new(A_SCORE_THRESHOLD, "A"), + new(S_SCORE_THRESHOLD, "S"), + new(S_PLUS_SCORE_THRESHOLD, "S+"), + new(S_PLUS_PLUS_SCORE_THRESHOLD, "S++") + }; +} \ No newline at end of file diff --git a/SharedProject/models/SongPlayData.cs b/SharedProject/models/SongPlayData.cs index 41744a1..67f7ef5 100644 --- a/SharedProject/models/SongPlayData.cs +++ b/SharedProject/models/SongPlayData.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using SharedProject.common; namespace SharedProject.models; @@ -10,7 +11,7 @@ public class SongPlayData public int MusicId { get; set; } - public SongPlayDetailData[] SongPlaySubDataList { get; set; } = new SongPlayDetailData[4]; + public SongPlayDetailData[] SongPlaySubDataList { get; set; } = new SongPlayDetailData[SharedConstants.DIFFICULTY_COUNT]; public bool IsFavorite { get; set; }