Skip to content

Commit 893d315

Browse files
committed
[R] 将FirstNoteTime的类型改为Duration,修改一些可见性级别等
1 parent a018239 commit 893d315

5 files changed

Lines changed: 29 additions & 16 deletions

File tree

chart/Chart.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void Sort()
2424
Notes = Notes.OrderBy(n => n.Time).ThenBy(n=>n.FalseEachIdx).ToList(); // LINQ OrderBy 是稳定排序
2525
}
2626

27+
// 谱面开头的BPM
2728
public decimal StartBpm {
2829
get
2930
{
@@ -32,14 +33,16 @@ public decimal StartBpm {
3233
}
3334
}
3435

35-
public Rational FirstNoteTime => Notes[0].Time;
36-
37-
public decimal FirstNoteTimeInSeconds => (decimal)Duration.ConvertTime(0, FirstNoteTime, null, 240, BpmList);
38-
36+
/**
37+
* 获得“谱面中第一个音符的时刻”,或者返回的Duration也可以理解成“从谱面开头到出现第一个音符所经过的时长”。
38+
* 所以同样的,它也有Bar、InvariantBar、Seconds的不同形态,因此使用Duration的形式存储。
39+
*/
40+
public Duration FirstNoteTime => new(new PseudoNote(this)) {Bar = Notes[0].Time};
41+
3942
/**
4043
* 对整首歌曲,应用一个偏移量进行整体平移。
4144
* <param name="offset">偏移量,正数表示歌曲整体向后,负数表示歌曲整体向前。</param>
42-
* <param name="bpm">上述偏移量所对应的Bpm。若不传,默认使用歌曲开头的BPM。</param>
45+
* <param name="bpm">上述偏移量所对应的Bpm。若不传,默认使用歌曲开头的BPM(即chart.StartBpm)。</param>
4346
*/
4447
public void Shift(Rational offset, decimal? bpm = null)
4548
{
@@ -63,4 +66,12 @@ public void Shift(Rational offset, decimal? bpm = null)
6366
Utils.Assert(BpmList[0].Time == 0, "BPM列表的开头必须为0时刻");
6467
Notes = Notes.Select(x => { x.Time += offset; return x; }).Where(x => x.Time >= 0).ToList();
6568
}
69+
70+
public bool IsDxChart => Notes.Any(note => // 判定DX谱的标准:存在
71+
note is Touch || note.IsEx || (note.IsBreak && note is not Tap) || // Touch 或者 保护套 或者 非Tap/Star的绝赞
72+
note is Slide { segments.Count: > 1 }); // 星星段数大于1(fes星星)
73+
74+
// TODO 把谱面统计搬到Chart类下面来
75+
76+
6677
}

chart/Duration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private Rational ConvertTime(Rational value, Rational? srcBpm, Rational? dstBpm)
130130
return ConvertTime(startTime, value, srcBpm, dstBpm, BpmList);
131131
}
132132

133-
public static Rational ConvertTime(Rational startTime, Rational value, Rational? srcBpm, Rational? dstBpm, BPMList bpmList)
133+
internal static Rational ConvertTime(Rational startTime, Rational value, Rational? srcBpm, Rational? dstBpm, BPMList bpmList)
134134
{
135135
if (srcBpm != null && dstBpm != null)
136136
{
@@ -200,5 +200,5 @@ public static Rational ConvertTime(Rational startTime, Rational value, Rational?
200200
return new Duration(a._note){_type = a._type, _data = (a._data / b).CanonicalForm};
201201
}
202202

203-
public string DebuggerDisplay() => _type == Type.Seconds ? $"[#{(float)_data}]" : $"[{_data.Denominator}:{_data.Numerator}]";
203+
internal string DebuggerDisplay() => _type == Type.Seconds ? $"[#{(float)_data}]" : $"[{_data.Denominator}:{_data.Numerator}]";
204204
}

chart/Note.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected Note(Chart chart, Rational time)
4343
[DebuggerDisplay("{DebuggerDisplay(),nq}")]
4444
public class Tap(Chart chart, Rational time) : Note(chart, time)
4545
{
46-
public string DebuggerDisplay() => $"{Key}{Modifiers}";
46+
internal string DebuggerDisplay() => $"{Key}{Modifiers}";
4747
}
4848

4949
[DebuggerDisplay("{DebuggerDisplay(),nq}")]
@@ -100,3 +100,6 @@ public class TouchHold : Touch
100100

101101
private string DebuggerDisplay() => $"{TouchArea}h{Modifiers}{Duration.DebuggerDisplay()}";
102102
}
103+
104+
// 仅用于内部实现某些trick时使用的“伪音符”。用户在正常的谱面中是不会看到这个的。
105+
internal class PseudoNote(Chart chart) : Note(chart, 0);

tests/ChartShift测试.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static Chart LoadChart(out List<Alert> alerts)
3232

3333
Assert.NotEmpty(chart.Notes);
3434
Assert.NotEmpty(chart.BpmList);
35-
Utils.Assert(chart.BpmList[0].Time == 0, "sanity");
35+
Assert.True(chart.BpmList[0].Time == 0, "sanity");
3636
Assert.DoesNotContain(alerts, a => a.Level >= Alert.LEVEL.Error);
3737
return chart;
3838
}
@@ -44,7 +44,7 @@ private static Chart LoadChart(out List<Alert> alerts)
4444

4545
private static void AssertShiftResultTimelineValid(Chart c)
4646
{
47-
Utils.Assert(c.BpmList[0].Time == 0, "BPM 起点应在 0");
47+
Assert.True(c.BpmList[0].Time == 0, "BPM 起点应在 0");
4848
foreach (var b in c.BpmList)
4949
Assert.True(b.Time >= 0);
5050
foreach (var n in c.Notes)
@@ -125,7 +125,7 @@ public void Shift_Zero()
125125
chart.Shift(0);
126126

127127
Assert.Equal(startBpm, chart.StartBpm);
128-
Utils.Assert(chart.BpmList[0].Time == 0, "BPM 起点应在 0");
128+
Assert.True(chart.BpmList[0].Time == 0, "BPM 起点应在 0");
129129
Assert.Equal(notesBefore, NotesInStableOrder(chart));
130130
Assert.Equal(bpmsBefore, BpmInOrder(chart));
131131
}
@@ -153,12 +153,11 @@ public void Shift_NegativeQuarterBar()
153153
var notesBefore = NotesInStableOrder(chart);
154154
var bpmsBefore = BpmInOrder(chart);
155155
var userOffset = -QuarterBar;
156-
var appliedBarOffset = -Duration.ConvertTime(Rational.Zero, -userOffset, (Rational)chart.StartBpm, null, chart.BpmList);
157156

158157
chart.Shift(userOffset);
159158

160159
AssertShiftResultTimelineValid(chart);
161-
AssertBpmAndNotesMatchPositiveShiftOffset(bpmsBefore, BpmInOrder(chart), notesBefore, NotesInStableOrder(chart), appliedBarOffset);
160+
AssertBpmAndNotesMatchPositiveShiftOffset(bpmsBefore, BpmInOrder(chart), notesBefore, NotesInStableOrder(chart), userOffset);
162161
}
163162

164163
[Fact]

utils/Utils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace MuConvert.utils;
77

88
public static class Utils
99
{
10-
public static void Assert(bool condition, string msg = "")
10+
internal static void Assert(bool condition, string msg = "")
1111
{
1212
if (!condition) throw new Exception(string.Format(Locale.AssertionFailed, msg));
1313
}
1414

15-
public static Exception Fail(string msg = "")
15+
internal static Exception Fail(string msg = "")
1616
{
1717
return new Exception(string.Format(Locale.AssertionFailed, msg));
1818
}
@@ -21,7 +21,7 @@ public static Exception Fail(string msg = "")
2121

2222
public static void SetLocale(CultureInfo culture) => Locale.Culture = culture;
2323

24-
public static void Add<K, V>(this Dictionary<K, List<V>> dict, K key, V value) where K : notnull
24+
internal static void Add<K, V>(this Dictionary<K, List<V>> dict, K key, V value) where K : notnull
2525
{
2626
if (!dict.ContainsKey(key)) dict[key] = new();
2727
dict[key].Add(value);

0 commit comments

Comments
 (0)