Skip to content
Merged
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
57 changes: 26 additions & 31 deletions pooltool/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,39 @@
from pooltool.system import MultiSystem, System

__all__ = [
# subpackages
"events",
"evolution",
"game",
"objects",
"physics",
"ptmath",
"ruleset",
"system",
"utils",
# submodules
"constants",
"interact",
"layouts",
# non-documented
"serialize",
"image",
"ai",
"pot",
"aim",
# objects
"EventType",
"GameType",
"Game",
"Ball",
"BallParams",
"Cue",
"Table",
"TableType",
"Player",
"EventType",
"Game",
"GameType",
"MultiSystem",
"Player",
"System",
# functions
"Table",
"TableType",
"ai",
"aim",
"constants",
"continuize",
"interpolate_ball_states",
"simulate",
"show",
"events",
"evolution",
"game",
"generate_layout",
"get_rack",
"get_ruleset",
"image",
"interact",
"interpolate_ball_states",
"layouts",
"objects",
"physics",
"pot",
"ptmath",
"ruleset",
"serialize",
"show",
"simulate",
"system",
"utils",
]
2 changes: 1 addition & 1 deletion pooltool/ai/aim/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _at_ball(cue_ball: Ball, object_ball: Ball, cut: float = 0.0) -> float:

assert -89.0 <= cut <= 89.0, "Cut must be less than 89 and more than -89"

left = True if cut < 0 else False
left = cut < 0
cut = np.abs(cut) * np.pi / 180
R = object_ball.params.R
d = ptmath.norm3d(object_ball.state.rvw[0] - cue_ball.state.rvw[0])
Expand Down
4 changes: 2 additions & 2 deletions pooltool/ai/pot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ def open_pockets(ball: Ball, table: Table, balls: Iterable[Ball]) -> set[str]:

See also: viable_pockets
"""
return set(
return {
pocket.id
for pocket in table.pockets.values()
if not is_pocket_occluded(ball, table, pocket, balls)
and is_room_for_cue_ball(ball, table, pocket, balls)
and not is_jaw_in_way(ball, table, pocket)
)
}


def required_precision(
Expand Down
2 changes: 0 additions & 2 deletions pooltool/ani/action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from pooltool.utils.strenum import StrEnum, auto


Expand Down
18 changes: 9 additions & 9 deletions pooltool/ani/animate.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

import gc
import sys
from collections.abc import Generator
Expand Down Expand Up @@ -339,7 +337,8 @@ class ShotViewer(Interface):
For usage, see :meth:`show`.
"""

def __init__(self, config=ShowBaseConfig.default()):
def __init__(self, config=None):
config = ShowBaseConfig.default() if config is None else config
Interface.__init__(self, config=config)
self._create_title("")

Expand Down Expand Up @@ -425,10 +424,10 @@ def show(
if settings.graphics.hud:
hud.init(hide=[HUDElement.help_text])

params = dict(
build_animations=True,
playback_mode=PlaybackMode.LOOP,
)
params = {
"build_animations": True,
"playback_mode": PlaybackMode.LOOP,
}
Global.mode_mgr.update_event_baseline()
Global.mode_mgr.change_mode(Mode.shot, enter_kwargs=params)
Global.task_mgr.run()
Expand Down Expand Up @@ -469,7 +468,8 @@ def _stop(self):
class Game(Interface):
"""This class runs the pooltool application"""

def __init__(self, config=ShowBaseConfig.default()):
def __init__(self, config=None):
config = ShowBaseConfig.default() if config is None else config
Interface.__init__(self, config=config)

# This task chain allows simulations to be run in parallel to the game processes
Expand Down Expand Up @@ -541,7 +541,7 @@ def start(self):


__all__ = [
"FrameStepper",
"Game",
"ShotViewer",
"FrameStepper",
]
2 changes: 1 addition & 1 deletion pooltool/ani/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
cam = Camera()

__all__ = [
"cam",
"Camera",
"CameraState",
"cam",
"camera_states",
]
13 changes: 5 additions & 8 deletions pooltool/ani/camera/_camera.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from __future__ import annotations

from pathlib import Path
Expand All @@ -19,6 +17,7 @@
)
from pooltool.ani.globals import Global, require_showbase
from pooltool.ani.mouse import mouse
from pooltool.error import PoolToolError
from pooltool.objects.table.datatypes import Table
from pooltool.ptmath import wiggle
from pooltool.serialize import conversion
Expand Down Expand Up @@ -90,10 +89,8 @@ def rotate_via_mouse(self, fine_control: bool = False, theta_only: bool = False)
theta = self.theta + dtheta
phi = self.phi + dphi

if theta > 90:
theta = 90
if theta < 0:
theta = 0
theta = min(theta, 90)
theta = max(theta, 0)

if theta_only:
self.rotate(theta=theta)
Expand Down Expand Up @@ -159,7 +156,7 @@ def fixate(self, pos, node):
def store_state(self, name, overwrite=False):
"""Store the current camera state in self.states"""
if name in self.states and not overwrite:
raise Exception(f"Camera :: '{name}' is already a camera state")
raise PoolToolError(f"Camera :: '{name}' is already a camera state")

self.states[name] = self.state
self.last_state = name
Expand All @@ -170,7 +167,7 @@ def load_saved_state(self, name, ok_if_not_exists=False):
if ok_if_not_exists:
return
else:
raise Exception(f"Camera :: '{name}' is not a camera state")
raise PoolToolError(f"Camera :: '{name}' is not a camera state")

self.load_state(self.states[name])

Expand Down
8 changes: 1 addition & 7 deletions pooltool/ani/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def collision_task(self, task):

for entry in self.collision_handler.entries:
min_theta = self.process_collision(entry)
if min_theta > max_min_theta:
max_min_theta = min_theta
max_min_theta = max(max_min_theta, min_theta)

self.min_theta = max_min_theta
return task.cont
Expand Down Expand Up @@ -108,11 +107,6 @@ def process_cushion_collision(self, entry):
self.avoid_nodes["scene"]
)

# Center ofthe cueing ball
Bx, By, Bz = self.avoid_nodes["cue_stick_focus"].getPos(
self.avoid_nodes["scene"]
)

# The desired point where cue contacts collision plane, excluding cue width
Dx, Dy, Dz = Px, Py, cushion_height

Expand Down
2 changes: 0 additions & 2 deletions pooltool/ani/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from __future__ import annotations

from pathlib import Path
Expand Down
2 changes: 0 additions & 2 deletions pooltool/ani/environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from panda3d.core import (
AmbientLight,
DirectionalLight,
Expand Down
11 changes: 4 additions & 7 deletions pooltool/ani/hud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from abc import ABC, abstractmethod
from collections import deque

Expand Down Expand Up @@ -42,8 +40,9 @@ def __init__(self):
self.elements = None
self.initialized = False

def init(self, hide: list[HUDElement] = list()):
def init(self, hide: list[HUDElement] | None = None):
"""Initialize HUD elements and start the HUD update task"""
hide = [] if hide is None else hide

self.elements = {
HUDElement.help_text: Help(),
Expand Down Expand Up @@ -475,10 +474,8 @@ def set(self, V0):
self.text.setText(f"{V0:.2f} m/s")

value = (V0 - min_stroke_speed) / (max_stroke_speed - min_stroke_speed)
if value < 0:
value = 0
if value > 1:
value = 1
value = max(value, 0)
value = min(value, 1)
self.fg.setScale(value, 1, 1)
self.bg.setScale(1.0 - value, 1, 1)

Expand Down
14 changes: 7 additions & 7 deletions pooltool/ani/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
from pooltool.ani.image.utils import ImageExt, gif, rgb2gray

__all__ = [
"save_images",
"image_stack",
"GzipArrayImages",
"HDF5Images",
"ImageExt",
"ImageStorageMethod",
"ImageZip",
"HDF5Images",
"GzipArrayImages",
"NpyImages",
"get_graphics_texture",
"gif",
"rgb2gray",
"image_array_from_texture",
"get_graphics_texture",
"ImageStorageMethod",
"image_stack",
"rgb2gray",
"save_images",
]
2 changes: 1 addition & 1 deletion pooltool/ani/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
MenuRegistry.register(SettingsMenu)

__all__ = [
"MenuRegistry",
"MenuNavigator",
"MenuRegistry",
]
2 changes: 1 addition & 1 deletion pooltool/ani/menu/_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def create(
def _command(text: str) -> None:
try:
cleaned_value = command(text)
except Exception as e:
except Exception as e: # noqa: BLE001
input_field.reset_value()
input_field._show_error_message(str(e))
return
Expand Down
5 changes: 3 additions & 2 deletions pooltool/ani/menu/_registry.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import sys
from collections.abc import Callable
from typing import ClassVar

from pooltool.ani.globals import Global
from pooltool.ani.menu._datatypes import BaseMenu


class MenuRegistry:
_menus: dict[str, type[BaseMenu]] = {}
_current_menu: BaseMenu | None = None
_menus: ClassVar[dict[str, type[BaseMenu]]] = {}
_current_menu: ClassVar[BaseMenu | None] = None

@classmethod
def register(cls, menu_class: type[BaseMenu]) -> None:
Expand Down
6 changes: 2 additions & 4 deletions pooltool/ani/modes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from pooltool.ani.modes.aim import AimMode
from pooltool.ani.modes.ball_in_hand import BallInHandMode
from pooltool.ani.modes.calculate import CalculateMode
Expand All @@ -19,8 +17,6 @@


__all__ = [
"Mode",
"ModeManager",
"AimMode",
"BallInHandMode",
"CalculateMode",
Expand All @@ -29,6 +25,8 @@
"CamSaveMode",
"GameOverMode",
"MenuMode",
"Mode",
"ModeManager",
"PickBallMode",
"PurgatoryMode",
"ShotMode",
Expand Down
12 changes: 5 additions & 7 deletions pooltool/ani/modes/aim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
from typing import ClassVar

import numpy as np

Expand Down Expand Up @@ -29,7 +29,7 @@

class AimMode(BaseMode):
name = Mode.aim
keymap = {
default_keymap: ClassVar[dict[Action, bool]] = {
Action.rotate_cue_left: False,
Action.rotate_cue_right: False,
Action.fine_control: False,
Expand Down Expand Up @@ -128,7 +128,7 @@ def exit(self):

def aim_task(self, task):
if self.keymap[Action.view]:
Global.mode_mgr.change_mode(Mode.view, enter_kwargs=dict(move_active=True))
Global.mode_mgr.change_mode(Mode.view, enter_kwargs={"move_active": True})
return task.done
elif self.keymap[Action.stroke]:
Global.mode_mgr.change_mode(Mode.stroke)
Expand Down Expand Up @@ -203,10 +203,8 @@ def aim_apply_power(self):
dy = mouse.get_dy()

V0 = multisystem.active.cue.V0 + dy * power_sensitivity
if V0 < min_stroke_speed:
V0 = min_stroke_speed
if V0 > max_stroke_speed:
V0 = max_stroke_speed
V0 = max(V0, min_stroke_speed)
V0 = min(V0, max_stroke_speed)

multisystem.active.cue.set_state(V0=V0)
self._update_hud()
Expand Down
Loading
Loading