batframework 1.0.9a11__py3-none-any.whl → 1.0.9a13__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 +3 -11
- 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.9a13.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/METADATA +24 -17
- batframework-1.0.9a13.dist-info/RECORD +72 -0
- batframework-1.0.9a11.dist-info/RECORD +0 -67
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/top_level.txt +0 -0
batFramework/baseScene.py
CHANGED
@@ -1,240 +1,249 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
from typing import TYPE_CHECKING, Any
|
3
|
-
if TYPE_CHECKING:
|
4
|
-
from .manager import Manager
|
5
|
-
from .sceneManager import SceneManager
|
6
|
-
|
7
|
-
import pygame
|
8
|
-
import itertools
|
9
|
-
import batFramework as bf
|
10
|
-
from .sceneLayer import SceneLayer
|
11
|
-
|
12
|
-
class BaseScene:
|
13
|
-
def __init__(self,name: str) -> None:
|
14
|
-
"""
|
15
|
-
Base Scene object.
|
16
|
-
Empty scene with no layers or gui setup
|
17
|
-
Args:
|
18
|
-
name: Name of the scene.
|
19
|
-
"""
|
20
|
-
bf.TimeManager().add_register(name,False)
|
21
|
-
self.scene_index = 0
|
22
|
-
self.name = name
|
23
|
-
self.manager: Manager | None = None
|
24
|
-
self.active = False
|
25
|
-
self.visible = False
|
26
|
-
self.clear_color = bf.color.BLACK
|
27
|
-
self.actions: bf.ActionContainer = bf.ActionContainer()
|
28
|
-
self.early_actions: bf.ActionContainer = bf.ActionContainer()
|
29
|
-
self.scene_layers : list[SceneLayer] = []
|
30
|
-
|
31
|
-
def set_clear_color(self,color):
|
32
|
-
"""
|
33
|
-
Sets the clear color of the entire scene.
|
34
|
-
This color will fill the scene before all layers are drawn.
|
35
|
-
Results will not show if a layer has an opaque fill color on top.
|
36
|
-
Set to None to skip.
|
37
|
-
"""
|
38
|
-
self.clear_color = color
|
39
|
-
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
self.scene_layers.
|
46
|
-
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
self.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
self.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def
|
110
|
-
"""
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
self.
|
160
|
-
|
161
|
-
|
162
|
-
self.
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
self.
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
def
|
240
|
-
pass
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import TYPE_CHECKING, Any
|
3
|
+
if TYPE_CHECKING:
|
4
|
+
from .manager import Manager
|
5
|
+
from .sceneManager import SceneManager
|
6
|
+
|
7
|
+
import pygame
|
8
|
+
import itertools
|
9
|
+
import batFramework as bf
|
10
|
+
from .sceneLayer import SceneLayer
|
11
|
+
|
12
|
+
class BaseScene:
|
13
|
+
def __init__(self,name: str) -> None:
|
14
|
+
"""
|
15
|
+
Base Scene object.
|
16
|
+
Empty scene with no layers or gui setup
|
17
|
+
Args:
|
18
|
+
name: Name of the scene.
|
19
|
+
"""
|
20
|
+
bf.TimeManager().add_register(name,False)
|
21
|
+
self.scene_index = 0
|
22
|
+
self.name = name
|
23
|
+
self.manager: Manager | None = None
|
24
|
+
self.active = False
|
25
|
+
self.visible = False
|
26
|
+
self.clear_color = bf.color.BLACK
|
27
|
+
self.actions: bf.ActionContainer = bf.ActionContainer()
|
28
|
+
self.early_actions: bf.ActionContainer = bf.ActionContainer()
|
29
|
+
self.scene_layers : list[SceneLayer] = []
|
30
|
+
|
31
|
+
def set_clear_color(self,color):
|
32
|
+
"""
|
33
|
+
Sets the clear color of the entire scene.
|
34
|
+
This color will fill the scene before all layers are drawn.
|
35
|
+
Results will not show if a layer has an opaque fill color on top.
|
36
|
+
Set to None to skip.
|
37
|
+
"""
|
38
|
+
self.clear_color = color
|
39
|
+
|
40
|
+
def get_clear_color(self)->pygame.typing.ColorLike:
|
41
|
+
return self.clear_color
|
42
|
+
|
43
|
+
def add_layer(self,layer:SceneLayer,index:int=0):
|
44
|
+
layer.set_scene(self)
|
45
|
+
self.scene_layers.insert(index,layer)
|
46
|
+
|
47
|
+
def remove_layer(self,index=0):
|
48
|
+
self.scene_layers.pop(index)
|
49
|
+
|
50
|
+
def set_layer(self,layername,layer:SceneLayer):
|
51
|
+
for i,l in enumerate(self.scene_layers[::]):
|
52
|
+
if l.name == layername:
|
53
|
+
self.scene_layers[i] = layer
|
54
|
+
layer.set_scene(self)
|
55
|
+
|
56
|
+
def set_layer_index(self,layername:str,index:int=-1):
|
57
|
+
index = min(index,len(self.scene_layers)-1)
|
58
|
+
layer = self.get_layer(layername)
|
59
|
+
if layer is None : return
|
60
|
+
self.scene_layers.remove(layer)
|
61
|
+
self.scene_layers.insert(index,layer)
|
62
|
+
|
63
|
+
def get_layer(self,name:str)->bf.SceneLayer:
|
64
|
+
for s in self.scene_layers:
|
65
|
+
if s.name == name:
|
66
|
+
return s
|
67
|
+
return None
|
68
|
+
|
69
|
+
def add(self,layer:str,*entities):
|
70
|
+
l = self.get_layer(layer)
|
71
|
+
if l is None : return
|
72
|
+
l.add(*entities)
|
73
|
+
|
74
|
+
def remove(self,layer:str,*entities):
|
75
|
+
l = self.get_layer(layer)
|
76
|
+
if l is None : return
|
77
|
+
l.remove(*entities)
|
78
|
+
|
79
|
+
def __str__(self)->str:
|
80
|
+
return f"Scene({self.name})"
|
81
|
+
|
82
|
+
def set_scene_index(self, index: int):
|
83
|
+
"""Set the scene index."""
|
84
|
+
self.scene_index = index
|
85
|
+
|
86
|
+
def get_scene_index(self) -> int:
|
87
|
+
"""Get the scene index."""
|
88
|
+
return self.scene_index
|
89
|
+
|
90
|
+
def when_added(self):
|
91
|
+
for s in self.scene_layers:
|
92
|
+
s.flush_entity_changes()
|
93
|
+
self.do_when_added()
|
94
|
+
|
95
|
+
def do_when_added(self):
|
96
|
+
pass
|
97
|
+
|
98
|
+
def set_manager(self, manager_link: Manager):
|
99
|
+
"""Set the manager link for the scene."""
|
100
|
+
self.manager = manager_link
|
101
|
+
self.manager.update_scene_states()
|
102
|
+
|
103
|
+
def set_visible(self, value: bool):
|
104
|
+
"""Set the visibility of the scene."""
|
105
|
+
self.visible = value
|
106
|
+
if self.manager:
|
107
|
+
self.manager.update_scene_states()
|
108
|
+
|
109
|
+
def set_active(self, value):
|
110
|
+
"""Set the activity of the scene."""
|
111
|
+
self.active = value
|
112
|
+
if self.manager:
|
113
|
+
self.manager.update_scene_states()
|
114
|
+
|
115
|
+
def is_active(self) -> bool:
|
116
|
+
"""Check if the scene is active."""
|
117
|
+
return self.active
|
118
|
+
|
119
|
+
def is_visible(self) -> bool:
|
120
|
+
"""Check if the scene is visible."""
|
121
|
+
return self.visible
|
122
|
+
|
123
|
+
def get_name(self) -> str:
|
124
|
+
"""Get the name of the scene."""
|
125
|
+
return self.name
|
126
|
+
|
127
|
+
def get_by_tags(self, *tags):
|
128
|
+
"""Get entities by their tags."""
|
129
|
+
return itertools.chain.from_iterable(l.get_by_tags(*tags) for l in self.scene_layers)
|
130
|
+
|
131
|
+
def get_by_uid(self, uid) -> bf.Entity | None:
|
132
|
+
"""Get an entity by its unique identifier."""
|
133
|
+
for l in self.scene_layers:
|
134
|
+
r = l.get_by_uid(uid)
|
135
|
+
if r is not None:
|
136
|
+
return r
|
137
|
+
return None
|
138
|
+
|
139
|
+
def add_actions(self, *action):
|
140
|
+
"""Add actions to the scene."""
|
141
|
+
self.actions.add_actions(*action)
|
142
|
+
|
143
|
+
def add_early_actions(self, *action):
|
144
|
+
"""Add actions to the scene."""
|
145
|
+
self.early_actions.add_actions(*action)
|
146
|
+
|
147
|
+
def process_event(self, event: pygame.Event):
|
148
|
+
"""
|
149
|
+
Propagates event while it is not consumed.
|
150
|
+
In order : do_early_handle_event
|
151
|
+
-> scene early_actions
|
152
|
+
-> propagate to all layers
|
153
|
+
-> handle_event
|
154
|
+
-> scene actions.
|
155
|
+
at each step, if the event is consumed the propagation stops
|
156
|
+
"""
|
157
|
+
self.do_early_handle_event(event)
|
158
|
+
if event.consumed: return
|
159
|
+
self.early_actions.process_event(event)
|
160
|
+
if event.consumed: return
|
161
|
+
|
162
|
+
if self.manager.current_transition and event.type in bf.enums.playerInput:
|
163
|
+
return
|
164
|
+
|
165
|
+
for l in self.scene_layers:
|
166
|
+
l.process_event(event)
|
167
|
+
if event.consumed : return
|
168
|
+
|
169
|
+
self.handle_event(event)
|
170
|
+
|
171
|
+
if event.consumed:return
|
172
|
+
self.actions.process_event(event)
|
173
|
+
|
174
|
+
# called before process event
|
175
|
+
def do_early_handle_event(self, event: pygame.Event):
|
176
|
+
"""Called early in event propagation"""
|
177
|
+
pass
|
178
|
+
|
179
|
+
def handle_event(self, event: pygame.Event):
|
180
|
+
"""called inside process_event but before resetting the scene's action container and propagating event to scene layers"""
|
181
|
+
pass
|
182
|
+
|
183
|
+
def update(self, dt):
|
184
|
+
"""Update the scene. Do NOT override"""
|
185
|
+
|
186
|
+
#update all scene layers
|
187
|
+
for l in self.scene_layers:
|
188
|
+
l.update(dt)
|
189
|
+
self.do_update(dt)
|
190
|
+
self.actions.reset()
|
191
|
+
self.early_actions.reset()
|
192
|
+
|
193
|
+
|
194
|
+
def do_update(self, dt):
|
195
|
+
"""Specific update within the scene."""
|
196
|
+
pass
|
197
|
+
|
198
|
+
|
199
|
+
def draw(self, surface: pygame.Surface):
|
200
|
+
if self.clear_color is not None:
|
201
|
+
surface.fill(self.clear_color)
|
202
|
+
self.do_early_draw(surface)
|
203
|
+
|
204
|
+
# Draw all layers back to front
|
205
|
+
for i,l in enumerate(reversed(self.scene_layers)):
|
206
|
+
#blit all layers onto surface
|
207
|
+
l.draw(surface)
|
208
|
+
if i < len(self.scene_layers)-1:
|
209
|
+
self.do_between_layer_draw(surface,l)
|
210
|
+
self.do_final_draw(surface)
|
211
|
+
|
212
|
+
|
213
|
+
def do_early_draw(self, surface: pygame.Surface):
|
214
|
+
"""Called before any layer draw"""
|
215
|
+
pass
|
216
|
+
|
217
|
+
def do_between_layer_draw(self, surface: pygame.Surface,layer:SceneLayer):
|
218
|
+
"""Called after drawing the argument layer (except the last layer)"""
|
219
|
+
pass
|
220
|
+
|
221
|
+
def do_final_draw(self, surface: pygame.Surface):
|
222
|
+
"Called after all layers"
|
223
|
+
pass
|
224
|
+
|
225
|
+
def on_enter(self):
|
226
|
+
self.set_active(True)
|
227
|
+
self.set_visible(True)
|
228
|
+
bf.TimeManager().activate_register(self.name)
|
229
|
+
self.do_on_enter()
|
230
|
+
|
231
|
+
def on_exit(self):
|
232
|
+
self.set_active(False)
|
233
|
+
self.set_visible(False)
|
234
|
+
self.actions.hard_reset()
|
235
|
+
self.early_actions.hard_reset()
|
236
|
+
bf.TimeManager().deactivate_register(self.name)
|
237
|
+
self.do_on_exit()
|
238
|
+
|
239
|
+
def do_on_enter(self) -> None:
|
240
|
+
pass
|
241
|
+
|
242
|
+
def do_on_exit(self) -> None:
|
243
|
+
pass
|
244
|
+
|
245
|
+
def do_on_enter_early(self) -> None:
|
246
|
+
pass
|
247
|
+
|
248
|
+
def do_on_exit_early(self) -> None:
|
249
|
+
pass
|