@@ -41,14 +41,14 @@ public class LegacyBeatmapEncoderTest
4141
4242 private static IEnumerable < string > allBeatmaps = beatmaps_resource_store . GetAvailableResources ( ) . Where ( res => res . EndsWith ( ".osu" , StringComparison . Ordinal ) ) ;
4343
44+ public record BeatmapComponents ( IBeatmap Beatmap , LegacySkin Skin , Storyboard Storyboard ) ;
45+
4446 [ Test ]
45- public void TestUnsupportedStoryboardEvents ( )
47+ public void TestStoryboardEvents ( )
4648 {
4749 const string name = "Resources/storyboard_only_video.osu" ;
4850
4951 var decoded = DecodeFromLegacy ( beatmaps_resource_store . GetStream ( name ) , beatmaps_resource_store , name ) ;
50- Assert . That ( decoded . beatmap . UnhandledEventLines . Count , Is . EqualTo ( 1 ) ) ;
51- Assert . That ( decoded . beatmap . UnhandledEventLines . Single ( ) , Is . EqualTo ( "Video,0,\" video.avi\" " ) ) ;
5252
5353 var memoryStream = EncodeToLegacy ( decoded ) ;
5454
@@ -63,8 +63,8 @@ public void TestEncodeDecodeStability(string name)
6363 var decoded = DecodeFromLegacy ( beatmaps_resource_store . GetStream ( name ) , beatmaps_resource_store , name ) ;
6464 var decodedAfterEncode = DecodeFromLegacy ( EncodeToLegacy ( decoded ) , beatmaps_resource_store , name ) ;
6565
66- Sort ( decoded . beatmap ) ;
67- Sort ( decodedAfterEncode . beatmap ) ;
66+ Sort ( decoded . Beatmap ) ;
67+ Sort ( decodedAfterEncode . Beatmap ) ;
6868
6969 CompareBeatmaps ( decoded , decodedAfterEncode ) ;
7070 }
@@ -76,10 +76,10 @@ public void TestEncodeDecodeStabilityDoubleConvert(string name)
7676 var decodedAfterEncode = DecodeFromLegacy ( EncodeToLegacy ( decoded ) , beatmaps_resource_store , name ) ;
7777
7878 // run an extra convert. this is expected to be stable.
79- decodedAfterEncode . beatmap = convert ( decodedAfterEncode . beatmap ) ;
79+ decodedAfterEncode = decodedAfterEncode with { Beatmap = convert ( decodedAfterEncode . Beatmap ) } ;
8080
81- Sort ( decoded . beatmap ) ;
82- Sort ( decodedAfterEncode . beatmap ) ;
81+ Sort ( decoded . Beatmap ) ;
82+ Sort ( decodedAfterEncode . Beatmap ) ;
8383
8484 CompareBeatmaps ( decoded , decodedAfterEncode ) ;
8585 }
@@ -91,7 +91,7 @@ public void TestEncodeDecodeStabilityWithNonLegacyControlPoints(string name)
9191
9292 // we are testing that the transfer of relevant data to hitobjects (from legacy control points) sticks through encode/decode.
9393 // before the encode step, the legacy information is removed here.
94- decoded . beatmap . ControlPointInfo = removeLegacyControlPointTypes ( decoded . beatmap . ControlPointInfo ) ;
94+ decoded . Beatmap . ControlPointInfo = removeLegacyControlPointTypes ( decoded . Beatmap . ControlPointInfo ) ;
9595
9696 var decodedAfterEncode = DecodeFromLegacy ( EncodeToLegacy ( decoded ) , beatmaps_resource_store , name ) ;
9797
@@ -120,17 +120,21 @@ static ControlPointInfo removeLegacyControlPointTypes(ControlPointInfo controlPo
120120 }
121121 }
122122
123- public static void CompareBeatmaps ( ( IBeatmap beatmap , TestLegacySkin skin ) expected , ( IBeatmap beatmap , TestLegacySkin skin ) actual )
123+ public static void CompareBeatmaps ( BeatmapComponents expected , BeatmapComponents actual )
124124 {
125125 // Check all control points that are still considered to be at a global level.
126- Assert . That ( actual . beatmap . ControlPointInfo . TimingPoints . Serialize ( ) , Is . EqualTo ( expected . beatmap . ControlPointInfo . TimingPoints . Serialize ( ) ) ) ;
127- Assert . That ( actual . beatmap . ControlPointInfo . EffectPoints . Serialize ( ) , Is . EqualTo ( expected . beatmap . ControlPointInfo . EffectPoints . Serialize ( ) ) ) ;
126+ Assert . That ( actual . Beatmap . ControlPointInfo . TimingPoints . Serialize ( ) , Is . EqualTo ( expected . Beatmap . ControlPointInfo . TimingPoints . Serialize ( ) ) ) ;
127+ Assert . That ( actual . Beatmap . ControlPointInfo . EffectPoints . Serialize ( ) , Is . EqualTo ( expected . Beatmap . ControlPointInfo . EffectPoints . Serialize ( ) ) ) ;
128128
129129 // Check all hitobjects.
130- Assert . That ( actual . beatmap . HitObjects . Serialize ( ) , Is . EqualTo ( expected . beatmap . HitObjects . Serialize ( ) ) ) ;
130+ Assert . That ( actual . Beatmap . HitObjects . Serialize ( ) , Is . EqualTo ( expected . Beatmap . HitObjects . Serialize ( ) ) ) ;
131131
132132 // Check skin.
133- ClassicAssert . True ( areComboColoursEqual ( expected . skin . Configuration , actual . skin . Configuration ) ) ;
133+ ClassicAssert . True ( areComboColoursEqual ( expected . Skin . Configuration , actual . Skin . Configuration ) ) ;
134+
135+ // Do a rough pass on storyboard layers.
136+ foreach ( string layer in actual . Storyboard . Layers . Concat ( expected . Storyboard . Layers ) . Select ( l => l . Name ) . Distinct ( ) )
137+ Assert . That ( actual . Storyboard . GetLayer ( layer ) . Elements . Count , Is . EqualTo ( expected . Storyboard . GetLayer ( layer ) . Elements . Count ) ) ;
134138 }
135139
136140 [ Test ]
@@ -153,9 +157,9 @@ public void TestEncodeBSplineCurveType()
153157 }
154158 } ;
155159
156- var encoded = EncodeToLegacy ( ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) ) ) ;
160+ var encoded = EncodeToLegacy ( new BeatmapComponents ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) , new Storyboard ( ) ) ) ;
157161 var decodedAfterEncode = DecodeFromLegacy ( encoded , beatmaps_resource_store , string . Empty ) ;
158- var decodedSlider = ( Slider ) decodedAfterEncode . beatmap . HitObjects [ 0 ] ;
162+ var decodedSlider = ( Slider ) decodedAfterEncode . Beatmap . HitObjects [ 0 ] ;
159163 Assert . That ( decodedSlider . Path . ControlPoints . Count , Is . EqualTo ( 4 ) ) ;
160164 Assert . That ( decodedSlider . Path . ControlPoints [ 0 ] . Type , Is . EqualTo ( PathType . BSpline ( 3 ) ) ) ;
161165 Assert . That ( decodedSlider . Path . ControlPoints [ 2 ] . Type , Is . EqualTo ( PathType . BSpline ( 3 ) ) ) ;
@@ -183,9 +187,9 @@ public void TestEncodeMultiSegmentSliderWithFloatingPointError()
183187 }
184188 } ;
185189
186- var encoded = EncodeToLegacy ( ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) ) ) ;
190+ var encoded = EncodeToLegacy ( new BeatmapComponents ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) , new Storyboard ( ) ) ) ;
187191 var decodedAfterEncode = DecodeFromLegacy ( encoded , beatmaps_resource_store , string . Empty ) ;
188- var decodedSlider = ( Slider ) decodedAfterEncode . beatmap . HitObjects [ 0 ] ;
192+ var decodedSlider = ( Slider ) decodedAfterEncode . Beatmap . HitObjects [ 0 ] ;
189193 Assert . That ( decodedSlider . Path . ControlPoints . Count , Is . EqualTo ( 5 ) ) ;
190194 }
191195
@@ -211,9 +215,9 @@ public void TestOnlyEightComboColoursEncoded()
211215 }
212216 } ;
213217
214- var encoded = EncodeToLegacy ( ( new Beatmap ( ) , beatmapSkin ) ) ;
218+ var encoded = EncodeToLegacy ( new BeatmapComponents ( new Beatmap ( ) , beatmapSkin , new Storyboard ( ) ) ) ;
215219 var decodedAfterEncode = DecodeFromLegacy ( encoded , beatmaps_resource_store , string . Empty ) ;
216- Assert . That ( decodedAfterEncode . skin . Configuration . CustomComboColours , Has . Count . EqualTo ( 8 ) ) ;
220+ Assert . That ( decodedAfterEncode . Skin . Configuration . CustomComboColours , Has . Count . EqualTo ( 8 ) ) ;
217221 }
218222
219223 [ Test ]
@@ -234,9 +238,9 @@ public void TestEncodeStabilityOfSliderWithFractionalCoordinates()
234238 HitObjects = { originalSlider }
235239 } ;
236240
237- var encoded = EncodeToLegacy ( ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) ) ) ;
241+ var encoded = EncodeToLegacy ( new BeatmapComponents ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) , new Storyboard ( ) ) ) ;
238242 var decodedAfterEncode = DecodeFromLegacy ( encoded , beatmaps_resource_store , string . Empty , version : LegacyBeatmapEncoder . FIRST_LAZER_VERSION ) ;
239- var decodedSlider = ( Slider ) decodedAfterEncode . beatmap . HitObjects [ 0 ] ;
243+ var decodedSlider = ( Slider ) decodedAfterEncode . Beatmap . HitObjects [ 0 ] ;
240244 Assert . That ( decodedSlider . Path . ControlPoints . Select ( p => p . Position ) ,
241245 Is . EquivalentTo ( originalSlider . Path . ControlPoints . Select ( p => p . Position ) ) ) ;
242246 }
@@ -254,17 +258,17 @@ public void TestEncodeCustomSampleBanks()
254258 }
255259 } ;
256260
257- var encoded = EncodeToLegacy ( ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) ) ) ;
261+ var encoded = EncodeToLegacy ( new BeatmapComponents ( beatmap , new TestLegacySkin ( beatmaps_resource_store , string . Empty ) , new Storyboard ( ) ) ) ;
258262 var decodedAfterEncode = DecodeFromLegacy ( encoded , beatmaps_resource_store , string . Empty ) ;
259263
260- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 0 ] . Samples [ 0 ] . Suffix , Is . Null ) ;
261- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 0 ] . Samples [ 0 ] . UseBeatmapSamples , Is . False ) ;
264+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 0 ] . Samples [ 0 ] . Suffix , Is . Null ) ;
265+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 0 ] . Samples [ 0 ] . UseBeatmapSamples , Is . False ) ;
262266
263- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 1 ] . Samples [ 0 ] . Suffix , Is . Null ) ;
264- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 1 ] . Samples [ 0 ] . UseBeatmapSamples , Is . True ) ;
267+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 1 ] . Samples [ 0 ] . Suffix , Is . Null ) ;
268+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 1 ] . Samples [ 0 ] . UseBeatmapSamples , Is . True ) ;
265269
266- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 2 ] . Samples [ 0 ] . Suffix , Is . EqualTo ( "3" ) ) ;
267- Assert . That ( decodedAfterEncode . beatmap . HitObjects [ 2 ] . Samples [ 0 ] . UseBeatmapSamples , Is . True ) ;
270+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 2 ] . Samples [ 0 ] . Suffix , Is . EqualTo ( "3" ) ) ;
271+ Assert . That ( decodedAfterEncode . Beatmap . HitObjects [ 2 ] . Samples [ 0 ] . UseBeatmapSamples , Is . True ) ;
268272 }
269273
270274 private static bool areComboColoursEqual ( IHasComboColours a , IHasComboColours b )
@@ -289,15 +293,17 @@ public static void Sort(IBeatmap beatmap)
289293 }
290294 }
291295
292- public static ( IBeatmap beatmap , TestLegacySkin skin ) DecodeFromLegacy ( Stream stream , IResourceStore < byte [ ] > beatmapsResourceStore , string name , int version = LegacyDecoder < Beatmap > . LATEST_VERSION )
296+ public static BeatmapComponents DecodeFromLegacy ( Stream stream , IResourceStore < byte [ ] > beatmapsResourceStore , string name , int version = LegacyDecoder < Beatmap > . LATEST_VERSION )
293297 {
294298 using ( var reader = new LineBufferedReader ( stream ) )
295299 {
296300 var beatmap = new LegacyBeatmapDecoder ( version ) { ApplyOffsets = false } . Decode ( reader ) ;
297301 var beatmapSkin = new TestLegacySkin ( beatmapsResourceStore , name ) ;
298302 stream . Seek ( 0 , SeekOrigin . Begin ) ;
299303 beatmapSkin . Configuration = new LegacySkinDecoder ( ) . Decode ( reader ) ;
300- return ( convert ( beatmap ) , beatmapSkin ) ;
304+ stream . Seek ( 0 , SeekOrigin . Begin ) ;
305+ var storyboard = new LegacyStoryboardDecoder ( ) . Decode ( reader ) ;
306+ return new BeatmapComponents ( convert ( beatmap ) , beatmapSkin , storyboard ) ;
301307 }
302308 }
303309
@@ -309,13 +315,13 @@ public TestLegacySkin(IResourceStore<byte[]> fallbackStore, string fileName)
309315 }
310316 }
311317
312- public static MemoryStream EncodeToLegacy ( ( IBeatmap beatmap , ISkin skin ) fullBeatmap )
318+ public static MemoryStream EncodeToLegacy ( BeatmapComponents fullBeatmap )
313319 {
314- var ( beatmap , beatmapSkin ) = fullBeatmap ;
320+ var ( beatmap , beatmapSkin , storyboard ) = fullBeatmap ;
315321 var stream = new MemoryStream ( ) ;
316322
317323 using ( var writer = new StreamWriter ( stream , Encoding . UTF8 , 1024 , true ) )
318- new LegacyBeatmapEncoder ( beatmap , beatmapSkin ) . Encode ( writer ) ;
324+ new LegacyBeatmapEncoder ( beatmap , beatmapSkin , storyboard ) . Encode ( writer ) ;
319325
320326 stream . Position = 0 ;
321327
0 commit comments