batframework 1.0.8a1__py3-none-any.whl → 1.0.8a2__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 (63) hide show
  1. batFramework/__init__.py +50 -53
  2. batFramework/action.py +105 -116
  3. batFramework/actionContainer.py +11 -53
  4. batFramework/animatedSprite.py +65 -115
  5. batFramework/audioManager.py +26 -70
  6. batFramework/camera.py +68 -253
  7. batFramework/constants.py +54 -16
  8. batFramework/cutscene.py +25 -34
  9. batFramework/cutsceneBlocks.py +42 -37
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +7 -9
  12. batFramework/easing.py +71 -0
  13. batFramework/entity.py +98 -42
  14. batFramework/gui/__init__.py +2 -8
  15. batFramework/gui/button.py +79 -7
  16. batFramework/gui/constraints.py +204 -0
  17. batFramework/gui/container.py +31 -155
  18. batFramework/gui/debugger.py +43 -124
  19. batFramework/gui/frame.py +19 -0
  20. batFramework/gui/image.py +17 -41
  21. batFramework/gui/indicator.py +21 -41
  22. batFramework/gui/interactiveWidget.py +13 -116
  23. batFramework/gui/label.py +73 -278
  24. batFramework/gui/layout.py +61 -148
  25. batFramework/gui/root.py +37 -102
  26. batFramework/gui/shape.py +57 -258
  27. batFramework/gui/toggle.py +46 -97
  28. batFramework/gui/widget.py +254 -268
  29. batFramework/manager.py +19 -40
  30. batFramework/particles.py +77 -0
  31. batFramework/scene.py +107 -214
  32. batFramework/sceneManager.py +107 -150
  33. batFramework/stateMachine.py +0 -1
  34. batFramework/time.py +57 -117
  35. batFramework/transition.py +126 -184
  36. batFramework/transitionManager.py +0 -0
  37. batFramework/utils.py +161 -34
  38. batframework-1.0.8a2.dist-info/METADATA +58 -0
  39. batframework-1.0.8a2.dist-info/RECORD +42 -0
  40. {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
  41. batFramework/easingController.py +0 -58
  42. batFramework/enums.py +0 -104
  43. batFramework/fontManager.py +0 -65
  44. batFramework/gui/clickableWidget.py +0 -206
  45. batFramework/gui/constraints/__init__.py +0 -1
  46. batFramework/gui/constraints/constraints.py +0 -378
  47. batFramework/gui/dialogueBox.py +0 -96
  48. batFramework/gui/draggableWidget.py +0 -38
  49. batFramework/gui/meter.py +0 -76
  50. batFramework/gui/radioButton.py +0 -62
  51. batFramework/gui/slider.py +0 -220
  52. batFramework/gui/textInput.py +0 -134
  53. batFramework/object.py +0 -115
  54. batFramework/particle.py +0 -101
  55. batFramework/renderGroup.py +0 -62
  56. batFramework/resourceManager.py +0 -84
  57. batFramework/scrollingSprite.py +0 -113
  58. batFramework/sprite.py +0 -45
  59. batFramework/tileset.py +0 -46
  60. batframework-1.0.8a1.dist-info/LICENCE +0 -21
  61. batframework-1.0.8a1.dist-info/METADATA +0 -55
  62. batframework-1.0.8a1.dist-info/RECORD +0 -56
  63. {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
@@ -2,6 +2,7 @@ import batFramework as bf
2
2
  import pygame
3
3
 
4
4
 
5
+
5
6
  def search_index(target, lst):
6
7
  cumulative_sum = 0
7
8
  for index, value in enumerate(lst):
@@ -12,156 +13,105 @@ def search_index(target, lst):
12
13
 
13
14
 
14
15
  class AnimState:
15
- def __init__(
16
- self,
17
- name: str,
18
- surface: pygame.Surface,
19
- width,
20
- height,
21
- duration_list: list | int,
22
- ) -> None:
23
- self.frames: list[pygame.Surface] = list(
24
- bf.utils.split_surface(
25
- surface, width, height, False, convert_alpha
26
- ).values()
27
- )
28
- self.frames_flipX: list[pygame.Surface] = list(
29
- bf.utils.split_surface(surface, width, height, True, convert_alpha).values()
16
+ def __init__(self, file, width, height, frame_length_list:list|int) -> None:
17
+ self.frames: list[pygame.Surface] = bf.utils.img_slice(file, width, height)
18
+ self.frames_flipX: list[pygame.Surface] = bf.utils.img_slice(
19
+ file, width, height, True
30
20
  )
31
21
 
32
- self.name = name
33
- self.duration_list: list[int] = []
34
- self.duration_list_length = 0
35
- self.set_duration_list(duration_list)
22
+ self.frame_length_list = []
23
+ self.ffl_length = 0
24
+ self.set_frame_length_list(frame_length_list)
36
25
 
37
- def __repr__(self):
38
- return f"AnimState({self.name})"
39
-
40
- def counter_to_frame(self, counter: float | int) -> int:
41
- return search_index(
42
- int(counter % self.duration_list_length), self.duration_list
43
- )
26
+ def get_frame_index(self, counter:float|int):
27
+ return search_index(int(counter % self.ffl_length), self.frame_length_list)
44
28
 
45
29
  def get_frame(self, counter, flip):
46
- i = self.counter_to_frame(counter)
30
+ i = self.get_frame_index(counter)
47
31
  return self.frames_flipX[i] if flip else self.frames[i]
48
32
 
49
- def set_duration_list(self, duration_list: list[int] | int):
50
- if isinstance(duration_list, int):
51
- duration_list = [duration_list] * len(self.frames)
52
- if len(duration_list) != len(self.frames):
53
- raise ValueError("duration_list should have values for all frames")
54
- self.duration_list = duration_list
55
- self.duration_list_length = sum(self.duration_list)
56
-
33
+ def set_frame_length_list(self,frame_length_list:list[int]|int):
34
+ if isinstance(frame_length_list,int):
35
+ frame_length_list = [frame_length_list] * len(self.frames)
36
+ if len(frame_length_list) != len(self.frames) :
37
+ raise ValueError("frame_length_list should have values for all frames")
38
+ self.frame_length_list = frame_length_list
39
+ self.ffl_length = sum(self.frame_length_list)
40
+
57
41
 
58
42
  class AnimatedSprite(bf.DynamicEntity):
59
43
  def __init__(self, size=None) -> None:
60
44
  super().__init__(size, no_surface=True)
61
- self.float_counter: float = 0
45
+ self.float_counter = 0
62
46
  self.animStates: dict[str, AnimState] = {}
63
- self.current_state: AnimState | None = None
47
+ self.current_animState :str = ""
64
48
  self.flipX = False
65
49
  self._locked = False
66
- self.paused: bool = False
67
-
68
- def pause(self) -> None:
69
- self.paused = True
70
-
71
- def resume(self) -> None:
72
- self.paused = False
73
50
 
74
- def toggle_pause(self) -> None:
75
- self.paused = not self.paused
76
-
77
- def set_counter(self, value: float) -> None:
51
+ def set_counter(self,value:float):
78
52
  self.float_counter = value
53
+
79
54
 
80
- def set_frame(self, frame_index: int) -> None:
81
- if not self.current_state:
82
- return
83
- total = sum(self.current_state.duration_list)
84
- frame_index = max(0, min(total, frame_index))
85
- new_counter = 0
86
- i = 0
87
- while frame_index < total:
88
- if self.current_state.counter_to_frame(new_counter) >= frame_index:
89
- break
90
- new_counter += self.current_state.duration_list[i]
91
- i += 1
92
- self.set_counter(new_counter)
93
-
94
- def lock(self) -> None:
55
+ def lock_animState(self):
95
56
  self._locked = True
96
57
 
97
- def unlock(self) -> None:
58
+ def unlock_animState(self):
98
59
  self._locked = False
99
60
 
100
- def set_flipX(self, value) -> None:
61
+ def set_flipX(self, value):
101
62
  self.flipX = value
102
63
 
103
- def remove_animState(self, name: str) -> bool:
104
- if not name in self.animStates:
105
- return False
106
- self.animStates.pop(name)
107
- if self.current_state and self.current_state.name == name:
108
- self.current_animState = (
109
- list(self.animStates.keys())[0] if self.animStates else ""
110
- )
111
- return True
64
+ def remove_animState(self, name:str):
65
+ if not name in self.animStates :return
66
+ self.animStates.pop(name)
67
+ if self.current_animState == name : self.current_animState = list(self.animStates.keys())[0] if self.animStates else ""
112
68
 
113
69
  def add_animState(
114
- self,
115
- name: str,
116
- surface: pygame.Surface,
117
- size: tuple[int, int],
118
- duration_list: list[int],
119
- convert_alpha: bool = True,
120
- ) -> bool:
70
+ self, name: str, file: str, size: tuple[int, int], frame_length_list: list[int]
71
+ ):
121
72
  if name in self.animStates:
122
- return False
123
- self.animStates[name] = AnimState(name, surface, *size, duration_list)
124
- if len(self.animStates) == 1:
125
- self.set_animState(name)
126
- return True
73
+ return
74
+ self.animStates[name] = AnimState(file, *size, frame_length_list)
75
+ if len(self.animStates) == 1 : self.set_animState(name)
127
76
 
128
- def set_animState(self, state: str, reset_counter=True, lock=False) -> bool:
77
+ def set_animState(self, state:str, reset_counter=True, lock=False):
129
78
  if state not in self.animStates or self._locked:
130
79
  return False
131
-
132
- animState = self.animStates[state]
133
- self.current_state = animState
134
-
135
- self.rect = self.current_state.frames[0].get_frect(center=self.rect.center)
136
-
137
- if reset_counter or self.float_counter > sum(animState.duration_list):
80
+ self.current_animState = state
81
+ self.rect = (
82
+ self.animStates[self.current_animState]
83
+ .frames[0]
84
+ .get_frect(center=self.rect.center)
85
+ )
86
+ if reset_counter or self.float_counter > sum(
87
+ self.get_state().frame_length_list
88
+ ):
138
89
  self.float_counter = 0
139
90
  if lock:
140
- self.lock()
91
+ self.lock_animState()
141
92
  return True
142
93
 
143
- def get_animState(self) -> AnimState | None:
144
- return self.current_state
94
+ def get_state(self):
95
+ return self.animStates.get(self.current_animState,None)
145
96
 
146
- def update(self, dt: float) -> None:
147
- s = self.get_animState()
148
- if not self.animStates or s is None:
149
- return
150
- if not self.paused:
151
- self.float_counter += 60 * dt
152
- if self.float_counter > s.duration_list_length:
153
- self.float_counter = 0
97
+ def get_frame_index(self):
98
+ return self.animStates[self.current_animState].get_frame_index(
99
+ self.float_counter
100
+ )
101
+
102
+ def update(self, dt: float):
103
+ if not self.animStates : return
104
+ self.float_counter += 60 * dt
105
+ if self.float_counter > self.get_state().ffl_length:
106
+ self.float_counter = 0
154
107
  self.do_update(dt)
155
108
 
156
- def draw(self, camera: bf.Camera) -> int:
157
- if (
158
- not self.visible
159
- or not camera.rect.colliderect(self.rect)
160
- or not self.current_state
161
- ):
162
- return 0
109
+ def draw(self, camera: bf.Camera) -> bool:
110
+ if not self.visible or not camera.intersects(self.rect) or not self.animStates:
111
+ return False
112
+ # pygame.draw.rect(camera.surface,"purple",camera.transpose(self.rect).move(2,2))
163
113
  camera.surface.blit(
164
- self.current_state.get_frame(self.float_counter, self.flipX),
165
- camera.world_to_screen(self.rect),
114
+ self.get_state().get_frame(self.float_counter, self.flipX),
115
+ camera.transpose(self.rect),
166
116
  )
167
- return 1
117
+ return True
@@ -5,26 +5,24 @@ pygame.mixer.init()
5
5
 
6
6
 
7
7
  class AudioManager(metaclass=bf.Singleton):
8
- def __init__(self) -> None:
9
- self.sounds: dict = {}
10
- self.musics: dict = {}
11
- self.current_music: str | None = None
12
- self.music_volume: float = 1
13
- self.sound_volume: float = 1
8
+ def __init__(self):
9
+ self.sounds: dict[str : dict[str, pygame.mixer.Sound, bool]] = {}
10
+ self.musics: dict[str:str] = {}
11
+ self.current_music = None
12
+ self.music_volume = 1
13
+ self.sound_volume = 1
14
14
  pygame.mixer_music.set_endevent(bf.const.MUSIC_END_EVENT)
15
15
 
16
- def free_sounds(self, force: bool = False):
16
+ def free_sounds(self, force=False):
17
17
  if force:
18
18
  self.sounds = {}
19
19
  return
20
- self.sounds: dict = {
21
- key: value for key, value in self.sounds.items() if value["persistent"]
22
- }
20
+ to_remove = []
21
+ for name, data in self.sounds.items():
22
+ if not data["persistent"]:
23
+ to_remove.append(name)
23
24
 
24
- def free_music(self):
25
- if self.current_music:
26
- pygame.mixer.music.unload(self.current_music)
27
-
25
+ _ = [self.sounds.pop(i) for i in to_remove]
28
26
 
29
27
  def set_sound_volume(self, volume: float):
30
28
  self.sound_volume = volume
@@ -33,19 +31,13 @@ class AudioManager(metaclass=bf.Singleton):
33
31
  self.music_volume = volume
34
32
  pygame.mixer_music.set_volume(volume)
35
33
 
36
- def get_music_volume(self) -> float:
37
- return self.music_volume
38
-
39
- def get_sound_volume(self) -> float:
40
- return self.sound_volume
41
-
42
- def has_sound(self, name: str):
34
+ def has_sound(self, name):
43
35
  return name in self.sounds
44
36
 
45
37
  def load_sound(self, name, path, persistent=False) -> pygame.mixer.Sound:
46
38
  if name in self.sounds:
47
39
  return self.sounds[name]["sound"]
48
- path = bf.ResourceManager().get_path(path)
40
+ path = bf.utils.get_path(path)
49
41
  self.sounds[name] = {
50
42
  "path": path,
51
43
  "sound": pygame.mixer.Sound(path),
@@ -53,57 +45,24 @@ class AudioManager(metaclass=bf.Singleton):
53
45
  }
54
46
  return self.sounds[name]["sound"]
55
47
 
56
- def load_sounds(self, sound_data_list: list[tuple[str, str, bool]]) -> None:
57
- for data in sound_data_list:
58
- self.load_sound(*data)
59
- return
60
-
61
- def play_sound(self, name, volume=1) -> bool:
62
- """
63
- Play the sound file with the given name.
64
- returns True if the sound was played
65
-
66
- """
67
- try:
68
- self.sounds[name]["sound"].set_volume(volume * self.sound_volume)
69
- self.sounds[name]["sound"].play()
70
- return True
71
- except KeyError:
72
- # print(f"Sound '{name}' not loaded in AudioManager.")
73
- return False
74
-
75
- def stop_sound(self, name) -> bool:
76
- try:
48
+ def play_sound(self, name, volume=1):
49
+ self.sounds[name]["sound"].set_volume(volume * self.sound_volume)
50
+ self.sounds[name]["sound"].play()
51
+
52
+ def stop_sound(self, name):
53
+ if name in self.sounds:
77
54
  self.sounds[name]["sound"].stop()
78
- return True
79
- except KeyError:
80
- return False
81
- # print(f"Sound '{name}' not loaded in AudioManager.")
82
55
 
83
56
  def load_music(self, name, path):
84
- self.musics[name] = bf.ResourceManager().get_path(path)
85
- return
86
-
87
- def load_musics(self, music_data_list: list[tuple[str, str]]):
88
- for data in music_data_list:
89
- self.load_music(*data)
90
- return
91
-
92
- def play_music(self, name, loop=0, fade=500) -> bool:
93
- """
94
- Play the sound file with the given 'name'.
95
- Fades with the given 'fade' time in ms.
96
- Music will loop 'loop' times (indefinitely if -1).
97
- returns True if the sound was played
98
- """
99
- try:
57
+ self.musics[name] = bf.utils.get_path(path)
58
+
59
+ def play_music(self, name, loop=0, fade=500):
60
+ if name in self.musics:
100
61
  pygame.mixer_music.load(self.musics[name])
101
62
  pygame.mixer_music.play(loop, fade_ms=fade)
102
63
  self.current_music = name
103
- return True
104
- except KeyError:
105
- return False
106
- # print(f"Music '{name}' not loaded in AudioManager.")
64
+ else:
65
+ print(f"Music '{name}' not found in AudioManager.")
107
66
 
108
67
  def stop_music(self):
109
68
  if not self.current_music:
@@ -124,6 +83,3 @@ class AudioManager(metaclass=bf.Singleton):
124
83
  if not self.current_music:
125
84
  return
126
85
  pygame.mixer_music.unpause()
127
-
128
- def get_current_music(self) -> str | None:
129
- return self.current_music