batframework 1.0.9a11__py3-none-any.whl → 1.0.9a12__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 +2 -0
- batFramework/action.py +280 -279
- batFramework/actionContainer.py +105 -82
- batFramework/animatedSprite.py +80 -58
- batFramework/animation.py +91 -77
- batFramework/audioManager.py +156 -131
- batFramework/baseScene.py +249 -240
- batFramework/camera.py +245 -317
- batFramework/constants.py +57 -51
- batFramework/cutscene.py +239 -253
- batFramework/cutsceneManager.py +34 -34
- batFramework/drawable.py +107 -77
- batFramework/dynamicEntity.py +30 -30
- batFramework/easingController.py +58 -58
- batFramework/entity.py +130 -130
- batFramework/enums.py +171 -135
- batFramework/fontManager.py +65 -65
- batFramework/gui/__init__.py +28 -25
- batFramework/gui/animatedLabel.py +90 -89
- batFramework/gui/button.py +17 -17
- batFramework/gui/clickableWidget.py +244 -244
- batFramework/gui/collapseContainer.py +98 -0
- batFramework/gui/constraints/__init__.py +1 -1
- batFramework/gui/constraints/constraints.py +1066 -980
- batFramework/gui/container.py +220 -206
- batFramework/gui/debugger.py +140 -130
- batFramework/gui/draggableWidget.py +63 -44
- batFramework/gui/image.py +61 -58
- batFramework/gui/indicator.py +116 -113
- batFramework/gui/interactiveWidget.py +243 -239
- batFramework/gui/label.py +147 -344
- batFramework/gui/layout.py +442 -429
- batFramework/gui/meter.py +155 -96
- batFramework/gui/radioButton.py +43 -35
- batFramework/gui/root.py +228 -228
- batFramework/gui/scrollingContainer.py +282 -0
- batFramework/gui/selector.py +232 -250
- batFramework/gui/shape.py +286 -276
- batFramework/gui/slider.py +353 -397
- batFramework/gui/style.py +10 -10
- batFramework/gui/styleManager.py +49 -54
- batFramework/gui/syncedVar.py +43 -49
- batFramework/gui/textInput.py +331 -306
- batFramework/gui/textWidget.py +308 -0
- batFramework/gui/toggle.py +140 -128
- batFramework/gui/tooltip.py +35 -30
- batFramework/gui/widget.py +546 -521
- batFramework/manager.py +131 -134
- batFramework/particle.py +118 -118
- batFramework/propertyEaser.py +79 -79
- batFramework/renderGroup.py +34 -34
- batFramework/resourceManager.py +130 -130
- batFramework/scene.py +31 -31
- batFramework/sceneLayer.py +134 -138
- batFramework/sceneManager.py +200 -197
- batFramework/scrollingSprite.py +115 -115
- batFramework/sprite.py +46 -51
- batFramework/stateMachine.py +49 -54
- batFramework/templates/__init__.py +2 -1
- batFramework/templates/character.py +15 -0
- batFramework/templates/controller.py +158 -97
- batFramework/templates/stateMachine.py +39 -0
- batFramework/tileset.py +46 -46
- batFramework/timeManager.py +213 -213
- batFramework/transition.py +162 -162
- batFramework/triggerZone.py +22 -22
- batFramework/utils.py +306 -306
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/METADATA +24 -17
- batframework-1.0.9a12.dist-info/RECORD +72 -0
- batframework-1.0.9a11.dist-info/RECORD +0 -67
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/top_level.txt +0 -0
batFramework/renderGroup.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
import pygame
|
3
|
-
from typing import Callable, Iterator
|
4
|
-
|
5
|
-
|
6
|
-
class RenderGroup(bf.Drawable):
|
7
|
-
def __init__(
|
8
|
-
self, entity_iterator: Callable[[], Iterator[bf.Drawable]], blit_flags: int = 0
|
9
|
-
) -> None:
|
10
|
-
super().__init__()
|
11
|
-
self.entity_iterator = entity_iterator
|
12
|
-
self.blit_flags = blit_flags
|
13
|
-
self.set_debug_color("white")
|
14
|
-
|
15
|
-
def draw(self, camera: bf.Camera) -> None:
|
16
|
-
if not self.visible:
|
17
|
-
return
|
18
|
-
|
19
|
-
fblits_data = []
|
20
|
-
for e in self.entity_iterator():
|
21
|
-
if not getattr(e, "drawn_by_group", False):
|
22
|
-
# Set flag to skip their individual draw call
|
23
|
-
e.drawn_by_group = True
|
24
|
-
|
25
|
-
if e.visible and camera.rect.colliderect(e.rect):
|
26
|
-
fblits_data.append(
|
27
|
-
(e.surface, (e.rect.x - camera.rect.x, e.rect.y - camera.rect.y))
|
28
|
-
)
|
29
|
-
|
30
|
-
camera.surface.fblits(fblits_data, self.blit_flags)
|
31
|
-
|
32
|
-
def get_debug_outlines(self):
|
33
|
-
for e in self.entity_iterator():
|
34
|
-
yield from e.get_debug_outlines()
|
1
|
+
import batFramework as bf
|
2
|
+
import pygame
|
3
|
+
from typing import Callable, Iterator
|
4
|
+
|
5
|
+
|
6
|
+
class RenderGroup(bf.Drawable):
|
7
|
+
def __init__(
|
8
|
+
self, entity_iterator: Callable[[], Iterator[bf.Drawable]], blit_flags: int = 0
|
9
|
+
) -> None:
|
10
|
+
super().__init__()
|
11
|
+
self.entity_iterator = entity_iterator
|
12
|
+
self.blit_flags = blit_flags
|
13
|
+
self.set_debug_color("white")
|
14
|
+
|
15
|
+
def draw(self, camera: bf.Camera) -> None:
|
16
|
+
if not self.visible:
|
17
|
+
return
|
18
|
+
|
19
|
+
fblits_data = []
|
20
|
+
for e in self.entity_iterator():
|
21
|
+
if not getattr(e, "drawn_by_group", False):
|
22
|
+
# Set flag to skip their individual draw call
|
23
|
+
e.drawn_by_group = True
|
24
|
+
|
25
|
+
if e.visible and camera.rect.colliderect(e.rect):
|
26
|
+
fblits_data.append(
|
27
|
+
(e.surface, (e.rect.x - camera.rect.x, e.rect.y - camera.rect.y))
|
28
|
+
)
|
29
|
+
|
30
|
+
camera.surface.fblits(fblits_data, self.blit_flags)
|
31
|
+
|
32
|
+
def get_debug_outlines(self):
|
33
|
+
for e in self.entity_iterator():
|
34
|
+
yield from e.get_debug_outlines()
|
batFramework/resourceManager.py
CHANGED
@@ -1,130 +1,130 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
import os
|
3
|
-
import pygame
|
4
|
-
import sys
|
5
|
-
import json
|
6
|
-
from typing import Any, Callable
|
7
|
-
from .utils import Singleton
|
8
|
-
import asyncio
|
9
|
-
|
10
|
-
|
11
|
-
if getattr(sys, "frozen", False):
|
12
|
-
# If the application is run as a bundle, the PyInstaller bootloader
|
13
|
-
# extends the sys module by a flag frozen=True and sets the app
|
14
|
-
# path into variable _MEIPASS'.
|
15
|
-
application_path = sys._MEIPASS
|
16
|
-
else:
|
17
|
-
application_path = os.getcwd()
|
18
|
-
|
19
|
-
|
20
|
-
class ResourceManager(metaclass=Singleton):
|
21
|
-
def __init__(self):
|
22
|
-
self.shared_variables: dict[str, Any] = {}
|
23
|
-
self.convert_image_cache = {}
|
24
|
-
self.convert_alpha_image_cache = {}
|
25
|
-
self.sound_cache = {}
|
26
|
-
self.RESOURCE_PATH = "."
|
27
|
-
self.loading_thread = None
|
28
|
-
|
29
|
-
def load_resources(self, path: str, progress_callback: Callable[[float], Any] = None):
|
30
|
-
"""
|
31
|
-
loads resources from a directory.
|
32
|
-
Progress is reported through the callback.
|
33
|
-
Supposed to be asynchronous but don't use it as such yet
|
34
|
-
"""
|
35
|
-
self.progress_callback = progress_callback
|
36
|
-
|
37
|
-
total_files = sum(
|
38
|
-
len(files) for _, _, files in os.walk(path) if not any(f.startswith(".") for f in files)
|
39
|
-
)
|
40
|
-
|
41
|
-
loaded_files = 0
|
42
|
-
|
43
|
-
for root, dirs, files in os.walk(path):
|
44
|
-
files = [f for f in files if not f.startswith(".")]
|
45
|
-
dirs[:] = [d for d in dirs if not (d.startswith(".") or d.startswith("__"))]
|
46
|
-
for file in files:
|
47
|
-
file_path = os.path.join(root, file)
|
48
|
-
|
49
|
-
# Simulate resource loading
|
50
|
-
# await asyncio.sleep(0) # Yield control to the event loop
|
51
|
-
|
52
|
-
if file.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
|
53
|
-
self.load_image(file_path)
|
54
|
-
elif file.lower().endswith((".mp3", ".wav", ".ogg")):
|
55
|
-
bf.AudioManager().load_sound(file.split(".")[0], file_path)
|
56
|
-
elif file.lower().endswith((".ttf", ".otf")):
|
57
|
-
bf.FontManager().load_font(file_path, file.split(".")[0])
|
58
|
-
|
59
|
-
loaded_files += 1
|
60
|
-
# Report progress
|
61
|
-
# if self.progress_callback:
|
62
|
-
# self.progress_callback(loaded_files / total_files)
|
63
|
-
|
64
|
-
print(f"Loaded resources in directory: '{path}'")
|
65
|
-
|
66
|
-
|
67
|
-
def set_resource_path(self, path: str):
|
68
|
-
self.RESOURCE_PATH = os.path.join(application_path, path)
|
69
|
-
print(f"Resource path : '{self.RESOURCE_PATH}'")
|
70
|
-
|
71
|
-
def get_path(self, path: str) -> str:
|
72
|
-
# Normalize path separators
|
73
|
-
normalized_path = path.replace("/", os.sep).replace("\\", os.sep)
|
74
|
-
return os.path.join(self.RESOURCE_PATH, normalized_path)
|
75
|
-
|
76
|
-
def load_image(self, path) -> None:
|
77
|
-
key = self.get_path(path)
|
78
|
-
if key in self.convert_image_cache:
|
79
|
-
return
|
80
|
-
self.convert_image_cache[key] = pygame.image.load(path).convert()
|
81
|
-
self.convert_alpha_image_cache[key] = pygame.image.load(path).convert_alpha()
|
82
|
-
|
83
|
-
|
84
|
-
def get_image(self, path, convert_alpha: bool = False) -> pygame.Surface | None:
|
85
|
-
key = self.get_path(path)
|
86
|
-
return (
|
87
|
-
self.convert_alpha_image_cache.get(key, None)
|
88
|
-
if convert_alpha
|
89
|
-
else self.convert_image_cache.get(key, None)
|
90
|
-
)
|
91
|
-
|
92
|
-
def load_json_from_file(self, path: str) -> dict | None:
|
93
|
-
try:
|
94
|
-
with open(self.get_path(path), "r") as file:
|
95
|
-
data = json.load(file)
|
96
|
-
return data
|
97
|
-
except FileNotFoundError:
|
98
|
-
print(f"File '{path}' not found")
|
99
|
-
return None
|
100
|
-
|
101
|
-
def save_json_to_file(self, path: str, data) -> bool:
|
102
|
-
try:
|
103
|
-
with open(self.get_path(path), "w") as file:
|
104
|
-
json.dump(data, file, indent=2)
|
105
|
-
return True
|
106
|
-
except FileNotFoundError:
|
107
|
-
return False
|
108
|
-
|
109
|
-
|
110
|
-
def set_sharedVar(self, name, value) -> bool:
|
111
|
-
"""
|
112
|
-
Set a shared variable of any type. This will be accessible (read/write) from any scene
|
113
|
-
"""
|
114
|
-
self.shared_variables[name] = value
|
115
|
-
return True
|
116
|
-
|
117
|
-
def set_sharedVars(self, variables: dict) -> bool:
|
118
|
-
"""
|
119
|
-
Set multiple shared variables at once. This will be accessible (read/write) from any scene.
|
120
|
-
"""
|
121
|
-
if not isinstance(variables, dict):
|
122
|
-
raise ValueError("Input must be a dictionary")
|
123
|
-
self.shared_variables.update(variables)
|
124
|
-
return True
|
125
|
-
|
126
|
-
def get_sharedVar(self, name, error_value=None):
|
127
|
-
"""
|
128
|
-
Get a shared variable
|
129
|
-
"""
|
130
|
-
return self.shared_variables.get(name, error_value)
|
1
|
+
import batFramework as bf
|
2
|
+
import os
|
3
|
+
import pygame
|
4
|
+
import sys
|
5
|
+
import json
|
6
|
+
from typing import Any, Callable
|
7
|
+
from .utils import Singleton
|
8
|
+
import asyncio
|
9
|
+
|
10
|
+
|
11
|
+
if getattr(sys, "frozen", False):
|
12
|
+
# If the application is run as a bundle, the PyInstaller bootloader
|
13
|
+
# extends the sys module by a flag frozen=True and sets the app
|
14
|
+
# path into variable _MEIPASS'.
|
15
|
+
application_path = sys._MEIPASS
|
16
|
+
else:
|
17
|
+
application_path = os.getcwd()
|
18
|
+
|
19
|
+
|
20
|
+
class ResourceManager(metaclass=Singleton):
|
21
|
+
def __init__(self):
|
22
|
+
self.shared_variables: dict[str, Any] = {}
|
23
|
+
self.convert_image_cache = {}
|
24
|
+
self.convert_alpha_image_cache = {}
|
25
|
+
self.sound_cache = {}
|
26
|
+
self.RESOURCE_PATH = "."
|
27
|
+
self.loading_thread = None
|
28
|
+
|
29
|
+
def load_resources(self, path: str, progress_callback: Callable[[float], Any] = None):
|
30
|
+
"""
|
31
|
+
loads resources from a directory.
|
32
|
+
Progress is reported through the callback.
|
33
|
+
Supposed to be asynchronous but don't use it as such yet
|
34
|
+
"""
|
35
|
+
self.progress_callback = progress_callback
|
36
|
+
|
37
|
+
total_files = sum(
|
38
|
+
len(files) for _, _, files in os.walk(path) if not any(f.startswith(".") for f in files)
|
39
|
+
)
|
40
|
+
|
41
|
+
loaded_files = 0
|
42
|
+
|
43
|
+
for root, dirs, files in os.walk(path):
|
44
|
+
files = [f for f in files if not f.startswith(".")]
|
45
|
+
dirs[:] = [d for d in dirs if not (d.startswith(".") or d.startswith("__"))]
|
46
|
+
for file in files:
|
47
|
+
file_path = os.path.join(root, file)
|
48
|
+
|
49
|
+
# Simulate resource loading
|
50
|
+
# await asyncio.sleep(0) # Yield control to the event loop
|
51
|
+
|
52
|
+
if file.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
|
53
|
+
self.load_image(file_path)
|
54
|
+
elif file.lower().endswith((".mp3", ".wav", ".ogg")):
|
55
|
+
bf.AudioManager().load_sound(file.split(".")[0], file_path)
|
56
|
+
elif file.lower().endswith((".ttf", ".otf")):
|
57
|
+
bf.FontManager().load_font(file_path, file.split(".")[0])
|
58
|
+
|
59
|
+
loaded_files += 1
|
60
|
+
# Report progress
|
61
|
+
# if self.progress_callback:
|
62
|
+
# self.progress_callback(loaded_files / total_files)
|
63
|
+
|
64
|
+
print(f"Loaded resources in directory: '{path}'")
|
65
|
+
|
66
|
+
|
67
|
+
def set_resource_path(self, path: str):
|
68
|
+
self.RESOURCE_PATH = os.path.join(application_path, path)
|
69
|
+
print(f"Resource path : '{self.RESOURCE_PATH}'")
|
70
|
+
|
71
|
+
def get_path(self, path: str) -> str:
|
72
|
+
# Normalize path separators
|
73
|
+
normalized_path = path.replace("/", os.sep).replace("\\", os.sep)
|
74
|
+
return os.path.join(self.RESOURCE_PATH, normalized_path)
|
75
|
+
|
76
|
+
def load_image(self, path) -> None:
|
77
|
+
key = self.get_path(path)
|
78
|
+
if key in self.convert_image_cache:
|
79
|
+
return
|
80
|
+
self.convert_image_cache[key] = pygame.image.load(path).convert()
|
81
|
+
self.convert_alpha_image_cache[key] = pygame.image.load(path).convert_alpha()
|
82
|
+
|
83
|
+
|
84
|
+
def get_image(self, path, convert_alpha: bool = False) -> pygame.Surface | None:
|
85
|
+
key = self.get_path(path)
|
86
|
+
return (
|
87
|
+
self.convert_alpha_image_cache.get(key, None)
|
88
|
+
if convert_alpha
|
89
|
+
else self.convert_image_cache.get(key, None)
|
90
|
+
)
|
91
|
+
|
92
|
+
def load_json_from_file(self, path: str) -> dict | None:
|
93
|
+
try:
|
94
|
+
with open(self.get_path(path), "r") as file:
|
95
|
+
data = json.load(file)
|
96
|
+
return data
|
97
|
+
except FileNotFoundError:
|
98
|
+
print(f"File '{path}' not found")
|
99
|
+
return None
|
100
|
+
|
101
|
+
def save_json_to_file(self, path: str, data) -> bool:
|
102
|
+
try:
|
103
|
+
with open(self.get_path(path), "w") as file:
|
104
|
+
json.dump(data, file, indent=2)
|
105
|
+
return True
|
106
|
+
except FileNotFoundError:
|
107
|
+
return False
|
108
|
+
|
109
|
+
|
110
|
+
def set_sharedVar(self, name, value) -> bool:
|
111
|
+
"""
|
112
|
+
Set a shared variable of any type. This will be accessible (read/write) from any scene
|
113
|
+
"""
|
114
|
+
self.shared_variables[name] = value
|
115
|
+
return True
|
116
|
+
|
117
|
+
def set_sharedVars(self, variables: dict) -> bool:
|
118
|
+
"""
|
119
|
+
Set multiple shared variables at once. This will be accessible (read/write) from any scene.
|
120
|
+
"""
|
121
|
+
if not isinstance(variables, dict):
|
122
|
+
raise ValueError("Input must be a dictionary")
|
123
|
+
self.shared_variables.update(variables)
|
124
|
+
return True
|
125
|
+
|
126
|
+
def get_sharedVar(self, name, error_value=None):
|
127
|
+
"""
|
128
|
+
Get a shared variable
|
129
|
+
"""
|
130
|
+
return self.shared_variables.get(name, error_value)
|
batFramework/scene.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
from .baseScene import BaseScene
|
2
|
-
import batFramework as bf
|
3
|
-
|
4
|
-
|
5
|
-
class Scene(BaseScene):
|
6
|
-
def __init__(self,name: str) -> None:
|
7
|
-
"""
|
8
|
-
Default Scene object.
|
9
|
-
Has 2 layers (world and hud) by default
|
10
|
-
Contains an exposed root gui object on the hud layer
|
11
|
-
Args:
|
12
|
-
name: Name of the scene.
|
13
|
-
"""
|
14
|
-
super().__init__(name)
|
15
|
-
self.add_layer(bf.SceneLayer("world",True))
|
16
|
-
hud_layer = bf.SceneLayer("hud",True)
|
17
|
-
self.add_layer(hud_layer)
|
18
|
-
self.root: bf.gui.Root = bf.gui.Root(hud_layer.camera)
|
19
|
-
self.root.rect.center = hud_layer.camera.get_center()
|
20
|
-
self.add("hud",self.root)
|
21
|
-
self.entities_to_remove = []
|
22
|
-
self.entities_to_add = []
|
23
|
-
|
24
|
-
def on_enter(self):
|
25
|
-
self.root.clear_hovered()
|
26
|
-
self.root.build()
|
27
|
-
super().on_enter()
|
28
|
-
|
29
|
-
def on_exit(self):
|
30
|
-
self.root.clear_hovered()
|
31
|
-
super().on_exit()
|
1
|
+
from .baseScene import BaseScene
|
2
|
+
import batFramework as bf
|
3
|
+
|
4
|
+
|
5
|
+
class Scene(BaseScene):
|
6
|
+
def __init__(self,name: str) -> None:
|
7
|
+
"""
|
8
|
+
Default Scene object.
|
9
|
+
Has 2 layers (world and hud) by default
|
10
|
+
Contains an exposed root gui object on the hud layer
|
11
|
+
Args:
|
12
|
+
name: Name of the scene.
|
13
|
+
"""
|
14
|
+
super().__init__(name)
|
15
|
+
self.add_layer(bf.SceneLayer("world",True))
|
16
|
+
hud_layer = bf.SceneLayer("hud",True)
|
17
|
+
self.add_layer(hud_layer)
|
18
|
+
self.root: bf.gui.Root = bf.gui.Root(hud_layer.camera)
|
19
|
+
self.root.rect.center = hud_layer.camera.get_center()
|
20
|
+
self.add("hud",self.root)
|
21
|
+
self.entities_to_remove = []
|
22
|
+
self.entities_to_add = []
|
23
|
+
|
24
|
+
def on_enter(self):
|
25
|
+
self.root.clear_hovered()
|
26
|
+
self.root.build()
|
27
|
+
super().on_enter()
|
28
|
+
|
29
|
+
def on_exit(self):
|
30
|
+
self.root.clear_hovered()
|
31
|
+
super().on_exit()
|