diff --git a/slider/beatmap.py b/slider/beatmap.py index 00cfbb2..d20a61a 100644 --- a/slider/beatmap.py +++ b/slider/beatmap.py @@ -1755,6 +1755,8 @@ def __init__(self, approach_rate, slider_multiplier, slider_tick_rate, + background, + video, timing_points, hit_objects): self.format_version = format_version @@ -1788,6 +1790,8 @@ def __init__(self, self.approach_rate = approach_rate self.slider_multiplier = slider_multiplier self.slider_tick_rate = slider_tick_rate + self.background = background + self.video = video self.timing_points = timing_points self._hit_objects = hit_objects # cache hit object stacking at different ar and cs values @@ -2571,6 +2575,15 @@ def parse(cls, data): default=1.0, # taken from wiki ) + background = None + video = None + if 'Events' in groups: + for line in groups['Events']: + if line.startswith('0'): + background = line.split('\"')[1] + elif line.startswith('Video') or line.startswith('1'): + video = line.split('\"')[1] + return cls( format_version=format_version, audio_filename=_get_as_str(groups, 'General', 'AudioFilename'), @@ -2660,6 +2673,8 @@ def parse(cls, data): ), slider_multiplier=slider_multiplier, slider_tick_rate=slider_tick_rate, + background=background, + video=video, timing_points=timing_points, hit_objects=list(map( partial( @@ -2794,8 +2809,12 @@ def pack_field( # pack Events section packed_str += '[Events]\n' - packed_str += '// Background and Video events\n' \ - '// Break Periods\n' \ + packed_str += '// Background and Video events\n' + if self.background is not None: + packed_str += f'0,0,"{self.background}",0,0\n' + if self.video is not None: + packed_str += f'Video,0,"{self.video}"\n' + packed_str += '// Break Periods\n' \ '// Storyboard Layer 0(Background)\n' \ '// Storyboard Layer 1(Fail)\n' \ '// Storyboard Layer 2(Pass)\n' \ diff --git a/slider/tests/test_beatmap.py b/slider/tests/test_beatmap.py index f98e883..e76e10c 100644 --- a/slider/tests/test_beatmap.py +++ b/slider/tests/test_beatmap.py @@ -286,6 +286,14 @@ def test_od(beatmap): assert beatmap.od() == 9 +def test_background(beatmap): + assert beatmap.background == "miiro_no_scenario.png" + + +def test_video(beatmap): + assert beatmap.video is None + + def test_pack(beatmap): # Pack the beatmap and parse it again to see if there is difference. packed_str = beatmap.pack() @@ -308,6 +316,8 @@ def test_pack(beatmap): # Difficulty section fields 'hp_drain_rate', 'circle_size', 'overall_difficulty', 'approach_rate', 'slider_multiplier', 'slider_tick_rate', + # Event section fields + 'background', 'video', ] hitobj_attrs = [ 'position', 'time', 'new_combo', 'combo_skip', 'hitsound', 'addition'