batframework 1.0.9a11__py3-none-any.whl → 1.1.0__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 (76) hide show
  1. batFramework/__init__.py +52 -76
  2. batFramework/action.py +99 -126
  3. batFramework/actionContainer.py +9 -53
  4. batFramework/animatedSprite.py +114 -56
  5. batFramework/audioManager.py +36 -82
  6. batFramework/camera.py +69 -263
  7. batFramework/constants.py +53 -29
  8. batFramework/cutscene.py +109 -243
  9. batFramework/cutsceneBlocks.py +176 -0
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +9 -16
  12. batFramework/easing.py +71 -0
  13. batFramework/entity.py +85 -92
  14. batFramework/gui/__init__.py +3 -14
  15. batFramework/gui/button.py +78 -12
  16. batFramework/gui/constraints.py +204 -0
  17. batFramework/gui/container.py +31 -188
  18. batFramework/gui/debugger.py +43 -126
  19. batFramework/gui/frame.py +19 -0
  20. batFramework/gui/image.py +20 -55
  21. batFramework/gui/indicator.py +22 -95
  22. batFramework/gui/interactiveWidget.py +12 -229
  23. batFramework/gui/label.py +77 -311
  24. batFramework/gui/layout.py +66 -414
  25. batFramework/gui/root.py +35 -203
  26. batFramework/gui/shape.py +57 -247
  27. batFramework/gui/toggle.py +48 -114
  28. batFramework/gui/widget.py +243 -457
  29. batFramework/manager.py +29 -113
  30. batFramework/particles.py +77 -0
  31. batFramework/scene.py +217 -22
  32. batFramework/sceneManager.py +129 -161
  33. batFramework/stateMachine.py +8 -11
  34. batFramework/time.py +75 -0
  35. batFramework/transition.py +124 -129
  36. batFramework/transitionManager.py +0 -0
  37. batFramework/triggerZone.py +4 -4
  38. batFramework/utils.py +144 -266
  39. {batframework-1.0.9a11.dist-info → batframework-1.1.0.dist-info}/METADATA +24 -22
  40. batframework-1.1.0.dist-info/RECORD +43 -0
  41. batFramework/animation.py +0 -77
  42. batFramework/baseScene.py +0 -240
  43. batFramework/cutsceneManager.py +0 -34
  44. batFramework/drawable.py +0 -77
  45. batFramework/easingController.py +0 -58
  46. batFramework/enums.py +0 -135
  47. batFramework/fontManager.py +0 -65
  48. batFramework/gui/animatedLabel.py +0 -89
  49. batFramework/gui/clickableWidget.py +0 -244
  50. batFramework/gui/constraints/__init__.py +0 -1
  51. batFramework/gui/constraints/constraints.py +0 -980
  52. batFramework/gui/draggableWidget.py +0 -44
  53. batFramework/gui/meter.py +0 -96
  54. batFramework/gui/radioButton.py +0 -35
  55. batFramework/gui/selector.py +0 -250
  56. batFramework/gui/slider.py +0 -397
  57. batFramework/gui/style.py +0 -10
  58. batFramework/gui/styleManager.py +0 -54
  59. batFramework/gui/syncedVar.py +0 -49
  60. batFramework/gui/textInput.py +0 -306
  61. batFramework/gui/tooltip.py +0 -30
  62. batFramework/particle.py +0 -118
  63. batFramework/propertyEaser.py +0 -79
  64. batFramework/renderGroup.py +0 -34
  65. batFramework/resourceManager.py +0 -130
  66. batFramework/sceneLayer.py +0 -138
  67. batFramework/scrollingSprite.py +0 -115
  68. batFramework/sprite.py +0 -51
  69. batFramework/templates/__init__.py +0 -1
  70. batFramework/templates/controller.py +0 -97
  71. batFramework/tileset.py +0 -46
  72. batFramework/timeManager.py +0 -213
  73. batframework-1.0.9a11.dist-info/RECORD +0 -67
  74. {batframework-1.0.9a11.dist-info → batframework-1.1.0.dist-info}/LICENSE +0 -0
  75. {batframework-1.0.9a11.dist-info → batframework-1.1.0.dist-info}/WHEEL +0 -0
  76. {batframework-1.0.9a11.dist-info → batframework-1.1.0.dist-info}/top_level.txt +0 -0
@@ -1,162 +1,157 @@
1
- import batFramework as bf
2
- from typing import Self,Callable,Any
3
1
  import pygame
4
-
5
- """
6
- Both surfaces to transition need to be the same size
7
-
8
- """
2
+ import batFramework as bf
9
3
 
10
4
 
11
- class Transition:
5
+ class BaseTransition:
12
6
  def __init__(
13
- self, duration: float=1, easing: bf.easing = bf.easing.LINEAR
7
+ self,
8
+ source_surf: pygame.Surface,
9
+ dest_surf: pygame.Surface,
10
+ duration=100,
11
+ **kwargs,
14
12
  ) -> 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
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
33
20
 
34
- def set_dest(self, surface: pygame.Surface) -> None:
35
- self.dest = surface
21
+ def set_scene_index(self,index):
22
+ self.index = index
36
23
 
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
24
+ def set_source_name(self, name):
25
+ self.source_scene_name = name
43
26
 
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()
27
+ def set_dest_name(self, name):
28
+ self.dest_scene_name = name
49
29
 
50
- def update(self, progression: float) -> None:
30
+ def update(self, dt):
51
31
  pass
52
32
 
53
- def end(self):
54
- self.controller.stop()
55
- self.is_over = True
56
-
57
- def draw(self, surface: pygame.Surface) -> None:
33
+ def draw(self, surface):
58
34
  pass
59
35
 
60
- def skip(self):
61
- self.end()
36
+ def has_ended(self):
37
+ return False
62
38
 
39
+ def set_ended(self, val):
40
+ self.ended = val
63
41
 
64
42
 
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)
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)
76
91
 
77
92
  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)
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))
84
96
 
85
- elif v < self.color_end:
86
- self.color_surf.set_alpha(255)
87
- surface.blit(self.color_surf)
88
97
 
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)
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()
94
103
 
95
- class Fade(Transition):
96
- def end(self):
97
- self.dest.set_alpha(255)
98
- return super().end()
104
+ def update_surface(self,progress):
105
+ self.source.set_alpha(int(255 - (255 * progress)))
106
+ self.dest.set_alpha(int(255 * progress))
99
107
 
100
- def start(self):
101
- super().start()
108
+ def has_ended(self):
109
+ return self.ended
102
110
 
103
111
  def draw(self, surface):
104
- dest_alpha = 255 * self.controller.get_value()
105
- self.dest.set_alpha(dest_alpha)
106
112
  surface.blit(self.source, (0, 0))
107
113
  surface.blit(self.dest, (0, 0))
108
114
 
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
115
 
136
- radius = self.surface_width * v
137
- pygame.draw.circle(
138
- self.circle_surf, "white", self.circle_surf.get_rect().center, radius
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),
139
146
  )
140
- mask = pygame.mask.from_surface(self.circle_surf)
141
- mask.to_surface(surface=surface, setsurface=self.dest, unsetsurface=self.source)
147
+ self.anim.start()
142
148
 
149
+ def update_offset(self, vec):
150
+ self.offset.update(vec)
143
151
 
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()
152
+ def has_ended(self):
153
+ return self.ended
151
154
 
152
155
  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
-
156
+ surface.blit(self.source, (0, 0))
157
+ surface.blit(self.dest, self.offset)
File without changes
@@ -1,10 +1,10 @@
1
1
  import batFramework as bf
2
- from typing import Callable,Any
2
+
3
3
 
4
4
  class TriggerZone(bf.Entity):
5
- def __init__(self, size, trigger, callback: Callable[[Any],Any], active=True) -> None:
5
+ def __init__(self, size, trigger, callback, active=True) -> None:
6
6
  super().__init__(size, True)
7
- self.set_debug_color(bf.color.RED)
7
+ self.set_debug_color(bf.color.RIVER_BLUE)
8
8
  self.active = active
9
9
  self.callback = callback
10
10
  self.trigger = trigger
@@ -13,7 +13,7 @@ class TriggerZone(bf.Entity):
13
13
  self.trigger = trigger
14
14
  return self
15
15
 
16
- def set_callback(self, callback: Callable[[Any],Any]):
16
+ def set_callback(self, callback):
17
17
  self.callback = callback
18
18
  return self
19
19