2222__title__ = "Checkers"
2323__author__ = "CoolCat467"
2424__license__ = "GNU General Public License Version 3"
25- __version__ = "2.0.1 "
25+ __version__ = "2.0.2 "
2626
2727# Note: Tile Ids are chess board tile titles, A1 to H8
2828# A8 ... H8
3434import contextlib
3535import platform
3636from collections import deque
37- from os import path
3837from pathlib import Path
39- from typing import TYPE_CHECKING , Any , Final , TypeAlias , TypeVar
38+ from typing import TYPE_CHECKING , Any , Final , TypeVar
4039
4140import pygame
4241import trio
5352 Event ,
5453 ExternalRaiseManager ,
5554)
56- from checkers .network_shared import DEFAULT_PORT , find_ip
55+ from checkers .network_shared import DEFAULT_PORT , Pos , find_ip
5756from checkers .objects import Button , OutlinedText
5857from checkers .server import GameServer
5958from checkers .sound import SoundData , play_sound as base_play_sound
105104
106105T = TypeVar ("T" )
107106
108- DATA_FOLDER : Final = Path (__file__ ).parent / "data"
107+ if globals ().get ("__file__" ) is None :
108+ import importlib
109109
110- IS_WINDOWS : Final = platform .system () == "Windows"
110+ __file__ = str (
111+ Path (importlib .import_module ("checkers.data" ).__path__ [0 ]).parent
112+ / "game.py" ,
113+ )
114+
115+ DATA_FOLDER : Final = Path (__file__ ).absolute ().parent / "data"
111116
112- Pos : TypeAlias = tuple [ int , int ]
117+ IS_WINDOWS : Final = platform . system () == "Windows"
113118
114119
115120def render_text (
@@ -704,7 +709,7 @@ def generate_tile_images(self) -> None:
704709 outline_ident = outline .precalculate_outline (name , outline_color )
705710 image .add_image (f"{ name } _outlined" , outline_ident )
706711
707- def get_tile_location (self , position : Pos ) -> Vector2 :
712+ def get_tile_location (self , position : tuple [ int , int ] ) -> Vector2 :
708713 """Return the center point of a given tile position."""
709714 location = Vector2 .from_iter (position ) * self .tile_size
710715 center = self .tile_size // 2
@@ -773,7 +778,7 @@ def generate_board_image(self) -> Surface:
773778 ### Blit the id of the tile at the tile's location
774779 ##surf.blit(
775780 ## render_text(
776- ## trio.Path(path.dirname(__file__), "data", "VeraSerif.ttf") ,
781+ ## DATA_FOLDER / "VeraSerif.ttf",
777782 ## 20,
778783 ## "".join(map(str, (x, y))),
779784 ## GREEN
@@ -826,7 +831,7 @@ async def update_selected(self) -> None:
826831
827832 if not self .selected :
828833 movement : sprite .MovementComponent = self .get_component ("movement" )
829- movement .speed = 0
834+ movement .speed = 0.0
830835
831836 async def click (self , event : Event [dict [str , int ]]) -> None :
832837 """Toggle selected."""
@@ -841,15 +846,18 @@ async def drag(self, event: Event[Any]) -> None:
841846 self .selected = True
842847 await self .update_selected ()
843848 movement : sprite .MovementComponent = self .get_component ("movement" )
844- movement .speed = 0
849+ movement .speed = 0.0
845850
846- async def mouse_down (self , event : Event [dict [str , int | Pos ]]) -> None :
851+ async def mouse_down (
852+ self ,
853+ event : Event [dict [str , int | tuple [int , int ]]],
854+ ) -> None :
847855 """Target click pos if selected."""
848856 if not self .selected :
849857 return
850858 if event .data ["button" ] == 1 :
851859 movement : sprite .MovementComponent = self .get_component ("movement" )
852- movement .speed = 200
860+ movement .speed = 200.0
853861 target : sprite .TargetingComponent = self .get_component ("targeting" )
854862 assert isinstance (event .data ["pos" ], tuple )
855863 target .destination = Vector2 .from_iter (event .data ["pos" ])
@@ -944,7 +952,7 @@ class FPSCounter(objects.Text):
944952 def __init__ (self ) -> None :
945953 """Initialize FPS counter."""
946954 font = pygame .font .Font (
947- trio . Path ( path . dirname ( __file__ ), "data" , "VeraSerif.ttf" ) ,
955+ DATA_FOLDER / "VeraSerif.ttf" ,
948956 28 ,
949957 )
950958 super ().__init__ ("fps" , font )
@@ -1112,11 +1120,11 @@ async def entry_actions(self) -> None:
11121120 self .id = self .machine .new_group ("title" )
11131121
11141122 button_font = pygame .font .Font (
1115- trio . Path ( path . dirname ( __file__ ), "data" , "VeraSerif.ttf" ) ,
1123+ DATA_FOLDER / "VeraSerif.ttf" ,
11161124 28 ,
11171125 )
11181126 title_font = pygame .font .Font (
1119- trio . Path ( path . dirname ( __file__ ), "data" , "VeraSerif.ttf" ) ,
1127+ DATA_FOLDER / "VeraSerif.ttf" ,
11201128 56 ,
11211129 )
11221130
@@ -1266,7 +1274,7 @@ def __init__(self) -> None:
12661274 self .buttons : dict [tuple [str , int ], int ] = {}
12671275
12681276 self .font = pygame .font .Font (
1269- trio . Path ( path . dirname ( __file__ ), "data" , "VeraSerif.ttf" ) ,
1277+ DATA_FOLDER / "VeraSerif.ttf" ,
12701278 28 ,
12711279 )
12721280
@@ -1412,7 +1420,7 @@ async def do_actions(self) -> None:
14121420 self .exit_data = (exit_status , message , True )
14131421
14141422 font = pygame .font .Font (
1415- trio . Path ( path . dirname ( __file__ ), "data" , "VeraSerif.ttf" ) ,
1423+ DATA_FOLDER / "VeraSerif.ttf" ,
14161424 28 ,
14171425 )
14181426
@@ -1503,7 +1511,7 @@ async def async_run() -> None:
15031511 client = CheckersClient (event_manager )
15041512
15051513 background = pygame .image .load (
1506- path . join ( path . dirname ( __file__ ), "data" , "background.png" ) ,
1514+ DATA_FOLDER / "background.png" ,
15071515 ).convert ()
15081516 client .clear (screen , background )
15091517
0 commit comments