Finish prototype for web interface
Only unlock unlockable songs at first write
This commit is contained in:
parent
d3265dbc02
commit
c8b8a2816e
@ -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<int> 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
|
||||
};
|
||||
}
|
@ -36,6 +36,9 @@ public interface IAppSettings
|
||||
|
||||
[Option(DefaultValue = Configs.DEFAULT_RELAY_PORT)]
|
||||
int RelayPort { get; }
|
||||
|
||||
[Option(DefaultValue = null)]
|
||||
IEnumerable<int>? UnlockableSongIds { get; }
|
||||
|
||||
IEnumerable<IDataResponse> ResponseData { get; }
|
||||
IEnumerable<IOptionServiceResponse> ResponseData { get; }
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace GCLocalServerRewrite.common;
|
||||
|
||||
public interface IDataResponse
|
||||
public interface IOptionServiceResponse
|
||||
{
|
||||
string FileName { get; }
|
||||
|
@ -8,7 +8,7 @@ public static class PathHelper
|
||||
/// <summary>
|
||||
/// Gets the local path of html/static files.
|
||||
/// </summary>
|
||||
public static string HtmlRootPath => Path.Combine(BasePath, Configs.STATIC_FOLDER);
|
||||
public static string HtmlRootPath => Path.Combine(BasePath, Configs.STATIC_FOLDER, Configs.WWWROOT);
|
||||
|
||||
/// <summary>
|
||||
/// Root path for database, when debug, it's under source root, when release, it's the exe dir
|
||||
|
@ -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",
|
||||
|
@ -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<int, SongPlayData> songPlayDataDict)
|
||||
{
|
||||
var option = cardSqLiteConnection.Table<CardDetail>()
|
||||
.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<CardDetail>()
|
||||
.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<CardDetail>()
|
||||
.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<CardDetail>()
|
||||
.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();
|
||||
}
|
||||
|
@ -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<CardDetail>()
|
||||
.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<Music>().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);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@ -6,6 +6,14 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<RunAOTCompilation>False</RunAOTCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<RunAOTCompilation>False</RunAOTCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GenFu" Version="1.6.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.4" />
|
||||
@ -17,5 +25,12 @@
|
||||
<ProjectReference Include="..\SharedProject\SharedProject.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="wwwroot\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
@ -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<User> 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;
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,4 @@
|
||||
<RootNamespace>SharedProject</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ChoETL" Version="1.2.1.47" />
|
||||
<PackageReference Include="sqlite-net2" Version="2.1.0-preB" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
9
SharedProject/common/ScoreGradeMap.cs
Normal file
9
SharedProject/common/ScoreGradeMap.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace SharedProject.common;
|
||||
|
||||
public record ScoreGradeMap(int Score, string Grade)
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ Score = {Score}, Grade = {Grade} }}";
|
||||
}
|
||||
}
|
34
SharedProject/common/SharedConstants.cs
Normal file
34
SharedProject/common/SharedConstants.cs
Normal file
@ -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++")
|
||||
};
|
||||
}
|
@ -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; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user