batframework 1.0.9a10__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.
Files changed (73) hide show
  1. batFramework/__init__.py +2 -0
  2. batFramework/action.py +280 -279
  3. batFramework/actionContainer.py +105 -82
  4. batFramework/animatedSprite.py +80 -58
  5. batFramework/animation.py +91 -77
  6. batFramework/audioManager.py +156 -131
  7. batFramework/baseScene.py +249 -240
  8. batFramework/camera.py +245 -317
  9. batFramework/constants.py +57 -51
  10. batFramework/cutscene.py +239 -253
  11. batFramework/cutsceneManager.py +34 -34
  12. batFramework/drawable.py +107 -77
  13. batFramework/dynamicEntity.py +30 -30
  14. batFramework/easingController.py +58 -58
  15. batFramework/entity.py +130 -130
  16. batFramework/enums.py +171 -135
  17. batFramework/fontManager.py +65 -65
  18. batFramework/gui/__init__.py +28 -25
  19. batFramework/gui/animatedLabel.py +90 -89
  20. batFramework/gui/button.py +17 -17
  21. batFramework/gui/clickableWidget.py +244 -245
  22. batFramework/gui/collapseContainer.py +98 -0
  23. batFramework/gui/constraints/__init__.py +1 -1
  24. batFramework/gui/constraints/constraints.py +1066 -980
  25. batFramework/gui/container.py +220 -201
  26. batFramework/gui/debugger.py +140 -130
  27. batFramework/gui/draggableWidget.py +63 -44
  28. batFramework/gui/image.py +61 -58
  29. batFramework/gui/indicator.py +116 -113
  30. batFramework/gui/interactiveWidget.py +243 -239
  31. batFramework/gui/label.py +147 -344
  32. batFramework/gui/layout.py +442 -426
  33. batFramework/gui/meter.py +155 -96
  34. batFramework/gui/radioButton.py +43 -35
  35. batFramework/gui/root.py +228 -228
  36. batFramework/gui/scrollingContainer.py +282 -0
  37. batFramework/gui/selector.py +232 -250
  38. batFramework/gui/shape.py +286 -276
  39. batFramework/gui/slider.py +353 -397
  40. batFramework/gui/style.py +10 -10
  41. batFramework/gui/styleManager.py +49 -54
  42. batFramework/gui/syncedVar.py +43 -49
  43. batFramework/gui/textInput.py +331 -306
  44. batFramework/gui/textWidget.py +308 -0
  45. batFramework/gui/toggle.py +140 -128
  46. batFramework/gui/tooltip.py +35 -30
  47. batFramework/gui/widget.py +546 -521
  48. batFramework/manager.py +131 -134
  49. batFramework/particle.py +118 -118
  50. batFramework/propertyEaser.py +79 -79
  51. batFramework/renderGroup.py +34 -34
  52. batFramework/resourceManager.py +130 -130
  53. batFramework/scene.py +31 -31
  54. batFramework/sceneLayer.py +134 -138
  55. batFramework/sceneManager.py +200 -197
  56. batFramework/scrollingSprite.py +115 -115
  57. batFramework/sprite.py +46 -51
  58. batFramework/stateMachine.py +49 -54
  59. batFramework/templates/__init__.py +2 -1
  60. batFramework/templates/character.py +15 -0
  61. batFramework/templates/controller.py +158 -97
  62. batFramework/templates/stateMachine.py +39 -0
  63. batFramework/tileset.py +46 -46
  64. batFramework/timeManager.py +213 -213
  65. batFramework/transition.py +162 -162
  66. batFramework/triggerZone.py +22 -22
  67. batFramework/utils.py +306 -306
  68. {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/LICENSE +20 -20
  69. {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/METADATA +24 -17
  70. batframework-1.0.9a12.dist-info/RECORD +72 -0
  71. batframework-1.0.9a10.dist-info/RECORD +0 -67
  72. {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/WHEEL +0 -0
  73. {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/top_level.txt +0 -0
@@ -1,138 +1,134 @@
1
- from __future__ import annotations
2
- import batFramework as bf
3
- import pygame
4
- from .entity import Entity
5
- from .drawable import Drawable
6
-
7
- from typing import TYPE_CHECKING, Any
8
- if TYPE_CHECKING:
9
- from .baseScene import BaseScene
10
-
11
- class SceneLayer:
12
- """
13
- A scene layer is a 'dimension' bound to a scene
14
- Each layer contains its own entities and camera
15
- One common use would be to separate GUI and game into two separate layers
16
- """
17
- def __init__(self,name:str,convert_alpha:bool = False):
18
- self.scene = None
19
- self.name = name
20
- self.entities : dict[int,Entity] = {}
21
- self.entities_to_add : set[Entity]= set()
22
- self.entities_to_remove : set[Entity]= set()
23
- self.draw_order : list[int] = []
24
- self.camera = bf.Camera(convert_alpha=convert_alpha)
25
-
26
- def set_clear_color(self,color):
27
- self.camera.set_clear_color(color)
28
-
29
- def set_scene(self, scene:BaseScene):
30
- self.scene = scene
31
-
32
- def add(self,*entities:Entity):
33
- for e in entities:
34
- if e.uid not in self.entities and e not in self.entities_to_add:
35
- self.entities_to_add.add(e)
36
-
37
-
38
- def get_by_tags(self,*tags)->list[Entity]:
39
- return [v for v in self.entities.values() if v.has_tags(*tags) ]
40
-
41
- def get_by_uid(self,uid:int)->Entity|None:
42
- return self.entities.get(uid,None)
43
-
44
- def remove(self,*entities:Entity):
45
- for e in entities:
46
- if e.uid in self.entities and e not in self.entities_to_remove:
47
- self.entities_to_remove.add(e)
48
-
49
- def process_event(self,event:pygame.Event):
50
- if event.type == pygame.VIDEORESIZE and not pygame.SCALED & bf.const.FLAGS:
51
- self.camera.set_size(bf.const.RESOLUTION)
52
-
53
- for e in self.entities.values():
54
- e.process_event(event)
55
- if event.consumed : return
56
-
57
- def update(self, dt):
58
- # Update all entities
59
- for e in self.entities.values():
60
- e.update(dt)
61
-
62
- self.flush_entity_changes()
63
-
64
- # Update the camera
65
- self.camera.update(dt)
66
-
67
- def flush_entity_changes(self):
68
- """
69
- Synchronizes entity changes by removing entities marked for removal,
70
- adding new entities, and updating the draw order if necessary.
71
- """
72
-
73
-
74
- # Remove entities marked for removal
75
- for e in self.entities_to_remove:
76
- if e.uid in self.entities.keys():
77
- e.set_parent_scene(None)
78
- self.entities.pop(e.uid)
79
- self.entities_to_remove.clear()
80
-
81
- # Add new entities
82
- reorder = False
83
- for e in self.entities_to_add:
84
- self.entities[e.uid] = e
85
- e.set_parent_layer(self)
86
- e.set_parent_scene(self.scene)
87
- if not reorder and isinstance(e, Drawable):
88
- reorder = True
89
- self.entities_to_add.clear()
90
-
91
- # Reorder draw order if necessary
92
- if reorder:
93
- self.update_draw_order()
94
-
95
- def clear(self):
96
- """
97
- Clear the camera surface
98
- """
99
- self.camera.clear()
100
-
101
- def draw(self, surface: pygame.Surface):
102
- self.camera.clear()
103
- debugMode = bf.ResourceManager().get_sharedVar("debug_mode")
104
- # Draw entities in the correct order
105
- for uid in self.draw_order:
106
- if uid in self.entities and not self.entities[uid].drawn_by_group: # Ensure the entity still exists
107
- self.entities[uid].draw(self.camera)
108
-
109
- # Draw debug outlines if in debug mode
110
- if debugMode == bf.debugMode.OUTLINES:
111
- [self.debug_entity(uid) for uid in self.draw_order if uid in self.entities]
112
-
113
- # Blit the camera surface onto the provided surface
114
- # surface.blit(self.camera.surface, (0, 0))
115
- self.camera.draw(surface)
116
-
117
- def update_draw_order(self):
118
- self.draw_order = sorted(
119
- (k for k,v in self.entities.items() if isinstance(v,Drawable) and not v.drawn_by_group),
120
- key= lambda uid : self.entities[uid].render_order
121
- )
122
-
123
- def debug_entity(self, uid: int):
124
- entity = self.entities[uid]
125
- def draw_rect(data):
126
- if data is None:
127
- return
128
- if isinstance(data, pygame.FRect) or isinstance(data, pygame.Rect):
129
- rect = data
130
- color = entity.debug_color
131
- else:
132
- rect = data[0]
133
- color = data[1]
134
- if self.camera.intersects(rect):
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)