Skip to content

Commit b954f3a

Browse files
committed
refactor & add: .pyi
1 parent 374783d commit b954f3a

File tree

3 files changed

+428
-138
lines changed

3 files changed

+428
-138
lines changed
Lines changed: 94 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pathlib import Path
2-
from typing import Dict, List, Optional, Tuple, Union
2+
from . import BaseGetter
3+
from typing import Dict, List, Optional, Tuple
34

45

5-
class DifficultyPoint:
6+
class DifficultyPoint(BaseGetter):
67
'''
78
DifficultyPoint object
89
@@ -14,27 +15,13 @@ class DifficultyPoint:
1415
time: float
1516
speed_multiplier: float
1617

17-
def __repr__(self) -> str:
18-
return f'<DifficultyPoint object ({self.attrs})>'
19-
20-
@property
21-
def as_string(self) -> str: ...
2218
@property
2319
def as_dict(self) -> Dict[str, float]: ...
24-
25-
# Properties -----
26-
@property
27-
def attrs(self) -> str:
28-
'''Get attrs as text'''
29-
return self.as_string
30-
3120
@property
32-
def attrs_dict(self) -> Dict[str, float]:
33-
'''Get attrs as dict'''
34-
return self.as_dict
21+
def attrs_dict(self) -> Dict[str, float]: ...
3522

3623

37-
class TimingPoint:
24+
class TimingPoint(BaseGetter):
3825
'''
3926
TimingPoint object
4027
@@ -46,28 +33,13 @@ class TimingPoint:
4633
time: float
4734
beat_len: float
4835

49-
def __repr__(self) -> str:
50-
return f'<TimingPoint object ({self.attrs})>'
51-
52-
@property
53-
def as_string(self) -> str: ...
54-
5536
@property
5637
def as_dict(self) -> Dict[str, float]: ...
57-
58-
# Properties -----
5938
@property
60-
def attrs(self) -> str:
61-
'''Get attrs as text'''
62-
return self.as_string
63-
64-
@property
65-
def attrs_dict(self) -> Dict[str, float]:
66-
'''Get attrs as dict'''
67-
return self.as_dict
39+
def attrs_dict(self) -> Dict[str, float]: ...
6840

6941

70-
class Pos2:
42+
class Pos2(BaseGetter):
7143
'''
7244
Pos2 object
7345
@@ -85,16 +57,8 @@ class Pos2:
8557
length_squared: float
8658
length: float
8759

88-
def __repr__(self) -> str:
89-
return f'<Pos2 object ({self.attrs})>'
90-
91-
@property
92-
def as_string(self) -> str: ...
93-
94-
@property
95-
def as_dict(self) -> Dict[str, float]: ...
96-
9760
# Methods ------
61+
9862
def dot(self, other: Pos2) -> float: ...
9963
def distance(self, other: Pos2) -> float: ...
10064
def normalize(self) -> Pos2: ...
@@ -104,25 +68,18 @@ class Pos2:
10468
def div(self, rhs: float) -> Pos2: ...
10569
def add_assign(self, other: Pos2): ...
10670

107-
# Properties -----
108-
10971
@property
110-
def attrs(self) -> str:
111-
'''Get attrs as text'''
112-
return self.as_string
113-
72+
def as_dict(self) -> Dict[str, float]: ...
11473
@property
115-
def attrs_dict(self) -> Dict[str, float]:
116-
'''Get attrs as dict'''
117-
return self.as_dict
74+
def attrs_dict(self) -> Dict[str, float]: ...
11875

11976
@property
12077
def as_tuple(self) -> Tuple[float, float]:
12178
'''Get (x, y) as tuple'''
122-
return self.as_tuple
79+
...
12380

12481

125-
class HitObjectKind:
82+
class HitObjectKind(BaseGetter):
12683
'''
12784
HitObjectKind object
12885
@@ -144,32 +101,15 @@ class HitObjectKind:
144101
repeats: Optional[int]
145102
path_type: Optional[str]
146103
end_time: Optional[float]
147-
148-
# cache needed attrs
149104
curve_points: Optional[List[Pos2]]
150105

151-
def __repr__(self) -> str:
152-
return f'<HitObjectKind object ({self.attrs})>'
153-
154-
@property
155-
def as_string(self) -> str: ...
156-
157106
@property
158107
def as_dict(self) -> Dict[str, float]: ...
159-
160-
# Properties -----
161-
@property
162-
def attrs(self) -> str:
163-
'''Get attrs as text'''
164-
return self.as_string
165-
166108
@property
167-
def attrs_dict(self) -> Dict[str, float]:
168-
'''Get attrs as dict'''
169-
return self.as_dict
109+
def attrs_dict(self) -> Dict[str, float]: ...
170110

171111

172-
class HitObject:
112+
class HitObject(BaseGetter):
173113
'''
174114
HitObject object
175115
@@ -199,34 +139,95 @@ class HitObject:
199139
is_slider: bool
200140
is_spinner: bool
201141
kind_str: str
202-
203-
# cache needed attrs
204142
pos: Pos2
205143
kind: HitObjectKind
206144

207-
def __repr__(self) -> str:
208-
return f'<HitObject object ({self.attrs})>'
209-
210-
@property
211-
def as_string(self) -> str: ...
212-
213145
@property
214146
def as_dict(self) -> Dict[str, float]: ...
215-
216-
# Properties -----
217147
@property
218-
def attrs(self) -> str:
219-
'''Get attrs as text'''
220-
return self.as_string
148+
def attrs_dict(self) -> Dict[str, float]: ...
221149

222-
@property
223-
def attrs_dict(self) -> Dict[str, float]:
224-
'''Get attrs as dict'''
225-
return self.as_dict
226150

151+
class Beatmap(BaseGetter):
152+
'''
153+
The Beatmap used to calculate the pp, it contains the parsed .osu beatmap.
154+
155+
`path`: `Optional[Path]`
156+
157+
`mode`: `int`
158+
159+
`mode_str`: `str`
160+
161+
`version`: `int`
162+
163+
`n_circles`: `int`
164+
165+
`n_sliders`: `int`
166+
167+
`n_spinners`: `int`
168+
169+
`ar`: `float`
170+
171+
`od`: `float`
172+
173+
`cs`: `float`
174+
175+
`hp`: `float`
176+
177+
`sv`: `float`
178+
179+
`tick_rate`: `float`
180+
181+
`stack_leniency`: `Optional[float]`
182+
183+
`hit_objects`: `Optional[List[HitObject]]`
227184
228-
class Beatmap:
229-
...
185+
`timing_points`: `Optional[List[TimingPoint]]`
186+
187+
`difficulty_points`: `Optional[List[DifficultyPoint]]`
188+
189+
190+
# Examples:
191+
```
192+
# Read and parse .osu files from local
193+
beatmap = Beatmap('path_to_osu_file')
194+
# Same as
195+
beatmap = Beatmap.create('path_to_osu_file')
196+
197+
# Async Rust
198+
beatmap = await Beatmap.create_async_rs('path_to_osu_file')
199+
# Async Python (wrapper)
200+
beatmap = await Beatmap.create_async_py('path_to_osu_file')
201+
202+
203+
204+
# We can reload this .osu files as:
205+
beatmap.reload()
206+
207+
# Async Rust
208+
await beatmap.reload_async_rs()
209+
# Async Python (wrapper)
210+
await beatmap.reload_async_py()
211+
212+
# We can load another .osu files as:
213+
beatmap.init('path_to_another_osu_file')
214+
215+
# Async Rust
216+
await beatmap.init_rs('path_to_another_osu_file')
217+
# Async Python (wrapper)
218+
await beatmap.init_py('path_to_another_osu_file')
219+
220+
# Calculate PP
221+
c = Calculator()
222+
c.set_acc(98.8)
223+
c.set_combo(727)
224+
# or
225+
c = Calculator({'acc': 98.8, 'combo': 727})
226+
# then
227+
result = c.calculate(beatmap)
228+
229+
```
230+
'''
230231
mode: int
231232
mode_str: str
232233
version: int
@@ -250,11 +251,6 @@ class Beatmap:
250251
@property
251252
def difficulty_points(self) -> List[DifficultyPoint]: ...
252253

253-
@property
254-
def as_string(self) -> str: ...
255-
@property
256-
def as_dict(self) -> Dict[str, Union[float, int, None]]: ...
257-
258254

259255
async def read_beatmap_async(path: Path) -> Beatmap: ...
260256
def read_beatmap_sync(path: Path) -> Beatmap: ...

0 commit comments

Comments
 (0)