Skip to content

Commit cedb4e5

Browse files
committed
[F] 修一些小bug,把目测到的MA2Parser的bug都修了
1 parent 6a84766 commit cedb4e5

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

chart/Slide.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private string DebuggerDisplay()
7878
else if (Head != null) result = Head.DebuggerDisplay();
7979
else result = Key.ToString();
8080
if (Head != null && !(Head is Star)) result += "@"; // Tap形状的头
81-
else if (Head == null) result += "?"; // 无头
81+
else if (Head == null && SharedHeadWith == null) result += "?"; // 无头
8282

8383
var segStart = Key;
8484
foreach (var s in segments)

parser/MA2Parser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void WarnParamsCount(int lineNo, ReadOnlySpan<char> line, Rational? time
6363
else if (cmd is "FES_MODE" or "BPM_DEF" or "GENERATED_BY" && AssertInHeader(lineNo, line)) {} // 这些不用解析,无事可做
6464
else if (cmd == "RESOLUTION" && AssertInHeader(lineNo, line))
6565
RSL = int.Parse(values[1]);
66-
else if (cmd == "CLOCK_DEF" && AssertInHeader(lineNo, line))
66+
else if (cmd == "CLK_DEF" && AssertInHeader(lineNo, line))
6767
chart.ClockCount = int.Parse(values[1]) / (RSL / 4);
6868
// BPM和MET
6969
else if (cmd == "BPM" && values.Length == 4 && int.TryParse(values[1], out var bbar) &&
@@ -109,7 +109,7 @@ private void WarnParamsCount(int lineNo, ReadOnlySpan<char> line, Rational? time
109109
}
110110
else if (cc == "THO" && values.Length >= 8 && int.TryParse(values[4], out len))
111111
{
112-
note = new TouchHold(chart, time) { TouchArea = values[4]+key, IsFirework = values[5] == "1", TouchSize = values[6]};
112+
note = new TouchHold(chart, time) { TouchArea = values[5]+key, IsFirework = values[6] == "1", TouchSize = values[7]};
113113
var duration = new Duration(note) { Bar = new Rational(len, RSL) };
114114
note.Duration = duration;
115115
if (values.Length != 8) WarnParamsCount(lineNo, line, time);
@@ -125,7 +125,7 @@ private void WarnParamsCount(int lineNo, ReadOnlySpan<char> line, Rational? time
125125
// 查找到前面的星星
126126
var a = _slides.GetValueOrDefault((time, key));
127127
if (a == null || a.Count == 0) Fail(Locale.MA2CNSlideNoPrevious, lineNo, line);
128-
slide = a[0];
128+
slide = a![0];
129129
a.RemoveAt(0); // 移除出来,因为一会会按照新的结束时间加回去
130130
}
131131
else
@@ -212,8 +212,8 @@ void pair()
212212
{
213213
for (int i = 0; i < 8; i++)
214214
{
215-
var pairedTap = taps[i];
216-
if (pairedTap == null) continue;
215+
if (taps[i] == null || slideLists[i].Count == 0) continue; // 当前时刻、当前键位不是星星和tap都有,所以不配对
216+
var pairedTap = taps[i]!;
217217
toRemove.Add(pairedTap);
218218
for (int j = 0; j < slideLists[i].Count; j++)
219219
{
@@ -236,7 +236,7 @@ void pair()
236236
}
237237
else if (note.Time < now) throw Utils.Fail("时间倒流,说明Chart.Sort写错了");
238238

239-
if (note is Tap tap) taps[tap.Key - 1] ??= tap; // 只有在数组中原本为空的情况下才set。不然不set。这是因为万一有人写宴谱,在同一时刻同一键位上塞了大于一个tap(这显然是无理)怎么办(x)
239+
if (note is Tap tap and not Hold) taps[tap.Key - 1] ??= tap; // 只有在数组中原本为空的情况下才set。不然不set。这是因为万一有人写宴谱,在同一时刻同一键位上塞了大于一个tap(这显然是无理)怎么办(x)
240240
else if (note is Slide slide) slideLists[slide.Key - 1].Add(slide);
241241
}
242242
pair(); // 最后一个时刻

tests/自制谱测试.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static (int, int, string) GetSlideTime(string slide)
9696
private static bool CompareLine(string exp, string act)
9797
{
9898
var result = string.Equals(exp, act, StringComparison.Ordinal);
99-
if (!result && exp[..5] == act[..5] && SlideTypeTool.IsSlide(exp))
99+
if (!result && exp[..5] == act[..5] && SlideTypeTool.IsSlide(exp[2..5]))
100100
{ // 如果是星星,则允许一定范围的误差。具体而言:
101101
var (expTime, expLen, expExtra) = GetSlideTime(exp);
102102
var (actTime, actLen, actExtra) = GetSlideTime(act);

utils/Enum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ public static SlideType FromSimai(string s, int? startKey)
9797

9898
public static bool IsSlide(string MA2Name)
9999
{
100-
return SlideNames.Contains(MA2Name[2..5]);
100+
return SlideNames.Contains(MA2Name);
101101
}
102102
}

utils/Utils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Globalization;
34
using System.Reflection;
45

@@ -20,7 +21,7 @@ public static Exception Fail(string msg = "")
2021

2122
public static void SetLocale(CultureInfo culture) => Locale.Culture = culture;
2223

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

0 commit comments

Comments
 (0)