PygameToolsKit 1.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ import pygame
2
+
3
+ def OnJoystick(axis: int, intensity: float = 0.5):
4
+
5
+ def decorator(func):
6
+
7
+ def execute(*args, **kwargs):
8
+ return func(*args, **kwargs)
9
+
10
+ if pygame.joystick.get_count() == 0:
11
+ return None
12
+
13
+ for i in range(pygame.joystick.get_count()):
14
+ joystick = pygame.joystick.Joystick(i)
15
+
16
+ if abs(joystick.get_axis(axis)) > intensity:
17
+ return execute
18
+ return decorator
@@ -0,0 +1,16 @@
1
+ import pygame
2
+
3
+ def OnKey(key: int | list[int]):
4
+
5
+ def decorator(func):
6
+
7
+ def execute(*args, **kwargs):
8
+ return func(*args, **kwargs)
9
+
10
+ keys = pygame.key.get_pressed()
11
+ if isinstance(key, list):
12
+ if any(keys[k] for k in key):
13
+ return execute
14
+ elif keys[key]:
15
+ return execute
16
+ return decorator
@@ -0,0 +1,21 @@
1
+ import pygame
2
+
3
+ def Timer(seconds: int=1):
4
+
5
+ now = pygame.time.get_ticks()
6
+
7
+ def decorator(function):
8
+
9
+ now = pygame.time.get_ticks()
10
+
11
+ def execute(*args, **kwargs):
12
+ nonlocal now
13
+
14
+ current = pygame.time.get_ticks()
15
+
16
+ if current - now >= seconds * 1000:
17
+ now = current
18
+ return function(*args, **kwargs)
19
+ return execute
20
+ return decorator
21
+
@@ -0,0 +1,19 @@
1
+ from functools import wraps
2
+ import pygame
3
+
4
+ from .eventManager import EventManager
5
+
6
+ def EventListener(event: int | list[int], condition: bool=True):
7
+
8
+ def decorator(func):
9
+
10
+ @wraps(func)
11
+ def wrapper(self, *args, **kwargs):
12
+ if condition:
13
+ return func(self, *args, **kwargs)
14
+
15
+ wrapper.__event_type__ = event
16
+
17
+ return wrapper
18
+
19
+ return decorator
@@ -0,0 +1,42 @@
1
+ import pygame
2
+
3
+ from DecoratorsToolKit.classes.singleton import Singleton #type: ignore
4
+
5
+ @Singleton()
6
+ class EventManager:
7
+
8
+ listeners = {}
9
+
10
+ def __init__(self):
11
+ pass
12
+
13
+ def register(self, instance):
14
+
15
+ for name in dir(instance):
16
+ method = getattr(instance, name)
17
+
18
+ if not hasattr(method, "__event_type__"):
19
+ continue
20
+
21
+ event_types = method.__event_type__
22
+ if not isinstance(event_types, (list, tuple, set)):
23
+ event_types = [event_types]
24
+
25
+ for event in event_types:
26
+ self.listeners.setdefault(event, []).append(method)
27
+
28
+ def clear(self):
29
+
30
+ self.listeners.clear()
31
+
32
+
33
+ @classmethod
34
+ def listen(cls, onQuit: callable):
35
+
36
+ for event in pygame.event.get():
37
+
38
+ if event.type == pygame.QUIT:
39
+ onQuit()
40
+
41
+ for listener in cls.listeners.get(event.type, []):
42
+ listener(event)
@@ -0,0 +1,9 @@
1
+ import pygame
2
+
3
+ from .eventManager import EventManager
4
+
5
+ class EventObject:
6
+
7
+ def __init__(self):
8
+
9
+ EventManager().register(self)
@@ -0,0 +1,27 @@
1
+ from .eventObject import EventObject
2
+ from functools import wraps
3
+
4
+ def IsEventObject():
5
+
6
+ def decorator(cls):
7
+
8
+ original_init = cls.__init__
9
+
10
+ @wraps(original_init)
11
+ def __init__(self, *args, **kwargs):
12
+
13
+ original_init(self, *args, **kwargs)
14
+
15
+ EventObject.__init__(self)
16
+
17
+
18
+ newType = type(
19
+ cls.__name__,
20
+ (cls, EventObject),
21
+ {
22
+ "__init__" : __init__
23
+ }
24
+ )
25
+
26
+ return newType
27
+ return decorator
@@ -0,0 +1,25 @@
1
+ from enum import Enum
2
+
3
+ class Color(Enum):
4
+
5
+ RED = (255, 0, 0)
6
+ GREEN = (0, 255, 0)
7
+ BLUE = (0, 0, 255)
8
+
9
+ PURPLE = (255, 0, 255)
10
+ YELLOW = (255, 255, 0)
11
+
12
+ BLACK = (0, 0, 0)
13
+ WHITE = (255, 255, 255)
14
+
15
+ @property
16
+ def r(self):
17
+ return self.value[0]
18
+
19
+ @property
20
+ def g(self):
21
+ return self.value[1]
22
+
23
+ @property
24
+ def b(self):
25
+ return self.value[2]
@@ -0,0 +1,9 @@
1
+ import pygame
2
+ from enum import Enum
3
+
4
+ class Direction(Enum):
5
+
6
+ UP = pygame.Vector2(0, -1)
7
+ DOWN = pygame.Vector2(0, 1)
8
+ LEFT = pygame.Vector2(-1, 0)
9
+ RIGHT = pygame.Vector2(1, 0)
@@ -0,0 +1,26 @@
1
+ import pygame
2
+
3
+ from .dir import Direction
4
+
5
+ from ..Decorators.onJoystick import OnJoystick
6
+
7
+ class JoystickManager:
8
+
9
+ def __init__(self):
10
+ pass
11
+
12
+ @OnJoystick(axis=1, intensity=-0.5)
13
+ def get_up(self):
14
+ return Direction.UP
15
+
16
+ @OnJoystick(axis=1, intensity=0.5)
17
+ def get_down(self):
18
+ return Direction.DOWN
19
+
20
+ @OnJoystick(axis=0, intensity=-0.5)
21
+ def get_left(self):
22
+ return Direction.LEFT
23
+
24
+ @OnJoystick(axis=0, intensity=0.5)
25
+ def get_right(self):
26
+ return Direction.RIGHT
@@ -0,0 +1,27 @@
1
+ import pygame
2
+
3
+ from .dir import Direction
4
+
5
+ from ..Decorators.onKey import OnKey
6
+
7
+ class KeyManager:
8
+
9
+ def __init__(self):
10
+
11
+ pass
12
+
13
+ @OnKey([pygame.K_w, pygame.K_UP])
14
+ def get_up(self):
15
+ return Direction.UP
16
+
17
+ @OnKey([pygame.K_s, pygame.K_DOWN])
18
+ def get_down(self):
19
+ return Direction.DOWN
20
+
21
+ @OnKey([pygame.K_a, pygame.K_LEFT])
22
+ def get_left(self):
23
+ return Direction.LEFT
24
+
25
+ @OnKey([pygame.K_d, pygame.K_RIGHT])
26
+ def get_right(self):
27
+ return Direction.RIGHT
@@ -0,0 +1,14 @@
1
+ from .updateManager import UpdateManager
2
+
3
+ def Update():
4
+
5
+ def decorator(func):
6
+
7
+ def execute(*args, **kwargs):
8
+ return func(*args, **kwargs)
9
+
10
+
11
+ UpdateManager().register(func)
12
+
13
+ return execute
14
+ return decorator
@@ -0,0 +1,22 @@
1
+ from DecoratorsToolKit.classes.singleton import Singleton #type: ignore
2
+
3
+ @Singleton()
4
+ class UpdateManager:
5
+
6
+ functions = []
7
+
8
+ def __init__(self):
9
+ pass
10
+
11
+
12
+ def register(self, function):
13
+ self.functions.append(function)
14
+
15
+ def clear(self):
16
+ self.functions.clear()
17
+
18
+ @classmethod
19
+ def update(cls):
20
+
21
+ for function in cls.functions:
22
+ function()
@@ -0,0 +1,10 @@
1
+ from .Event.eventListener import EventListener
2
+ from .Event.eventManager import EventManager
3
+ from .Decorators.timer import Timer
4
+
5
+
6
+ __all__ = [
7
+ EventManager,
8
+ EventListener,
9
+ Timer
10
+ ]
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: PygameToolsKit
3
+ Version: 1.1.3
4
+ Summary: Bibliothèque qui dispose de divers classes, fonctions et décorateurs pour aider au développement avec pygame
5
+ Requires-Dist: DecoratorsToolKit>=1.0.0
6
+ Requires-Dist: pygame-ce>=2.5.0
@@ -0,0 +1,18 @@
1
+ PygameToolsKit/__init__.py,sha256=Dp3KuXk3GqhiVEmJ2oYAwO54_duSsPDn7gOGcSMsXe4,199
2
+ PygameToolsKit/Decorators/onJoystick.py,sha256=OSc6zQ18wGyP-S1OhCl9MVsn_ulNn-nY9JW5KiZBdL4,481
3
+ PygameToolsKit/Decorators/onKey.py,sha256=VGKMncOOouIs04eASofQ524mkqkgVmSSGF79LEz6K-A,396
4
+ PygameToolsKit/Decorators/timer.py,sha256=ETzIox027Ix0t2asjDDOu69RNba0-9X75U_CoCxUXrI,453
5
+ PygameToolsKit/Event/eventListener.py,sha256=7FvCoMKg-NaBlTtrmnYD_TQpz4Z1qOfSC8RjbN_X9ZU,420
6
+ PygameToolsKit/Event/eventManager.py,sha256=zoMmMdNWYkmMEA2oY8_BoN4UuEd-mIFVpve9Y1qo6o0,1041
7
+ PygameToolsKit/Event/eventObject.py,sha256=3PosSVZIUvgGb8RsJSUZ8Se2bputAb9vzyQy-YzvPTs,147
8
+ PygameToolsKit/Event/isEventObject.py,sha256=bIPWAhwNwiQUWb6kYYHGhjmR1s8sDa1-CDH4xy7TW_s,558
9
+ PygameToolsKit/Graphics/color.py,sha256=TcKiyq7CnGHdEnAE3u17Fnrc6Mj5L1hh8p9Vt247Whg,424
10
+ PygameToolsKit/Inputs/dir.py,sha256=w8KDqO82T8DMnT45ZNHYbOvSFQ7lDVZLzJvs0jqbz8A,197
11
+ PygameToolsKit/Inputs/joystickManager.py,sha256=XTCKBawA1HW2AYMBACdA5tX125bIrtVvVF6Jli4niAY,558
12
+ PygameToolsKit/Inputs/keyManager.py,sha256=5CJlQvLv4zr_1sgPeiLGSR4afHcsoxMjUqjZjTX6mWU,540
13
+ PygameToolsKit/Update/update.py,sha256=xqXIZxqewDXjB0F1QcXrV2V8E_0ReE6LMNG9F3EkCPY,268
14
+ PygameToolsKit/Update/updateManager.py,sha256=Ae-HQmHa_-dL8lITEW6P9KKmH_xGCVG74UBILhiq1lM,416
15
+ pygametoolskit-1.1.3.dist-info/METADATA,sha256=sLES3bIuMdeZVNw5kcmlFgLIUfxKOOqwsDf4AYE3u1E,257
16
+ pygametoolskit-1.1.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
17
+ pygametoolskit-1.1.3.dist-info/top_level.txt,sha256=eJgRVhXT3DMSHVT7aoeiviyxfvIjKODNnYKm4OccqRw,15
18
+ pygametoolskit-1.1.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ PygameToolsKit