1
0
mirror of synced 2024-11-28 00:20:53 +01:00

SongIntroduction

This commit is contained in:
TLH 2022-09-14 21:08:28 +09:00
parent 95dc84d4b2
commit 1941ef86cb
5 changed files with 82 additions and 6 deletions

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace SharedProject.Models;
public class SongIntroductionData
{
[JsonPropertyName("setId")]
public uint SetId { get; set; }
[JsonPropertyName("verupNo")]
public uint VerupNo { get; set; }
[JsonPropertyName("mainSongNo")]
public uint MainSongNo { get; set; }
[JsonPropertyName("subSongNo")]
public uint[]? SubSongNo { get; set; }
}

View File

@ -24,6 +24,8 @@ public static class Constants
public const string DAN_DATA_FILE_NAME = "dan_data.json"; public const string DAN_DATA_FILE_NAME = "dan_data.json";
public const string INTRO_DATA_FILE_NAME = "intro_data.json";
public const int MIN_DAN_ID = 1; public const int MIN_DAN_ID = 1;
public const int MAX_DAN_ID = 19; public const int MAX_DAN_ID = 19;
public const int GOT_DAN_BITS = MAX_DAN_ID * 4; public const int GOT_DAN_BITS = MAX_DAN_ID * 4;

View File

@ -0,0 +1,42 @@
using System.Collections.Immutable;
using System.Text.Json;
using SharedProject.Models;
namespace TaikoLocalServer.Common.Utils;
public class SongIntroductionDataManager
{
public ImmutableDictionary<uint, GetSongIntroductionResponse.SongIntroductionData> IntroDataList { get; }
static SongIntroductionDataManager() { }
private SongIntroductionDataManager()
{
var dataPath = PathHelper.GetDataPath();
var filePath = Path.Combine(dataPath, Constants.INTRO_DATA_FILE_NAME);
var jsonString = File.ReadAllText(filePath);
var result = JsonSerializer.Deserialize<List<SongIntroductionData>>(jsonString);
if (result is null)
{
throw new ApplicationException("Cannot parse intro data json!");
}
IntroDataList = result.ToImmutableDictionary(data => data.SetId, ToResponseIntroData);
}
private GetSongIntroductionResponse.SongIntroductionData ToResponseIntroData(SongIntroductionData data)
{
var responseOdaiData = new GetSongIntroductionResponse.SongIntroductionData
{
SetId = data.SetId,
VerupNo = data.VerupNo,
MainSongNo = data.MainSongNo,
SubSongNoes = data.SubSongNo
};
return responseOdaiData;
}
public static SongIntroductionDataManager Instance { get; } = new();
}

View File

@ -15,15 +15,17 @@ public class GetSongIntroductionController : BaseController<GetSongIntroductionC
Result = 1 Result = 1
}; };
var manager = SongIntroductionDataManager.Instance;
foreach (var setId in request.SetIds) foreach (var setId in request.SetIds)
{ {
response.ArySongIntroductionDatas.Add(new GetSongIntroductionResponse.SongIntroductionData manager.IntroDataList.TryGetValue(setId, out var introData);
if (introData is null)
{ {
MainSongNo = 2, Logger.LogWarning("Requested set id {Id} does not exist!", setId);
SubSongNoes = new uint[] {177,193,3,4}, continue;
SetId = setId, }
VerupNo = 1
}); response.ArySongIntroductionDatas.Add(introData);
} }
return Ok(response); return Ok(response);

View File

@ -32,6 +32,17 @@ public class InitialDataCheckController : BaseController<InitialDataCheckControl
}); });
} }
var manager = SongIntroductionDataManager.Instance;
var introData = new List<InitialdatacheckResponse.InformationData>();
for (var setId = 1; setId <= manager.IntroDataList.Count; setId++)
{
introData.Add(new InitialdatacheckResponse.InformationData
{
InfoId = (uint)setId,
VerupNo = 1
});
}
var response = new InitialdatacheckResponse var response = new InitialdatacheckResponse
{ {
Result = 1, Result = 1,
@ -100,6 +111,7 @@ public class InitialDataCheckController : BaseController<InitialDataCheckControl
});*/ });*/
}; };
response.AryDanOdaiDatas.AddRange(danData); response.AryDanOdaiDatas.AddRange(danData);
response.ArySongIntroductionDatas.AddRange(introData);
return Ok(response); return Ok(response);
} }