From f7f3ed7659bd993716db1185038dea8f4d769c77 Mon Sep 17 00:00:00 2001 From: DragonMoffon Date: Mon, 7 Aug 2023 00:55:03 +1200 Subject: [PATCH 1/4] Fixed PyRight issues. The latest version of PyRight is a little over zealous.. There where two flagged non-issues. One where it didn't realise that the code would escape early, and another which is all pyglets fault. --- arcade/gui/widgets/text.py | 9 +++++---- arcade/physics_engines.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index 05b30af31..297b9026b 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -23,7 +23,6 @@ from arcade.types import RGBA255, Color, RGBOrA255, RGB - class UILabel(UIWidget): """A simple text label. This widget is meant to display user instructions or information. This label supports multiline text. @@ -488,8 +487,10 @@ def __init__( # Set how fast the mouse scroll wheel will scroll text in the pane. # Measured in pixels per 'click' - self.scroll_speed = scroll_speed if scroll_speed is not None \ - else font_size + self.scroll_speed = ( + scroll_speed if scroll_speed is not None + else font_size + ) self.doc: AbstractDocument = pyglet.text.decode_text(text) self.doc.set_style( @@ -551,7 +552,7 @@ def do_render(self, surface: Surface): def on_event(self, event: UIEvent) -> Optional[bool]: if isinstance(event, UIMouseScrollEvent): if self.rect.collide_with_point(event.x, event.y): - self.layout.view_y += event.scroll_y * self.scroll_speed + self.layout.view_y += event.scroll_y * self.scroll_speed # type: ignore self.trigger_full_render() if super().on_event(event): diff --git a/arcade/physics_engines.py b/arcade/physics_engines.py index 413afce3f..73b916d72 100644 --- a/arcade/physics_engines.py +++ b/arcade/physics_engines.py @@ -7,6 +7,7 @@ from typing import Iterable, List, Optional, Union from arcade import ( + BasicSprite, Sprite, SpriteList, check_for_collision, @@ -53,7 +54,7 @@ def _circular_check(player: Sprite, walls: List[SpriteList]): vary *= 2 -def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) -> List[Sprite]: +def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) -> List[Sprite | BasicSprite]: # See if we are starting this turn with a sprite already colliding with us. if len(check_for_collision_with_lists(moving_sprite, walls)) > 0: @@ -109,7 +110,7 @@ def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) # NOTE: Not all sprites have velocity if getattr(item, "change_x", 0.0) != 0: - moving_sprite.center_x += item.change_x + moving_sprite.center_x += item.change_x # type: ignore # print(f"Spot Y ({self.player_sprite.center_x}, {self.player_sprite.center_y})") else: From 4194441b7c2ebdf58996ae45cdec79cf6362e611 Mon Sep 17 00:00:00 2001 From: DragonMoffon Date: Mon, 7 Aug 2023 00:58:39 +1200 Subject: [PATCH 2/4] oof python versions --- arcade/physics_engines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/physics_engines.py b/arcade/physics_engines.py index 73b916d72..69ecf2dc7 100644 --- a/arcade/physics_engines.py +++ b/arcade/physics_engines.py @@ -54,7 +54,7 @@ def _circular_check(player: Sprite, walls: List[SpriteList]): vary *= 2 -def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) -> List[Sprite | BasicSprite]: +def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) -> List[Union[Sprite, BasicSprite]]: # See if we are starting this turn with a sprite already colliding with us. if len(check_for_collision_with_lists(moving_sprite, walls)) > 0: From e83e77bd37a57605291a2ae8ddaad7f0063c77d7 Mon Sep 17 00:00:00 2001 From: DragonMoffon <86714785+DragonMoffon@users.noreply.github.com> Date: Mon, 7 Aug 2023 13:28:54 +1200 Subject: [PATCH 3/4] add pending comment --- arcade/gui/widgets/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index 297b9026b..90077bd29 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -552,7 +552,7 @@ def do_render(self, surface: Surface): def on_event(self, event: UIEvent) -> Optional[bool]: if isinstance(event, UIMouseScrollEvent): if self.rect.collide_with_point(event.x, event.y): - self.layout.view_y += event.scroll_y * self.scroll_speed # type: ignore + self.layout.view_y += event.scroll_y * self.scroll_speed # type: ignore # pending https://github.com/pyglet/pyglet/issues/916 self.trigger_full_render() if super().on_event(event): From b6aa75ac8bfcb22b5fc1bcb7d537c55d77b6bc51 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 14 Aug 2023 13:58:56 -0400 Subject: [PATCH 4/4] Make `_move_sprite()` generic --- arcade/physics_engines.py | 9 +++++---- arcade/sprite_list/collision.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arcade/physics_engines.py b/arcade/physics_engines.py index 69ecf2dc7..fa300fa00 100644 --- a/arcade/physics_engines.py +++ b/arcade/physics_engines.py @@ -4,12 +4,13 @@ # pylint: disable=too-many-arguments, too-many-locals, too-few-public-methods import math -from typing import Iterable, List, Optional, Union +from typing import Iterable, List, Optional, Union, cast from arcade import ( BasicSprite, Sprite, SpriteList, + SpriteType, check_for_collision, check_for_collision_with_lists ) @@ -54,7 +55,7 @@ def _circular_check(player: Sprite, walls: List[SpriteList]): vary *= 2 -def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList], ramp_up: bool) -> List[Union[Sprite, BasicSprite]]: +def _move_sprite(moving_sprite: Sprite, walls: List[SpriteList[SpriteType]], ramp_up: bool) -> List[SpriteType]: # See if we are starting this turn with a sprite already colliding with us. if len(check_for_collision_with_lists(moving_sprite, walls)) > 0: @@ -231,12 +232,12 @@ class PhysicsEngineSimple: This can be one or multiple spritelists. """ - def __init__(self, player_sprite: Sprite, walls: Union[SpriteList, Iterable[SpriteList]]): + def __init__(self, player_sprite: Sprite, walls: Union[SpriteList[BasicSprite], Iterable[SpriteList[BasicSprite]]]): assert isinstance(player_sprite, Sprite) if walls: if isinstance(walls, SpriteList): - self.walls = [walls] + self.walls = [cast(SpriteList[BasicSprite], walls)] else: self.walls = list(walls) else: diff --git a/arcade/sprite_list/collision.py b/arcade/sprite_list/collision.py index f6c4f6abb..322e0ca54 100644 --- a/arcade/sprite_list/collision.py +++ b/arcade/sprite_list/collision.py @@ -59,7 +59,7 @@ def get_closest_sprite( return sprite_list[min_pos], min_distance -def check_for_collision(sprite1: SpriteType, sprite2: SpriteType) -> bool: +def check_for_collision(sprite1: BasicSprite, sprite2: BasicSprite) -> bool: """ Check for a collision between two sprites.