batframework 1.0.9a3__py3-none-any.whl → 1.0.9a5__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 CHANGED
@@ -9,8 +9,8 @@ from .utils import Utils as utils
9
9
  from .tileset import Tileset
10
10
  from .timeManager import TimeManager,Timer,SceneTimer
11
11
  from .easingController import EasingController
12
- from .cutscene import Cutscene, CutsceneManager
13
- import batFramework.cutsceneBlocks
12
+ from .cutsceneManager import CutsceneManager
13
+ from .cutscene import *
14
14
  from .audioManager import AudioManager
15
15
  import batFramework.transition as transition
16
16
  from .action import Action
batFramework/cutscene.py CHANGED
@@ -1,129 +1,53 @@
1
1
  import batFramework as bf
2
- from typing import TYPE_CHECKING,Self
3
-
4
- class CutsceneBlock: ...
5
-
6
- if TYPE_CHECKING:
7
- from .cutsceneBlocks import CutsceneBlock
8
-
9
-
10
- class Cutscene: ...
11
-
12
-
13
- class CutsceneManager(metaclass=bf.Singleton):
14
- def __init__(self) -> None:
15
- self.current_cutscene: Cutscene = None
16
- self.cutscenes: list[bf.Cutscene] = []
17
- self.manager: bf.Manager = None
18
-
19
- def set_manager(self, manager):
20
- self.manager = manager
21
-
22
- def get_flag(self, flag):
23
- return None
24
-
25
- def process_event(self, event):
26
- if self.current_cutscene:
27
- self.current_cutscene.process_event(event)
28
-
29
- def queue(self, *cutscenes):
30
- self.cutscenes.extend(cutscenes)
31
- if self.current_cutscene is None:
32
- self.play(self.cutscenes.pop(0))
33
-
34
- def play(self, cutscene: Cutscene):
35
- if self.current_cutscene is None:
36
- self.current_cutscene = cutscene
37
- self.current_cutscene.on_enter()
38
- self.current_cutscene.init_blocks()
39
- self.current_cutscene.play()
40
-
41
- def enable_player_control(self) -> None:
42
- pass
43
-
44
- def disable_player_control(self) -> None:
45
- pass
46
-
47
- def update(self, dt):
48
- if not self.current_cutscene is None:
49
- self.current_cutscene.update(dt)
50
- # print("cutscene manager update")
51
- if self.current_cutscene.has_ended():
52
- self.current_cutscene.on_exit()
53
- self.current_cutscene = None
54
- if self.cutscenes:
55
- self.play(self.cutscenes.pop(0))
56
- else:
57
- self.current_cutscene = None
58
-
59
-
2
+ from .transition import Transition
60
3
  class Cutscene:
61
- def __init__(self) -> None:
62
- self.cutscene_blocks : list[CutsceneBlock] = []
63
- self.block_index = 0
64
- self.end_blocks: list[CutsceneBlock] = []
65
- self.ended = False
66
-
67
- def on_enter(self):
68
- pass
69
-
70
- def on_exit(self):
71
- pass
72
-
73
- def init_blocks(self):
74
- pass
75
-
76
- def add_blocks(self, *blocks: CutsceneBlock)->Self:
77
- self.cutscene_blocks.extend(blocks)
78
- return self
79
-
80
- def add_end_blocks(self, *blocks: CutsceneBlock)->Self:
81
- _ = [block.set_parent_cutscene(self) for block in blocks]
82
- self.end_blocks.extend(blocks)
83
- return self
84
-
85
- def get_scene_at(self, index):
86
- return bf.CutsceneManager().manager.scenes[index]
87
-
88
- def get_current_scene(self):
89
- return bf.CutsceneManager().manager.get_current_scene()
90
-
91
- def set_scene(self, name, index=0):
92
- return bf.CutsceneManager().manager.set_scene(name, index)
4
+ def __init__(self,*cutscenes):
5
+ self.is_over : bool = False
6
+ self.sub_cutscenes : list[Cutscene] = list(cutscenes)
7
+ self.sub_index = -1
8
+
9
+ def start(self):
10
+ if self.sub_cutscenes:
11
+ self.sub_index = 0
12
+ self.sub_cutscenes[self.sub_index].start()
13
+ else:
14
+ self.end()
15
+
16
+ def process_event(self,event):
17
+ if self.sub_index > 0:
18
+ self.sub_cutscenes[self.sub_index].process_event(event)
19
+
20
+ def update(self,dt):
21
+ if self.sub_index >= 0:
22
+ self.sub_cutscenes[self.sub_index].update(dt)
23
+ if self.sub_cutscenes[self.sub_index].is_over:
24
+ self.sub_index +=1
25
+ if self.sub_index >= len(self.sub_cutscenes):
26
+ self.end()
27
+ return
28
+ self.sub_cutscenes[self.sub_index].start()
29
+
30
+ def end(self):
31
+ self.is_over = True
93
32
 
94
- def get_scene(self, name):
95
- return bf.CutsceneManager().manager.get_scene(name)
96
33
 
97
- def add_block(self, *blocks: CutsceneBlock):
98
- for block in blocks:
99
- block.set_parent_cutscene(self)
100
- self.cutscene_blocks.append(block)
34
+ class Wait(Cutscene):
35
+ def __init__(self,duration:float,scene_name:str="global"):
36
+ super().__init__()
37
+ self.duration = duration
38
+ self.scene_name = scene_name
39
+ def start(self):
40
+ self.timer = bf.SceneTimer(duration=self.duration,end_callback=self.end,scene_name=self.scene_name)
41
+ self.timer.start()
101
42
 
102
- def process_event(self, event):
103
- if not self.ended and self.block_index < len(self.cutscene_blocks):
104
- self.cutscene_blocks[self.block_index].process_event(event)
105
43
 
106
- def play(self):
107
- self.block_index = 0
108
- if self.cutscene_blocks:
109
- self.cutscene_blocks[self.block_index].start()
110
- else:
111
- self.ended
112
44
 
113
- def update(self, dt):
114
- if self.ended:
115
- return
116
- self.cutscene_blocks[self.block_index].update(dt)
117
- if self.cutscene_blocks[self.block_index].has_ended():
118
- self.block_index += 1
119
- if self.block_index == len(self.cutscene_blocks):
120
- if not self.end_blocks:
121
- self.ended = True
122
- return
123
- else:
124
- self.cutscene_blocks.extend(self.end_blocks)
125
- self.end_blocks = []
126
- self.cutscene_blocks[self.block_index].start()
45
+ class TransitionToScene(Cutscene):
46
+ def __init__(self,scene_name:str,transition:Transition):
47
+ super().__init__()
48
+ self.scene_name = scene_name
49
+ self.transition: Transition = transition
127
50
 
128
- def has_ended(self):
129
- return self.ended
51
+ def start(self):
52
+ bf.CutsceneManager().manager.transition_to_scene(self.scene_name,self.transition)
53
+ bf.Timer(self.transition.duration,end_callback=self.end).start()
@@ -0,0 +1,31 @@
1
+ import batFramework as bf
2
+ from typing import TYPE_CHECKING,Self
3
+ import pygame
4
+ # if TYPE_CHECKING:
5
+ from .cutscene import Cutscene
6
+
7
+
8
+ class CutsceneManager(metaclass=bf.Singleton):
9
+ def __init__(self) -> None:
10
+ self.current_cutscene: Cutscene = None
11
+ self.manager: bf.Manager = None
12
+
13
+ def set_manager(self, manager):
14
+ self.manager = manager
15
+
16
+ def process_event(self, event):
17
+ if self.current_cutscene is not None:
18
+ self.current_cutscene.process_event(event)
19
+ if event.type in bf.enums.playerInput:
20
+ event.consumed = True
21
+
22
+ def play(self,cutscene:Cutscene):
23
+ if self.current_cutscene is not None:return
24
+ self.current_cutscene = cutscene
25
+ cutscene.start()
26
+
27
+ def update(self,dt):
28
+ if self.current_cutscene:
29
+ self.current_cutscene.update(dt)
30
+ if self.current_cutscene.is_over:
31
+ self.current_cutscene = None
batFramework/enums.py CHANGED
@@ -1,4 +1,8 @@
1
1
  from enum import Enum
2
+ import pygame
3
+
4
+ playerInput = [pygame.KEYDOWN,pygame.MOUSEBUTTONDOWN,pygame.KEYUP,pygame.MOUSEBUTTONUP]
5
+
2
6
 
3
7
 
4
8
  class color:
@@ -111,4 +115,6 @@ class textMode(Enum):
111
115
  ALPHABETICAL = 0
112
116
  NUMERICAL = 1
113
117
  ALPHANUMERICAL = 3
114
-
118
+
119
+
120
+
batFramework/gui/label.py CHANGED
@@ -246,9 +246,9 @@ class Label(Shape):
246
246
 
247
247
  def _build_layout(self) -> None:
248
248
 
249
+ # print(self.text_rect.size,self._get_text_rect_required_size(),repr(self.text))
249
250
  self.text_rect.size = self._get_text_rect_required_size()
250
- # self.text_rect.w = ceil(self.text_rect.w)
251
- # self.text_rect.h = ceil(self.text_rect.h)
251
+
252
252
  if self.autoresize_h or self.autoresize_w:
253
253
  target_rect = self.inflate_rect_by_padding((0, 0, *self.text_rect.size))
254
254
  if not self.autoresize_w:
@@ -256,9 +256,10 @@ class Label(Shape):
256
256
  if not self.autoresize_h:
257
257
  target_rect.h = self.rect.h
258
258
  if self.rect.size != target_rect.size:
259
+ # print("Size not good ! ",self.rect.size,target_rect.size,repr(self.text))
259
260
  self.set_size(target_rect.size)
260
261
  self.apply_updates()
261
- return
262
+
262
263
  offset = self._get_outline_offset() if self.show_text_outline else (0,0)
263
264
  padded = self.get_padded_rect().move(-self.rect.x + offset[0], -self.rect.y + offset[1])
264
265
  self.align_text(self.text_rect, padded, self.alignment)
@@ -271,7 +272,6 @@ class Label(Shape):
271
272
  if self.font_object is None:
272
273
  print(f"No font for widget with text : '{self}' :(")
273
274
  return
274
-
275
275
  params = {
276
276
  "font_name": self.font_object.name,
277
277
  "text": self.text,
@@ -333,6 +333,3 @@ class Label(Shape):
333
333
  super().paint()
334
334
  if self.font_object:
335
335
  self._paint_text()
336
-
337
- # def set_alignment(self, alignment: bf.alignment) -> Self:
338
- # return self
@@ -25,7 +25,7 @@ class StyleManager(metaclass=Singleton):
25
25
 
26
26
  def refresh_widget(self, widget: Widget):
27
27
  if widget in self.widgets:
28
- self.lookup[widget] = True
28
+ self.lookup[widget] = False
29
29
  self.update()
30
30
 
31
31
  def remove_widget(self, widget: Widget):
batFramework/manager.py CHANGED
@@ -74,6 +74,8 @@ class Manager(bf.SceneManager):
74
74
  if event.key == pygame.K_p:
75
75
  self.print_status()
76
76
  return
77
+ self.cutsceneManager.process_event(event)
78
+ if event.consumed: return
77
79
  super().process_event(event)
78
80
  if not event.consumed:
79
81
  if event.type == pygame.QUIT:
@@ -8,13 +8,13 @@ from typing import Self, Iterator, Callable
8
8
  """
9
9
 
10
10
 
11
- class RenderGroup(bf.Entity):
11
+ class RenderGroup(bf.Drawable):
12
12
  def __init__(
13
- self, entity_iterator: Callable[[], Iterator[bf.Entity]], blit_flags: int = 0
13
+ self, entity_iterator: Callable[[], Iterator[bf.Drawable]], blit_flags: int = 0
14
14
  ) -> None:
15
15
  super().__init__()
16
16
  self.entity_iterator = entity_iterator
17
- self.set_blit_flags(blit_flags)
17
+ # self.set_blit_flags(blit_flags)
18
18
  self.set_debug_color("white")
19
19
 
20
20
  def get_debug_outlines(self):
@@ -171,6 +171,9 @@ class SceneManager:
171
171
 
172
172
  def process_event(self, event: pygame.Event):
173
173
 
174
+ if self.current_transitions and event in bf.enums.playerInput:
175
+ return
176
+
174
177
  if event.type in self.shared_events:
175
178
  [s.process_event(event) for s in self.scenes]
176
179
  else:
@@ -17,19 +17,15 @@ class ScrollingSprite(bf.Sprite):
17
17
  # Use integer values for the starting points, converted from floating point scroll values
18
18
 
19
19
  super().__init__(size, data, convert_alpha)
20
- self.original_width, self.original_height = self.original_surface.get_size()
20
+ if self.original_surface:
21
+ self.original_width, self.original_height = self.original_surface.get_size()
22
+
21
23
 
22
24
  def get_debug_outlines(self):
23
25
  yield from super().get_debug_outlines()
24
26
  for r in self._get_mosaic_rect_list():
25
27
  yield r.move(*self.rect.topleft)
26
28
 
27
- def set_image(
28
- self, data: pygame.Surface | str, size: None | tuple[int, int] = None
29
- ) -> Self:
30
- super().set_image(data, size)
31
- self.original_width, self.original_height = self.original_surface.get_size()
32
- return self
33
29
 
34
30
  def set_autoscroll(self, x: float, y: float) -> Self:
35
31
  self.auto_scroll.update(x, y)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: batframework
3
- Version: 1.0.9a3
3
+ Version: 1.0.9a5
4
4
  Summary: Pygame framework for making games easier.
5
5
  Author-email: Turan Baturay <baturayturan@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
@@ -1,4 +1,4 @@
1
- batFramework/__init__.py,sha256=vcfe0wd5ggzu2NfHoHMfGwMjpBZTPujMt3Fr2W_PWkE,2604
1
+ batFramework/__init__.py,sha256=Wu_8kpeyR_XgD5zewnX_xXAF8CwStcO7vivideqsgIw,2590
2
2
  batFramework/action.py,sha256=919IVYKviLyVYDtQL7oZvlVuE_aodjJCuwz6fGi5sCk,8420
3
3
  batFramework/actionContainer.py,sha256=qy6-YY3iX26KJ8NqFMSYo6JExohD8HFk0sC1qhb7qA8,2602
4
4
  batFramework/animatedSprite.py,sha256=IWE8zUgpFaqQPUr7iOUo7TJ_E10aUaMNqlIqv8dW87E,4242
@@ -7,21 +7,21 @@ batFramework/audioManager.py,sha256=ANn6GXDm5bcThih0KD8jrF54Re20A6kxHQrVJu9QYxc,
7
7
  batFramework/camera.py,sha256=tSy9n20QLeJD3Uz352q-uejzAHPtQczvahaNz7APJcY,9408
8
8
  batFramework/character.py,sha256=AK5sQLvAOY3X4-7vzeHeIO5WDFsubn_TADLYxmYc0Qo,789
9
9
  batFramework/constants.py,sha256=x8a0GqBJdiwMEjlVohyL3AWHaSxyrBy-4pucVKVNakg,1354
10
- batFramework/cutscene.py,sha256=zra-hvAVY5buBPfFiog4psvLZW07qCt8LZzd7Vd-4qM,3858
11
- batFramework/cutsceneBlocks.py,sha256=3jtmTpV48NKCu-Qgjg7KN5KnwXn0kycIQ7t7G3RH3VE,4862
10
+ batFramework/cutscene.py,sha256=UOz3NApbz4W7Wi6wD_ZEmkxaZCAWt1YWh5ZFzXw5Xco,1749
11
+ batFramework/cutsceneManager.py,sha256=mvBR4KOv6KV9eHzhYH7r6IJMVLjM71C30C2OuvwbuSU,945
12
12
  batFramework/drawable.py,sha256=5We2ITq3M5ERG22-iQw7Mo_1LNo0nqma1P13tvphDjY,2197
13
13
  batFramework/dynamicEntity.py,sha256=SjXShy5aT4cQzjlTem05zSQRiNeq52AUXEBVodEG6gI,736
14
14
  batFramework/easingController.py,sha256=ql_nt8unwUZLy7MC7unzDn5eTW44VtjrOTCDs8WS0eY,1750
15
15
  batFramework/entity.py,sha256=wMQKR6IxQ69vtPY4nGsz7WnY9ApPhO_VY08IYx6yUu8,2910
16
- batFramework/enums.py,sha256=r7vAWBm5g3qrvN-WzBN-2ErNKFFqQ5mTrib2GjmDHmE,2083
16
+ batFramework/enums.py,sha256=xkT4yepdLLQn-5YWoSxhHamXE7w_M-GIw47dWWHfKIs,2185
17
17
  batFramework/fontManager.py,sha256=M7h6AVq9Fwr51UTCFoGsg_PSurdjByA4w8qouXq4EKE,2254
18
- batFramework/manager.py,sha256=vu7TfDnJu08_I-pPWSn450NDrMY-LysLe8y3t2fTy_o,4404
18
+ batFramework/manager.py,sha256=TQ0Q1f_GbQE8h4G9zCNQgtNTKNCj630S43Ai4e0yZik,4488
19
19
  batFramework/particle.py,sha256=Aps9eJNdFag-TlduMSezKp4ocFQVvI6iZ98chhdhbgE,3081
20
- batFramework/renderGroup.py,sha256=_VDvmP4iB-XarFJo_Uh5YKwWq1cazHmOBmTXZkqKk40,2020
20
+ batFramework/renderGroup.py,sha256=CO8LtTP1gYI1i_8OwmMk2SlU33Nv4iXnHvK0RVK3D24,2026
21
21
  batFramework/resourceManager.py,sha256=0cOIAFXT7UzzvgHn9QkWcXsTp8H2bIS70NvvgpBL2_4,3554
22
22
  batFramework/scene.py,sha256=0E7omgNUEl5Uhbx8iO3exyCy4p1MC7bSvqfwncW4KMw,11281
23
- batFramework/sceneManager.py,sha256=_VPPi0WepH8_NQuwq6d4gfTFdmku3VxrDkJ8cu3oxqU,7008
24
- batFramework/scrollingSprite.py,sha256=_1-hp7y3pC5m8g2VhFVgGOuJsOkOi8adhQiI2Rb0uPY,4133
23
+ batFramework/sceneManager.py,sha256=GCGt7DYoty_wX2LVEhv0C6TaNyNWhKvWocwOqxUIBXc,7099
24
+ batFramework/scrollingSprite.py,sha256=6FFS27kPaPto6-lIM7k3zHW1pnlEJ4mFopYP_tyvzb0,3917
25
25
  batFramework/sprite.py,sha256=Cz8qzl8jR8y33DUSCObJQOk5e8PcZeavtFhBdR2TogU,1627
26
26
  batFramework/stateMachine.py,sha256=wC-5xbKvf-vGm_N16X9KhgMya5915GyVXL79uk5Bapw,1359
27
27
  batFramework/tileset.py,sha256=3AJBWHx90PC43BdLYCBFm811XBrMvWoB-nsUgyo6s-I,1728
@@ -39,7 +39,7 @@ batFramework/gui/draggableWidget.py,sha256=SKG7oMInZ_GTnrbv2T0aqlppuiuLX1tkVSCQJ
39
39
  batFramework/gui/image.py,sha256=CPDSF7Fz1zmGAK-ii7R4MIAD5EZCnPw4mpD_cGv77U8,1925
40
40
  batFramework/gui/indicator.py,sha256=31QAyvT9w-eCWUSoK4pV-4TsTzFvkY_g5snoeI1hATM,1619
41
41
  batFramework/gui/interactiveWidget.py,sha256=ww9WsR2Y87og7NtnzCcyc1zIPE-Bjtn0YZ0SOfKMUbQ,6633
42
- batFramework/gui/label.py,sha256=6hkD54lrp8ZPnKm75001NnfTli22rSKUdWlC-1bRIdE,11672
42
+ batFramework/gui/label.py,sha256=6GY_2f4el1KmJ3JoLgE57oPl7Xdbx1codaHdAW3h_x0,11639
43
43
  batFramework/gui/layout.py,sha256=MJjcz6fjTWtt4-Td0dAqKd3XRDlRJ5QaDpRbdYEj1w8,21661
44
44
  batFramework/gui/meter.py,sha256=RFzAhSzR3O-Pw0wjdfApWGWFQSJoYa4WohkiREDAAJc,2395
45
45
  batFramework/gui/radioButton.py,sha256=DgCtN1j1s2rUITpdYqArqQ36NnNGump7FiTe_ndEzJg,2436
@@ -47,7 +47,7 @@ batFramework/gui/root.py,sha256=r8dhI2xd2h5bUbTe4x_On77BTTZ7Sf8qY5wWJimWXds,5078
47
47
  batFramework/gui/shape.py,sha256=PSQRqa8jYA8VsBXRQcpcCuEvTYmWDW8zJkzA_eRFPIo,9349
48
48
  batFramework/gui/slider.py,sha256=rt0f2jnxyd89uepyBqBueP3qw6y9ZTIRGXipI9fhBs4,8467
49
49
  batFramework/gui/style.py,sha256=OeLbft0RkIslQ2IcZpBeF6TaQDONIoBcAHj_Bkh9gFw,131
50
- batFramework/gui/styleManager.py,sha256=ZWkGBkNQngJVU8k9OHrTeKzGYc5Hj4JAVATrU1MufB4,1423
50
+ batFramework/gui/styleManager.py,sha256=mg9VbK0Ux9pwTbq9oICilnQG3xJLnnZEjOzzSg0IVpY,1424
51
51
  batFramework/gui/textInput.py,sha256=v4r110mYmPj0RB97DsCG81U06dUd-7cnNeBj-mnbdiE,11002
52
52
  batFramework/gui/toggle.py,sha256=icvg0GY0pErCZPWoje_SO7L6Ik_sM--XHTM-pUAwdY8,3997
53
53
  batFramework/gui/widget.py,sha256=KrkQH8Z2tSVcnCHhet-xXlHy3SqSjHByBQVNoTOs54E,14597
@@ -56,8 +56,8 @@ batFramework/gui/constraints/constraints.py,sha256=XFvrjFFN1nmbYzI6l54DlZkrRP-wW
56
56
  batFramework/templates/__init__.py,sha256=8XN-7JwYFKTRx_lnUL_If3spwgn5_2b7bwmrRRBPON0,46
57
57
  batFramework/templates/character.py,sha256=4UEcegUIeIgj48sVgzyRcT6yjpFOZ8Q_gHTtiB5j6kw,1348
58
58
  batFramework/templates/states.py,sha256=WeomVrQ10vHxVCj9Wnk1PcinKyb871uV910mQe287kI,5370
59
- batframework-1.0.9a3.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
60
- batframework-1.0.9a3.dist-info/METADATA,sha256=UpbSgm9XCqqMyFjRrXOdmPHYD70b-BW0SPVzedEvmCk,1694
61
- batframework-1.0.9a3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
62
- batframework-1.0.9a3.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
63
- batframework-1.0.9a3.dist-info/RECORD,,
59
+ batframework-1.0.9a5.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
60
+ batframework-1.0.9a5.dist-info/METADATA,sha256=-DZG32_J-cAgxPkZB9ZUcCkbVYif7bDtTM_8rnJCG7o,1694
61
+ batframework-1.0.9a5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
62
+ batframework-1.0.9a5.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
63
+ batframework-1.0.9a5.dist-info/RECORD,,
@@ -1,169 +0,0 @@
1
- import batFramework as bf
2
- from .cutscene import Cutscene, CutsceneManager
3
- from .transition import *
4
- from typing import Optional,Callable
5
-
6
- # Define the base CutsceneBlock class
7
- class CutsceneBlock:
8
- """
9
- Base class for cutscene blocks. Represents a unit of action in a cutscene.
10
- """
11
-
12
- # Constructor for the CutsceneBlock
13
- def __init__(self) -> None:
14
- # Callback function, parent cutscene, and state variables
15
- self.callback = None
16
- self.parent_cutscene: Cutscene = None
17
- self.get_flag = CutsceneManager().get_flag
18
- self.ended = False
19
- self.started = False
20
-
21
- def get_scene_at(self, index):
22
- return bf.CutsceneManager().manager.scenes[index]
23
-
24
- def set_scene(self, name, index=0):
25
- return CutsceneManager().manager.set_scene(name, index)
26
-
27
- def get_current_scene(self):
28
- return CutsceneManager().manager.get_current_scene()
29
-
30
- def get_scene(self, name):
31
- return CutsceneManager().manager.get_scene(name)
32
-
33
- # Set the parent cutscene for this block
34
- def set_parent_cutscene(self, parent):
35
- """
36
- Set the parent cutscene for this block.
37
-
38
- Args:
39
- parent: The parent cutscene object.
40
- """
41
- self.parent_cutscene = parent
42
-
43
- # Process an event (placeholder implementation, to be overridden in subclasses)
44
- def process_event(self, event):
45
- """
46
- Process an event for this cutscene block.
47
-
48
- Args:
49
- event: The event to be processed.
50
- """
51
- pass
52
-
53
- # Update the block (placeholder implementation, to be overridden in subclasses)
54
- def update(self, dt):
55
- """
56
- Update the cutscene block.
57
-
58
- Args:
59
- dt: Time elapsed since the last update.
60
- """
61
- pass
62
-
63
- # Start the block
64
- def start(self):
65
- """
66
- Start the cutscene block.
67
- """
68
- self.started = True
69
-
70
- # Mark the block as ended
71
- def end(self):
72
- """
73
- Mark the cutscene block as ended.
74
- """
75
- self.ended = True
76
-
77
- # Check if the block has ended
78
- def has_ended(self):
79
- """
80
- Check if the cutscene block has ended.
81
-
82
- Returns:
83
- bool: True if the block has ended, False otherwise.
84
- """
85
- return self.ended
86
-
87
-
88
- # Define the ParallelBlock class, a type of CutsceneBlock
89
- class ParallelBlock(CutsceneBlock):
90
- """
91
- Represents a parallel execution block for multiple Cutscene blocks.
92
- """
93
-
94
- def __init__(self, *blocks) -> None:
95
- super().__init__()
96
- # List of blocks to run in parallel
97
- self.blocks: list[CutsceneBlock] = list(blocks)
98
-
99
- # Start the parallel block (override the base class method)
100
- def start(self):
101
- super().start()
102
- # Start each block in parallel
103
- for block in self.blocks:
104
- block.start()
105
-
106
- # Process an event for each block in parallel
107
- def process_event(self, event):
108
- _ = [b.process_event(event) for b in self.blocks]
109
-
110
- # Update each block in parallel
111
- def update(self, dt):
112
- _ = [b.update(dt) for b in self.blocks]
113
-
114
- # Check if all blocks have ended
115
- def has_ended(self):
116
- return all(b.has_ended() for b in self.blocks)
117
-
118
-
119
- # Define the SceneTransitionBlock class, a type of CutsceneBlock
120
- class SceneTransitionBlock(CutsceneBlock):
121
- """
122
- Represents a scene transition Cutscene block.
123
- """
124
-
125
- # Constructor for SceneTransitionBlock
126
- def __init__(
127
- self, scene, transition: Transition = Fade(0.1), index: int = 0
128
- ) -> None:
129
- super().__init__()
130
- # Target scene, transition type, duration, and additional keyword arguments
131
- self.target_scene = scene
132
- self.transition = transition
133
- self.index = index
134
- # Timer to handle the end of the transition
135
- self.timer = bf.Timer(transition.duration, self.end)
136
-
137
- # Start the scene transition block
138
- def start(self):
139
- """
140
- Start the scene transition block.
141
- """
142
- super().start()
143
- # Initiate the scene transition
144
- if self.get_current_scene().name == self.target_scene:
145
- self.end()
146
- return
147
- CutsceneManager().manager.transition_to_scene(
148
- self.target_scene, self.transition, self.index
149
- )
150
- # Start the timer to handle the end of the transition
151
- self.timer.start()
152
-
153
- class DelayBlock(CutsceneBlock):
154
- def __init__(self, duration) -> None:
155
- super().__init__()
156
- self.timer = bf.Timer(duration=duration, end_callback=self.end)
157
-
158
- def start(self):
159
- super().start()
160
- self.timer.start()
161
-
162
- class FunctionBlock(CutsceneBlock):
163
- def __init__(self, func : Optional[Callable]) -> None:
164
- self.function = func
165
-
166
- def start(self):
167
- super().start()
168
- if self.function : self.function()
169
- self.end()