Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymunk import #2458

Draft
wants to merge 7 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions arcade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ def configure_logging(level: int | None = None):
from .tilemap import read_tmx
from .tilemap import TileMap

from .pymunk_physics_engine import PymunkPhysicsEngine
from .pymunk_physics_engine import PymunkPhysicsObject
from .pymunk_physics_engine import PymunkException
try:
from .pymunk_physics_engine import PymunkPhysicsEngine
from .pymunk_physics_engine import PymunkPhysicsObject
from .pymunk_physics_engine import PymunkException
except ImportError:
print("Pymunk is not installed. Pymunk physics engine will not be available.")

from .version import VERSION

Expand Down
5 changes: 2 additions & 3 deletions arcade/camera/camera_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ def point_in_view(self, point: Point2) -> bool:
"""
# This is unwrapped from standard Vec2 operations,
# The construction and garbage collection of the vectors would
# increase this method's cost by ~4x
# increase this method's cost by ~4x

pos = self.position
diff = point[0] - pos[0], point[1] - pos[1]

Expand Down Expand Up @@ -569,7 +569,6 @@ def projection(self) -> Rect:

@projection.setter
def projection(self, value: Rect) -> None:

# Unpack and validate
if not value:
raise ZeroProjectionDimension((f"Projection area is 0, {value.lrbt}"))
Expand Down
2 changes: 1 addition & 1 deletion arcade/future/splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ArcadeSplash(View):
dark_mode: If True, the splash screen will be shown in dark mode. (Default False)
"""

def __init__(self, view: View, duration: int = 3, dark_mode: bool = False):
def __init__(self, view: View, duration: float = 3.0, dark_mode: bool = False):
super().__init__()
self._next_view = view
self._duration = duration
Expand Down
13 changes: 10 additions & 3 deletions arcade/hitbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@

from .base import HitBox, HitBoxAlgorithm, RotatableHitBox
from .bounding_box import BoundingHitBoxAlgorithm
from .pymunk import PymunkHitBoxAlgorithm
from .simple import SimpleHitBoxAlgorithm

#: The simple hit box algorithm.
algo_simple = SimpleHitBoxAlgorithm()
#: The detailed hit box algorithm.
algo_detailed = PymunkHitBoxAlgorithm()
#: The bounding box hit box algorithm.
algo_bounding_box = BoundingHitBoxAlgorithm()
#: The default hit box algorithm.
algo_default = algo_simple

#: The detailed hit box algorithm, if pymunk available.
try:
from .pymunk import PymunkHitBoxAlgorithm

algo_detailed = PymunkHitBoxAlgorithm()
except ImportError:
algo_detailed = None # type: ignore
print("Warning: pymunk is not installed. PymunkHitBoxAlgorithm will not be available.")


# Temporary functions for backwards compatibility
def calculate_hit_box_points_simple(image: Image, *args) -> Point2List:
Expand Down Expand Up @@ -46,6 +52,7 @@ def calculate_hit_box_points_detailed(
How detailed to make the hit box. There's a
trade-off in number of points vs. accuracy.
"""
assert algo_detailed, "PymunkHitBoxAlgorithm is not available."
return algo_detailed.calculate(image, detail=hit_box_detail)


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ version = { attr = "arcade.version.VERSION" }
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.uv]
prerelease = "allow"

[tool.ruff]
# --- Description of what we ignore ---
Expand Down
Loading