PygameToolsKit 1.1.3__tar.gz
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.
- pygametoolskit-1.1.3/PKG-INFO +6 -0
- pygametoolskit-1.1.3/PygameToolsKit/Decorators/onJoystick.py +18 -0
- pygametoolskit-1.1.3/PygameToolsKit/Decorators/onKey.py +16 -0
- pygametoolskit-1.1.3/PygameToolsKit/Decorators/timer.py +21 -0
- pygametoolskit-1.1.3/PygameToolsKit/Event/eventListener.py +19 -0
- pygametoolskit-1.1.3/PygameToolsKit/Event/eventManager.py +42 -0
- pygametoolskit-1.1.3/PygameToolsKit/Event/eventObject.py +9 -0
- pygametoolskit-1.1.3/PygameToolsKit/Event/isEventObject.py +27 -0
- pygametoolskit-1.1.3/PygameToolsKit/Graphics/color.py +25 -0
- pygametoolskit-1.1.3/PygameToolsKit/Inputs/dir.py +9 -0
- pygametoolskit-1.1.3/PygameToolsKit/Inputs/joystickManager.py +26 -0
- pygametoolskit-1.1.3/PygameToolsKit/Inputs/keyManager.py +27 -0
- pygametoolskit-1.1.3/PygameToolsKit/Update/update.py +14 -0
- pygametoolskit-1.1.3/PygameToolsKit/Update/updateManager.py +22 -0
- pygametoolskit-1.1.3/PygameToolsKit/__init__.py +10 -0
- pygametoolskit-1.1.3/PygameToolsKit.egg-info/PKG-INFO +6 -0
- pygametoolskit-1.1.3/PygameToolsKit.egg-info/SOURCES.txt +20 -0
- pygametoolskit-1.1.3/PygameToolsKit.egg-info/dependency_links.txt +1 -0
- pygametoolskit-1.1.3/PygameToolsKit.egg-info/requires.txt +2 -0
- pygametoolskit-1.1.3/PygameToolsKit.egg-info/top_level.txt +2 -0
- pygametoolskit-1.1.3/pyproject.toml +16 -0
- pygametoolskit-1.1.3/setup.cfg +4 -0
|
@@ -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,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,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,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,20 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
PygameToolsKit/__init__.py
|
|
3
|
+
PygameToolsKit.egg-info/PKG-INFO
|
|
4
|
+
PygameToolsKit.egg-info/SOURCES.txt
|
|
5
|
+
PygameToolsKit.egg-info/dependency_links.txt
|
|
6
|
+
PygameToolsKit.egg-info/requires.txt
|
|
7
|
+
PygameToolsKit.egg-info/top_level.txt
|
|
8
|
+
PygameToolsKit/Decorators/onJoystick.py
|
|
9
|
+
PygameToolsKit/Decorators/onKey.py
|
|
10
|
+
PygameToolsKit/Decorators/timer.py
|
|
11
|
+
PygameToolsKit/Event/eventListener.py
|
|
12
|
+
PygameToolsKit/Event/eventManager.py
|
|
13
|
+
PygameToolsKit/Event/eventObject.py
|
|
14
|
+
PygameToolsKit/Event/isEventObject.py
|
|
15
|
+
PygameToolsKit/Graphics/color.py
|
|
16
|
+
PygameToolsKit/Inputs/dir.py
|
|
17
|
+
PygameToolsKit/Inputs/joystickManager.py
|
|
18
|
+
PygameToolsKit/Inputs/keyManager.py
|
|
19
|
+
PygameToolsKit/Update/update.py
|
|
20
|
+
PygameToolsKit/Update/updateManager.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "PygameToolsKit"
|
|
7
|
+
version = "1.1.3"
|
|
8
|
+
description = "Bibliothèque qui dispose de divers classes, fonctions et décorateurs pour aider au développement avec pygame"
|
|
9
|
+
|
|
10
|
+
dependencies = [
|
|
11
|
+
"DecoratorsToolKit>=1.0.0",
|
|
12
|
+
"pygame-ce>=2.5.0"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.setuptools.packages.find]
|
|
16
|
+
where = ["."]
|