Skip to content

Commit

Permalink
make pymunk imports optional, which allows to exclude it during packa…
Browse files Browse the repository at this point in the history
…ging with cx_freeze
  • Loading branch information
eruvanos committed Nov 18, 2024
1 parent 3501f26 commit dc2ad56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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
12 changes: 9 additions & 3 deletions arcade/hitbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@

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
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 +51,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

0 comments on commit dc2ad56

Please sign in to comment.