Skip to content

Commit bdab8d8

Browse files
committed
[F] Air-Crush的颜色
1 parent d656b78 commit bdab8d8

8 files changed

Lines changed: 85 additions & 23 deletions

File tree

generator/chu/C2sGenerator.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,23 @@ private string Serialize(ChuChart chart, List<Alert> alerts)
6868
return sb.ToString();
6969
}
7070

71-
private static readonly List<string> allowedAirColors = ["DEF", "I"]; // TODO 搞清楚UGC里的'I'颜色,在C2S里,对应的字符串是什么
72-
private static string AirColorTag(ChuNote n)
71+
private static string AirColorTag(ChuNote n, List<Alert> alerts)
7372
{
74-
if (allowedAirColors.Contains(n.Tag)) return n.Tag;
75-
else return "DEF";
73+
if (C2sAllowedColors.Contains(n.Tag)) return n.Tag;
74+
else
75+
{
76+
if (n.Tag != "") alerts.Add(new Alert(Alert.LEVEL.Warning, string.Format(Locale.C2SUnsupportedAirColor, "C2S Generator", n.Type, n.Tag), n.Time));
77+
return "DEF";
78+
}
79+
}
80+
private static string AirCrushColorTag(ChuNote n, List<Alert> alerts)
81+
{
82+
if (C2sAllowedCrushColors.Contains(n.Tag)) return n.Tag;
83+
else
84+
{
85+
if (n.Tag != "") alerts.Add(new Alert(Alert.LEVEL.Warning, string.Format(Locale.C2SUnsupportedAirColor, "C2S Generator", n.Type, n.Tag), n.Time));
86+
return "DEF";
87+
}
7688
}
7789

7890
private static string FLKTag(ChuNote n) => n.Tag is "L" or "R" ? n.Tag : "L";
@@ -97,10 +109,10 @@ private static bool IsSlideContinueSegments(ChuNote n) // Air Slide的前驱只
97109
"SLD" or "SLC" or "SXD" or "SXC" => $"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{durTicks}\t{n.EndCell}\t{n.EndWidth}",
98110
"FLK" => $"FLK\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{FLKTag(n)}",
99111
"AIR" or "AUR" or "AUL" or "ADW" or "ADR" or "ADL" =>
100-
$"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{AirColorTag(n)}",
101-
"AHD" or "AHX" => $"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{durTicks}\t{AirColorTag(n)}",
102-
"ASD" or "ASC" => FormatAsdAsc(n, m, o, durTicks),
103-
"ALD" => FormatAld(n, m, o, durTicks),
112+
$"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{AirColorTag(n, alerts)}",
113+
"AHD" or "AHX" => $"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{durTicks}\t{AirColorTag(n, alerts)}",
114+
"ASD" or "ASC" => FormatAsdAsc(n, m, o, durTicks, alerts),
115+
"ALD" => FormatAld(n, m, o, durTicks, alerts),
104116
"MNE" => $"MNE\t{m}\t{o}\t{n.Cell}\t{n.Width}",
105117
_ => alert(),
106118
};
@@ -112,13 +124,13 @@ private static bool IsSlideContinueSegments(ChuNote n) // Air Slide的前驱只
112124
}
113125
}
114126

115-
private static string FormatAsdAsc(ChuNote n, int m, int o, int durTicks)
127+
private static string FormatAsdAsc(ChuNote n, int m, int o, int durTicks, List<Alert> alerts)
116128
{
117-
return FormattableString.Invariant($"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{n.Height:0.#}\t{durTicks}\t{n.EndCell}\t{n.EndWidth}\t{n.EndHeight:0.#}\t{AirColorTag(n)}");
129+
return FormattableString.Invariant($"{n.Type}\t{m}\t{o}\t{n.Cell}\t{n.Width}\t{n.TargetNote}\t{n.Height:0.#}\t{durTicks}\t{n.EndCell}\t{n.EndWidth}\t{n.EndHeight:0.#}\t{AirColorTag(n, alerts)}");
118130
}
119131

120-
private static string FormatAld(ChuNote n, int m, int o, int durTicks)
132+
private static string FormatAld(ChuNote n, int m, int o, int durTicks, List<Alert> alerts)
121133
{
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.#}");
134+
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.#}\t{AirCrushColorTag(n, alerts)}");
123135
}
124136
}

generator/chu/UgcGenerator.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ namespace MuConvert.chu;
99
public class UgcGenerator : IGenerator<ChuChart>
1010
{
1111
private int RSL = 480 * 4;
12+
private List<Alert> alerts = [];
1213

1314
public (string, List<Alert>) Generate(ChuChart chart)
1415
{
15-
var alerts = new List<Alert>();
16-
var text = Serialize(chart, alerts);
16+
alerts = new List<Alert>();
17+
var text = Serialize(chart);
1718
return (text, alerts);
1819
}
1920

@@ -44,7 +45,7 @@ void Dfs(ChuNote n)
4445
}
4546
}
4647

47-
private string Serialize(ChuChart ugc, List<Alert> alerts)
48+
private string Serialize(ChuChart ugc)
4849
{
4950
ugc.Sort();
5051

@@ -184,7 +185,26 @@ private static bool IsSlideContinueSegments(ChuNote n) // Air Slide的前驱只
184185

185186
private static string EncodeAirHeight(decimal value) => IToH36((int)Math.Round(C2U_Height(value) * 10)).PadLeft(2, '0');
186187

187-
private static string CrushColor(string t) => C2U_AirColor.GetValueOrDefault(t, t.Length > 0 ? t[..1] : "0");
188+
private string AirColor(ChuNote n)
189+
{
190+
if (C2U_AirColor.TryGetValue(n.Tag, out var color)) return color;
191+
else
192+
{
193+
if (n.Tag != "") alerts.Add(new Alert(Alert.LEVEL.Warning, string.Format(Locale.C2SUnsupportedAirColor, "UGC Generator", n.Type, n.Tag), n.Time));
194+
return "N";
195+
}
196+
}
197+
private string CrushColor(ChuNote n)
198+
{
199+
if (C2U_AirCrushColor.TryGetValue(n.Tag, out var color)) return color;
200+
else if (n.Tag.Length == 1) return n.Tag;
201+
else
202+
{
203+
if (n.Tag != "") alerts.Add(new Alert(Alert.LEVEL.Warning, string.Format(Locale.C2SUnsupportedAirColor, "UGC Generator", n.Type, n.Tag), n.Time));
204+
return "0";
205+
}
206+
}
207+
188208
private string CrushInterval(Rational crushInterval)
189209
{
190210
return crushInterval > 25 ? "$" : Utils.Tick(crushInterval, RSL).ToString();
@@ -203,11 +223,11 @@ private string UCode(ChuNote n)
203223
"FLK" => $"f{c}{w}{n.Tag}",
204224
"MNE" => $"d{c}{w}",
205225
// AIR-SLIDE (v8): #BarTick:S x w hh c
206-
"ASD" or "ASC" => $"S{c}{w}{EncodeAirHeight(n.Height)}{C2U_AirColor.GetValueOrDefault(n.Tag, "N")}",
207-
"AIR" or "AUR" or "AUL" or "ADW" or "ADR" or "ADL" => $"a{c}{w}{C2U_AirDirections[n.Type]}{C2U_AirColor.GetValueOrDefault(n.Tag, "N")}",
226+
"ASD" or "ASC" => $"S{c}{w}{EncodeAirHeight(n.Height)}{AirColor(n)}",
227+
"AIR" or "AUR" or "AUL" or "ADW" or "ADR" or "ADL" => $"a{c}{w}{C2U_AirDirections[n.Type]}{AirColor(n)}",
208228
// AIR-HOLD (v8): #BarTick:H x w c + 子行 #OffsetTick:s / :c(见 Umiguri Chart v8 doc)
209-
"AHD" or "AHX" => $"H{c}{w}{C2U_AirColor.GetValueOrDefault(n.Tag, "N")}",
210-
"ALD" => $"C{c}{w}{EncodeAirHeight(n.Height)}{CrushColor(n.Tag)},{CrushInterval(n.CrushInterval)}",
229+
"AHD" or "AHX" => $"H{c}{w}{AirColor(n)}",
230+
"ALD" => $"C{c}{w}{EncodeAirHeight(n.Height)}{CrushColor(n)},{CrushInterval(n.CrushInterval)}",
211231
_ => ""
212232
};
213233
}

i18n/Locale.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

i18n/Locale.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
<data name="C2SUnknownNoteType" xml:space="preserve">
215215
<value>Unknown C2S note type: {0}</value>
216216
</data>
217+
<data name="C2SUnsupportedAirColor" xml:space="preserve">
218+
<value>{0} encountered an unsupported Air color ({2}) while processing {1} notes. We would greatly appreciate it if you could report this chart to us (via https://github.com/MuNET-OSS/MuConvert/issues)!</value>
219+
</data>
217220
<data name="ChuGeneratorUnsupported" xml:space="preserve">
218221
<value>Cannot convert chart to target format: {0}</value>
219222
</data>

i18n/Locale.zh-hant.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
<data name="C2SUnknownNoteType" xml:space="preserve">
215215
<value>C2S 中存在無法識別的音符類型: {0}</value>
216216
</data>
217+
<data name="C2SUnsupportedAirColor" xml:space="preserve">
218+
<value>{0}處理{1}音符時,遇到了不支援的Air顏色: {2}。若您能將這份譜面回報給我們(透過 https://github.com/MuNET-OSS/MuConvert/issues ),我們將非常感激!</value>
219+
</data>
217220
<data name="ChuGeneratorUnsupported" xml:space="preserve">
218221
<value>無法將譜面轉換為目標格式: {0}</value>
219222
</data>

i18n/Locale.zh.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
<data name="C2SUnknownNoteType" xml:space="preserve">
215215
<value>C2S 中存在无法识别的音符类型: {0}</value>
216216
</data>
217+
<data name="C2SUnsupportedAirColor" xml:space="preserve">
218+
<value>{0}处理{1}音符时,遇到了不支持的Air颜色: {2}。如果您能将这个谱面报告给我们(通过 https://github.com/MuNET-OSS/MuConvert/issues )的话,我们会非常感谢!</value>
219+
</data>
217220
<data name="ChuGeneratorUnsupported" xml:space="preserve">
218221
<value>无法将谱面转换为目标格式: {0}</value>
219222
</data>

parser/chu/UgcParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private void ParseHeightAndColor(ChuNote n, string str, List<Alert> alerts, int
371371
if (str.Length > 0)
372372
{ // 解析颜色
373373
var rawColorStr = str.Last().ToString();
374-
n.Tag = U2C_AirColor.GetValueOrDefault(rawColorStr, rawColorStr);
374+
n.Tag = (noteType == "C" ? U2C_AirCrushColor : U2C_AirColor).GetValueOrDefault(rawColorStr, rawColorStr);
375375
}
376376
if (str.Length > 1)
377377
{ // 解析高度

utils/ChuUtils.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ public class ChuUtils
2626
public static readonly Dictionary<string, string> U2C_AirColor = new()
2727
{
2828
["N"] = "DEF",
29-
["I"] = "I", // TODO 搞清楚UGC里的'I'颜色,在C2S里,对应的字符串是什么
29+
// ["I"] = "I", // TODO 搞清楚UGC里的'I'颜色,在C2S里,对应的字符串是什么
3030
};
3131
public static readonly Dictionary<string, string> C2U_AirColor = Utils.ReverseDict(U2C_AirColor);
32-
32+
public static readonly HashSet<string> C2sAllowedColors = C2U_AirColor.Keys.ToHashSet();
33+
34+
public static readonly Dictionary<string, string> U2C_AirCrushColor = new()
35+
{
36+
["0"] = "DEF",
37+
["Z"] = "NON",
38+
["6"] = "CYN",
39+
["A"] = "VLT",
40+
// TODO 补充更多对应关系
41+
};
42+
public static readonly Dictionary<string, string> C2U_AirCrushColor = Utils.ReverseDict(U2C_AirCrushColor);
43+
public static readonly HashSet<string> C2sAllowedCrushColors = C2U_AirCrushColor.Keys.ToHashSet();
44+
3345
public static decimal U2C_Height(decimal input) => input / 1.6m;
3446
public static decimal C2U_Height(decimal input) => input * 1.6m;
3547

0 commit comments

Comments
 (0)