python-type-stubs/pygame/sprite.pyi

125 строки
4.8 KiB
Python

from typing import Callable, Dict, Iterator, List, Mapping, Optional, Sequence, SupportsFloat, Tuple, Union
from . import rect as r, surface
_RectStyle = Union[
Tuple[float, float, float, float], Tuple[Tuple[float, float], Tuple[float, float]], List[float], r.Rect,
]
# Some functions violate Liskov substitution principle so mypy will throw errors for this file, but this are the
# best type hints I could do
class Sprite:
image: Optional[surface.Surface]
rect: Optional[r.Rect]
def __init__(self, *groups: AbstractGroup) -> None: ...
def update(self, *args, **kwargs) -> None: ...
def add(self, *groups: AbstractGroup) -> None: ...
def remove(self, *groups: AbstractGroup) -> None: ...
def kill(self) -> None: ...
def alive(self) -> bool: ...
def groups(self) -> List[AbstractGroup]: ...
class DirtySprite(Sprite):
dirty: int
blendmode: int
source_rect: r.Rect
visible: int
class AbstractGroup:
spritedict: Mapping[Sprite, int]
lostsprites: Sequence[int] # I think
def __init__(self) -> None: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Sprite]: ...
def copy(self) -> AbstractGroup: ...
def sprites(self) -> List[Sprite]: ...
def add(self, *sprites: Sprite) -> None: ...
def remove(self, *sprites: Sprite) -> None: ...
def has(self, *sprites: Sprite) -> bool: ...
def update(self, *args, **kwargs) -> None: ...
def draw(self, surface: surface.Surface) -> List[r.Rect]: ...
def clear(self, surface_dest: surface.Surface, background: surface.Surface) -> None: ...
def empty(self) -> None: ...
class Group(AbstractGroup):
def __init__(self, *sprites: Sprite) -> None: ...
def copy(self) -> Group: ...
class RenderPlain(Group):
def copy(self) -> RenderPlain: ...
class RenderClear(Group):
def copy(self) -> RenderClear: ...
class RenderUpdates(Group):
def copy(self) -> RenderUpdates: ...
def draw(self, surface: surface.Surface) -> List[r.Rect]: ...
class OrderedUpdates(RenderUpdates):
def copy(self) -> OrderedUpdates: ...
class LayeredUpdates(AbstractGroup):
def __init__(self, *sprites: Sprite, **kwargs) -> None: ...
def copy(self) -> LayeredUpdates: ...
def add(self, *sprites: Sprite, **kwargs: int) -> None: ...
def draw(self, surface: surface.Surface) -> List[r.Rect]: ...
def get_sprites_at(self, pos: Union[Tuple[int, int], Sequence[int]]) -> List[Sprite]: ...
def get_sprite(self, idx: int) -> Sprite: ...
def remove_sprites_of_layer(self, layer_nr: int) -> List[Sprite]: ...
def layers(self) -> List[int]: ...
def change_layer(self, sprite: Sprite, new_layer: int) -> None: ...
def get_layer_of_sprite(self, sprite: Sprite) -> int: ...
def get_top_layer(self) -> int: ...
def get_bottom_layer(self) -> int: ...
def move_to_front(self, sprite: Sprite) -> None: ...
def move_to_back(self, sprite: Sprite) -> None: ...
def get_top_sprite(self) -> Sprite: ...
def get_sprites_from_layer(self, layer: int) -> List[Sprite]: ...
def switch_layer(self, layer1_nr: int, layer2_nr: int) -> None: ...
class LayeredDirty(LayeredUpdates):
def __init__(self, *sprites: DirtySprite, **kwargs: int) -> None: ...
def copy(self) -> LayeredDirty: ...
def draw(self, surface: surface.Surface, bgd: Optional[surface.Surface] = ...) -> None: ...
def clear(self, surface: surface.Surface, bgd: surface.Surface) -> None: ...
def repaint_rect(self, screen_rect: _RectStyle) -> None: ...
def set_clip(self, screen_rect: Optional[_RectStyle]) -> None: ...
def get_clip(self) -> r.Rect: ...
def set_timing_treshold(self, time_ms: SupportsFloat) -> None: ...
class GroupSingle(AbstractGroup):
sprite: Sprite
def __init__(self, sprite: Optional[Sprite] = ...) -> None: ...
def copy(self) -> GroupSingle: ...
def spritecollide(
sprite: Sprite, group: AbstractGroup, dokill: bool, collided: Optional[Callable[[Sprite, Sprite], bool]] = ...,
) -> List[Sprite]: ...
def collide_rect(left: Sprite, right: Sprite) -> bool: ...
class collide_rect_ratio:
ratio: float
def __init__(self, ratio: float) -> None: ...
def __call__(self, left: Sprite, right: Sprite) -> bool: ...
def collide_circle(left: Sprite, right: Sprite) -> bool: ...
class collide_circle_ratio:
ratio: float
def __init__(self, ratio: float) -> None: ...
def __call__(self, left: Sprite, right: Sprite) -> bool: ...
def collide_mask(sprite1: Sprite, sprite2: Sprite) -> Tuple[int, int]: ...
def groupcollide(
group1: AbstractGroup,
group2: AbstractGroup,
dokill: bool,
dokill2: bool,
collided: Optional[Callable[[Sprite, Sprite], bool]] = ...,
) -> Dict[Sprite, Sprite]: ...
def spritecollideany(
sprite: Sprite, group: AbstractGroup, collided: Optional[Callable[[Sprite, Sprite], bool]] = ...,
) -> Sprite: ...