Skip to content

Commit d656b78

Browse files
committed
[F] Air-Crush interval 处理错误
1 parent 89f1894 commit d656b78

8 files changed

Lines changed: 20 additions & 16 deletions

File tree

chart/chu/ChuNote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public int EndWidth
4949
/** 结束高度。仅在Air Slide/Air Crush上具有。存储的是C2S格式中的数值,转UGC时需要乘以1.6。 */
5050
public decimal EndHeight { get; set; } = 5;
5151
/** Air Crush的interval值 */
52-
public int CrushInterval { get; set; } = 0;
52+
public Rational CrushInterval { get; set; } = 0;
5353

5454
public override Rational EndTime => (Time + Duration).CanonicalForm;
5555
/** Air系列音符/Slide系列音符的 关联的目标音符类型。仅供向前兼容使用。 */

generator/chu/C2sGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ private static string FormatAsdAsc(ChuNote n, int m, int o, int durTicks)
119119

120120
private static string FormatAld(ChuNote n, int m, int o, int durTicks)
121121
{
122-
return FormattableString.Invariant($"ALD\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.CrushInterval}\t{n.Height:0.#}\t{durTicks}\t{n.EndCell}\t{n.EndWidth}\t{n.EndHeight:0.#}");
122+
return FormattableString.Invariant($"ALD\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{Utils.Tick(n.CrushInterval, RSL)}\t{n.Height:0.#}\t{durTicks}\t{n.EndCell}\t{n.EndWidth}\t{n.EndHeight:0.#}");
123123
}
124124
}

generator/chu/UgcGenerator.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text;
22
using MuConvert.generator;
33
using MuConvert.utils;
4+
using Rationals;
45
using static MuConvert.utils.ChuUtils;
56

67
namespace MuConvert.chu;
@@ -184,9 +185,12 @@ private static bool IsSlideContinueSegments(ChuNote n) // Air Slide的前驱只
184185
private static string EncodeAirHeight(decimal value) => IToH36((int)Math.Round(C2U_Height(value) * 10)).PadLeft(2, '0');
185186

186187
private static string CrushColor(string t) => C2U_AirColor.GetValueOrDefault(t, t.Length > 0 ? t[..1] : "0");
187-
private static string CrushInterval(int crushInterval) => crushInterval > 10000 ? "$" : crushInterval.ToString();
188-
189-
private static string UCode(ChuNote n)
188+
private string CrushInterval(Rational crushInterval)
189+
{
190+
return crushInterval > 25 ? "$" : Utils.Tick(crushInterval, RSL).ToString();
191+
}
192+
193+
private string UCode(ChuNote n)
190194
{
191195
string c = IToH36(n.Cell), w = IToH36(n.Width);
192196
return n.Type switch

parser/chu/C2sParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void ParseNote(string[] p, ChuChart chart, List<Alert> alerts, int lineN
144144
return;
145145
}
146146
note.Cell = Int(p, 3); note.Width = Math.Max(1, Int(p, 4, 1));
147-
note.CrushInterval = Int(p, 5);
147+
note.CrushInterval = new Rational(Int(p, 5), RSL);
148148
note.Height = Decimal(p, 6, 5); note.EndHeight = Decimal(p, 10, 5);
149149
note.Duration = new Rational(Int(p, 7), RSL);
150150
note.EndCell = Int(p, 8); note.EndWidth = Math.Max(1, Int(p, 9, 1));

parser/chu/UgcParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ private void ParseHeightAndColor(ChuNote n, string str, List<Alert> alerts, int
362362
{
363363
var intervalStr = str[(posOfComma+1)..];
364364
str = str[..posOfComma];
365-
if (intervalStr == "$") n.CrushInterval = 38400;
366-
else if (int.TryParse(intervalStr, out var interval)) n.CrushInterval = interval;
365+
if (intervalStr == "$") n.CrushInterval = 100;
366+
else if (int.TryParse(intervalStr, out var interval)) n.CrushInterval = new Rational(interval, RSL);
367367
else alerts.Add(new Alert(Warning, "解析Air-Crush的interval属性失败!", n.Time, null, lineNum, FormatNoteRef(n, str)));
368368
}
369369

@@ -575,7 +575,7 @@ private int ParseAirCrushNote(string[] lines, int idx, string code, ChuNote note
575575

576576
if (Version <= 6 && !intervalSet && marker == "s")
577577
{
578-
note.CrushInterval = endTick;
578+
note.CrushInterval = new Rational(endTick, RSL);
579579
intervalSet = true;
580580
}
581581

tests/chu/ChuTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static bool CompareNote(ChuNote expected, ChuNote actual, bool allowExDif
8787
if (expected.Cell != actual.Cell || expected.Width != actual.Width) return false;
8888
if (expected.EndCell != actual.EndCell || expected.EndWidth != actual.EndWidth) return false;
8989
if (Math.Abs(expected.Height - actual.Height) > 0.05m || Math.Abs(expected.EndHeight - actual.EndHeight) > 0.05m) return false;
90-
if (expected.CrushInterval != actual.CrushInterval) return false;
90+
if (!TimesEquivalent(expected.CrushInterval, actual.CrushInterval)) return false;
9191
if (!TagsEquivalent(expected, actual)) return false;
9292
if (!TypesEquivalent(expected.TargetNote, actual.TargetNote, allowExDiff)) return false;
9393
return true;

utils/ChuUtils.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,25 @@ public class ChuUtils
1313
["DR"] = "ADR",
1414
["DL"] = "ADL",
1515
};
16-
public static readonly Dictionary<string, string> C2U_AirDirections = ReverseDict(U2C_AirDirections);
16+
public static readonly Dictionary<string, string> C2U_AirDirections = Utils.ReverseDict(U2C_AirDirections);
1717

1818
public static readonly Dictionary<string, string> U2C_ChrExtras = new()
1919
{
2020
["U"] = "UP",
2121
["D"] = "DW",
2222
["C"] = "CE",
2323
};
24-
public static readonly Dictionary<string, string> C2U_ChrExtras = ReverseDict(U2C_ChrExtras);
24+
public static readonly Dictionary<string, string> C2U_ChrExtras = Utils.ReverseDict(U2C_ChrExtras);
2525

2626
public static readonly Dictionary<string, string> U2C_AirColor = new()
2727
{
2828
["N"] = "DEF",
2929
["I"] = "I", // TODO 搞清楚UGC里的'I'颜色,在C2S里,对应的字符串是什么
3030
};
31-
public static readonly Dictionary<string, string> C2U_AirColor = ReverseDict(U2C_AirColor);
31+
public static readonly Dictionary<string, string> C2U_AirColor = Utils.ReverseDict(U2C_AirColor);
3232

3333
public static decimal U2C_Height(decimal input) => input / 1.6m;
3434
public static decimal C2U_Height(decimal input) => input * 1.6m;
35-
36-
private static Dictionary<string, string> ReverseDict(Dictionary<string, string> dict) =>
37-
dict.ToDictionary(x => x.Value, x => x.Key);
3835

3936
public static bool IsHold(string t) => t is "HLD" or "HXD";
4037
public static bool IsSlide(string t) => t is "SLD" or "SLC" or "SXD" or "SXC";

utils/Utils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public static string IToH(int value, int N)
135135
if (negative) sb.Append('-');
136136
return new string(sb.ToString().Reverse().ToArray());
137137
}
138+
139+
public static Dictionary<string, string> ReverseDict(Dictionary<string, string> dict) =>
140+
dict.ToDictionary(x => x.Value, x => x.Key);
138141
}
139142

140143
public static class ExtensionUtils

0 commit comments

Comments
 (0)