11using System . Globalization ;
22using System . Text ;
3+ using MuConvert . chart ;
34using MuConvert . generator ;
45using MuConvert . utils ;
56using static MuConvert . utils . Alert . LEVEL ;
@@ -12,8 +13,6 @@ namespace MuConvert.chu;
1213 */
1314public class C2sGenerator : IGenerator < IChuChart >
1415{
15- private const int C2sResolution = 384 ;
16-
1716 public ( string , List < Alert > ) Generate ( IChuChart chart )
1817 {
1918 var alerts = new List < Alert > ( ) ;
@@ -32,18 +31,19 @@ private static C2sChart ConvertToC2s(IChuChart chart, List<Alert> alerts)
3231 {
3332 Designer = ugc . Designer ,
3433 } ;
35- foreach ( var b in ugc . BpmEvents )
36- result . BpmEvents . Add ( ( b . Measure , ScaleDown ( b . Offset , ugc . TicksPerBeat ) , b . Bpm ) ) ;
37- foreach ( var b in ugc . BeatEvents )
38- result . MetEvents . Add ( ( b . Measure , 0 , b . Den , b . Num ) ) ;
34+ result . BpmList . AddRange ( ugc . BpmList ) ;
35+ result . MetList . AddRange ( ugc . MetList ) ;
3936 result . Notes = ugc . Notes ;
4037 return result ;
4138 }
4239
4340 if ( chart is SusChart sus )
4441 {
4542 var result = new C2sChart ( ) ;
46- // result.BpmEvents.Add((0, 0, sus.Bpm));
43+ if ( sus . BpmList . Count > 0 )
44+ result . BpmList . AddRange ( sus . BpmList ) ;
45+ else
46+ result . BpmList . Add ( new BPM ( 0 , 120m ) ) ;
4747 result . Notes = sus . Notes ;
4848 return result ;
4949 }
@@ -52,8 +52,6 @@ private static C2sChart ConvertToC2s(IChuChart chart, List<Alert> alerts)
5252 throw new ConversionException ( alerts ) ;
5353 }
5454
55- private static int ScaleDown ( int ticks , int tpb ) => ( int ) ( ( long ) ticks * ( C2sResolution / 4 ) / tpb ) ;
56-
5755 private static string Serialize ( C2sChart chart )
5856 {
5957 chart . Sort ( ) ;
@@ -76,12 +74,25 @@ private static string Serialize(C2sChart chart)
7674 sb . AppendLine ( "TUTORIAL\t 0" ) ;
7775 sb . AppendLine ( ) ;
7876
79- foreach ( var b in chart . BpmEvents )
80- sb . AppendLine ( $ "BPM\t { b . Measure } \t { b . Offset } \t { Fmt ( b . Bpm ) } ") ;
81- foreach ( var m in chart . MetEvents )
82- sb . AppendLine ( $ "MET\t { m . Measure } \t { m . Offset } \t { m . Denom } \t { m . Num } ") ;
83- foreach ( var s in chart . SflEvents )
84- sb . AppendLine ( $ "SFL\t { s . Measure } \t { s . Offset } \t { s . Duration } \t { Mlt ( s . Multiplier ) } ") ;
77+ var res = chart . Resolution ;
78+ foreach ( var b in chart . BpmList )
79+ {
80+ var ( m , o ) = Utils . BarAndTick ( b . Time , res ) ;
81+ sb . AppendLine ( $ "BPM\t { m } \t { o } \t { b . Bpm : 0.000} ") ;
82+ }
83+
84+ foreach ( var met in chart . MetList )
85+ {
86+ var ( m , o ) = Utils . BarAndTick ( met . Time , res ) ;
87+ sb . AppendLine ( $ "MET\t { m } \t { o } \t { met . Denominator } \t { met . Numerator } ") ;
88+ }
89+
90+ foreach ( var s in chart . SflList . OrderBy ( s => s . Time ) )
91+ {
92+ var ( m , o ) = Utils . BarAndTick ( s . Time , res ) ;
93+ var durTicks = Utils . Tick ( s . Duration , res ) ;
94+ sb . AppendLine ( $ "SFL\t { m } \t { o } \t { durTicks } \t { s . Multiplier : 0.000000} ") ;
95+ }
8596 sb . AppendLine ( ) ;
8697
8798 foreach ( var n in chart . Notes )
@@ -93,8 +104,8 @@ private static string Serialize(C2sChart chart)
93104
94105 private static string FormatNote ( ChuNote n , int tpm )
95106 {
96- var ( m , o ) = Utils . BarAndTick ( n . Time , tpm , 0 ) ;
97- var durTicks = Utils . Tick ( n . Duration , tpm , 0 ) ;
107+ var ( m , o ) = Utils . BarAndTick ( n . Time , tpm ) ;
108+ var durTicks = Utils . Tick ( n . Duration , tpm ) ;
98109 return n . Type switch
99110 {
100111 "TAP" => $ "TAP\t { m } \t { o } \t { n . Cell } \t { n . Width } ",
@@ -132,7 +143,4 @@ private static string FormatAld(ChuNote n, int m, int o)
132143 var tail = n . ExtraData . Count > 3 ? n . ExtraData [ 3 ] : 0 ;
133144 return $ "ALD\t { m } \t { o } \t { n . Cell } \t { n . Width } \t { a } \t { b } \t { c } \t { n . EndCell } \t { n . EndWidth } \t { tail } ";
134145 }
135-
136- private static string Fmt ( double v ) => v . ToString ( "0.000" , CultureInfo . InvariantCulture ) ;
137- private static string Mlt ( double v ) => v . ToString ( "0.000000" , CultureInfo . InvariantCulture ) ;
138146}
0 commit comments