Skip to content

EffectCharacter

Module: terminaltexteffects.engine.base_character

A class representing a single character from the input data. EffectCharacters are managed by the Terminal and are used to apply animations and effects to individual characters.

Add an EffectCharacter to the Terminal using the add_character method of the Terminal class.

Methods:

Name Description
tick

Progress the character's animation and motion by one step.

Attributes:

Name Type Description
character_id int

The unique ID of the character, generated by the Terminal.

input_symbol str

The symbol for the character in the input data.

input_coord Coord

The coordinate of the character in the input data.

is_visible bool

Whether the character is currently visible and should be printed to the terminal.

animation Animation

The animation object that controls the character's appearance.

motion Motion

The motion object that controls the character's movement.

event_handler EventHandler

The event handler object that handles events related to the character.

layer int

The layer of the character. The layer determines the order in which characters are printed.

is_fill_character bool

Whether the character is a fill character. Fill characters are used to fill the empty cells of the Canvas.

Source code in terminaltexteffects/engine/base_character.py
class EffectCharacter:
    """
    A class representing a single character from the input data. EffectCharacters are managed by the Terminal and are used
    to apply animations and effects to individual characters.

    Add an EffectCharacter to the Terminal using the add_character method of the Terminal class.

    Methods:
        tick: Progress the character's animation and motion by one step.

    Attributes:
        character_id (int): The unique ID of the character, generated by the Terminal.
        input_symbol (str): The symbol for the character in the input data.
        input_coord (Coord): The coordinate of the character in the input data.
        is_visible (bool): Whether the character is currently visible and should be printed to the terminal.
        animation (graphics.Animation): The animation object that controls the character's appearance.
        motion (motion.Motion): The motion object that controls the character's movement.
        event_handler (EventHandler): The event handler object that handles events related to the character.
        layer (int): The layer of the character. The layer determines the order in which characters are printed.
        is_fill_character (bool): Whether the character is a fill character. Fill characters are used to fill the empty cells of the Canvas.
    """

    def __init__(self, character_id: int, symbol: str, input_column: int, input_row: int):
        """Initializes the character instance with the character ID, symbol, and input coordinates.

        Args:
            character_id (int): The unique ID of the character, generated by the Terminal.
            symbol (str): The symbol for the character in the input data.
            input_column (int): The column of the character in the input data.
            input_row (int): The row of the character in the input data.
        """
        self._character_id: int = character_id
        self._input_symbol: str = symbol
        self._input_coord: Coord = Coord(input_column, input_row)
        self._is_visible: bool = False
        self.animation: animation.Animation = animation.Animation(self)
        self.motion: motion.Motion = motion.Motion(self)
        self.event_handler: EventHandler = EventHandler(self)
        self.layer: int = 0
        self.is_fill_character = False

    @property
    def input_symbol(self) -> str:
        return self._input_symbol

    @property
    def input_coord(self) -> Coord:
        return self._input_coord

    @property
    def is_visible(self) -> bool:
        return self._is_visible

    @property
    def character_id(self) -> int:
        return self._character_id

    @property
    def is_active(self) -> bool:
        """Returns whether the character is currently active. A character is active if its animation or motion is not complete.

        Returns:
            bool: True if the character is active, False if not.
        """
        if not self.animation.active_scene_is_complete() or not self.motion.movement_is_complete():
            return True
        return False

    def tick(self) -> None:
        """Progress the character's animation and motion by one step."""
        self.motion.move()
        self.animation.step_animation()

    def __hash__(self) -> int:
        return hash(self.character_id)

    def __eq__(self, other: typing.Any) -> bool:
        if not isinstance(other, EffectCharacter):
            return NotImplemented
        return self.character_id == other.character_id

is_active: bool property

Returns whether the character is currently active. A character is active if its animation or motion is not complete.

Returns:

Name Type Description
bool bool

True if the character is active, False if not.

__init__(character_id, symbol, input_column, input_row)

Initializes the character instance with the character ID, symbol, and input coordinates.

Parameters:

Name Type Description Default
character_id int

The unique ID of the character, generated by the Terminal.

required
symbol str

The symbol for the character in the input data.

required
input_column int

The column of the character in the input data.

required
input_row int

The row of the character in the input data.

required
Source code in terminaltexteffects/engine/base_character.py
def __init__(self, character_id: int, symbol: str, input_column: int, input_row: int):
    """Initializes the character instance with the character ID, symbol, and input coordinates.

    Args:
        character_id (int): The unique ID of the character, generated by the Terminal.
        symbol (str): The symbol for the character in the input data.
        input_column (int): The column of the character in the input data.
        input_row (int): The row of the character in the input data.
    """
    self._character_id: int = character_id
    self._input_symbol: str = symbol
    self._input_coord: Coord = Coord(input_column, input_row)
    self._is_visible: bool = False
    self.animation: animation.Animation = animation.Animation(self)
    self.motion: motion.Motion = motion.Motion(self)
    self.event_handler: EventHandler = EventHandler(self)
    self.layer: int = 0
    self.is_fill_character = False

tick()

Progress the character's animation and motion by one step.

Source code in terminaltexteffects/engine/base_character.py
def tick(self) -> None:
    """Progress the character's animation and motion by one step."""
    self.motion.move()
    self.animation.step_animation()