Skip to content

Commit 6e55ba6

Browse files
committed
应用AI给的三条建议
1 parent aec66c8 commit 6e55ba6

2 files changed

Lines changed: 20 additions & 32 deletions

File tree

MaiChartManager/Controllers/Charts/ImportChartController.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,14 @@ public ImportChartCheckResult ImportChartCheck(IFormFile file, [FromForm] bool i
4343
}
4444

4545
var allChartText = new Dictionary<int, string>();
46-
for (var i = 2; i < 9; i++)
46+
for (var i = 0; i < 9; i++)
4747
{
4848
if (!string.IsNullOrWhiteSpace(maiData.GetValueOrDefault($"inote_{i}")))
4949
{
5050
allChartText.Add(i, maiData.GetValueOrDefault($"inote_{i}"));
5151
}
5252
}
53-
54-
if (!string.IsNullOrWhiteSpace(maiData.GetValueOrDefault("inote_0")))
55-
{
56-
allChartText.Add(0, maiData.GetValueOrDefault($"inote_0"));
57-
}
58-
var targetLevelMap = importService.mapMaidataLevelToGame(allChartText.Keys.ToList());
53+
var targetLevelMap = MaidataImportService.MapMaidataLevelToGame(allChartText.Keys.ToList());
5954

6055
# region 向前端返回,关于导入谱面的inote_映射到游戏中的难度的提示信息
6156
string[] levelNames = [Locale.DifficultyBasic, Locale.DifficultyAdvanced, Locale.DifficultyExpert, Locale.DifficultyMaster, Locale.DifficultyReMaster];

MaiChartManager/Services/MaidataImportService.cs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public static Dictionary<ShiftMethod, float> CalcChartPadding(List<MaiChart> cha
258258
private record AllChartsEntry(string chartText, MaiChart simaiSharpChart);
259259

260260
/** 根据maidata中定义的所有难度,将其映射到游戏中的难度。 **/
261-
public Dictionary<int, int> mapMaidataLevelToGame(List<int> maidataLevels)
261+
public static Dictionary<int, int> MapMaidataLevelToGame(List<int> maidataLevels)
262262
{
263263
var result = new Dictionary<int, int>();
264264
var gameLevels = new bool[5];
@@ -272,32 +272,25 @@ public Dictionary<int, int> mapMaidataLevelToGame(List<int> maidataLevels)
272272
gameLevels[targetLevel] = true;
273273
}
274274

275-
// 再映射78
276-
foreach (var lv in (int[])[7,8])
275+
// 再映射非标准难度
276+
var nonStandardMappings = new[]
277277
{
278-
if (!maidataLevels.Contains(lv)) continue;
279-
foreach (var targetLevel in (int[])[3,4,0]) // 匹配顺序:紫,白,绿
280-
{
281-
if (!gameLevels[targetLevel])
282-
{
283-
result.Add(lv, targetLevel);
284-
gameLevels[targetLevel] = true;
285-
break;
286-
}
287-
}
288-
}
289-
290-
// 再映射0
291-
foreach (var lv in (int[])[0])
278+
new { Levels = new[] { 7, 8 }, Targets = new[] { 3, 4, 0 } }, // lv7和8的匹配顺序:紫,白,绿
279+
new { Levels = new[] { 0 }, Targets = new[] { 0, 3, 4 } } // lv0的匹配顺序:绿,紫,白
280+
};
281+
foreach (var mapping in nonStandardMappings)
292282
{
293-
if (!maidataLevels.Contains(lv)) continue;
294-
foreach (var targetLevel in (int[])[0,3,4]) // 匹配顺序:绿,紫,白
283+
foreach (var lv in mapping.Levels)
295284
{
296-
if (!gameLevels[targetLevel])
285+
if (!maidataLevels.Contains(lv)) continue;
286+
foreach (var targetLevel in mapping.Targets)
297287
{
298-
result.Add(lv, targetLevel);
299-
gameLevels[targetLevel] = true;
300-
break;
288+
if (!gameLevels[targetLevel])
289+
{
290+
result.Add(lv, targetLevel);
291+
gameLevels[targetLevel] = true;
292+
break;
293+
}
301294
}
302295
}
303296
}
@@ -361,7 +354,7 @@ public ImportChartResult ImportMaidata(
361354
}
362355

363356
float bpm = 0f;
364-
var targetLevelMap = mapMaidataLevelToGame(allCharts.Keys.ToList());
357+
var targetLevelMap = MapMaidataLevelToGame(allCharts.Keys.ToList());
365358
foreach (var (level, chart) in allCharts)
366359
{
367360
// 宴会场只导入第一个谱面
@@ -382,7 +375,7 @@ public ImportChartResult ImportMaidata(
382375
{
383376
if (isUtage && !char.IsDigit(levelNumStr[0]))
384377
{
385-
music.UtageKanji = levelNumStr;
378+
music.UtageKanji = levelNumStr.Substring(0, 1);
386379
levelNumStr = levelNumStr.Substring(1).Replace("?", ""); // 为了处理类似“奏13+?”这种情况,留下13+给后面的逻辑处理
387380
}
388381
levelNumStr = levelNumStr.Replace("+", ".7");

0 commit comments

Comments
 (0)