PygameToolsOcto 1.0.0__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.
- PygameTools/Decorators/timer.py +21 -0
- PygameTools/Event/eventListener.py +19 -0
- PygameTools/Event/eventManager.py +42 -0
- PygameTools/Event/eventObject.py +9 -0
- PygameTools/Event/isEventObject.py +27 -0
- PygameTools/Graphics/color.py +25 -0
- PygameTools/__init__.py +10 -0
- pygametoolsocto-1.0.0.dist-info/METADATA +6 -0
- pygametoolsocto-1.0.0.dist-info/RECORD +11 -0
- pygametoolsocto-1.0.0.dist-info/WHEEL +5 -0
- pygametoolsocto-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -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 Decorators.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]
|
PygameTools/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
PygameTools/__init__.py,sha256=Dp3KuXk3GqhiVEmJ2oYAwO54_duSsPDn7gOGcSMsXe4,199
|
|
2
|
+
PygameTools/Decorators/timer.py,sha256=ETzIox027Ix0t2asjDDOu69RNba0-9X75U_CoCxUXrI,453
|
|
3
|
+
PygameTools/Event/eventListener.py,sha256=7FvCoMKg-NaBlTtrmnYD_TQpz4Z1qOfSC8RjbN_X9ZU,420
|
|
4
|
+
PygameTools/Event/eventManager.py,sha256=0gShAEmg-VGsJppxtmuNBaAKR5xPyV2r980i0ftN1c4,1034
|
|
5
|
+
PygameTools/Event/eventObject.py,sha256=3PosSVZIUvgGb8RsJSUZ8Se2bputAb9vzyQy-YzvPTs,147
|
|
6
|
+
PygameTools/Event/isEventObject.py,sha256=bIPWAhwNwiQUWb6kYYHGhjmR1s8sDa1-CDH4xy7TW_s,558
|
|
7
|
+
PygameTools/Graphics/color.py,sha256=TcKiyq7CnGHdEnAE3u17Fnrc6Mj5L1hh8p9Vt247Whg,424
|
|
8
|
+
pygametoolsocto-1.0.0.dist-info/METADATA,sha256=m-TBWUd0uPEXjA32uwZsygTObw98QxQwb7LOHbIsmTY,257
|
|
9
|
+
pygametoolsocto-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
pygametoolsocto-1.0.0.dist-info/top_level.txt,sha256=lnOXJs338Hf-bdXpnutX9lGCt33trEwHMMejksIF6H0,12
|
|
11
|
+
pygametoolsocto-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PygameTools
|