Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NiceAesth/aiosu
Browse files Browse the repository at this point in the history
  • Loading branch information
NiceAesth committed Jul 20, 2023
2 parents 712c441 + 42702e4 commit 896bc96
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion aiosu/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .comment import *
from .common import *
from .event import *
from .files import *
from .forum import *
from .gamemode import *
from .kudosu import *
Expand All @@ -22,7 +23,6 @@
from .oauthtoken import *
from .performance import *
from .rankings import *
from .replay import *
from .scopes import *
from .score import *
from .search import *
Expand Down
3 changes: 3 additions & 0 deletions aiosu/models/files/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

from .replay import *
20 changes: 10 additions & 10 deletions aiosu/models/replay.py → aiosu/models/files/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

from pydantic import model_validator

from .base import BaseModel
from .gamemode import Gamemode
from .lazer import LazerReplayData
from .mods import Mod
from .mods import Mods
from .score import ScoreStatistics
from ..base import BaseModel
from ..gamemode import Gamemode
from ..lazer import LazerReplayData
from ..mods import Mod
from ..mods import Mods
from ..score import ScoreStatistics

__all__ = (
"Replay",
"ReplayFile",
"ReplayKey",
"ReplayLifebarEvent",
"ReplayEvent",
Expand Down Expand Up @@ -81,7 +81,7 @@ class ReplayEvent(BaseModel):
keys: ReplayKey


class Replay(BaseModel):
class ReplayFile(BaseModel):
"""Replay file data."""

mode: Gamemode
Expand Down Expand Up @@ -111,7 +111,7 @@ def __str__(self) -> str:

@model_validator(mode="after") # type: ignore
@classmethod
def _add_skip_offset(cls, obj: Replay) -> Replay:
def _add_skip_offset(cls, obj: ReplayFile) -> ReplayFile:
if not obj.skip_offset:
obj.skip_offset = _parse_skip_offset(
obj.replay_data,
Expand All @@ -121,7 +121,7 @@ def _add_skip_offset(cls, obj: Replay) -> Replay:

@model_validator(mode="after") # type: ignore
@classmethod
def _add_rng_seed(cls, obj: Replay) -> Replay:
def _add_rng_seed(cls, obj: ReplayFile) -> ReplayFile:
if not obj.rng_seed and obj.version >= 2013_03_19:
obj.rng_seed = _parse_rng_seed(obj.replay_data)
return obj
18 changes: 9 additions & 9 deletions aiosu/utils/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typing import Any
from typing import BinaryIO

from ..models.files.replay import ReplayEvent
from ..models.files.replay import ReplayFile
from ..models.files.replay import ReplayKey
from ..models.files.replay import ReplayLifebarEvent
from ..models.lazer import LazerReplayData
from ..models.mods import Mod
from ..models.replay import Replay
from ..models.replay import ReplayEvent
from ..models.replay import ReplayKey
from ..models.replay import ReplayLifebarEvent
from .binary import pack_byte
from .binary import pack_float64
from .binary import pack_int
Expand Down Expand Up @@ -66,7 +66,7 @@ def _parse_life_graph_data(data: str) -> list[ReplayLifebarEvent]:
return events


def parse_file(file: BinaryIO) -> Replay:
def parse_file(file: BinaryIO) -> ReplayFile:
"""Parse a replay file and return a dictionary with the replay data.
:param file: The replay file.
Expand Down Expand Up @@ -108,10 +108,10 @@ def parse_file(file: BinaryIO) -> Replay:
replay["lazer_replay_data"] = LazerReplayData.model_validate_json(
lazer_replay_data_str,
)
return Replay(**replay)
return ReplayFile(**replay)


def parse_path(path: str) -> Replay:
def parse_path(path: str) -> ReplayFile:
"""Parse a replay file and return a dictionary with the replay data.
:param path: The path to the replay file.
Expand All @@ -123,7 +123,7 @@ def parse_path(path: str) -> Replay:
return parse_file(file)


def write_replay(file: BinaryIO, replay: Replay) -> None:
def write_replay(file: BinaryIO, replay: ReplayFile) -> None:
"""Write a replay to a file.
:param file: The file to write to.
Expand Down Expand Up @@ -178,7 +178,7 @@ def write_replay(file: BinaryIO, replay: Replay) -> None:
)


def write_path(path: str, replay: Replay) -> None:
def write_path(path: str, replay: ReplayFile) -> None:
"""Write a replay to a file.
:param path: The path to the file to write to.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/models/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Score
Replay
------

.. automodule:: aiosu.models.replay
.. automodule:: aiosu.models.files.replay
:members:
:exclude-members: Config
:undoc-members:
Expand Down
4 changes: 2 additions & 2 deletions examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pp_calc = aiosu.utils.performance.OsuPerformanceCalculator(diff_atribs)
pp_atribs: aiosu.models.OsuPerformanceAttributes = pp_calc.calculate(score)

replay: aiosu.models.Replay = aiosu.utils.replay.parse_path("./replay.osr")
replay: aiosu.models.ReplayFile = aiosu.utils.replay.parse_path("./replay.osr")

with open("./replay.osr", "rb") as f:
replay: aiosu.models.Replay = aiosu.utils.replay.parse_file(f)
replay: aiosu.models.ReplayFile = aiosu.utils.replay.parse_file(f)
2 changes: 1 addition & 1 deletion tests/test_utils/test_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_parse_replay(replay_file):
for mode in modes:
data = BytesIO(replay_file(mode))
replay = aiosu.utils.replay.parse_file(data)
assert isinstance(replay, aiosu.models.Replay)
assert isinstance(replay, aiosu.models.ReplayFile)


def test_write_replay(replay_file):
Expand Down

0 comments on commit 896bc96

Please sign in to comment.