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/sceneLayer.py
CHANGED
@@ -1,138 +1,134 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
from .
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
self.
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.
|
25
|
-
|
26
|
-
|
27
|
-
self.camera.
|
28
|
-
|
29
|
-
def
|
30
|
-
self.
|
31
|
-
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def
|
42
|
-
return self.entities.
|
43
|
-
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
self.
|
63
|
-
|
64
|
-
|
65
|
-
self.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"""
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
e.
|
86
|
-
e.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
#
|
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
|
-
pygame.draw.rect(self.camera.surface, color, self.camera.world_to_screen(rect), 1)
|
136
|
-
|
137
|
-
for data in entity.get_debug_outlines():
|
138
|
-
draw_rect(data)
|
1
|
+
from __future__ import annotations
|
2
|
+
import math
|
3
|
+
import batFramework as bf
|
4
|
+
import pygame
|
5
|
+
from .entity import Entity
|
6
|
+
from .drawable import Drawable
|
7
|
+
|
8
|
+
from typing import TYPE_CHECKING, Any
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from .baseScene import BaseScene
|
11
|
+
|
12
|
+
class SceneLayer:
|
13
|
+
"""
|
14
|
+
A scene layer is a 'dimension' bound to a scene
|
15
|
+
Each layer contains its own entities and camera
|
16
|
+
Allows sorting out different types of content in a single scene
|
17
|
+
One common use would be to separate GUI and game into two separate layers
|
18
|
+
Entities are drawn only if they inherit the Drawable class and are not in a RenderGroup
|
19
|
+
"""
|
20
|
+
def __init__(self,name:str,convert_alpha:bool = False):
|
21
|
+
self.scene = None
|
22
|
+
self.name = name
|
23
|
+
self.entities : dict[int,Entity] = {} # contains all scene entities : key is uid
|
24
|
+
self.entities_to_add : set[Entity]= set() # entities to add to the scene, (1 frame delay after calling add)
|
25
|
+
self.entities_to_remove : set[Entity]= set() # entities to remove from the scene
|
26
|
+
self.draw_order : list[int] = [] # stores the uid of entities to draw (in draw order)
|
27
|
+
self.camera = bf.Camera(convert_alpha=convert_alpha)
|
28
|
+
|
29
|
+
def set_clear_color(self,color):
|
30
|
+
self.camera.set_clear_color(color)
|
31
|
+
|
32
|
+
def set_scene(self, scene:BaseScene):
|
33
|
+
self.scene = scene
|
34
|
+
|
35
|
+
def add(self,*entities:Entity):
|
36
|
+
for e in entities:
|
37
|
+
if e.uid not in self.entities and e not in self.entities_to_add:
|
38
|
+
self.entities_to_add.add(e)
|
39
|
+
|
40
|
+
|
41
|
+
def get_by_tags(self,*tags)->list[Entity]:
|
42
|
+
return [v for v in self.entities.values() if v.has_tags(*tags) ]
|
43
|
+
|
44
|
+
def get_by_uid(self,uid:int)->Entity|None:
|
45
|
+
return self.entities.get(uid,None)
|
46
|
+
|
47
|
+
def remove(self,*entities:Entity):
|
48
|
+
for e in entities:
|
49
|
+
if e.uid in self.entities and e not in self.entities_to_remove:
|
50
|
+
self.entities_to_remove.add(e)
|
51
|
+
|
52
|
+
def process_event(self,event:pygame.Event):
|
53
|
+
if self.camera.fullscreen and event.type == pygame.VIDEORESIZE and not pygame.SCALED & bf.const.FLAGS:
|
54
|
+
self.camera.set_size(bf.const.RESOLUTION)
|
55
|
+
|
56
|
+
for e in self.entities.values():
|
57
|
+
e.process_event(event)
|
58
|
+
if event.consumed : return
|
59
|
+
|
60
|
+
def update(self, dt):
|
61
|
+
# Update all entities
|
62
|
+
for e in self.entities.values():
|
63
|
+
e.update(dt)
|
64
|
+
|
65
|
+
self.flush_entity_changes()
|
66
|
+
|
67
|
+
# Update the camera
|
68
|
+
self.camera.update(dt)
|
69
|
+
|
70
|
+
def flush_entity_changes(self):
|
71
|
+
"""
|
72
|
+
Synchronizes entity changes by removing entities marked for removal,
|
73
|
+
adding new entities, and updating the draw order if necessary.
|
74
|
+
"""
|
75
|
+
# Remove entities marked for removal
|
76
|
+
for e in self.entities_to_remove:
|
77
|
+
if e.uid in self.entities.keys():
|
78
|
+
e.set_parent_scene(None)
|
79
|
+
self.entities.pop(e.uid)
|
80
|
+
self.entities_to_remove.clear()
|
81
|
+
|
82
|
+
# Add new entities
|
83
|
+
reorder = False
|
84
|
+
for e in self.entities_to_add:
|
85
|
+
self.entities[e.uid] = e
|
86
|
+
e.set_parent_layer(self)
|
87
|
+
e.set_parent_scene(self.scene)
|
88
|
+
if not reorder and isinstance(e, Drawable):
|
89
|
+
reorder = True
|
90
|
+
self.entities_to_add.clear()
|
91
|
+
|
92
|
+
# Reorder draw order if necessary
|
93
|
+
if reorder:
|
94
|
+
self.update_draw_order()
|
95
|
+
|
96
|
+
|
97
|
+
def draw(self, surface: pygame.Surface):
|
98
|
+
self.camera.clear()
|
99
|
+
debugMode = bf.ResourceManager().get_sharedVar("debug_mode")
|
100
|
+
# Draw entities in the correct order
|
101
|
+
for uid in self.draw_order:
|
102
|
+
if uid in self.entities and not self.entities[uid].drawn_by_group: # Ensure the entity still exists
|
103
|
+
self.entities[uid].draw(self.camera)
|
104
|
+
|
105
|
+
# Draw debug outlines if in debug mode
|
106
|
+
if debugMode == bf.debugMode.OUTLINES:
|
107
|
+
[self.debug_entity(uid) for uid in self.draw_order if uid in self.entities]
|
108
|
+
|
109
|
+
# surface.fill("white")
|
110
|
+
self.camera.draw(surface)
|
111
|
+
|
112
|
+
def update_draw_order(self):
|
113
|
+
self.draw_order = sorted(
|
114
|
+
(k for k,v in self.entities.items() if isinstance(v,Drawable) and not v.drawn_by_group),
|
115
|
+
key= lambda uid : self.entities[uid].render_order
|
116
|
+
)
|
117
|
+
|
118
|
+
def debug_entity(self, uid: int):
|
119
|
+
entity = self.entities[uid]
|
120
|
+
def draw_rect(data):
|
121
|
+
if data is None:
|
122
|
+
return
|
123
|
+
if isinstance(data, pygame.FRect) or isinstance(data, pygame.Rect):
|
124
|
+
rect = data
|
125
|
+
color = entity.debug_color
|
126
|
+
else:
|
127
|
+
rect = data[0]
|
128
|
+
color = data[1]
|
129
|
+
if self.camera.intersects(rect):
|
130
|
+
line_width = 1 if self.camera.zoom_factor >= 1 else int(-math.log2(self.camera.zoom_factor)) + 2
|
131
|
+
pygame.draw.rect(self.camera.surface, color, self.camera.world_to_screen(rect), line_width )
|
132
|
+
|
133
|
+
for data in entity.get_debug_outlines():
|
134
|
+
draw_rect(data)
|