batframework 1.1.0__py3-none-any.whl → 2.0.0a1__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 (81) hide show
  1. batFramework/__init__.py +84 -52
  2. batFramework/action.py +280 -252
  3. batFramework/actionContainer.py +105 -38
  4. batFramework/animatedSprite.py +81 -117
  5. batFramework/animation.py +91 -0
  6. batFramework/audioManager.py +156 -85
  7. batFramework/baseScene.py +249 -0
  8. batFramework/camera.py +245 -123
  9. batFramework/constants.py +57 -75
  10. batFramework/cutscene.py +239 -119
  11. batFramework/cutsceneManager.py +34 -0
  12. batFramework/drawable.py +107 -0
  13. batFramework/dynamicEntity.py +30 -23
  14. batFramework/easingController.py +58 -0
  15. batFramework/entity.py +130 -123
  16. batFramework/enums.py +171 -0
  17. batFramework/fontManager.py +65 -0
  18. batFramework/gui/__init__.py +28 -14
  19. batFramework/gui/animatedLabel.py +90 -0
  20. batFramework/gui/button.py +18 -84
  21. batFramework/gui/clickableWidget.py +244 -0
  22. batFramework/gui/collapseContainer.py +98 -0
  23. batFramework/gui/constraints/__init__.py +1 -0
  24. batFramework/gui/constraints/constraints.py +1066 -0
  25. batFramework/gui/container.py +220 -49
  26. batFramework/gui/debugger.py +140 -47
  27. batFramework/gui/draggableWidget.py +63 -0
  28. batFramework/gui/image.py +61 -23
  29. batFramework/gui/indicator.py +116 -40
  30. batFramework/gui/interactiveWidget.py +243 -22
  31. batFramework/gui/label.py +147 -110
  32. batFramework/gui/layout.py +442 -81
  33. batFramework/gui/meter.py +155 -0
  34. batFramework/gui/radioButton.py +43 -0
  35. batFramework/gui/root.py +228 -60
  36. batFramework/gui/scrollingContainer.py +282 -0
  37. batFramework/gui/selector.py +232 -0
  38. batFramework/gui/shape.py +286 -86
  39. batFramework/gui/slider.py +353 -0
  40. batFramework/gui/style.py +10 -0
  41. batFramework/gui/styleManager.py +49 -0
  42. batFramework/gui/syncedVar.py +43 -0
  43. batFramework/gui/textInput.py +331 -0
  44. batFramework/gui/textWidget.py +308 -0
  45. batFramework/gui/toggle.py +140 -62
  46. batFramework/gui/tooltip.py +35 -0
  47. batFramework/gui/widget.py +546 -307
  48. batFramework/manager.py +131 -50
  49. batFramework/particle.py +118 -0
  50. batFramework/propertyEaser.py +79 -0
  51. batFramework/renderGroup.py +34 -0
  52. batFramework/resourceManager.py +130 -0
  53. batFramework/scene.py +31 -226
  54. batFramework/sceneLayer.py +134 -0
  55. batFramework/sceneManager.py +200 -165
  56. batFramework/scrollingSprite.py +115 -0
  57. batFramework/sprite.py +46 -0
  58. batFramework/stateMachine.py +49 -51
  59. batFramework/templates/__init__.py +2 -0
  60. batFramework/templates/character.py +15 -0
  61. batFramework/templates/controller.py +158 -0
  62. batFramework/templates/stateMachine.py +39 -0
  63. batFramework/tileset.py +46 -0
  64. batFramework/timeManager.py +213 -0
  65. batFramework/transition.py +162 -157
  66. batFramework/triggerZone.py +22 -22
  67. batFramework/utils.py +306 -184
  68. {batframework-1.1.0.dist-info → batframework-2.0.0a1.dist-info}/LICENSE +20 -20
  69. {batframework-1.1.0.dist-info → batframework-2.0.0a1.dist-info}/METADATA +7 -2
  70. batframework-2.0.0a1.dist-info/RECORD +72 -0
  71. batFramework/cutsceneBlocks.py +0 -176
  72. batFramework/debugger.py +0 -48
  73. batFramework/easing.py +0 -71
  74. batFramework/gui/constraints.py +0 -204
  75. batFramework/gui/frame.py +0 -19
  76. batFramework/particles.py +0 -77
  77. batFramework/time.py +0 -75
  78. batFramework/transitionManager.py +0 -0
  79. batframework-1.1.0.dist-info/RECORD +0 -43
  80. {batframework-1.1.0.dist-info → batframework-2.0.0a1.dist-info}/WHEEL +0 -0
  81. {batframework-1.1.0.dist-info → batframework-2.0.0a1.dist-info}/top_level.txt +0 -0
@@ -1,157 +1,162 @@
1
- import pygame
2
- import batFramework as bf
3
-
4
-
5
- class BaseTransition:
6
- def __init__(
7
- self,
8
- source_surf: pygame.Surface,
9
- dest_surf: pygame.Surface,
10
- duration=100,
11
- **kwargs,
12
- ) -> None:
13
- self.source = source_surf
14
- self.dest = dest_surf
15
- self.ended = False
16
- self.source_scene_name = ""
17
- self.dest_scene_name = ""
18
- self.duration = duration
19
- self.index = 0
20
-
21
- def set_scene_index(self,index):
22
- self.index = index
23
-
24
- def set_source_name(self, name):
25
- self.source_scene_name = name
26
-
27
- def set_dest_name(self, name):
28
- self.dest_scene_name = name
29
-
30
- def update(self, dt):
31
- pass
32
-
33
- def draw(self, surface):
34
- pass
35
-
36
- def has_ended(self):
37
- return False
38
-
39
- def set_ended(self, val):
40
- self.ended = val
41
-
42
-
43
- class FadeColorTransition(BaseTransition):
44
- def __init__(
45
- self,
46
- source_surf,
47
- dest_surf,
48
- duration=600,
49
- color_duration=200,
50
- color=bf.color.CLOUD_WHITE,
51
- **kwargs,
52
- ) -> None:
53
- super().__init__(source_surf, dest_surf, duration)
54
- self.target_time = duration * 2 + color_duration
55
- self.color_surf = pygame.Surface((source_surf.get_rect().size)).convert_alpha()
56
- self.color_surf.fill(color)
57
- self.ease_out = bf.EasingAnimation(
58
- easing_function=bf.Easing.EASE_IN,
59
- duration=(duration-color_duration)//2,
60
- update_callback = lambda x: self.color_surf.set_alpha(int(255 - (255 * x))),
61
- end_callback=lambda: self.set_ended(True))
62
-
63
- self.color_timer = bf.Timer(
64
- duration=color_duration,
65
- end_callback=lambda: self.set_state("out"))
66
- self.ease_in = bf.EasingAnimation(
67
- easing_function=bf.Easing.EASE_IN,
68
- duration=(duration-color_duration)//2,
69
- update_callback=lambda x: self.color_surf.set_alpha(int(255 * x)),
70
- # update_callback=lambda x: print(x),
71
- end_callback=lambda: self.set_state("color"))
72
- self.state = None
73
-
74
- self.state = "in"
75
- self.ease_in.start()
76
-
77
- def set_state(self, state: str):
78
- self.state = state
79
- if state == "in":
80
- self.ease_in.start()
81
- elif state == "color":
82
- self.color_timer.start()
83
- elif state == "out":
84
- self.ease_out.start()
85
-
86
- def has_ended(self):
87
- return self.ended
88
-
89
- def set_ended(self, val):
90
- super().set_ended(val)
91
-
92
- def draw(self, surface):
93
- if self.state != "color":
94
- surface.blit(self.source if self.state == "in" else self.dest, (0, 0))
95
- surface.blit(self.color_surf, (0, 0))
96
-
97
-
98
- class FadeTransition(BaseTransition):
99
- def __init__(self, source_surf, dest_surf, duration=500) -> None:
100
- super().__init__(source_surf, dest_surf)
101
- self.anim = bf.EasingAnimation(None,bf.Easing.EASE_IN_OUT,duration,self.update_surface,lambda : self.set_ended(True))
102
- self.anim.start()
103
-
104
- def update_surface(self,progress):
105
- self.source.set_alpha(int(255 - (255 * progress)))
106
- self.dest.set_alpha(int(255 * progress))
107
-
108
- def has_ended(self):
109
- return self.ended
110
-
111
- def draw(self, surface):
112
- surface.blit(self.source, (0, 0))
113
- surface.blit(self.dest, (0, 0))
114
-
115
-
116
- class SlideTransition(BaseTransition):
117
- def __init__(
118
- self,
119
- source_surf,
120
- dest_surf,
121
- duration=1000,
122
- source_alignment: bf.Alignment = bf.Alignment.BOTTOM,
123
- easing: bf.Easing = bf.Easing.EASE_IN_OUT,
124
- **kwargs,
125
- ) -> None:
126
- super().__init__(source_surf, dest_surf, duration)
127
- self.offset = pygame.Vector2(0, 0)
128
- if source_alignment in [bf.Alignment.TOP, bf.Alignment.BOTTOM]:
129
- self.offset.y = bf.const.RESOLUTION[1]
130
- if source_alignment == bf.Alignment.TOP:
131
- self.offset.y *= -1
132
- elif source_alignment in [bf.Alignment.LEFT, bf.Alignment.RIGHT]:
133
- self.offset.x = bf.const.RESOLUTION[0]
134
- if source_alignment == bf.Alignment.LEFT:
135
- self.offset.x *= -1
136
- else:
137
- self.offset.x = -bf.const.RESOLUTION[0]
138
- print(
139
- f"Unsupported Alignment : {source_alignment.value}, set to default : {bf.Alignment.LEFT.value} "
140
- )
141
- self.anim = bf.EasingAnimation(
142
- easing_function=easing,
143
- duration=duration,
144
- update_callback =lambda x: self.update_offset(self.offset.lerp((0, 0), x)),
145
- end_callback =lambda: self.set_ended(True),
146
- )
147
- self.anim.start()
148
-
149
- def update_offset(self, vec):
150
- self.offset.update(vec)
151
-
152
- def has_ended(self):
153
- return self.ended
154
-
155
- def draw(self, surface):
156
- surface.blit(self.source, (0, 0))
157
- surface.blit(self.dest, self.offset)
1
+ import batFramework as bf
2
+ from typing import Self,Callable,Any
3
+ import pygame
4
+
5
+ """
6
+ Both surfaces to transition need to be the same size
7
+
8
+ """
9
+
10
+
11
+ class Transition:
12
+ def __init__(
13
+ self, duration: float=1, easing: bf.easing = bf.easing.LINEAR
14
+ ) -> None:
15
+ """
16
+ duration : time in seconds
17
+ easing function : controls the progression rate
18
+ """
19
+ self.duration: float = duration
20
+ self.controller = bf.EasingController( # main controller for the transition progression
21
+ duration,easing,
22
+ update_callback=self.update,end_callback=self.end,
23
+ )
24
+ self.source: pygame.Surface = None
25
+ self.dest: pygame.Surface = None
26
+ self.is_over : bool = False # this flag tells the manager the transition is over
27
+
28
+ def __repr__(self) -> str:
29
+ return f"Transition ({self.__class__},{self.duration})"
30
+
31
+ def set_source(self, surface: pygame.Surface) -> None:
32
+ self.source = surface
33
+
34
+ def set_dest(self, surface: pygame.Surface) -> None:
35
+ self.dest = surface
36
+
37
+ def start(self):
38
+ if self.controller.has_started(): # can't start again while it's in progress
39
+ return
40
+ if self.duration: # start the transition
41
+ self.controller.start()
42
+ return
43
+
44
+ # if no duration the transition is instantaneous
45
+ self.controller.start()
46
+ self.controller.end()
47
+ self.update(1)# to prevent weird behaviour, update once with progression at max value
48
+ self.end()
49
+
50
+ def update(self, progression: float) -> None:
51
+ pass
52
+
53
+ def end(self):
54
+ self.controller.stop()
55
+ self.is_over = True
56
+
57
+ def draw(self, surface: pygame.Surface) -> None:
58
+ pass
59
+
60
+ def skip(self):
61
+ self.end()
62
+
63
+
64
+
65
+ class FadeColor(Transition):
66
+ def __init__(self,duration:float,color=(0,0,0),color_start:float=0.3,color_end:float=0.7, easing = bf.easing.LINEAR):
67
+ super().__init__(duration, easing)
68
+ self.color = color
69
+ self.color_start = color_start
70
+ self.color_end = color_end
71
+
72
+ def start(self):
73
+ super().start()
74
+ self.color_surf = pygame.Surface(self.source.get_size())
75
+ self.color_surf.fill(self.color)
76
+
77
+ def draw(self, surface):
78
+ v = self.controller.get_value()
79
+ if v < self.color_start:
80
+ v = v/(self.color_start)
81
+ self.color_surf.set_alpha(255*v)
82
+ surface.blit(self.source)
83
+ surface.blit(self.color_surf)
84
+
85
+ elif v < self.color_end:
86
+ self.color_surf.set_alpha(255)
87
+ surface.blit(self.color_surf)
88
+
89
+ else:
90
+ v = (v-self.color_end)/(1-self.color_end)
91
+ surface.blit(self.color_surf)
92
+ self.dest.set_alpha(255*v)
93
+ surface.blit(self.dest)
94
+
95
+ class Fade(Transition):
96
+ def end(self):
97
+ self.dest.set_alpha(255)
98
+ return super().end()
99
+
100
+ def start(self):
101
+ super().start()
102
+
103
+ def draw(self, surface):
104
+ dest_alpha = 255 * self.controller.get_value()
105
+ self.dest.set_alpha(dest_alpha)
106
+ surface.blit(self.source, (0, 0))
107
+ surface.blit(self.dest, (0, 0))
108
+
109
+ class GlideRight(Transition):
110
+ def draw(self, surface):
111
+ width = surface.get_width()
112
+ source_x = -self.controller.get_value() * width
113
+ surface.blit(self.source, (source_x, 0))
114
+ surface.blit(self.dest, (width + source_x, 0))
115
+
116
+
117
+ class GlideLeft(Transition):
118
+ def draw(self, surface):
119
+ width = surface.get_width()
120
+ source_x = self.controller.get_value() * width
121
+ surface.blit(self.source, (source_x, 0))
122
+ surface.blit(self.dest, (source_x - width, 0))
123
+
124
+
125
+ class CircleOut(Transition):
126
+ def start(self):
127
+ super().start()
128
+ self.circle_surf = self.source.copy()
129
+ self.circle_surf.set_colorkey((0, 0, 0))
130
+ self.circle_surf.fill((0, 0, 0))
131
+ self.surface_width = self.circle_surf.get_width()
132
+
133
+ def draw(self, surface):
134
+ v = self.controller.get_value()
135
+
136
+ radius = self.surface_width * v
137
+ pygame.draw.circle(
138
+ self.circle_surf, "white", self.circle_surf.get_rect().center, radius
139
+ )
140
+ mask = pygame.mask.from_surface(self.circle_surf)
141
+ mask.to_surface(surface=surface, setsurface=self.dest, unsetsurface=self.source)
142
+
143
+
144
+ class CircleIn(Transition):
145
+ def start(self):
146
+ super().start()
147
+ self.circle_surf = self.source.copy()
148
+ self.circle_surf.set_colorkey((0, 0, 0))
149
+ self.circle_surf.fill((0, 0, 0))
150
+ self.surface_width = self.circle_surf.get_width()
151
+
152
+ def draw(self, surface):
153
+ v = self.controller.get_value()
154
+ radius = self.surface_width - (self.surface_width * v)
155
+ self.circle_surf.fill((0, 0, 0))
156
+ pygame.draw.circle(
157
+ self.circle_surf, "white", self.circle_surf.get_rect().center, radius
158
+ )
159
+ mask = pygame.mask.from_surface(self.circle_surf)
160
+ mask.to_surface(surface=surface, setsurface=self.source, unsetsurface=self.dest)
161
+
162
+
@@ -1,22 +1,22 @@
1
- import batFramework as bf
2
-
3
-
4
- class TriggerZone(bf.Entity):
5
- def __init__(self, size, trigger, callback, active=True) -> None:
6
- super().__init__(size, True)
7
- self.set_debug_color(bf.color.RIVER_BLUE)
8
- self.active = active
9
- self.callback = callback
10
- self.trigger = trigger
11
-
12
- def set_trigger(self, trigger):
13
- self.trigger = trigger
14
- return self
15
-
16
- def set_callback(self, callback):
17
- self.callback = callback
18
- return self
19
-
20
- def update(self, dt):
21
- if self.active and self.trigger():
22
- self.callback()
1
+ import batFramework as bf
2
+ from typing import Callable,Any
3
+
4
+ class TriggerZone(bf.Entity):
5
+ def __init__(self, size, trigger, callback: Callable[[Any],Any], active=True) -> None:
6
+ super().__init__(size, True)
7
+ self.set_debug_color(bf.color.RED)
8
+ self.active = active
9
+ self.callback = callback
10
+ self.trigger = trigger
11
+
12
+ def set_trigger(self, trigger):
13
+ self.trigger = trigger
14
+ return self
15
+
16
+ def set_callback(self, callback: Callable[[Any],Any]):
17
+ self.callback = callback
18
+ return self
19
+
20
+ def update(self, dt):
21
+ if self.active and self.trigger():
22
+ self.callback()