Skip to content

Recorder

Bases: ABC

Source code in gamms/typing/recorder.py
class IRecorder(ABC):
    @abstractmethod
    def record(self) -> bool:
        """
        Boolean to inform whether game is being recorded or not and ctx is alive

        Returns:
            bool: True if recording, False otherwise
        """
        pass

    @abstractmethod
    def start(self, path: Union[str, BinaryIO]) -> None:
        """
        Start recording to the path. Raise error if file already exists
        Adds ".ggr" extension if not present.

        If path is a file object, it will be used as the file handler.

        Args:
            path (Union[str, BinaryIO]): Path to record the game.

        Raises:
            FileExistsError: If the file already exists.
            TypeError: If the path is not a string or file object.
        """
        pass
    @abstractmethod
    def stop(self) -> None:
        """
        Stop recording to the path and close the file handler.

        Raises:
            RuntimeError: If recording has not started.
        """
        pass
    @abstractmethod
    def pause(self) -> None:
        """
        Pause the recording process. `self.record()` should return false if paused.  If not started or stopped, give warning.
        """
        pass
    @abstractmethod
    def play(self) -> None:
        """
        Resume recording if paused. If not started or stopped, give warning.
        """
        pass
    @abstractmethod    
    def replay(self, path: Union[str, BinaryIO]) -> Iterator[Dict[str, Any]]:
        """
        Checks validity of the file and output an iterator.

        Args:
            path (Union[str, BinaryIO]): Path to the recording file.

        Returns:
            Iterator: Iterator to replay the recording.

        Raises:
            RuntimeError: If replay is already in progress.
            FileNotFoundError: If the file does not exist.
            TypeError: If the path is not a string or file object.
            ValueError: If the file is not a valid recording file or if recording terminated unexpectedly.
            ValueError: If the version of the file is not supported.
        """
        pass
    @abstractmethod
    def time(self) -> int:
        """
        Return record time if replaying. Else return the local time `(time.time())` in nano seconds.

        Returns:
            int: Time in nanoseconds.
        """
        pass
    @abstractmethod
    def write(self, opCode: OpCodes, data: Dict[str, JsonType]) -> None:
        """
        Write to record buffer if recording. If not recording raise error as it should not happen.

        WARNING: This function should not be required to be called by the user in most cases.
        """
        pass

    @abstractmethod
    def component(self, struct: Dict[str, Type[_T]]) -> Callable[[Type[_T]], Type[_T]]:
        """
        Decorator to add a component to the recorder.

        Args:
            struct (Dict[str, Type[_T]]): Dictionary with component name and type.

        Returns:
            Callable[[Type[_T]], Type[_T]]: Decorator function.

        """
        pass

    @abstractmethod
    def get_component(self, name: str) -> object:
        """
        Get the component from the name.

        Args:
            name (str): Name of the component.

        Returns:
            Type[_T]: Component object.

        Raises:
            KeyError: If the component is not found.
        """
        pass

    @abstractmethod
    def delete_component(self, name: str) -> None:
        """
        Delete the component from the name.

        Args:
            name (str): Name of the component.

        Raises:
            KeyError: If the component is not found.

        """
        pass

    @abstractmethod
    def component_iter(self) -> Iterator[str]:
        """
        Iterator for the component names.
        """
        pass

    @abstractmethod
    def add_component(self, name: str, obj: Type[_T]) -> None:
        """
        Add a component to the recorder.

        Args:
            name (str): Name of the component.
            obj (Type[_T]): Component object.

        Raises:
            ValueError: If the component already exists.
        """
        pass

    @abstractmethod
    def is_component_registered(self, key: Tuple[str, str]) -> bool:
        """
        Check if the component is registered.
        Key is (module_name, qualname)

        Args:
            key (Tuple[str, str]): Key to check.

        Returns:
            bool: True if registered, False otherwise.
        """
        pass

    @abstractmethod
    def unregister_component(self, key: Tuple[str, str]) -> None:
        """
        Unregister the component.
        Key is (module_name, qualname)

        Args:
            key (Tuple[str, str]): Key to unregister.

        Raises:
            KeyError: If the component is not found.
        """
        pass

add_component(name, obj) abstractmethod

Add a component to the recorder.

Parameters:

Name Type Description Default
name str

Name of the component.

required
obj Type[_T]

Component object.

required

Raises:

Type Description
ValueError

If the component already exists.

Source code in gamms/typing/recorder.py
@abstractmethod
def add_component(self, name: str, obj: Type[_T]) -> None:
    """
    Add a component to the recorder.

    Args:
        name (str): Name of the component.
        obj (Type[_T]): Component object.

    Raises:
        ValueError: If the component already exists.
    """
    pass

component(struct) abstractmethod

Decorator to add a component to the recorder.

Parameters:

Name Type Description Default
struct Dict[str, Type[_T]]

Dictionary with component name and type.

required

Returns:

Type Description
Callable[[Type[_T]], Type[_T]]

Callable[[Type[_T]], Type[_T]]: Decorator function.

Source code in gamms/typing/recorder.py
@abstractmethod
def component(self, struct: Dict[str, Type[_T]]) -> Callable[[Type[_T]], Type[_T]]:
    """
    Decorator to add a component to the recorder.

    Args:
        struct (Dict[str, Type[_T]]): Dictionary with component name and type.

    Returns:
        Callable[[Type[_T]], Type[_T]]: Decorator function.

    """
    pass

component_iter() abstractmethod

Iterator for the component names.

Source code in gamms/typing/recorder.py
@abstractmethod
def component_iter(self) -> Iterator[str]:
    """
    Iterator for the component names.
    """
    pass

delete_component(name) abstractmethod

Delete the component from the name.

Parameters:

Name Type Description Default
name str

Name of the component.

required

Raises:

Type Description
KeyError

If the component is not found.

Source code in gamms/typing/recorder.py
@abstractmethod
def delete_component(self, name: str) -> None:
    """
    Delete the component from the name.

    Args:
        name (str): Name of the component.

    Raises:
        KeyError: If the component is not found.

    """
    pass

get_component(name) abstractmethod

Get the component from the name.

Parameters:

Name Type Description Default
name str

Name of the component.

required

Returns:

Type Description
object

Type[_T]: Component object.

Raises:

Type Description
KeyError

If the component is not found.

Source code in gamms/typing/recorder.py
@abstractmethod
def get_component(self, name: str) -> object:
    """
    Get the component from the name.

    Args:
        name (str): Name of the component.

    Returns:
        Type[_T]: Component object.

    Raises:
        KeyError: If the component is not found.
    """
    pass

is_component_registered(key) abstractmethod

Check if the component is registered. Key is (module_name, qualname)

Parameters:

Name Type Description Default
key Tuple[str, str]

Key to check.

required

Returns:

Name Type Description
bool bool

True if registered, False otherwise.

Source code in gamms/typing/recorder.py
@abstractmethod
def is_component_registered(self, key: Tuple[str, str]) -> bool:
    """
    Check if the component is registered.
    Key is (module_name, qualname)

    Args:
        key (Tuple[str, str]): Key to check.

    Returns:
        bool: True if registered, False otherwise.
    """
    pass

pause() abstractmethod

Pause the recording process. self.record() should return false if paused. If not started or stopped, give warning.

Source code in gamms/typing/recorder.py
@abstractmethod
def pause(self) -> None:
    """
    Pause the recording process. `self.record()` should return false if paused.  If not started or stopped, give warning.
    """
    pass

play() abstractmethod

Resume recording if paused. If not started or stopped, give warning.

Source code in gamms/typing/recorder.py
@abstractmethod
def play(self) -> None:
    """
    Resume recording if paused. If not started or stopped, give warning.
    """
    pass

record() abstractmethod

Boolean to inform whether game is being recorded or not and ctx is alive

Returns:

Name Type Description
bool bool

True if recording, False otherwise

Source code in gamms/typing/recorder.py
@abstractmethod
def record(self) -> bool:
    """
    Boolean to inform whether game is being recorded or not and ctx is alive

    Returns:
        bool: True if recording, False otherwise
    """
    pass

replay(path) abstractmethod

Checks validity of the file and output an iterator.

Parameters:

Name Type Description Default
path Union[str, BinaryIO]

Path to the recording file.

required

Returns:

Name Type Description
Iterator Iterator[Dict[str, Any]]

Iterator to replay the recording.

Raises:

Type Description
RuntimeError

If replay is already in progress.

FileNotFoundError

If the file does not exist.

TypeError

If the path is not a string or file object.

ValueError

If the file is not a valid recording file or if recording terminated unexpectedly.

ValueError

If the version of the file is not supported.

Source code in gamms/typing/recorder.py
@abstractmethod    
def replay(self, path: Union[str, BinaryIO]) -> Iterator[Dict[str, Any]]:
    """
    Checks validity of the file and output an iterator.

    Args:
        path (Union[str, BinaryIO]): Path to the recording file.

    Returns:
        Iterator: Iterator to replay the recording.

    Raises:
        RuntimeError: If replay is already in progress.
        FileNotFoundError: If the file does not exist.
        TypeError: If the path is not a string or file object.
        ValueError: If the file is not a valid recording file or if recording terminated unexpectedly.
        ValueError: If the version of the file is not supported.
    """
    pass

start(path) abstractmethod

Start recording to the path. Raise error if file already exists Adds ".ggr" extension if not present.

If path is a file object, it will be used as the file handler.

Parameters:

Name Type Description Default
path Union[str, BinaryIO]

Path to record the game.

required

Raises:

Type Description
FileExistsError

If the file already exists.

TypeError

If the path is not a string or file object.

Source code in gamms/typing/recorder.py
@abstractmethod
def start(self, path: Union[str, BinaryIO]) -> None:
    """
    Start recording to the path. Raise error if file already exists
    Adds ".ggr" extension if not present.

    If path is a file object, it will be used as the file handler.

    Args:
        path (Union[str, BinaryIO]): Path to record the game.

    Raises:
        FileExistsError: If the file already exists.
        TypeError: If the path is not a string or file object.
    """
    pass

stop() abstractmethod

Stop recording to the path and close the file handler.

Raises:

Type Description
RuntimeError

If recording has not started.

Source code in gamms/typing/recorder.py
@abstractmethod
def stop(self) -> None:
    """
    Stop recording to the path and close the file handler.

    Raises:
        RuntimeError: If recording has not started.
    """
    pass

time() abstractmethod

Return record time if replaying. Else return the local time (time.time()) in nano seconds.

Returns:

Name Type Description
int int

Time in nanoseconds.

Source code in gamms/typing/recorder.py
@abstractmethod
def time(self) -> int:
    """
    Return record time if replaying. Else return the local time `(time.time())` in nano seconds.

    Returns:
        int: Time in nanoseconds.
    """
    pass

unregister_component(key) abstractmethod

Unregister the component. Key is (module_name, qualname)

Parameters:

Name Type Description Default
key Tuple[str, str]

Key to unregister.

required

Raises:

Type Description
KeyError

If the component is not found.

Source code in gamms/typing/recorder.py
@abstractmethod
def unregister_component(self, key: Tuple[str, str]) -> None:
    """
    Unregister the component.
    Key is (module_name, qualname)

    Args:
        key (Tuple[str, str]): Key to unregister.

    Raises:
        KeyError: If the component is not found.
    """
    pass

write(opCode, data) abstractmethod

Write to record buffer if recording. If not recording raise error as it should not happen.

WARNING: This function should not be required to be called by the user in most cases.

Source code in gamms/typing/recorder.py
@abstractmethod
def write(self, opCode: OpCodes, data: Dict[str, JsonType]) -> None:
    """
    Write to record buffer if recording. If not recording raise error as it should not happen.

    WARNING: This function should not be required to be called by the user in most cases.
    """
    pass