Skip to content

Commit 91a0455

Browse files
committed
[F&R] 修复若干问题
1 parent cd61fd7 commit 91a0455

5 files changed

Lines changed: 18 additions & 48 deletions

File tree

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ riderModule.iml
88
.cursor
99
/.tmp*
1010
*scratch*
11-
*.lscache
12-
13-
# 测试 dump 输出
14-
*_output.*
15-
placeholder.txt
11+
*.lscache

generator/chu/C2sGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ private static C2sChart ConvertToC2s(IChuChart chart, List<Alert> alerts)
5353
return result;
5454
}
5555

56-
alerts.Add(new Alert(Warning, string.Format(Locale.ChuGeneratorUnsupported, "→ C2S")));
57-
return new C2sChart();
56+
alerts.Add(new Alert(Error, string.Format(Locale.ChuGeneratorUnsupported, "→ C2S")));
57+
throw new ConversionException(alerts);
5858
}
5959

6060
private static ChuNote ScaleNote(ChuNote n, int tpb)

generator/chu/SusGenerator.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace MuConvert.chu;
1313
public class SusGenerator : IGenerator<IChuChart>
1414
{
1515
private const int SusTpb = 480;
16-
private const int C2sRsl = 384;
1716

1817
public (string, List<Alert>) Generate(IChuChart chart)
1918
{
@@ -33,26 +32,27 @@ private static SusChart ConvertToSus(IChuChart chart, List<Alert> alerts)
3332
if (chart is C2sChart c2s)
3433
{
3534
bpm = c2s.BpmEvents.Count > 0 ? c2s.BpmEvents[0].Bpm : c2s.DefBpm;
35+
int c2sTpb = c2s.Resolution / 4;
3636
var result = new SusChart { Bpm = bpm, TicksPerBeat = SusTpb, Title = title, Artist = artist };
37-
foreach (var n in c2s.Notes) result.Notes.Add(ScaleUp(n));
37+
foreach (var n in c2s.Notes) result.Notes.Add(ScaleUp(n, c2sTpb));
3838
return result;
3939
}
4040

4141
if (chart is UgcChart ugc)
4242
{
4343
bpm = ugc.BpmEvents.Count > 0 ? ugc.BpmEvents[0].Bpm : 120.0;
4444
var result = new SusChart { Bpm = bpm, TicksPerBeat = SusTpb, Title = ugc.Title, Artist = ugc.Artist };
45-
foreach (var n in ugc.Notes) result.Notes.Add(MapLaneOnly(n));
45+
foreach (var n in ugc.Notes) result.Notes.Add(ScaleUp(n, ugc.TicksPerBeat));
4646
return result;
4747
}
4848

49-
alerts.Add(new Alert(Warning, string.Format(Locale.ChuGeneratorUnsupported, "→ SUS")));
50-
return new SusChart();
49+
alerts.Add(new Alert(Error, string.Format(Locale.ChuGeneratorUnsupported, "→ SUS")));
50+
throw new ConversionException(alerts);
5151
}
5252

53-
private static ChuNote ScaleUp(ChuNote n)
53+
private static ChuNote ScaleUp(ChuNote n, int sourceTicksPerBeat)
5454
{
55-
int s(int v) => (int)((long)v * SusTpb / (C2sRsl / 4));
55+
int s(int v) => (int)((long)v * SusTpb / sourceTicksPerBeat);
5656
return new ChuNote
5757
{
5858
Type = n.Type, Measure = n.Measure, Offset = s(n.Offset),
@@ -63,15 +63,6 @@ private static ChuNote ScaleUp(ChuNote n)
6363
};
6464
}
6565

66-
private static ChuNote MapLaneOnly(ChuNote n) => new()
67-
{
68-
Type = n.Type, Measure = n.Measure, Offset = n.Offset,
69-
Cell = n.Cell * 2, Width = n.Width * 2,
70-
HoldDuration = n.HoldDuration, SlideDuration = n.SlideDuration,
71-
EndCell = n.EndCell * 2, EndWidth = n.EndWidth * 2,
72-
Extra = n.Extra, TargetNote = n.TargetNote, AirHoldDuration = n.AirHoldDuration,
73-
};
74-
7566
private static string Serialize(SusChart sus)
7667
{
7768
var sb = new StringBuilder();

generator/chu/UgcGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private static UgcChart ConvertToUgc(IChuChart chart, List<Alert> alerts)
4545
return result;
4646
}
4747

48-
alerts.Add(new Alert(Warning, string.Format(Locale.ChuGeneratorUnsupported, "→ UGC")));
49-
return new UgcChart();
48+
alerts.Add(new Alert(Error, string.Format(Locale.ChuGeneratorUnsupported, "→ UGC")));
49+
throw new ConversionException(alerts);
5050
}
5151

5252
private static ChuNote ScaleUpNote(ChuNote n)

tests/chu/ChuTests.cs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,12 @@ public void UgcToC2sViaGenerator()
5151
}
5252

5353
[Fact]
54-
public void DumpOutputFiles()
54+
public void C2sToUgcViaGenerator()
5555
{
56-
var tempDir = Path.Combine(Path.GetTempPath(), "ChuTests", Guid.NewGuid().ToString("N"));
57-
Directory.CreateDirectory(tempDir);
58-
59-
try
60-
{
61-
if (!File.Exists(UgcPath)) throw new SkipException($"Missing: {UgcPath}");
62-
var (ugc, _) = new UgcParser().Parse(File.ReadAllText(UgcPath));
63-
var (c2sText, _) = new C2sGenerator().Generate(ugc);
64-
File.WriteAllText(Path.Combine(tempDir, "basic_output.c2s"), c2sText);
65-
66-
if (!File.Exists(C2sPath)) throw new SkipException($"Missing: {C2sPath}");
67-
var (c2s, _) = new C2sParser().Parse(File.ReadAllText(C2sPath));
68-
var (ugcText, _) = new UgcGenerator().Generate(c2s);
69-
File.WriteAllText(Path.Combine(tempDir, "0003_output.ugc"), ugcText);
70-
71-
Assert.True(File.Exists(Path.Combine(tempDir, "basic_output.c2s")));
72-
Assert.True(File.Exists(Path.Combine(tempDir, "0003_output.ugc")));
73-
}
74-
finally
75-
{
76-
try { Directory.Delete(tempDir, true); } catch { }
77-
}
56+
if (!File.Exists(C2sPath)) throw new SkipException($"Missing: {C2sPath}");
57+
var (c2s, _) = new C2sParser().Parse(File.ReadAllText(C2sPath));
58+
var (ugcText, _) = new UgcGenerator().Generate(c2s);
59+
Assert.Contains("@VER", ugcText);
60+
Assert.Contains("#5'0", ugcText);
7861
}
7962
}

0 commit comments

Comments
 (0)