Skip to content

Recorder

Bases: ABC

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.

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.

component_iter() abstractmethod

Iterator for the component names.

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.

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.

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.

pause() abstractmethod

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

play() abstractmethod

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

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

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.

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.

stop() abstractmethod

Stop recording to the path and close the file handler.

Raises:

Type Description
RuntimeError

If recording has not started.

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.

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.

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.