batframework 1.0.9a2__py3-none-any.whl → 1.0.9a4__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 +4 -3
- batFramework/audioManager.py +1 -1
- batFramework/cutscene.py +40 -125
- batFramework/cutsceneManager.py +31 -0
- batFramework/easingController.py +3 -2
- batFramework/enums.py +7 -1
- batFramework/gui/button.py +2 -2
- batFramework/gui/clickableWidget.py +12 -5
- batFramework/gui/constraints/constraints.py +4 -4
- batFramework/gui/container.py +1 -1
- batFramework/gui/debugger.py +6 -6
- batFramework/gui/image.py +6 -0
- batFramework/gui/indicator.py +2 -2
- batFramework/gui/layout.py +1 -1
- batFramework/gui/radioButton.py +2 -2
- batFramework/gui/root.py +9 -0
- batFramework/gui/slider.py +3 -2
- batFramework/gui/styleManager.py +6 -0
- batFramework/gui/textInput.py +3 -5
- batFramework/gui/toggle.py +3 -3
- batFramework/gui/widget.py +19 -12
- batFramework/manager.py +2 -0
- batFramework/renderGroup.py +3 -3
- batFramework/sceneManager.py +3 -0
- batFramework/timeManager.py +2 -3
- batFramework/transition.py +8 -8
- batFramework/triggerZone.py +3 -3
- {batframework-1.0.9a2.dist-info → batframework-1.0.9a4.dist-info}/METADATA +1 -1
- {batframework-1.0.9a2.dist-info → batframework-1.0.9a4.dist-info}/RECORD +32 -32
- {batframework-1.0.9a2.dist-info → batframework-1.0.9a4.dist-info}/WHEEL +1 -1
- batFramework/cutsceneBlocks.py +0 -169
- {batframework-1.0.9a2.dist-info → batframework-1.0.9a4.dist-info}/LICENCE +0 -0
- {batframework-1.0.9a2.dist-info → batframework-1.0.9a4.dist-info}/top_level.txt +0 -0
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
|
-
|
13
|
-
import
|
12
|
+
import batFramework.cutscene
|
13
|
+
from .cutsceneManager import CutsceneManager
|
14
14
|
from .audioManager import AudioManager
|
15
15
|
import batFramework.transition as transition
|
16
16
|
from .action import Action
|
@@ -67,7 +67,8 @@ def init(
|
|
67
67
|
print_version()
|
68
68
|
pygame.display.set_caption(window_caption)
|
69
69
|
init_screen(resolution, flags, vsync)
|
70
|
-
|
70
|
+
pygame.mixer.init()
|
71
|
+
|
71
72
|
ResourceManager().set_resource_path(
|
72
73
|
resource_path if resource_path is not None else "."
|
73
74
|
)
|
batFramework/audioManager.py
CHANGED
batFramework/cutscene.py
CHANGED
@@ -1,129 +1,44 @@
|
|
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
|
|
60
3
|
class Cutscene:
|
61
|
-
def __init__(self)
|
62
|
-
self.
|
63
|
-
self.
|
64
|
-
self.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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)
|
93
|
-
|
94
|
-
def get_scene(self, name):
|
95
|
-
return bf.CutsceneManager().manager.get_scene(name)
|
96
|
-
|
97
|
-
def add_block(self, *blocks: CutsceneBlock):
|
98
|
-
for block in blocks:
|
99
|
-
block.set_parent_cutscene(self)
|
100
|
-
self.cutscene_blocks.append(block)
|
101
|
-
|
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
|
-
|
106
|
-
def play(self):
|
107
|
-
self.block_index = 0
|
108
|
-
if self.cutscene_blocks:
|
109
|
-
self.cutscene_blocks[self.block_index].start()
|
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()
|
110
13
|
else:
|
111
|
-
self.
|
112
|
-
|
113
|
-
def
|
114
|
-
if self.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
+
|
28
|
+
def end(self):
|
29
|
+
self.is_over = True
|
30
|
+
|
31
|
+
|
32
|
+
class Wait(Cutscene):
|
33
|
+
def __init__(self,duration:float,scene_name:str="global"):
|
34
|
+
super().__init__()
|
35
|
+
self.duration = duration
|
36
|
+
self.scene_name = scene_name
|
37
|
+
def start(self):
|
38
|
+
self.timer = bf.SceneTimer(duration=self.duration,end_callback=self.end,scene_name=self.scene_name)
|
39
|
+
self.timer.start()
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# class TransitionToScene(bf.Cutscene):
|
44
|
+
# def __init__(self,scene_name:str,)
|
@@ -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/easingController.py
CHANGED
@@ -2,6 +2,7 @@ import pygame
|
|
2
2
|
import batFramework as bf
|
3
3
|
from functools import lru_cache
|
4
4
|
from .enums import easing
|
5
|
+
from typing import Callable,Any
|
5
6
|
|
6
7
|
|
7
8
|
@lru_cache(maxsize=None)
|
@@ -22,11 +23,11 @@ class EasingController(bf.Timer):
|
|
22
23
|
easing_function: easing = easing.LINEAR,
|
23
24
|
duration: float = 1,
|
24
25
|
update_callback=None,
|
25
|
-
end_callback=None,
|
26
|
+
end_callback: Callable[[],Any]=None,
|
26
27
|
loop: bool = False,
|
27
28
|
) -> None:
|
28
29
|
self.easing_function = easing_function
|
29
|
-
self.update_callback = update_callback
|
30
|
+
self.update_callback: Callable[[float],Any] = update_callback
|
30
31
|
self.value: float = 0.0
|
31
32
|
super().__init__(duration, end_callback, loop)
|
32
33
|
|
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/button.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
from .label import Label
|
2
2
|
import batFramework as bf
|
3
|
-
from typing import Self, Callable
|
3
|
+
from typing import Self, Callable,Any
|
4
4
|
from .clickableWidget import ClickableWidget
|
5
5
|
import pygame
|
6
6
|
from math import ceil
|
7
7
|
|
8
8
|
|
9
9
|
class Button(Label, ClickableWidget):
|
10
|
-
def __init__(self, text: str = "", callback:
|
10
|
+
def __init__(self, text: str = "", callback: Callable[[],Any] = None) -> None:
|
11
11
|
super().__init__(text=text)
|
12
12
|
self.set_callback(callback)
|
13
13
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from .label import Label
|
2
2
|
import batFramework as bf
|
3
|
-
from typing import Self, Callable
|
3
|
+
from typing import Self, Callable, Any
|
4
4
|
from .interactiveWidget import InteractiveWidget
|
5
5
|
from .shape import Shape
|
6
6
|
import pygame
|
@@ -10,7 +10,7 @@ from math import ceil
|
|
10
10
|
class ClickableWidget(Shape, InteractiveWidget):
|
11
11
|
_cache: dict = {}
|
12
12
|
|
13
|
-
def __init__(self, callback:
|
13
|
+
def __init__(self, callback: Callable[[],Any] = None, *args, **kwargs) -> None:
|
14
14
|
super().__init__(*args, **kwargs)
|
15
15
|
self.callback = callback
|
16
16
|
self.is_pressed: bool = False
|
@@ -28,8 +28,15 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
28
28
|
self.set_relief(self.unpressed_relief)
|
29
29
|
|
30
30
|
def get_min_required_size(self) -> tuple[float, float]:
|
31
|
-
|
32
|
-
|
31
|
+
if not (self.autoresize_w or self.autoresize_h):
|
32
|
+
return self.rect.size
|
33
|
+
|
34
|
+
res = super().get_min_required_size()
|
35
|
+
res = res[0],res[1]+self.unpressed_relief
|
36
|
+
print("hey",res)
|
37
|
+
return res[0] if self.autoresize_w else self.rect.w, (
|
38
|
+
res[1] if self.autoresize_h else self.rect.h
|
39
|
+
)
|
33
40
|
|
34
41
|
|
35
42
|
def set_unpressed_relief(self, relief: int) -> Self:
|
@@ -111,7 +118,7 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
111
118
|
def is_enabled(self) -> bool:
|
112
119
|
return self.enabled
|
113
120
|
|
114
|
-
def set_callback(self, callback: Callable) -> Self:
|
121
|
+
def set_callback(self, callback: Callable[[],Any]) -> Self:
|
115
122
|
self.callback = callback
|
116
123
|
return self
|
117
124
|
|
@@ -41,16 +41,16 @@ class MinWidth(Constraint):
|
|
41
41
|
self.min_width = width
|
42
42
|
|
43
43
|
def on_removal(self, child_widget: Widget) -> None:
|
44
|
-
|
44
|
+
return
|
45
|
+
# child_widget.set_autoresize_w(False)
|
45
46
|
|
46
47
|
def evaluate(self, parent_widget, child_widget):
|
47
48
|
res = child_widget.rect.width >= self.min_width
|
48
|
-
if not res:
|
49
|
-
child_widget.set_autoresize_w(False)
|
49
|
+
# if not res:
|
50
|
+
# child_widget.set_autoresize_w(False)
|
50
51
|
return res
|
51
52
|
|
52
53
|
def apply_constraint(self, parent_widget, child_widget):
|
53
|
-
child_widget.set_autoresize_w(True)
|
54
54
|
child_widget.set_size((self.min_width, None))
|
55
55
|
|
56
56
|
def __eq__(self,other:"Constraint")->bool:
|
batFramework/gui/container.py
CHANGED
@@ -106,7 +106,7 @@ class Container(Shape, InteractiveWidget):
|
|
106
106
|
return self
|
107
107
|
|
108
108
|
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
109
|
-
if self.
|
109
|
+
if self.rect.collidepoint(x, y):
|
110
110
|
for child in reversed(self.children):
|
111
111
|
result = child.top_at(x, y)
|
112
112
|
if result is not None:
|
batFramework/gui/debugger.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from .label import Label
|
2
|
-
from typing import Self
|
2
|
+
from typing import Self,Callable,Any
|
3
3
|
import batFramework as bf
|
4
4
|
import pygame
|
5
5
|
|
@@ -11,8 +11,8 @@ def convert_to_int(*args):
|
|
11
11
|
class Debugger(Label):
|
12
12
|
def __init__(self) -> None:
|
13
13
|
super().__init__("")
|
14
|
-
self.static_data: dict = {}
|
15
|
-
self.dynamic_data: dict = {}
|
14
|
+
self.static_data: dict[str,Any] = {}
|
15
|
+
self.dynamic_data: dict[str,Callable[[],str]] = {}
|
16
16
|
self.refresh_rate = 10
|
17
17
|
self.refresh_counter: float = 0
|
18
18
|
self.add_tags("debugger")
|
@@ -26,18 +26,18 @@ class Debugger(Label):
|
|
26
26
|
self.static_data[key] = str(data)
|
27
27
|
self.update_text()
|
28
28
|
|
29
|
-
def add_dynamic(self, key: str, func) -> None:
|
29
|
+
def add_dynamic(self, key: str, func:Callable[[],str]) -> None:
|
30
30
|
self.dynamic_data[key] = func
|
31
31
|
self.update_text()
|
32
32
|
|
33
|
-
def remove_static(self, key) -> bool:
|
33
|
+
def remove_static(self, key:str) -> bool:
|
34
34
|
try:
|
35
35
|
self.static_data.pop(key)
|
36
36
|
return True
|
37
37
|
except KeyError:
|
38
38
|
return False
|
39
39
|
|
40
|
-
def remove_dynamic(self, key) -> bool:
|
40
|
+
def remove_dynamic(self, key:str) -> bool:
|
41
41
|
try:
|
42
42
|
self.dynamic_data.pop(key)
|
43
43
|
return True
|
batFramework/gui/image.py
CHANGED
@@ -37,6 +37,12 @@ class Image(Shape):
|
|
37
37
|
)
|
38
38
|
super().build()
|
39
39
|
|
40
|
+
def get_min_required_size(self) -> tuple[float, float]:
|
41
|
+
res = self.rect.size
|
42
|
+
return self.inflate_rect_by_padding((0, 0, *res)).size
|
43
|
+
|
44
|
+
|
45
|
+
|
40
46
|
|
41
47
|
def from_path(self, path: str) -> Self:
|
42
48
|
tmp = bf.ResourceManager().get_image(path, self.convert_alpha)
|
batFramework/gui/indicator.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from .shape import Shape
|
2
|
-
from typing import Any, Self
|
2
|
+
from typing import Any, Self, Callable
|
3
3
|
import pygame
|
4
4
|
from .widget import Widget
|
5
5
|
from .interactiveWidget import InteractiveWidget
|
@@ -37,7 +37,7 @@ class ToggleIndicator(Indicator):
|
|
37
37
|
# TODO aspect ratio would be good right about here
|
38
38
|
# self.add_constraint(ConstraintAspectRatio(1))
|
39
39
|
|
40
|
-
def set_callback(self, callback) -> Self:
|
40
|
+
def set_callback(self, callback : Callable[[bool],Any]) -> Self:
|
41
41
|
self.callback = callback
|
42
42
|
return self
|
43
43
|
|
batFramework/gui/layout.py
CHANGED
batFramework/gui/radioButton.py
CHANGED
@@ -45,9 +45,9 @@ class RadioVariable:
|
|
45
45
|
def __init__(self) -> None:
|
46
46
|
self.buttons: list[RadioButton] = []
|
47
47
|
self.value = None
|
48
|
-
self.modify_callback: Callable[[
|
48
|
+
self.modify_callback: Callable[[bool],Any] = None
|
49
49
|
|
50
|
-
def set_modify_callback(self, callback) -> Self:
|
50
|
+
def set_modify_callback(self, callback:Callable[[bool],Any]) -> Self:
|
51
51
|
self.modify_callback = callback
|
52
52
|
return self
|
53
53
|
|
batFramework/gui/root.py
CHANGED
@@ -138,6 +138,15 @@ class Root(InteractiveWidget):
|
|
138
138
|
if self.hovered and isinstance(self.hovered, InteractiveWidget):
|
139
139
|
self.hovered.on_enter()
|
140
140
|
|
141
|
+
def apply_updates(self):
|
142
|
+
if any(child.dirty_shape for child in self.children):
|
143
|
+
self.dirty_shape = True # Mark layout as dirty if any child changed size
|
144
|
+
|
145
|
+
if self.dirty_shape:
|
146
|
+
for child in self.children:
|
147
|
+
child.apply_updates()
|
148
|
+
self.dirty_shape = False
|
149
|
+
|
141
150
|
def draw(self, camera: bf.Camera) -> None:
|
142
151
|
super().draw(camera)
|
143
152
|
if (
|
batFramework/gui/slider.py
CHANGED
@@ -66,7 +66,7 @@ class Slider(Button):
|
|
66
66
|
super().__init__(text, None)
|
67
67
|
self.gap: float | int = 0
|
68
68
|
self.spacing: bf.spacing = bf.spacing.MANUAL
|
69
|
-
self.modified_callback = None
|
69
|
+
self.modified_callback : Callable[[float],Any] = None
|
70
70
|
self.meter: SliderMeter = SliderMeter()
|
71
71
|
self.handle = SliderHandle()
|
72
72
|
self.add(self.meter, self.handle)
|
@@ -102,7 +102,7 @@ class Slider(Button):
|
|
102
102
|
self.dirty_shape = True
|
103
103
|
return self
|
104
104
|
|
105
|
-
def set_modify_callback(self, callback) -> Self:
|
105
|
+
def set_modify_callback(self, callback : Callable[[float],Any]) -> Self:
|
106
106
|
self.modified_callback = callback
|
107
107
|
return self
|
108
108
|
|
@@ -175,6 +175,7 @@ class Slider(Button):
|
|
175
175
|
if not self.text_rect:
|
176
176
|
self.text_rect.size = self._get_text_rect_required_size()
|
177
177
|
w, h = self.text_rect.size
|
178
|
+
h+=self.unpressed_relief
|
178
179
|
return self.inflate_rect_by_padding((0, 0, w + gap + self.meter.get_min_required_size()[1], h)).size
|
179
180
|
|
180
181
|
def _build_layout(self) -> None:
|
batFramework/gui/styleManager.py
CHANGED
@@ -39,6 +39,12 @@ class StyleManager(metaclass=Singleton):
|
|
39
39
|
self.lookup = {key: False for key in self.lookup}
|
40
40
|
self.update()
|
41
41
|
|
42
|
+
def update_forced(self):
|
43
|
+
for widget in self.widgets:
|
44
|
+
for style in self.styles:
|
45
|
+
style.apply(widget)
|
46
|
+
self.lookup[widget] = True
|
47
|
+
|
42
48
|
def update(self):
|
43
49
|
for widget in self.widgets:
|
44
50
|
if self.lookup[widget]:
|
batFramework/gui/textInput.py
CHANGED
@@ -140,7 +140,7 @@ class TextInput(Label, InteractiveWidget):
|
|
140
140
|
lines = self.text.split('\n')
|
141
141
|
line_x, line_y = self.cursor_position
|
142
142
|
|
143
|
-
height = self.font_object.
|
143
|
+
height = self.font_object.get_linesize()
|
144
144
|
|
145
145
|
cursor_y = self.get_padded_rect().__getattribute__(self.alignment.value)[1] - self.rect.top
|
146
146
|
cursor_y += line_y * height
|
@@ -248,10 +248,8 @@ class TextInput(Label, InteractiveWidget):
|
|
248
248
|
return
|
249
249
|
cursor_rect = self.get_cursor_rect()
|
250
250
|
cursor_rect.move_ip(-self.scroll)
|
251
|
-
|
252
251
|
|
253
252
|
pygame.draw.rect(self.surface, bf.color.CLOUD, cursor_rect.inflate(2,2))
|
254
|
-
|
255
253
|
pygame.draw.rect(self.surface, self.text_color, cursor_rect)
|
256
254
|
|
257
255
|
def paint(self) -> None:
|
@@ -272,9 +270,9 @@ class TextInput(Label, InteractiveWidget):
|
|
272
270
|
|
273
271
|
|
274
272
|
if cursor_rect.right > area.right+self.scroll.x:
|
275
|
-
self.scroll.x=cursor_rect.right - area.right
|
273
|
+
self.scroll.x=cursor_rect.right - area.right - cursor_rect.w*2
|
276
274
|
elif cursor_rect.x < self.scroll.x+area.left:
|
277
|
-
self.scroll.x= cursor_rect.left - area.left
|
275
|
+
self.scroll.x= cursor_rect.left - area.left
|
278
276
|
self.scroll.x = max(self.scroll.x,0)
|
279
277
|
|
280
278
|
if cursor_rect.bottom > area.bottom + self.scroll.y:
|
batFramework/gui/toggle.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
from .button import Button
|
2
2
|
from .indicator import Indicator, ToggleIndicator
|
3
3
|
import batFramework as bf
|
4
|
-
from typing import Self
|
4
|
+
from typing import Self,Callable,Any
|
5
5
|
import pygame
|
6
6
|
|
7
7
|
|
8
8
|
class Toggle(Button):
|
9
|
-
def __init__(self, text: str = "", callback=None, default_value: bool = False) -> None:
|
9
|
+
def __init__(self, text: str = "", callback : Callable[[bool],Any]=None, default_value: bool = False) -> None:
|
10
10
|
self.value: bool = default_value
|
11
11
|
self.indicator: ToggleIndicator = ToggleIndicator(default_value)
|
12
12
|
self.gap: float | int = 0
|
@@ -59,7 +59,7 @@ class Toggle(Button):
|
|
59
59
|
self.indicator.get_min_required_size()[0],
|
60
60
|
self.text_rect.w + self.font_object.point_size + (self.gap if self.text else 0),
|
61
61
|
),
|
62
|
-
self.text_rect.h,
|
62
|
+
self.text_rect.h+self.unpressed_relief,
|
63
63
|
)
|
64
64
|
return self.inflate_rect_by_padding((0, 0, *size)).size
|
65
65
|
|
batFramework/gui/widget.py
CHANGED
@@ -174,11 +174,11 @@ class Widget(bf.Drawable, metaclass=WidgetMeta):
|
|
174
174
|
return self.rect.bottom - self.padding[3]
|
175
175
|
|
176
176
|
def get_debug_outlines(self):
|
177
|
-
if
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
if self.visible:
|
178
|
+
if any(self.padding):
|
179
|
+
yield (self.get_padded_rect(), self.debug_color)
|
180
|
+
else:
|
181
|
+
yield (self.rect, self.debug_color)
|
182
182
|
for child in self.children:
|
183
183
|
yield from child.get_debug_outlines()
|
184
184
|
|
@@ -272,11 +272,11 @@ class Widget(bf.Drawable, metaclass=WidgetMeta):
|
|
272
272
|
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
273
273
|
if self.children:
|
274
274
|
for child in reversed(self.children):
|
275
|
-
if child.visible:
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
return self if
|
275
|
+
# if child.visible:
|
276
|
+
r = child.top_at(x, y)
|
277
|
+
if r is not None:
|
278
|
+
return r
|
279
|
+
return self if self.rect.collidepoint(x, y) else None
|
280
280
|
|
281
281
|
def add(self, *children: "Widget") -> Self:
|
282
282
|
self.children.extend(children)
|
@@ -387,20 +387,27 @@ class Widget(bf.Drawable, metaclass=WidgetMeta):
|
|
387
387
|
|
388
388
|
|
389
389
|
def apply_updates(self) -> None:
|
390
|
-
|
390
|
+
|
391
|
+
if self.dirty_constraints:
|
392
|
+
self.resolve_constraints() # Finalize positioning based on final size
|
393
|
+
self.dirty_constraints = False
|
394
|
+
|
395
|
+
# Build shape if needed
|
391
396
|
if self.dirty_shape:
|
392
397
|
self.build() # Finalize widget size
|
393
398
|
self.dirty_shape = False
|
394
399
|
self.dirty_surface = True
|
400
|
+
self.dirty_constraints = True
|
395
401
|
# Propagate dirty_constraints to children in case size affects their position
|
396
402
|
for child in self.children:
|
397
403
|
child.dirty_constraints = True
|
398
404
|
|
399
|
-
#
|
405
|
+
# Resolve constraints now that size is finalized
|
400
406
|
if self.dirty_constraints:
|
401
407
|
self.resolve_constraints() # Finalize positioning based on final size
|
402
408
|
self.dirty_constraints = False
|
403
409
|
|
410
|
+
|
404
411
|
# Step 3: Paint the surface if flagged as dirty
|
405
412
|
if self.dirty_surface:
|
406
413
|
self.paint()
|
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:
|
batFramework/renderGroup.py
CHANGED
@@ -8,13 +8,13 @@ from typing import Self, Iterator, Callable
|
|
8
8
|
"""
|
9
9
|
|
10
10
|
|
11
|
-
class RenderGroup(bf.
|
11
|
+
class RenderGroup(bf.Drawable):
|
12
12
|
def __init__(
|
13
|
-
self, entity_iterator: Callable[[], Iterator[bf.
|
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):
|
batFramework/sceneManager.py
CHANGED
@@ -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:
|
batFramework/timeManager.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
import batFramework as bf
|
2
|
-
from typing import Self
|
3
|
-
from typing import Callable, Union, Self
|
2
|
+
from typing import Callable, Union, Self,Any
|
4
3
|
|
5
4
|
|
6
5
|
class Timer:
|
7
6
|
_count: int = 0
|
8
7
|
_available_ids: set[int] = set()
|
9
8
|
|
10
|
-
def __init__(self, duration: Union[float, int], end_callback: Callable, loop: bool = False, register: str = "global") -> None:
|
9
|
+
def __init__(self, duration: Union[float, int], end_callback: Callable[[],Any], loop: bool = False, register: str = "global") -> None:
|
11
10
|
if Timer._available_ids:
|
12
11
|
self.uid = Timer._available_ids.pop()
|
13
12
|
else:
|
batFramework/transition.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import batFramework as bf
|
2
|
-
from typing import Self
|
2
|
+
from typing import Self,Callable,Any
|
3
3
|
import pygame
|
4
4
|
|
5
5
|
"""
|
@@ -23,24 +23,24 @@ class Transition:
|
|
23
23
|
update_callback=self.update,
|
24
24
|
end_callback=self.end,
|
25
25
|
)
|
26
|
-
self.start_callback = None
|
27
|
-
self.update_callback = None
|
28
|
-
self.end_callback = None
|
26
|
+
self.start_callback : Callable[[],Any] = None
|
27
|
+
self.update_callback : Callable[[float],Any]= None
|
28
|
+
self.end_callback : Callable[[],Any]= None
|
29
29
|
self.source: pygame.Surface = None
|
30
30
|
self.dest: pygame.Surface = None
|
31
31
|
|
32
32
|
def __repr__(self) -> str:
|
33
33
|
return f"Transition {self.__class__},{self.duration}"
|
34
34
|
|
35
|
-
def set_start_callback(self, func) -> Self:
|
35
|
+
def set_start_callback(self, func : Callable[[],Any]) -> Self:
|
36
36
|
self.start_callback = func
|
37
37
|
return self
|
38
38
|
|
39
|
-
def set_update_callback(self, func) -> Self:
|
39
|
+
def set_update_callback(self, func : Callable[[float],Any]) -> Self:
|
40
40
|
self.update_callback = func
|
41
41
|
return self
|
42
42
|
|
43
|
-
def set_end_callback(self, func) -> Self:
|
43
|
+
def set_end_callback(self, func : Callable[[],Any]) -> Self:
|
44
44
|
self.end_callback = func
|
45
45
|
return self
|
46
46
|
|
@@ -118,7 +118,7 @@ class FadeColor(Transition):
|
|
118
118
|
def transition_to_end(self):
|
119
119
|
self.next_step(self.end)
|
120
120
|
|
121
|
-
def next_step(self, callback=None) -> None:
|
121
|
+
def next_step(self, callback : Callable[[],Any]=None) -> None:
|
122
122
|
self.index += 1
|
123
123
|
if callback:
|
124
124
|
callback()
|
batFramework/triggerZone.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import batFramework as bf
|
2
|
-
|
2
|
+
from typing import Callable,Any
|
3
3
|
|
4
4
|
class TriggerZone(bf.Entity):
|
5
|
-
def __init__(self, size, trigger, callback, active=True) -> None:
|
5
|
+
def __init__(self, size, trigger, callback: Callable[[Any],Any], active=True) -> None:
|
6
6
|
super().__init__(size, True)
|
7
7
|
self.set_debug_color(bf.color.RED)
|
8
8
|
self.active = active
|
@@ -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):
|
16
|
+
def set_callback(self, callback: Callable[[Any],Any]):
|
17
17
|
self.callback = callback
|
18
18
|
return self
|
19
19
|
|
@@ -1,63 +1,63 @@
|
|
1
|
-
batFramework/__init__.py,sha256=
|
1
|
+
batFramework/__init__.py,sha256=Fc9uFdDnmhJ1bhCI550T9cu_Zy-ni-avSs5pLmPEgiM,2595
|
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
|
5
5
|
batFramework/animation.py,sha256=_XcH6r3TVQZUcLbhzUnTNlXrjy-J-nYiRmFpxvTYEoc,1934
|
6
|
-
batFramework/audioManager.py,sha256=
|
6
|
+
batFramework/audioManager.py,sha256=ANn6GXDm5bcThih0KD8jrF54Re20A6kxHQrVJu9QYxc,3850
|
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=
|
11
|
-
batFramework/
|
10
|
+
batFramework/cutscene.py,sha256=oc6Ktl2t7zO-oH-HWU18wB5ABMyWg7-h3jREGKpcu50,1315
|
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
|
-
batFramework/easingController.py,sha256=
|
14
|
+
batFramework/easingController.py,sha256=ql_nt8unwUZLy7MC7unzDn5eTW44VtjrOTCDs8WS0eY,1750
|
15
15
|
batFramework/entity.py,sha256=wMQKR6IxQ69vtPY4nGsz7WnY9ApPhO_VY08IYx6yUu8,2910
|
16
|
-
batFramework/enums.py,sha256=
|
16
|
+
batFramework/enums.py,sha256=xkT4yepdLLQn-5YWoSxhHamXE7w_M-GIw47dWWHfKIs,2185
|
17
17
|
batFramework/fontManager.py,sha256=M7h6AVq9Fwr51UTCFoGsg_PSurdjByA4w8qouXq4EKE,2254
|
18
|
-
batFramework/manager.py,sha256=
|
18
|
+
batFramework/manager.py,sha256=TQ0Q1f_GbQE8h4G9zCNQgtNTKNCj630S43Ai4e0yZik,4488
|
19
19
|
batFramework/particle.py,sha256=Aps9eJNdFag-TlduMSezKp4ocFQVvI6iZ98chhdhbgE,3081
|
20
|
-
batFramework/renderGroup.py,sha256=
|
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=
|
23
|
+
batFramework/sceneManager.py,sha256=GCGt7DYoty_wX2LVEhv0C6TaNyNWhKvWocwOqxUIBXc,7099
|
24
24
|
batFramework/scrollingSprite.py,sha256=_1-hp7y3pC5m8g2VhFVgGOuJsOkOi8adhQiI2Rb0uPY,4133
|
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
|
28
|
-
batFramework/timeManager.py,sha256=
|
29
|
-
batFramework/transition.py,sha256
|
30
|
-
batFramework/triggerZone.py,sha256=
|
28
|
+
batFramework/timeManager.py,sha256=TT_pynpS1wYmSK6s8ksQTt-coR9EeB0mYimhq5yrK08,4975
|
29
|
+
batFramework/transition.py,sha256=tKthKfGyv1V39eIiNGSGL---KcZXix3YIGg9RirOcLc,6809
|
30
|
+
batFramework/triggerZone.py,sha256=MaPp20UoyRHAMiN0_sBanJJ_0cWnYXZEeY-BEaDTDxQ,652
|
31
31
|
batFramework/utils.py,sha256=vfndaYn4wMy0W746C6oCWCvnUyk9BxPL2vIpGyEDssU,9958
|
32
32
|
batFramework/gui/__init__.py,sha256=OFAKZkafWX-BfDjF4MILmigVT1lywnsfH2pOIJwUybY,691
|
33
33
|
batFramework/gui/animatedLabel.py,sha256=KePSSd6bTeJ5UXoPUpvY7QRx5Uah5-qpBDGby6xRgqU,2752
|
34
|
-
batFramework/gui/button.py,sha256=
|
35
|
-
batFramework/gui/clickableWidget.py,sha256=
|
36
|
-
batFramework/gui/container.py,sha256=
|
37
|
-
batFramework/gui/debugger.py,sha256=
|
34
|
+
batFramework/gui/button.py,sha256=p_wMcaijpUbNuoRBNkhplrZqsB3gdl7mVpduR-UFm_4,1803
|
35
|
+
batFramework/gui/clickableWidget.py,sha256=8wHuH_aBuNrzG5_YZLfmtc65n0jtlDrJV3rFd9M4QSg,7477
|
36
|
+
batFramework/gui/container.py,sha256=2EIPpumiswH365Tq-3iF2FzApY2T440O9qijAx7SkpU,6280
|
37
|
+
batFramework/gui/debugger.py,sha256=0w2B4qQ5MeFwwP46zG7KTzIFzh2fmtU10UH96b_hT9Y,3997
|
38
38
|
batFramework/gui/draggableWidget.py,sha256=SKG7oMInZ_GTnrbv2T0aqlppuiuLX1tkVSCQJtRMlk8,1392
|
39
|
-
batFramework/gui/image.py,sha256=
|
40
|
-
batFramework/gui/indicator.py,sha256=
|
39
|
+
batFramework/gui/image.py,sha256=CPDSF7Fz1zmGAK-ii7R4MIAD5EZCnPw4mpD_cGv77U8,1925
|
40
|
+
batFramework/gui/indicator.py,sha256=31QAyvT9w-eCWUSoK4pV-4TsTzFvkY_g5snoeI1hATM,1619
|
41
41
|
batFramework/gui/interactiveWidget.py,sha256=ww9WsR2Y87og7NtnzCcyc1zIPE-Bjtn0YZ0SOfKMUbQ,6633
|
42
42
|
batFramework/gui/label.py,sha256=6hkD54lrp8ZPnKm75001NnfTli22rSKUdWlC-1bRIdE,11672
|
43
|
-
batFramework/gui/layout.py,sha256
|
43
|
+
batFramework/gui/layout.py,sha256=MJjcz6fjTWtt4-Td0dAqKd3XRDlRJ5QaDpRbdYEj1w8,21661
|
44
44
|
batFramework/gui/meter.py,sha256=RFzAhSzR3O-Pw0wjdfApWGWFQSJoYa4WohkiREDAAJc,2395
|
45
|
-
batFramework/gui/radioButton.py,sha256=
|
46
|
-
batFramework/gui/root.py,sha256=
|
45
|
+
batFramework/gui/radioButton.py,sha256=DgCtN1j1s2rUITpdYqArqQ36NnNGump7FiTe_ndEzJg,2436
|
46
|
+
batFramework/gui/root.py,sha256=r8dhI2xd2h5bUbTe4x_On77BTTZ7Sf8qY5wWJimWXds,5078
|
47
47
|
batFramework/gui/shape.py,sha256=PSQRqa8jYA8VsBXRQcpcCuEvTYmWDW8zJkzA_eRFPIo,9349
|
48
|
-
batFramework/gui/slider.py,sha256=
|
48
|
+
batFramework/gui/slider.py,sha256=rt0f2jnxyd89uepyBqBueP3qw6y9ZTIRGXipI9fhBs4,8467
|
49
49
|
batFramework/gui/style.py,sha256=OeLbft0RkIslQ2IcZpBeF6TaQDONIoBcAHj_Bkh9gFw,131
|
50
|
-
batFramework/gui/styleManager.py,sha256=
|
51
|
-
batFramework/gui/textInput.py,sha256=
|
52
|
-
batFramework/gui/toggle.py,sha256=
|
53
|
-
batFramework/gui/widget.py,sha256=
|
50
|
+
batFramework/gui/styleManager.py,sha256=ZWkGBkNQngJVU8k9OHrTeKzGYc5Hj4JAVATrU1MufB4,1423
|
51
|
+
batFramework/gui/textInput.py,sha256=v4r110mYmPj0RB97DsCG81U06dUd-7cnNeBj-mnbdiE,11002
|
52
|
+
batFramework/gui/toggle.py,sha256=icvg0GY0pErCZPWoje_SO7L6Ik_sM--XHTM-pUAwdY8,3997
|
53
|
+
batFramework/gui/widget.py,sha256=KrkQH8Z2tSVcnCHhet-xXlHy3SqSjHByBQVNoTOs54E,14597
|
54
54
|
batFramework/gui/constraints/__init__.py,sha256=qqXE8nnSrEvCSeHdqY8UYPZLetqdubFPI7IdZuh35QE,26
|
55
|
-
batFramework/gui/constraints/constraints.py,sha256=
|
55
|
+
batFramework/gui/constraints/constraints.py,sha256=XFvrjFFN1nmbYzI6l54DlZkrRP-wWXfgXrtE4T5egCA,29707
|
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.
|
60
|
-
batframework-1.0.
|
61
|
-
batframework-1.0.
|
62
|
-
batframework-1.0.
|
63
|
-
batframework-1.0.
|
59
|
+
batframework-1.0.9a4.dist-info/LICENCE,sha256=A65iXbMDbOxQLDNOODJLqA7o5RxszYlEqIgNSzBQRf4,1073
|
60
|
+
batframework-1.0.9a4.dist-info/METADATA,sha256=JIZ73b5rzLH38fgZtEOrFNIVvQpMoI5dpT0Y7CZJ5iU,1694
|
61
|
+
batframework-1.0.9a4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
62
|
+
batframework-1.0.9a4.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
|
63
|
+
batframework-1.0.9a4.dist-info/RECORD,,
|
batFramework/cutsceneBlocks.py
DELETED
@@ -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()
|
File without changes
|
File without changes
|