Finish prototype for web interface
Only unlock unlockable songs at first write
This commit is contained in:
@@ -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
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user