batframework 1.0.8a1__py3-none-any.whl → 1.0.8a2__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.
- batFramework/__init__.py +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/easingController.py
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
import pygame
|
2
|
-
import batFramework as bf
|
3
|
-
from functools import lru_cache
|
4
|
-
from .enums import easing
|
5
|
-
|
6
|
-
|
7
|
-
@lru_cache(maxsize=None)
|
8
|
-
def process_value(progress: float, p0: float, p1: float, p2: float, p3: float) -> float:
|
9
|
-
if p0 == 0 and p1 == 0 and p2 == 1 and p3 == 1: # Linear easing control points
|
10
|
-
return progress
|
11
|
-
t = progress
|
12
|
-
t_inv = 1.0 - t
|
13
|
-
t2 = t * t
|
14
|
-
t3 = t * t2
|
15
|
-
t_inv2 = t_inv * t_inv
|
16
|
-
return 3 * t_inv2 * t * p1 + 3 * t_inv * t2 * p3 + t3
|
17
|
-
|
18
|
-
|
19
|
-
class EasingController(bf.Timer):
|
20
|
-
def __init__(
|
21
|
-
self,
|
22
|
-
easing_function: easing = easing.LINEAR,
|
23
|
-
duration: float = 1,
|
24
|
-
update_callback=None,
|
25
|
-
end_callback=None,
|
26
|
-
loop: bool = False,
|
27
|
-
) -> None:
|
28
|
-
self.easing_function = easing_function
|
29
|
-
self.update_callback = update_callback
|
30
|
-
self.value: float = 0.0
|
31
|
-
super().__init__(duration, end_callback, loop)
|
32
|
-
|
33
|
-
def get_value(self) -> float:
|
34
|
-
return self.value
|
35
|
-
|
36
|
-
def start(self, force: bool = False):
|
37
|
-
super().start(force)
|
38
|
-
self.value = 0
|
39
|
-
|
40
|
-
def update(self, dt: float) -> None:
|
41
|
-
if self.get_progression() == 1:
|
42
|
-
return
|
43
|
-
super().update(dt)
|
44
|
-
if self.get_progression() == 0:
|
45
|
-
return
|
46
|
-
if self.easing_function == easing.LINEAR:
|
47
|
-
self.value = self.get_progression()
|
48
|
-
else:
|
49
|
-
self.value = process_value(
|
50
|
-
self.get_progression(), *self.easing_function.control_points
|
51
|
-
)
|
52
|
-
if self.update_callback:
|
53
|
-
self.update_callback(self.value)
|
54
|
-
|
55
|
-
def end(self):
|
56
|
-
if self.update_callback:
|
57
|
-
self.update_callback(1)
|
58
|
-
super().end()
|
batFramework/enums.py
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
from enum import Enum
|
2
|
-
|
3
|
-
|
4
|
-
class color:
|
5
|
-
WHITE = (255, 255, 255)
|
6
|
-
LIGHTER_GRAY = (236, 240, 241)
|
7
|
-
LIGHT_GRAY = (189, 195, 199)
|
8
|
-
DARK_GRAY = (66, 66, 66)
|
9
|
-
DARKER_GRAY = (23, 23, 23)
|
10
|
-
BLACK = (0, 0, 0)
|
11
|
-
|
12
|
-
TURQUOISE = (26, 188, 156)
|
13
|
-
TURQUOISE_SHADE = (22, 160, 133)
|
14
|
-
|
15
|
-
GREEN = (46, 204, 113)
|
16
|
-
GREEN_SHADE = (39, 174, 96)
|
17
|
-
|
18
|
-
BLUE = (52, 152, 219)
|
19
|
-
BLUE_SHADE = (41, 128, 185)
|
20
|
-
|
21
|
-
PURPLE = (155, 89, 182)
|
22
|
-
PURPLE_SHADE = (142, 68, 173)
|
23
|
-
|
24
|
-
CHARCOAL = (52, 73, 94)
|
25
|
-
CHARCOAL_SHADE = (44, 62, 80)
|
26
|
-
|
27
|
-
GOLD = (241, 196, 15)
|
28
|
-
GOLD_SHADE = (243, 156, 18)
|
29
|
-
|
30
|
-
ORANGE = (230, 126, 34)
|
31
|
-
ORANGE_SHADE = (211, 84, 0)
|
32
|
-
|
33
|
-
RED = (231, 76, 60)
|
34
|
-
RED_SHADE = (192, 57, 43)
|
35
|
-
|
36
|
-
CLOUD = (236, 240, 241)
|
37
|
-
CLOUD_SHADE = (189, 195, 199)
|
38
|
-
|
39
|
-
CONCRETE = (149, 165, 166)
|
40
|
-
CONCRETE_SHADE = (127, 140, 141)
|
41
|
-
|
42
|
-
# GB
|
43
|
-
DARKER_GB = (27, 42, 9)
|
44
|
-
DARK_GB = (14, 69, 11)
|
45
|
-
LIGHT_GB = (73, 107, 34)
|
46
|
-
LIGHTER_GB = (154, 158, 63)
|
47
|
-
|
48
|
-
class easing(Enum):
|
49
|
-
LINEAR = (0, 0, 1, 1)
|
50
|
-
EASE_IN = (0.95, 0, 1, 0.55)
|
51
|
-
EASE_OUT = (0.5, 1, 0.5, 1)
|
52
|
-
EASE_IN_OUT = (0.55, 0, 0.45, 1)
|
53
|
-
EASE_IN_OUT_ELASTIC = (0.39, -0.55, 0.3, 1.3)
|
54
|
-
|
55
|
-
def __init__(self, *control_points):
|
56
|
-
self.control_points = control_points
|
57
|
-
|
58
|
-
class axis(Enum):
|
59
|
-
HORIZONTAL = "horizontal"
|
60
|
-
VERTICAL = "vertical"
|
61
|
-
|
62
|
-
class spacing(Enum):
|
63
|
-
MIN = "min"
|
64
|
-
HALF = "half"
|
65
|
-
MAX = "max"
|
66
|
-
MANUAL = "manual"
|
67
|
-
class alignment(Enum):
|
68
|
-
LEFT = "left"
|
69
|
-
RIGHT = "right"
|
70
|
-
CENTER = "center"
|
71
|
-
TOP = "top"
|
72
|
-
BOTTOM = "bottom"
|
73
|
-
TOPLEFT = "topleft"
|
74
|
-
TOPRIGHT = "topright"
|
75
|
-
MIDLEFT = "midleft"
|
76
|
-
MIDRIGHT = "midright"
|
77
|
-
BOTTOMLEFT = "bottomleft"
|
78
|
-
BOTTOMRIGHT = "bottomright"
|
79
|
-
|
80
|
-
class direction(Enum):
|
81
|
-
LEFT = 0
|
82
|
-
UP = 1
|
83
|
-
RIGHT = 2
|
84
|
-
DOWN = 3
|
85
|
-
|
86
|
-
class drawMode(Enum):
|
87
|
-
SOLID = 0
|
88
|
-
TEXTURED = 1
|
89
|
-
|
90
|
-
class debugMode(Enum):
|
91
|
-
HIDDEN = 0
|
92
|
-
DEBUGGER = 1
|
93
|
-
OUTLINES = 2
|
94
|
-
|
95
|
-
class actionType(Enum):
|
96
|
-
INSTANTANEOUS = 0
|
97
|
-
CONTINUOUS = 1
|
98
|
-
HOLDING = 2
|
99
|
-
|
100
|
-
|
101
|
-
class textMode(Enum):
|
102
|
-
ALPHABETICAL = 0
|
103
|
-
NUMERICAL = 1
|
104
|
-
ALPHANUMERIC = 3
|
batFramework/fontManager.py
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
from .utils import Singleton
|
2
|
-
|
3
|
-
# put font stuff here later
|
4
|
-
import pygame
|
5
|
-
import os
|
6
|
-
import batFramework as bf
|
7
|
-
|
8
|
-
|
9
|
-
class FontManager(metaclass=Singleton):
|
10
|
-
def __init__(self):
|
11
|
-
pygame.font.init()
|
12
|
-
self.DEFAULT_TEXT_SIZE = 16
|
13
|
-
self.MIN_FONT_SIZE = 8
|
14
|
-
self.MAX_FONT_SIZE = 64
|
15
|
-
self.DEFAULT_ANTIALIAS = False
|
16
|
-
self.FONTS = {}
|
17
|
-
|
18
|
-
def set_antialias(self,value:bool):
|
19
|
-
self.DEFAULT_ANTIALIAS = value
|
20
|
-
|
21
|
-
def set_default_text_size(self, size: int):
|
22
|
-
self.DEFAULT_TEXT_SIZE = size
|
23
|
-
|
24
|
-
def init_font(self, raw_path: str | None):
|
25
|
-
try:
|
26
|
-
if raw_path is not None:
|
27
|
-
self.load_font(raw_path if raw_path else None, None)
|
28
|
-
self.load_font(raw_path)
|
29
|
-
except FileNotFoundError:
|
30
|
-
self.load_sysfont(raw_path)
|
31
|
-
self.load_sysfont(raw_path, None)
|
32
|
-
|
33
|
-
def load_font(self, path: str | None, name: str | None = ""):
|
34
|
-
if path is not None:
|
35
|
-
path = bf.ResourceManager().get_path(path) # convert path if given
|
36
|
-
filename = None
|
37
|
-
if path is not None:
|
38
|
-
filename = os.path.basename(path).split(".")[0]
|
39
|
-
|
40
|
-
# get filename if path is given, else None
|
41
|
-
if name != "":
|
42
|
-
filename = name # if name is not given, name is the filename
|
43
|
-
self.FONTS[filename] = {}
|
44
|
-
# fill the dict
|
45
|
-
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE, 2):
|
46
|
-
self.FONTS[filename][size] = pygame.font.Font(path, size=size)
|
47
|
-
|
48
|
-
def load_sysfont(self, font_name: str | None, key: str | None = ""):
|
49
|
-
if key == "":
|
50
|
-
key = font_name
|
51
|
-
if font_name is None or pygame.font.match_font(font_name) is None:
|
52
|
-
raise FileNotFoundError(f"Requested font '{font_name}' was not found")
|
53
|
-
self.FONTS[font_name] = {}
|
54
|
-
|
55
|
-
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE, 2):
|
56
|
-
self.FONTS[key][size] = pygame.font.SysFont(font_name, size=size)
|
57
|
-
|
58
|
-
def get_font(
|
59
|
-
self, name: str | None = None, text_size: int = 12
|
60
|
-
) -> pygame.Font | None:
|
61
|
-
if not name in self.FONTS:
|
62
|
-
return None
|
63
|
-
if not text_size in self.FONTS[name]:
|
64
|
-
return None
|
65
|
-
return self.FONTS[name][text_size]
|
@@ -1,206 +0,0 @@
|
|
1
|
-
from .label import Label
|
2
|
-
import batFramework as bf
|
3
|
-
from typing import Self, Callable
|
4
|
-
from .interactiveWidget import InteractiveWidget
|
5
|
-
from .shape import Shape
|
6
|
-
import pygame
|
7
|
-
from math import ceil
|
8
|
-
|
9
|
-
|
10
|
-
class ClickableWidget(Shape,InteractiveWidget):
|
11
|
-
_cache: dict = {}
|
12
|
-
|
13
|
-
def __init__(self,callback: None | Callable = None,*args,**kwargs) -> None:
|
14
|
-
super().__init__(*args, **kwargs)
|
15
|
-
self.callback = callback
|
16
|
-
self.is_pressed: bool = False
|
17
|
-
self.enabled: bool = True
|
18
|
-
self.hover_cursor = bf.const.DEFAULT_HOVER_CURSOR
|
19
|
-
self.click_cursor = bf.const.DEFAULT_CLICK_CURSOR
|
20
|
-
self.click_down_sound = None
|
21
|
-
self.click_up_sound = None
|
22
|
-
self.get_focus_sound = None
|
23
|
-
self.lose_focus_sound = None
|
24
|
-
self.pressed_relief : int = 1
|
25
|
-
self.unpressed_relief : int = 2
|
26
|
-
self.silent_focus : bool = False
|
27
|
-
self.set_debug_color("cyan")
|
28
|
-
self.set_relief(self.unpressed_relief)
|
29
|
-
|
30
|
-
def set_unpressed_relief(self,relief:int=0)->Self:
|
31
|
-
if relief == self.unpressed_relief : return self
|
32
|
-
self.unpressed_relief = relief
|
33
|
-
self.dirty_shape = True
|
34
|
-
if not self.is_pressed : self.set_relief(relief)
|
35
|
-
return self
|
36
|
-
|
37
|
-
def set_silent_focus(self,value:bool)->Self:
|
38
|
-
self.silent_focus = value
|
39
|
-
return self
|
40
|
-
|
41
|
-
|
42
|
-
def set_pressed_relief(self,relief:int=0)->Self:
|
43
|
-
if relief == self.pressed_relief : return self
|
44
|
-
self.pressed_relief = relief
|
45
|
-
self.dirty_shape = True
|
46
|
-
if self.is_pressed : self.set_relief(relief)
|
47
|
-
|
48
|
-
return self
|
49
|
-
|
50
|
-
def set_click_down_sound(self, sound_name: str) -> Self:
|
51
|
-
self.click_down_sound = sound_name
|
52
|
-
return self
|
53
|
-
|
54
|
-
def set_click_up_sound(self, sound_name: str) -> Self:
|
55
|
-
self.click_up_sound = sound_name
|
56
|
-
return self
|
57
|
-
|
58
|
-
def set_get_focus_sound(self, sound_name: str) -> Self:
|
59
|
-
self.get_focus_sound = sound_name
|
60
|
-
return self
|
61
|
-
|
62
|
-
def set_lose_focus_sound(self, sound_name: str) -> Self:
|
63
|
-
self.lose_focus_sound = sound_name
|
64
|
-
return self
|
65
|
-
|
66
|
-
def set_hover_cursor(self, cursor: pygame.Cursor) -> Self:
|
67
|
-
self.hover_cursor = cursor
|
68
|
-
return self
|
69
|
-
|
70
|
-
def set_click_cursor(self, cursor: pygame.Cursor) -> Self:
|
71
|
-
self.click_cursor = cursor
|
72
|
-
return self
|
73
|
-
|
74
|
-
def get_surface_filter(self) -> pygame.Surface | None:
|
75
|
-
size = int(self.rect.w),int(self.rect.h)
|
76
|
-
surface_filter = ClickableWidget._cache.get((size, *self.border_radius), None)
|
77
|
-
if surface_filter is None:
|
78
|
-
# Create a mask from the original surface
|
79
|
-
mask = pygame.mask.from_surface(self.surface, threshold=0)
|
80
|
-
|
81
|
-
silhouette_surface = mask.to_surface(setcolor=(30, 30, 30), unsetcolor=(0,0,0))
|
82
|
-
|
83
|
-
ClickableWidget._cache[(size, *self.border_radius)] = silhouette_surface
|
84
|
-
|
85
|
-
surface_filter = silhouette_surface
|
86
|
-
|
87
|
-
return surface_filter
|
88
|
-
|
89
|
-
def allow_focus_to_self(self)->bool:
|
90
|
-
return True
|
91
|
-
|
92
|
-
def enable(self) -> Self:
|
93
|
-
self.enabled = True
|
94
|
-
self.dirty_surface = True
|
95
|
-
return self
|
96
|
-
|
97
|
-
def disable(self) -> Self:
|
98
|
-
self.enabled = False
|
99
|
-
self.dirty_surface = True
|
100
|
-
return self
|
101
|
-
|
102
|
-
def is_enabled(self) -> bool:
|
103
|
-
return self.enabled
|
104
|
-
|
105
|
-
def set_callback(self, callback: Callable) -> Self:
|
106
|
-
self.callback = callback
|
107
|
-
return self
|
108
|
-
|
109
|
-
def on_get_focus(self):
|
110
|
-
super().on_get_focus()
|
111
|
-
if self.get_focus_sound and not self.silent_focus:
|
112
|
-
if self.parent_scene and self.parent_scene.visible:
|
113
|
-
bf.AudioManager().play_sound(self.get_focus_sound)
|
114
|
-
if self.silent_focus :
|
115
|
-
self.silent_focus = False
|
116
|
-
|
117
|
-
def on_lose_focus(self):
|
118
|
-
super().on_lose_focus()
|
119
|
-
if self.lose_focus_sound and not self.silent_focus:
|
120
|
-
if self.parent_scene and self.parent_scene.visible:
|
121
|
-
bf.AudioManager().play_sound(self.lose_focus_sound)
|
122
|
-
if self.silent_focus :
|
123
|
-
self.silent_focus = False
|
124
|
-
|
125
|
-
def __str__(self) -> str:
|
126
|
-
return f"ClickableWidget"
|
127
|
-
|
128
|
-
def click(self, force=False) -> None:
|
129
|
-
if not self.enabled and not force:
|
130
|
-
return
|
131
|
-
if self.callback is not None:
|
132
|
-
self.callback()
|
133
|
-
|
134
|
-
def do_on_click_down(self, button) -> None:
|
135
|
-
if self.enabled and button == 1 :
|
136
|
-
if not self.get_focus():
|
137
|
-
return
|
138
|
-
self.is_pressed = True
|
139
|
-
bf.AudioManager().play_sound(self.click_down_sound)
|
140
|
-
|
141
|
-
pygame.mouse.set_cursor(self.click_cursor)
|
142
|
-
self.set_relief(self.pressed_relief)
|
143
|
-
|
144
|
-
def do_on_click_up(self, button) -> None:
|
145
|
-
if self.enabled and button == 1 and self.is_pressed:
|
146
|
-
self.is_pressed = False
|
147
|
-
bf.AudioManager().play_sound(self.click_up_sound)
|
148
|
-
self.set_relief(self.unpressed_relief)
|
149
|
-
self.click()
|
150
|
-
|
151
|
-
def on_enter(self) -> None:
|
152
|
-
if not self.enabled:
|
153
|
-
return
|
154
|
-
super().on_enter()
|
155
|
-
self.dirty_surface = True
|
156
|
-
pygame.mouse.set_cursor(self.hover_cursor)
|
157
|
-
|
158
|
-
def on_exit(self) -> None:
|
159
|
-
super().on_exit()
|
160
|
-
if self.is_pressed:
|
161
|
-
self.set_relief(self.unpressed_relief)
|
162
|
-
self.is_pressed = False
|
163
|
-
self.dirty_surface = True
|
164
|
-
|
165
|
-
pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
|
166
|
-
|
167
|
-
def on_lose_focus(self):
|
168
|
-
super().on_lose_focus()
|
169
|
-
self.on_exit()
|
170
|
-
|
171
|
-
def on_key_down(self, key):
|
172
|
-
if key == pygame.K_SPACE:
|
173
|
-
self.on_click_down(1)
|
174
|
-
super().on_key_down(key)
|
175
|
-
|
176
|
-
def on_key_up(self, key):
|
177
|
-
if key == pygame.K_SPACE:
|
178
|
-
self.on_click_up(1)
|
179
|
-
super().on_key_up(key)
|
180
|
-
|
181
|
-
def _paint_disabled(self) -> None:
|
182
|
-
self.surface.blit(
|
183
|
-
self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_SUB
|
184
|
-
)
|
185
|
-
|
186
|
-
def _paint_hovered(self) -> None:
|
187
|
-
self.surface.blit(
|
188
|
-
self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_ADD
|
189
|
-
)
|
190
|
-
|
191
|
-
def get_padded_rect(self)->pygame.FRect:
|
192
|
-
return pygame.FRect(
|
193
|
-
self.rect.x + self.padding[0], self.rect.y + self.padding[1] + (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
|
194
|
-
self.rect.w - self.padding[2] - self.padding[0],
|
195
|
-
self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3] #
|
196
|
-
)
|
197
|
-
|
198
|
-
def _get_elevated_rect(self) -> pygame.FRect:
|
199
|
-
return pygame.FRect(0, self.unpressed_relief - self.pressed_relief if self.is_pressed else 0 , self.rect.w, self.rect.h - self.unpressed_relief)
|
200
|
-
|
201
|
-
def paint(self) -> None:
|
202
|
-
super().paint()
|
203
|
-
if not self.enabled:
|
204
|
-
self._paint_disabled()
|
205
|
-
elif self.is_hovered:
|
206
|
-
self._paint_hovered()
|
@@ -1 +0,0 @@
|
|
1
|
-
from . import constraints
|