Skip to content

Commit f9cefb6

Browse files
authored
Merge pull request #5 from asesidaa/CostumeUI
Add costume menu to profile page, add player titles
2 parents ca449e6 + b52544c commit f9cefb6

20 files changed

Lines changed: 682 additions & 171 deletions

File tree

SharedProject/Models/UserSetting.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,36 @@ public class UserSetting
2020

2121
public int NotesPosition { get; set; }
2222

23-
public string MyDonName { get; set; } = String.Empty;
23+
public string MyDonName { get; set; } = string.Empty;
2424

25-
public string Title { get; set; } = String.Empty;
25+
public string Title { get; set; } = string.Empty;
2626

2727
public uint TitlePlateId { get; set; }
28+
29+
public uint Kigurumi { get; set; }
30+
31+
public uint Head { get; set; }
32+
33+
public uint Body { get; set; }
34+
35+
public uint Face { get; set; }
36+
37+
public uint Puchi { get; set; }
38+
39+
public List<uint> UnlockedKigurumi { get; set; } = new();
40+
41+
public List<uint> UnlockedHead { get; set; } = new();
42+
43+
public List<uint> UnlockedBody { get; set; } = new();
44+
45+
public List<uint> UnlockedFace { get; set; } = new();
46+
47+
public List<uint> UnlockedPuchi { get; set; } = new();
48+
49+
public uint FaceColor { get; set; }
50+
51+
public uint BodyColor { get; set; }
52+
53+
public uint LimbColor { get; set; }
54+
2855
}

TaikoLocalServer.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kigurumi/@EntryIndexedValue">True</s:Boolean>
23
<s:Boolean x:Key="/Default/UserDictionary/Words/=musicinfo/@EntryIndexedValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/UserDictionary/Words/=Namco/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Puchi/@EntryIndexedValue">True</s:Boolean>
46
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vocaloid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Text.Json;
2+
3+
namespace TaikoLocalServer.Common.Utils;
4+
5+
public static class JsonHelper
6+
{
7+
public static List<uint> GetCostumeDataFromUserData(UserDatum userData, ILogger logger)
8+
{
9+
var costumeData = new List<uint> { 0, 0, 0, 0, 0 };
10+
try
11+
{
12+
costumeData = JsonSerializer.Deserialize<List<uint>>(userData.CostumeData);
13+
}
14+
catch (JsonException e)
15+
{
16+
logger.LogError(e, "Parsing costume json data failed");
17+
}
18+
19+
if (costumeData != null && costumeData.Count >= 5)
20+
{
21+
return costumeData;
22+
}
23+
24+
logger.LogWarning("Costume data is null or count less than 5!");
25+
costumeData = new List<uint> { 0, 0, 0, 0, 0 };
26+
27+
return costumeData;
28+
}
29+
30+
public static List<List<uint>> GetCostumeUnlockDataFromUserData(UserDatum userData, ILogger logger)
31+
{
32+
var costumeUnlockData = new List<List<uint>> { new(), new(), new(), new(), new() };
33+
try
34+
{
35+
costumeUnlockData = JsonSerializer.Deserialize<List<List<uint>>>(userData.CostumeFlgArray);
36+
}
37+
catch (JsonException e)
38+
{
39+
logger.LogError(e, "Parsing costume json data failed");
40+
}
41+
42+
if (costumeUnlockData != null && costumeUnlockData.Count >= 5)
43+
{
44+
return costumeUnlockData;
45+
}
46+
47+
logger.LogWarning("Costume unlock data is null or count less than 5!");
48+
costumeUnlockData = new List<List<uint>> { new(), new(), new(), new(), new() };
49+
50+
return costumeUnlockData;
51+
}
52+
}

TaikoLocalServer/Common/Utils/PathHelper.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static class PathHelper
44
{
5-
public static string GetDataPath()
5+
public static string GetRootPath()
66
{
77
var path = Environment.ProcessPath;
88
if (path is null)
@@ -14,6 +14,11 @@ public static string GetDataPath()
1414
{
1515
throw new ApplicationException();
1616
}
17-
return Path.Combine(parentPath.ToString(), "wwwroot", "data");
17+
return Path.Combine(parentPath.ToString(), "wwwroot");
18+
}
19+
20+
public static string GetDataPath()
21+
{
22+
return Path.Combine(GetRootPath(), "data");
1823
}
1924
}

TaikoLocalServer/Context/TaikoDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2222
{
2323
return;
2424
}
25-
var path = Path.Combine(PathHelper.GetDataPath(), Constants.DEFAULT_DB_NAME);
25+
var path = Path.Combine(PathHelper.GetRootPath(), Constants.DEFAULT_DB_NAME);
2626
optionsBuilder.UseSqlite($"Data Source={path}");
2727
}
2828

TaikoLocalServer/Controllers/Api/UserSettingsController.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Buffers.Binary;
2+
using System.Text.Json;
23
using SharedProject.Models;
34
using SharedProject.Models.Responses;
45
using SharedProject.Utils;
56
using TaikoLocalServer.Services;
67
using TaikoLocalServer.Services.Interfaces;
8+
using Throw;
79

810
namespace TaikoLocalServer.Controllers.Api;
911

@@ -28,6 +30,10 @@ public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
2830
return NotFound();
2931
}
3032

33+
var costumeData = JsonHelper.GetCostumeDataFromUserData(user, Logger);
34+
35+
var costumeUnlockData = JsonHelper.GetCostumeUnlockDataFromUserData(user, Logger);
36+
3137
var response = new UserSetting
3238
{
3339
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
@@ -40,7 +46,20 @@ public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
4046
ToneId = user.SelectedToneId,
4147
MyDonName = user.MyDonName,
4248
Title = user.Title,
43-
TitlePlateId = user.TitlePlateId
49+
TitlePlateId = user.TitlePlateId,
50+
Kigurumi = costumeData[0],
51+
Head = costumeData[1],
52+
Body = costumeData[2],
53+
Face = costumeData[3],
54+
Puchi = costumeData[4],
55+
UnlockedKigurumi = costumeUnlockData[0],
56+
UnlockedHead = costumeUnlockData[1],
57+
UnlockedBody = costumeUnlockData[2],
58+
UnlockedFace = costumeUnlockData[3],
59+
UnlockedPuchi = costumeUnlockData[4],
60+
BodyColor = user.ColorBody,
61+
FaceColor = user.ColorFace,
62+
LimbColor = user.ColorLimb
4463
};
4564
return Ok(response);
4665
}
@@ -55,6 +74,15 @@ public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSett
5574
return NotFound();
5675
}
5776

77+
var costumes = new List<uint>
78+
{
79+
userSetting.Kigurumi,
80+
userSetting.Head,
81+
userSetting.Body,
82+
userSetting.Face,
83+
userSetting.Puchi,
84+
};
85+
5886
user.IsSkipOn = userSetting.IsSkipOn;
5987
user.IsVoiceOn = userSetting.IsVoiceOn;
6088
user.DisplayAchievement = userSetting.IsDisplayAchievement;
@@ -66,6 +94,11 @@ public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSett
6694
user.MyDonName = userSetting.MyDonName;
6795
user.Title = userSetting.Title;
6896
user.TitlePlateId = userSetting.TitlePlateId;
97+
user.ColorBody = userSetting.BodyColor;
98+
user.ColorFace = userSetting.FaceColor;
99+
user.ColorLimb = userSetting.LimbColor;
100+
user.CostumeData = JsonSerializer.Serialize(costumes);
101+
69102

70103
await userDatumService.UpdateUserDatum(user);
71104

TaikoLocalServer/Controllers/Game/BaidController.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Text.Json;
2-
using TaikoLocalServer.Services.Interfaces;
3-
using Throw;
1+
using TaikoLocalServer.Services.Interfaces;
42

53
namespace TaikoLocalServer.Controllers.Game;
64

@@ -79,34 +77,9 @@ public async Task<IActionResult> GetBaid([FromBody] BAIDRequest request)
7977
var scoreRankCount = CalculateScoreRankCount(songCountData);
8078

8179

82-
var costumeData = new List<uint>{ 0, 0, 0, 0, 0 };
83-
try
84-
{
85-
costumeData = JsonSerializer.Deserialize<List<uint>>(userData.CostumeData);
86-
}
87-
catch (JsonException e)
88-
{
89-
Logger.LogError(e, "Parsing costume json data failed");
90-
}
91-
if (costumeData == null || costumeData.Count < 5)
92-
{
93-
Logger.LogWarning("Costume data is null or count less than 5!");
94-
costumeData = new List<uint> { 0, 0, 0, 0, 0 };
95-
}
96-
97-
var costumeArrays = Array.Empty<uint[]>();
98-
try
99-
{
100-
costumeArrays = JsonSerializer.Deserialize<uint[][]>(userData.CostumeFlgArray);
101-
}
102-
catch (JsonException e)
103-
{
104-
Logger.LogError(e, "Parsing costume flg json data failed");
105-
}
80+
var costumeData = JsonHelper.GetCostumeDataFromUserData(userData, Logger);
10681

107-
// The only way to get a null is provide string "null" as input,
108-
// which means database content need to be fixed, so better throw
109-
costumeArrays.ThrowIfNull("Costume flg should never be null!");
82+
var costumeArrays = JsonHelper.GetCostumeUnlockDataFromUserData(userData, Logger);
11083

11184
var costumeFlagArrays = Constants.CostumeFlagArraySizes
11285
.Select((size, index) => FlagCalculator.GetBitArrayFromIds(costumeArrays[index], size, Logger))

TaikoLocalServer/Entities/UserDatum.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ public partial class UserDatum
66
public string MyDonName { get; set; } = string.Empty;
77
public string Title { get; set; } = string.Empty;
88
public uint TitlePlateId { get; set; }
9-
public string FavoriteSongsArray { get; set; } = string.Empty;
10-
public string ToneFlgArray { get; set; } = string.Empty;
11-
public string TitleFlgArray { get; set; } = string.Empty;
12-
public string CostumeFlgArray { get; set; } = string.Empty;
9+
public string FavoriteSongsArray { get; set; } = "[]";
10+
public string ToneFlgArray { get; set; } = "[]";
11+
public string TitleFlgArray { get; set; } = "[]";
12+
public string CostumeFlgArray { get; set; } = "[]";
1313
public short OptionSetting { get; set; }
1414
public int NotesPosition { get; set; }
1515
public bool IsVoiceOn { get; set; }
@@ -20,7 +20,7 @@ public partial class UserDatum
2020
public uint ColorBody { get; set; }
2121
public uint ColorFace { get; set; }
2222
public uint ColorLimb { get; set; }
23-
public string CostumeData { get; set; } = string.Empty;
23+
public string CostumeData { get; set; } = "[[],[],[],[],[]]";
2424
public bool DisplayDan { get; set; }
2525
public bool DisplayAchievement { get; set; }
2626
public Difficulty AchievementDisplayDifficulty { get; set; }

TaikoLocalServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{
3131
dbName = Constants.DEFAULT_DB_NAME;
3232
}
33-
var path = Path.Combine(PathHelper.GetDataPath(), dbName);
33+
var path = Path.Combine(PathHelper.GetRootPath(), dbName);
3434
option.UseSqlite($"Data Source={path}");
3535
});
3636
builder.Services.AddHttpLogging(options =>

TaikoLocalServer/Services/Interfaces/IUserDatumService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public interface IUserDatumService
1717
public Task<List<uint>> GetFavoriteSongIds(uint baid);
1818

1919
public Task UpdateFavoriteSong(uint baid, uint songId, bool isFavorite);
20+
21+
2022
}

0 commit comments

Comments
 (0)