Skip to content

Commit

Permalink
added new combo and combo skip
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Sep 2, 2023
1 parent c63fbfa commit b67bf88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
38 changes: 25 additions & 13 deletions slider/beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ class HitObject:
"""
time_related_attributes = frozenset({'time'})

def __init__(self, position, time, hitsound, addition='0:0:0:0:'):
def __init__(self, position, time, new_combo, combo_skip, hitsound, addition='0:0:0:0:'):
self.position = position
self.time = time
self.new_combo = bool(new_combo)
self.combo_skip = combo_skip
self.hitsound = hitsound
self.addition = addition
self.ht_enabled = False
Expand Down Expand Up @@ -297,6 +299,9 @@ def _time_modify(self, coefficient):

return type(self)(**kwargs)

def _get_combo_bits(self):
return (self.new_combo << 2) | (self.combo_skip << 4)

@lazyval
def half_time(self):
"""The ``HitObject`` as it would appear with
Expand Down Expand Up @@ -420,7 +425,7 @@ def parse(cls, data, timing_points, slider_multiplier, slider_tick_rate):
else:
raise ValueError(f'unknown type code {type_!r}')

return parse(Position(x, y), time, hitsound, rest)
return parse(Position(x, y), time, (type_ & 4) >> 2, (type_ & 112) >> 4, hitsound, rest)

@abstractmethod
def pack(self):
Expand Down Expand Up @@ -454,11 +459,11 @@ class Circle(HitObject):
type_code = 1

@classmethod
def _parse(cls, position, time, hitsound, rest):
def _parse(cls, position, time, new_combo, combo_skip, hitsound, rest):
if len(rest) > 1:
raise ValueError('extra data: {rest!r}')

return cls(position, time, hitsound, *rest)
return cls(position, time, new_combo, combo_skip, hitsound, *rest)

def pack(self):
"""The string representing this circle hit element used in ``.osu`` file,
Expand All @@ -479,7 +484,7 @@ def pack(self):
return ','.join([_pack_float('x', self.position.x),
_pack_float('y', self.position.y),
_pack_timedelta('time', self.time),
_pack_int('type', Circle.type_code),
_pack_int('type', Circle.type_code | self._get_combo_bits()),
_pack_int('hitSound', self.hitsound),
_pack_str('hitSample', self.addition)])

Expand All @@ -504,14 +509,15 @@ class Spinner(HitObject):
def __init__(self,
position,
time,
new_combo,
hitsound,
end_time,
addition='0:0:0:0:'):
super().__init__(position, time, hitsound, addition)
super().__init__(position, time, new_combo, 0, hitsound, addition)
self.end_time = end_time

@classmethod
def _parse(cls, position, time, hitsound, rest):
def _parse(cls, position, time, new_combo, _, hitsound, rest):
try:
end_time, *rest = rest
except ValueError:
Expand All @@ -525,7 +531,7 @@ def _parse(cls, position, time, hitsound, rest):
if len(rest) > 1:
raise ValueError(f'extra data: {rest!r}')

return cls(position, time, hitsound, end_time, *rest)
return cls(position, time, new_combo, hitsound, end_time, *rest)

def pack(self):
"""The string representing this spinner hit element used in ``.osu`` file,
Expand All @@ -545,7 +551,7 @@ def pack(self):
return ','.join([_pack_float('x', self.position.x),
_pack_float('y', self.position.y),
_pack_timedelta('time', self.time),
_pack_int('type', Spinner.type_code),
_pack_int('type', Spinner.type_code | self._get_combo_bits()),
_pack_int('hitSound', self.hitsound),
_pack_timedelta('endTime', self.end_time),
_pack_str('hitSample', self.addition)])
Expand Down Expand Up @@ -591,6 +597,8 @@ class Slider(HitObject):
def __init__(self,
position,
time,
new_combo,
combo_skip,
end_time,
hitsound,
curve,
Expand All @@ -603,7 +611,7 @@ def __init__(self,
edge_sounds,
edge_additions,
addition='0:0:0:0:'):
super().__init__(position, time, hitsound, addition)
super().__init__(position, time, new_combo, combo_skip, hitsound, addition)
self.end_time = end_time
self.curve = curve
self.repeat = repeat
Expand Down Expand Up @@ -715,6 +723,8 @@ def hard_rock(self):
def _parse(cls,
position,
time,
new_combo,
combo_skip,
hitsound,
rest,
timing_points,
Expand Down Expand Up @@ -837,6 +847,8 @@ def _parse(cls,
return cls(
position,
time,
new_combo,
combo_skip,
time + duration,
hitsound,
Curve.from_kind_and_points(slider_type, points, pixel_length),
Expand Down Expand Up @@ -869,7 +881,7 @@ def pack(self):
return ','.join([_pack_float('x', self.position.x),
_pack_float('y', self.position.y),
_pack_timedelta('time', self.time),
_pack_int('type', Slider.type_code),
_pack_int('type', Slider.type_code | self._get_combo_bits()),
_pack_int('hitSound', self.hitsound),
self.curve.pack(),
_pack_int('slides', self.repeat),
Expand Down Expand Up @@ -904,11 +916,11 @@ def __init__(self,
hitsound,
end_time,
addition='0:0:0:0:'):
super().__init__(position, time, hitsound, addition)
super().__init__(position, time, False, 0, hitsound, addition)
self.end_time = end_time

@classmethod
def _parse(cls, position, time, hitsound, rest):
def _parse(cls, position, time, new_combo, combo_skip, hitsound, rest):
try:
end_time, *rest = rest
except ValueError:
Expand Down
4 changes: 3 additions & 1 deletion slider/tests/test_beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def test_parse_section_hit_objects(beatmap):
def test_hit_objects_stacking():
hit_objects = [slider.beatmap.Circle(Position(128, 128),
timedelta(milliseconds=x*10),
False,
0,
hitsound=1) for x in range(10)]

beatmap = slider.Beatmap(
Expand Down Expand Up @@ -307,7 +309,7 @@ def test_pack(beatmap):
'hp_drain_rate', 'circle_size', 'overall_difficulty', 'approach_rate',
'slider_multiplier', 'slider_tick_rate',
]
hitobj_attrs = ['position', 'time', 'hitsound', 'addition']
hitobj_attrs = ['position', 'time', 'new_combo', 'combo_skip', 'hitsound', 'addition']
slider_attrs = [
'end_time', 'hitsound', 'repeat', 'length', 'ticks', 'num_beats',
'tick_rate', 'ms_per_beat', 'edge_sounds', 'edge_additions', 'addition'
Expand Down

0 comments on commit b67bf88

Please sign in to comment.