Skip to content

Commit

Permalink
Parse background and video events
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Sep 14, 2024
1 parent e33c32a commit 6536ee3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 21 additions & 2 deletions slider/beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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' \
Expand Down
10 changes: 10 additions & 0 deletions slider/tests/test_beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'
Expand Down

0 comments on commit 6536ee3

Please sign in to comment.