Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can there ever be more than one background or video? I supported multiple in #69. I only ask because it matters whether we expose .background or .backgrounds to the user.

Copy link
Contributor Author

@OliBomby OliBomby Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some tests in osu! stable and it seems to only load the first background in the file and for videos im not sure, because it seems to support multiple videos but the second video wouldn't play for me, at most showing a black screen or a single frame.

I have a vague memory of some issue thread that wanted to fix multiple videos, but I can't find it.

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
Loading