@@ -11,15 +11,18 @@ namespace MuConvert.chu;
1111 * C2S 格式解析器(官方格式,RESOLUTION=384 tick/小节)。
1212 * Tab 分隔文本,识别 HEADER / TIMING / NOTES 区段。
1313 */
14- public class C2sParser : IParser < ChuChart >
14+ public class C2sParser : BaseChuParser
1515{
1616 private static int RSL = 384 ;
1717 private static readonly HashSet < string > HeadTags = new ( StringComparer . OrdinalIgnoreCase )
1818 { "VERSION" , "MUSIC" , "SEQUENCEID" , "DIFFICULT" , "LEVEL" , "CREATOR" , "BPM_DEF" , "MET_DEF" , "RESOLUTION" , "CLK_DEF" , "PROGJUDGE_BPM" , "PROGJUDGE_AER" , "TUTORIAL" } ;
1919 private static readonly HashSet < string > TimingTags = new ( StringComparer . OrdinalIgnoreCase )
2020 { "BPM" , "MET" , "SFL" } ;
2121
22- public ( ChuChart , List < Alert > ) Parse ( string text )
22+ // C2S 会原始记录 targetNote 字符串;用于在 Previous 推断有多个候选时优先匹配。
23+ private readonly Dictionary < ChuNote , string > _rawTargetNote = new ( ) ;
24+
25+ public override ( ChuChart , List < Alert > ) Parse ( string text )
2326 {
2427 var chart = new ChuChart ( ) ;
2528 var alerts = new List < Alert > ( ) ;
@@ -51,6 +54,7 @@ public class C2sParser : IParser<ChuChart>
5154 }
5255 }
5356
57+ FillAllPrevious ( chart , alerts , _rawTargetNote ) ;
5458 return ( chart , alerts ) ;
5559 }
5660
@@ -86,10 +90,11 @@ private static void ParseTiming(string[] p, ChuChart chart)
8690 }
8791 }
8892
89- private static void ParseNote ( string [ ] p , ChuChart chart , List < Alert > alerts , int lineNum )
93+ private void ParseNote ( string [ ] p , ChuChart chart , List < Alert > alerts , int lineNum )
9094 {
9195 var tag = p [ 0 ] . ToUpperInvariant ( ) ;
9296 var note = new ChuNote { Type = tag , Time = Int ( p , 1 ) + new Rational ( Int ( p , 2 ) , RSL ) } ;
97+ string ? targetNote = null ;
9398
9499 switch ( tag )
95100 {
@@ -107,12 +112,12 @@ private static void ParseNote(string[] p, ChuChart chart, List<Alert> alerts, in
107112 case "FLK" :
108113 note . Cell = Int ( p , 3 ) ; note . Width = Math . Max ( 1 , Int ( p , 4 , 1 ) ) ; note . Tag = Str ( p , 5 ) ; break ;
109114 case "AIR" : case "AUR" : case "AUL" : case "ADW" : case "ADR" : case "ADL" :
110- note . Cell = Int ( p , 3 ) ; note . Width = Math . Max ( 1 , Int ( p , 4 , 1 ) ) ; note . TargetNote = Str ( p , 5 ) ;
115+ note . Cell = Int ( p , 3 ) ; note . Width = Math . Max ( 1 , Int ( p , 4 , 1 ) ) ; targetNote = Str ( p , 5 ) ;
111116 if ( p . Length >= 7 ) note . Tag = Str ( p , 6 ) ;
112117 break ;
113118 case "AHD" : case "AHX" :
114119 note . Cell = Int ( p , 3 ) ; note . Width = Math . Max ( 1 , Int ( p , 4 , 1 ) ) ;
115- note . TargetNote = Str ( p , 5 ) ; note . Duration = new Rational ( Int ( p , 6 ) , RSL ) ;
120+ targetNote = Str ( p , 5 ) ; note . Duration = new Rational ( Int ( p , 6 ) , RSL ) ;
116121 if ( p . Length >= 8 ) note . Tag = Str ( p , 7 ) ;
117122 break ;
118123 case "ASD" : case "ASC" :
@@ -123,7 +128,7 @@ private static void ParseNote(string[] p, ChuChart chart, List<Alert> alerts, in
123128 return ;
124129 }
125130 note . Cell = Int ( p , 3 ) ; note . Width = Math . Max ( 1 , Int ( p , 4 , 1 ) ) ;
126- note . TargetNote = Str ( p , 5 ) ;
131+ targetNote = Str ( p , 5 ) ;
127132 note . ExtraData = [ Int ( p , 6 ) , Int ( p , 10 ) ] ;
128133 note . Duration = new Rational ( Int ( p , 7 ) , RSL ) ;
129134 note . EndCell = Int ( p , 8 ) ; note . EndWidth = Math . Max ( 1 , Int ( p , 9 , 1 ) ) ;
@@ -144,6 +149,7 @@ private static void ParseNote(string[] p, ChuChart chart, List<Alert> alerts, in
144149 alerts . Add ( new Alert ( Warning , string . Format ( Locale . C2SUnknownNoteType , tag ) ) { Line = lineNum } ) ; return ;
145150 }
146151
152+ if ( targetNote != null ) _rawTargetNote [ note ] = targetNote ;
147153 chart . Notes . Add ( note ) ;
148154 }
149155
0 commit comments