Utility

build_sprites_from_paths(sprite_paths: List[TraitSpritePathsData], desired_size: Tuple[int, int] = (32, 32))TraitSpritesData[source]

Build a TraitSpritesData class from a list of TraitSpritePathsData. For each member in TraitSpritePathsData, combines the sprites from each TraitSpritePathsData in the list and flattens to a single surface.

clamp(value: _V, min_value: _V, max_value: _V)_V[source]

Return the value, clamped between min and max.

convert_direction_to_name(direction: DirectionType)str[source]

Get the direction name from the direction. e.g. (0,1) = ‘up’ etc.

convert_tile_string_to_xy(tile_pos_string: str)Tuple[int, int][source]

Convert a tile position string to (x, y)

flatten_images(images: List[pygame.Surface])pygame.Surface[source]

Flatten a list of images into a single image. All images must be the same size. Images are blitted in order.

get_class_members(cls: Type[Any])List[str][source]

Get a class’ members, excluding special methods e.g. anything prefixed with ‘__’. Useful for use with dataclasses.

get_coords_from_shape(shape: ShapeType, size: int, direction: Optional[Tuple[int, int]])List[Tuple[int, int]][source]

Get a list of coordinates from a shape, size and direction.

get_image(img_path: str, desired_dimensions: Tuple[int, int] = (32, 32), copy: bool = False)pygame.Surface[source]

Get the specified image and resize if dimensions provided. Dimensions are in (width, height) format. If img path is “none” then a blank surface is created to the size of the desired dimensions, or TILE_SIZE if no dimensions provided.

get_images(img_paths: List[str], desired_dimensions: Tuple[int, int] = (32, 32), copy: bool = False)List[pygame.Surface][source]

Get a collection of images.

is_close(current_pos: Tuple[float, float], target_pos: Tuple[float, float], delta: float = 0.05)bool[source]

True if the absolute distance between both coordinates is less than delta.

lerp(initial_value: float, target_value: float, lerp_fraction: float)float[source]

Linear interpolation between initial and target by amount. Fraction clamped between 0 and 1. >=0.99 is treated as 1 to handle float imprecision.

roll(min_value: int = 0, max_value: int = 99)int[source]

Roll for a number between min and max

value_to_member(value: Any, cls: Type[Any])str[source]

Get a member of a class that matches the value given