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.
- batFramework/__init__.py +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/gui/slider.py
DELETED
@@ -1,220 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from .meter import Meter
|
3
|
-
from .button import Button
|
4
|
-
from .indicator import *
|
5
|
-
from .meter import Meter
|
6
|
-
from .shape import Shape
|
7
|
-
from .interactiveWidget import InteractiveWidget
|
8
|
-
|
9
|
-
class SliderHandle(Indicator, DraggableWidget):
|
10
|
-
|
11
|
-
def __str__(self) -> str:
|
12
|
-
return "SliderHandle"
|
13
|
-
|
14
|
-
def on_click_down(self, button: int) -> None:
|
15
|
-
super().on_click_down(button)
|
16
|
-
if button == 1:
|
17
|
-
self.parent.get_focus()
|
18
|
-
|
19
|
-
def on_exit(self) -> None:
|
20
|
-
self.is_hovered = False
|
21
|
-
self.do_on_exit()
|
22
|
-
|
23
|
-
def do_on_drag(self,drag_start:tuple[float,float],drag_end: tuple[float,float]) -> None:
|
24
|
-
super().do_on_drag(drag_start,drag_end)
|
25
|
-
m : Meter = self.parent.meter
|
26
|
-
r = m.get_padded_rect()
|
27
|
-
position = self.rect.centerx
|
28
|
-
self.rect.clamp_ip(r)
|
29
|
-
# Adjust handle position to value
|
30
|
-
new_value = self.parent.position_to_value(position)
|
31
|
-
self.parent.set_value(new_value)
|
32
|
-
self.rect.centerx = self.parent.value_to_position(new_value)
|
33
|
-
|
34
|
-
def top_at(self, x, y):
|
35
|
-
return Widget.top_at(self, x, y)
|
36
|
-
|
37
|
-
|
38
|
-
class SliderMeter(Meter,InteractiveWidget):
|
39
|
-
|
40
|
-
def __str__(self) -> str:
|
41
|
-
return "SliderMeter"
|
42
|
-
|
43
|
-
def on_click_down(self,button:int)->None:
|
44
|
-
if button == 1 :
|
45
|
-
self.parent.get_focus()
|
46
|
-
r = self.get_root()
|
47
|
-
if r:
|
48
|
-
pos = r.drawing_camera.screen_to_world(pygame.mouse.get_pos())[0]
|
49
|
-
self.parent.set_value(self.parent.position_to_value(pos))
|
50
|
-
|
51
|
-
self.do_on_click_down(button)
|
52
|
-
|
53
|
-
class Slider(Button):
|
54
|
-
def __init__(self, text: str, default_value: float = 1.0) -> None:
|
55
|
-
super().__init__(text, None)
|
56
|
-
self.gap: float | int = 0
|
57
|
-
self.spacing :bf.spacing = bf.spacing.MANUAL
|
58
|
-
self.modified_callback = None
|
59
|
-
self.meter: SliderMeter = SliderMeter()
|
60
|
-
self.handle = SliderHandle().set_color(bf.color.CLOUD)
|
61
|
-
self.add(self.meter,self.handle)
|
62
|
-
self.meter.set_debug_color(bf.color.RED)
|
63
|
-
self.set_value(default_value,True)
|
64
|
-
# print(self.handle.rect)
|
65
|
-
# self.handle.set_visible(False)
|
66
|
-
|
67
|
-
def __str__(self) -> str:
|
68
|
-
return "Slider"
|
69
|
-
|
70
|
-
def set_gap(self, value: int | float) -> Self:
|
71
|
-
value = max(0, value)
|
72
|
-
self.gap = value
|
73
|
-
return self
|
74
|
-
|
75
|
-
def get_min_required_size(self) -> tuple[float, float]:
|
76
|
-
gap = self.gap if self.text else 0
|
77
|
-
if not self.text_rect:
|
78
|
-
params = {
|
79
|
-
"font_name": self.font_object.name,
|
80
|
-
"text": self.text,
|
81
|
-
"antialias": False,
|
82
|
-
"color": "white",
|
83
|
-
"bgcolor": "black", # if (self.has_alpha_color() or self.draw_mode == bf.drawMode.TEXTURED) else self.color,
|
84
|
-
"wraplength": int(self.get_padded_width()) if self.auto_wraplength else 0,
|
85
|
-
}
|
86
|
-
self.text_rect.size = self._render_font(params).get_size()
|
87
|
-
w,h = self.text_rect.size
|
88
|
-
return self.inflate_rect_by_padding((0, 0,w + gap + self.meter.rect.w,h)).size
|
89
|
-
|
90
|
-
def set_spacing(self,spacing:bf.spacing)->Self:
|
91
|
-
if spacing == self.spacing : return self
|
92
|
-
self.spacing = spacing
|
93
|
-
self.dirty_shape = True
|
94
|
-
return self
|
95
|
-
|
96
|
-
def set_modify_callback(self, callback) -> Self:
|
97
|
-
self.modified_callback = callback
|
98
|
-
return self
|
99
|
-
|
100
|
-
def set_range(self, range_min: float, range_max: float) -> Self:
|
101
|
-
self.meter.set_range(range_min, range_max)
|
102
|
-
return self
|
103
|
-
|
104
|
-
def set_step(self, step: float) -> Self:
|
105
|
-
self.meter.set_step(step)
|
106
|
-
return self
|
107
|
-
|
108
|
-
def set_value(self, value, no_callback: bool = False) -> Self:
|
109
|
-
if self.meter.value != value :
|
110
|
-
self.meter.set_value(value)
|
111
|
-
self.dirty_shape = True
|
112
|
-
if self.modified_callback and (not no_callback):
|
113
|
-
self.modified_callback(self.meter.value)
|
114
|
-
return self
|
115
|
-
|
116
|
-
def get_value(self)->float:
|
117
|
-
return self.meter.get_value()
|
118
|
-
|
119
|
-
def do_on_key_down(self, key):
|
120
|
-
if key == pygame.K_RIGHT:
|
121
|
-
self.set_value(self.meter.get_value() + self.meter.step)
|
122
|
-
bf.AudioManager().play_sound(self.click_down_sound)
|
123
|
-
elif key == pygame.K_LEFT:
|
124
|
-
self.set_value(self.meter.get_value() - self.meter.step)
|
125
|
-
bf.AudioManager().play_sound(self.click_down_sound)
|
126
|
-
|
127
|
-
def do_on_click_down(self, button) -> None:
|
128
|
-
if button == 1 : self.get_focus()
|
129
|
-
|
130
|
-
def value_to_position(self, value: float) -> float:
|
131
|
-
"""
|
132
|
-
Converts a value to a position on the meter, considering the step size.
|
133
|
-
"""
|
134
|
-
rect = self.meter.get_padded_rect()
|
135
|
-
value_range = self.meter.get_range()
|
136
|
-
value = round(value / self.meter.step) * self.meter.step
|
137
|
-
position_ratio = (value - self.meter.min_value) / value_range
|
138
|
-
# print(self.handle.rect)
|
139
|
-
# print(rect.left + (self.handle.rect.w/2) + position_ratio * (rect.width - self.handle.rect.w),self.handle.rect.w,self.rect.right)
|
140
|
-
return rect.left + (self.handle.rect.w/2) + position_ratio * (rect.width - self.handle.rect.w)
|
141
|
-
|
142
|
-
def position_to_value(self, position: float) -> float:
|
143
|
-
"""
|
144
|
-
Converts a position on the meter to a value, considering the step size.
|
145
|
-
"""
|
146
|
-
handle_half = self.handle.rect.w/2
|
147
|
-
rect = self.meter.get_padded_rect()
|
148
|
-
position = max(rect.left + handle_half, min(position, rect.right - handle_half))
|
149
|
-
|
150
|
-
position_ratio = (position - rect.left - handle_half) / (rect.width - self.handle.rect.w)
|
151
|
-
value_range = self.meter.get_range()
|
152
|
-
value = self.meter.min_value + position_ratio * value_range
|
153
|
-
return round(value / self.meter.step) * self.meter.step
|
154
|
-
|
155
|
-
def _build_layout(self) -> None:
|
156
|
-
|
157
|
-
gap = self.gap if self.text else 0
|
158
|
-
|
159
|
-
params = {
|
160
|
-
"font_name": self.font_object.name,
|
161
|
-
"text": self.text,
|
162
|
-
"antialias": False,
|
163
|
-
"color": "white",
|
164
|
-
"bgcolor": "black", # if (self.has_alpha_color() or self.draw_mode == bf.drawMode.TEXTURED) else self.color,
|
165
|
-
"wraplength": int(self.get_padded_width()) if self.auto_wraplength else 0,
|
166
|
-
}
|
167
|
-
|
168
|
-
self.text_rect.size = self._render_font(params).get_size()
|
169
|
-
|
170
|
-
meter_size = [self.text_rect.h * 10, self.font_object.point_size]
|
171
|
-
if not self.autoresize_w:
|
172
|
-
meter_size[0] = self.get_padded_width() - self.text_rect.w - gap
|
173
|
-
|
174
|
-
tmp_rect = pygame.FRect(0,0,self.text_rect.w + gap + meter_size[0],self.text_rect.h)
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
if self.autoresize_h or self.autoresize_w:
|
179
|
-
target_rect = self.inflate_rect_by_padding(tmp_rect)
|
180
|
-
if not self.autoresize_w : target_rect.w = self.rect.w
|
181
|
-
if not self.autoresize_h : target_rect.h = self.rect.h
|
182
|
-
if self.rect.size != target_rect.size:
|
183
|
-
self.set_size(target_rect.size)
|
184
|
-
self.build()
|
185
|
-
return
|
186
|
-
|
187
|
-
# ------------------------------------ size is ok
|
188
|
-
padded = self.get_padded_rect().move(-self.rect.x,-self.rect.y)
|
189
|
-
|
190
|
-
self.meter.set_size_if_autoresize(meter_size)
|
191
|
-
handle_size = 2*[self.meter.get_padded_height()]
|
192
|
-
|
193
|
-
self.handle.set_size_if_autoresize(handle_size)
|
194
|
-
|
195
|
-
self.align_text(tmp_rect,padded,self.alignment)
|
196
|
-
self.text_rect.midleft = tmp_rect.midleft
|
197
|
-
|
198
|
-
if self.text :
|
199
|
-
match self.spacing:
|
200
|
-
case bf.spacing.MAX:
|
201
|
-
gap = padded.w - self.text_rect.w - self.meter.rect.w
|
202
|
-
case bf.spacing.MIN:
|
203
|
-
gap = 0
|
204
|
-
case bf.spacing.HALF:
|
205
|
-
gap = (padded.w)/2 - self.text_rect.w
|
206
|
-
|
207
|
-
# place meter
|
208
|
-
|
209
|
-
self.meter.set_position(*self.text_rect.move(self.rect.x + gap,self.rect.y + (self.text_rect.h /2) - meter_size[1]/2).topright)
|
210
|
-
# place handle
|
211
|
-
|
212
|
-
# print(self.meter.rect.top - self.rect.top)
|
213
|
-
# print(self.meter.rect.h)
|
214
|
-
|
215
|
-
x = self.value_to_position(self.meter.value)
|
216
|
-
r = self.meter.get_padded_rect()
|
217
|
-
self.handle.set_center(x,r.centery)
|
218
|
-
|
219
|
-
# self.handle.set_center(x,self.rect.top)
|
220
|
-
|
batFramework/gui/textInput.py
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from typing import Self,Callable
|
3
|
-
from .label import Label
|
4
|
-
from .interactiveWidget import InteractiveWidget
|
5
|
-
import pygame
|
6
|
-
|
7
|
-
|
8
|
-
class TextInput(Label, InteractiveWidget):
|
9
|
-
def __init__(self) -> None:
|
10
|
-
self.cursor_position = 0
|
11
|
-
self.old_key_repeat: tuple = (0, 0)
|
12
|
-
self.cursor_timer = bf.Timer(0.3, self._cursor_toggle, loop=True).start()
|
13
|
-
self.cursor_timer.pause()
|
14
|
-
self.show_cursor: bool = False
|
15
|
-
self.on_modify :Callable[[str],str] = None
|
16
|
-
self.set_focusable(True)
|
17
|
-
self.set_outline_color("black")
|
18
|
-
super().__init__("")
|
19
|
-
|
20
|
-
def set_modify_callback(self,callback : Callable[[str],str])->Self:
|
21
|
-
self.on_modify = callback
|
22
|
-
return self
|
23
|
-
|
24
|
-
def to_string_id(self) -> str:
|
25
|
-
return f"TextInput({self.text})"
|
26
|
-
|
27
|
-
def _cursor_toggle(self,value:bool = None):
|
28
|
-
if value is None : value = not self.show_cursor
|
29
|
-
self.show_cursor = value
|
30
|
-
self.dirty_surface = True
|
31
|
-
|
32
|
-
def do_on_click_down(self, button):
|
33
|
-
if button != 1:
|
34
|
-
return
|
35
|
-
self.get_focus()
|
36
|
-
|
37
|
-
def do_on_enter(self):
|
38
|
-
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_IBEAM)
|
39
|
-
|
40
|
-
def do_on_exit(self):
|
41
|
-
pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
|
42
|
-
|
43
|
-
def do_on_get_focus(self):
|
44
|
-
self.old_key_repeat = pygame.key.get_repeat()
|
45
|
-
self.cursor_timer.resume()
|
46
|
-
self._cursor_toggle(True)
|
47
|
-
pygame.key.set_repeat(200, 50)
|
48
|
-
|
49
|
-
def do_on_lose_focus(self):
|
50
|
-
self.cursor_timer.pause()
|
51
|
-
self._cursor_toggle(False)
|
52
|
-
pygame.key.set_repeat(*self.old_key_repeat)
|
53
|
-
|
54
|
-
def set_cursor_position(self, position: int) -> Self:
|
55
|
-
if position < 0:
|
56
|
-
position = 0
|
57
|
-
elif position > len(self.get_text()):
|
58
|
-
position = len(self.get_text())
|
59
|
-
self.cursor_position = position
|
60
|
-
self.show_cursor = True
|
61
|
-
self.dirty_surface = True
|
62
|
-
if self.text_rect.w > self.get_padded_width():
|
63
|
-
self.dirty_shape = True
|
64
|
-
return self
|
65
|
-
|
66
|
-
def do_handle_event(self, event):
|
67
|
-
if not self.is_focused:
|
68
|
-
return
|
69
|
-
text = self.get_text()
|
70
|
-
cursor_position = self.cursor_position
|
71
|
-
|
72
|
-
if event.type == pygame.TEXTINPUT:
|
73
|
-
self.set_text(text[:cursor_position] + event.text + text[cursor_position:])
|
74
|
-
self.set_cursor_position(cursor_position + 1)
|
75
|
-
elif event.type == pygame.KEYDOWN:
|
76
|
-
if event.key == pygame.K_ESCAPE:
|
77
|
-
self.lose_focus()
|
78
|
-
|
79
|
-
elif event.key == pygame.K_BACKSPACE:
|
80
|
-
if cursor_position > 0:
|
81
|
-
self.set_text(text[:cursor_position - 1] + text[cursor_position:])
|
82
|
-
self.set_cursor_position(cursor_position - 1)
|
83
|
-
|
84
|
-
elif event.key == pygame.K_RIGHT:
|
85
|
-
self.set_cursor_position(cursor_position + 1)
|
86
|
-
|
87
|
-
elif event.key == pygame.K_LEFT:
|
88
|
-
self.set_cursor_position(cursor_position - 1)
|
89
|
-
|
90
|
-
else:
|
91
|
-
return
|
92
|
-
else :
|
93
|
-
return
|
94
|
-
|
95
|
-
event.consumed = True
|
96
|
-
|
97
|
-
def set_text(self, text: str) -> Self:
|
98
|
-
if self.on_modify : text = self.on_modify(text)
|
99
|
-
return super().set_text(text)
|
100
|
-
|
101
|
-
def _paint_cursor(self) -> None:
|
102
|
-
if not self.font_object or not self.show_cursor:
|
103
|
-
return
|
104
|
-
partial_text_size = self.font_object.size(
|
105
|
-
self.get_text()[: self.cursor_position]
|
106
|
-
)
|
107
|
-
|
108
|
-
cursor_rect = pygame.Rect(0, 0,1, self.font_object.point_size )
|
109
|
-
if self.cursor_position != 0: # align left properly
|
110
|
-
cursor_rect.midleft = self.text_rect.move(partial_text_size[0], 0).midleft
|
111
|
-
else:
|
112
|
-
cursor_rect.midright = self.text_rect.midleft
|
113
|
-
|
114
|
-
pygame.draw.rect(self.surface, self.text_color, cursor_rect)
|
115
|
-
|
116
|
-
def paint(self) -> None:
|
117
|
-
super().paint()
|
118
|
-
self._paint_cursor()
|
119
|
-
|
120
|
-
|
121
|
-
def align_text(self,text_rect:pygame.FRect,area:pygame.FRect,alignment: bf.alignment):
|
122
|
-
if alignment == bf.alignment.LEFT : alignment = bf.alignment.MIDLEFT
|
123
|
-
elif alignment == bf.alignment.MIDRIGHT : alignment = bf.alignment.MIDRIGHT
|
124
|
-
|
125
|
-
pos = area.__getattribute__(alignment.value)
|
126
|
-
text_rect.__setattr__(alignment.value,pos)
|
127
|
-
w = self.font_object.size(
|
128
|
-
self.get_text()[: self.cursor_position]
|
129
|
-
)[0]
|
130
|
-
if self.text_rect.x + w > area.right:
|
131
|
-
self.text_rect.right = area.right
|
132
|
-
elif self.text_rect.x + w < area.left:
|
133
|
-
self.text_rect.left = area.left - w
|
134
|
-
|
batFramework/object.py
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
from typing import Any, Self
|
2
|
-
import pygame
|
3
|
-
import batFramework as bf
|
4
|
-
from typing import TYPE_CHECKING
|
5
|
-
|
6
|
-
if TYPE_CHECKING:
|
7
|
-
from .camera import Camera
|
8
|
-
|
9
|
-
|
10
|
-
class Object:
|
11
|
-
__instance_count = 0
|
12
|
-
|
13
|
-
def __init__(self) -> None:
|
14
|
-
self.rect = pygame.FRect(0, 0, 0, 0)
|
15
|
-
self.tags: list[str] = []
|
16
|
-
self.parent_scene: bf.Scene | None = None
|
17
|
-
self.debug_color: tuple | str = "red"
|
18
|
-
self.render_order: int = 0
|
19
|
-
self.uid: int = Object.__instance_count
|
20
|
-
Object.__instance_count += 1
|
21
|
-
|
22
|
-
@staticmethod
|
23
|
-
def new_uid() -> int:
|
24
|
-
i = Object.__instance_count
|
25
|
-
Object.__instance_count += 1
|
26
|
-
return i
|
27
|
-
|
28
|
-
def set_position(self,x,y)->Self:
|
29
|
-
self.rect.topleft = x,y
|
30
|
-
return self
|
31
|
-
|
32
|
-
def set_center(self,x,y)->Self:
|
33
|
-
self.rect.center = x,y
|
34
|
-
return self
|
35
|
-
|
36
|
-
def get_debug_outlines(self):
|
37
|
-
yield (self.rect, self.debug_color)
|
38
|
-
|
39
|
-
def set_debug_color(self, color) -> Self:
|
40
|
-
self.debug_color = color
|
41
|
-
return self
|
42
|
-
|
43
|
-
def set_parent_scene(self, scene) -> Self:
|
44
|
-
if scene == self.parent_scene : return self
|
45
|
-
if self.parent_scene is not None:
|
46
|
-
self.do_when_removed()
|
47
|
-
self.parent_scene = scene
|
48
|
-
if scene is not None:
|
49
|
-
self.do_when_added()
|
50
|
-
return self
|
51
|
-
|
52
|
-
def do_when_added(self):
|
53
|
-
pass
|
54
|
-
|
55
|
-
def do_when_removed(self):
|
56
|
-
pass
|
57
|
-
|
58
|
-
def set_uid(self, uid: int) -> Self:
|
59
|
-
self.uid = uid
|
60
|
-
return self
|
61
|
-
|
62
|
-
def get_uid(self) -> int:
|
63
|
-
return self.uid
|
64
|
-
|
65
|
-
def add_tags(self, *tags) -> Self:
|
66
|
-
for tag in tags:
|
67
|
-
if tag not in self.tags:
|
68
|
-
self.tags.append(tag)
|
69
|
-
self.tags.sort()
|
70
|
-
return self
|
71
|
-
|
72
|
-
def remove_tags(self, *tags):
|
73
|
-
self.tags = [tag for tag in self.tags if tag not in tags]
|
74
|
-
|
75
|
-
def has_tags(self, *tags) -> bool:
|
76
|
-
return all(tag in self.tags for tag in tags)
|
77
|
-
|
78
|
-
def get_tags(self) -> list[str]:
|
79
|
-
return self.tags
|
80
|
-
|
81
|
-
def process_event(self, event: pygame.Event) -> bool:
|
82
|
-
"""
|
83
|
-
Returns bool : True if the method is blocking (no propagation to next object of the scene)
|
84
|
-
"""
|
85
|
-
if event.consumed : return
|
86
|
-
self.do_process_actions(event)
|
87
|
-
self.do_handle_event(event)
|
88
|
-
|
89
|
-
def do_process_actions(self, event: pygame.Event) -> None:
|
90
|
-
"""
|
91
|
-
Process entity actions you may have set
|
92
|
-
"""
|
93
|
-
|
94
|
-
def do_reset_actions(self) -> None:
|
95
|
-
"""
|
96
|
-
Reset entity actions you may have set
|
97
|
-
"""
|
98
|
-
|
99
|
-
def do_handle_event(self, event: pygame.Event):
|
100
|
-
"""
|
101
|
-
Handle specific events with no action support
|
102
|
-
"""
|
103
|
-
return False
|
104
|
-
|
105
|
-
def update(self, dt: float) -> None:
|
106
|
-
"""
|
107
|
-
Update method to be overriden by subclasses of object (must call do_update and do_reset_actions)
|
108
|
-
"""
|
109
|
-
self.do_update(dt)
|
110
|
-
self.do_reset_actions()
|
111
|
-
|
112
|
-
def do_update(self, dt: float) -> None:
|
113
|
-
"""
|
114
|
-
Update method to be overriden for specific behavior by the end user
|
115
|
-
"""
|
batFramework/particle.py
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
import pygame
|
3
|
-
from pygame.math import Vector2
|
4
|
-
|
5
|
-
|
6
|
-
class Particle:
|
7
|
-
def __init__(self, *args, **kwargs):
|
8
|
-
self.dead = False
|
9
|
-
self.surface = None
|
10
|
-
|
11
|
-
def update(self, dt):
|
12
|
-
pass
|
13
|
-
|
14
|
-
def kill(self):
|
15
|
-
self.dead = True
|
16
|
-
|
17
|
-
def update_surface(self):
|
18
|
-
pass
|
19
|
-
|
20
|
-
|
21
|
-
class TimedParticle(Particle):
|
22
|
-
def __init__(self, duration):
|
23
|
-
super().__init__()
|
24
|
-
self.timer = bf.Timer(duration, end_callback=self.kill).start()
|
25
|
-
|
26
|
-
|
27
|
-
class BasicParticle(TimedParticle):
|
28
|
-
def __init__(
|
29
|
-
self,
|
30
|
-
start_pos: tuple[float, float],
|
31
|
-
start_vel: tuple[float, float],
|
32
|
-
duration=1,
|
33
|
-
color=None,
|
34
|
-
size: tuple[int, int] = (4, 4),
|
35
|
-
*args,
|
36
|
-
**kwargs,
|
37
|
-
):
|
38
|
-
super().__init__(duration)
|
39
|
-
self.rect = pygame.FRect(*start_pos, *size)
|
40
|
-
self.surface = pygame.Surface(size).convert()
|
41
|
-
self.velocity = Vector2(start_vel)
|
42
|
-
if color:
|
43
|
-
self.surface.fill(color)
|
44
|
-
self.start()
|
45
|
-
|
46
|
-
def start(self):
|
47
|
-
pass
|
48
|
-
|
49
|
-
def update(self, dt):
|
50
|
-
super().update(dt)
|
51
|
-
self.rect.center += self.velocity * dt
|
52
|
-
self.update_surface()
|
53
|
-
|
54
|
-
def update_surface(self):
|
55
|
-
self.surface.set_alpha(255 - int(self.timer.get_progression() * 255))
|
56
|
-
|
57
|
-
|
58
|
-
class DirectionalParticle(BasicParticle):
|
59
|
-
def start(self):
|
60
|
-
self.surface = self.surface.convert_alpha()
|
61
|
-
self.original_surface = self.surface.copy()
|
62
|
-
|
63
|
-
def update_surface(self):
|
64
|
-
angle = self.velocity.angle_to(Vector2(1, 0))
|
65
|
-
self.surface = pygame.transform.rotate(self.original_surface, angle)
|
66
|
-
super().update_surface()
|
67
|
-
|
68
|
-
|
69
|
-
class ParticleGenerator(bf.Entity):
|
70
|
-
def __init__(self) -> None:
|
71
|
-
super().__init__((0, 0))
|
72
|
-
self.particles: list[Particle] = []
|
73
|
-
|
74
|
-
def get_debug_outlines(self):
|
75
|
-
for particle in self.particles:
|
76
|
-
yield (
|
77
|
-
particle.rect.move(particle.rect.w // 2, particle.rect.h // 2),
|
78
|
-
"blue",
|
79
|
-
)
|
80
|
-
yield (self.rect, "cyan")
|
81
|
-
|
82
|
-
def add_particle(self, particle):
|
83
|
-
self.particles.append(particle)
|
84
|
-
|
85
|
-
def clear(self):
|
86
|
-
self.particles = []
|
87
|
-
|
88
|
-
def update(self, dt: float):
|
89
|
-
particles_to_remove = []
|
90
|
-
for particle in self.particles:
|
91
|
-
particle.update(dt)
|
92
|
-
if particle.dead:
|
93
|
-
particles_to_remove.append(particle)
|
94
|
-
for p in particles_to_remove:
|
95
|
-
self.particles.remove(p)
|
96
|
-
|
97
|
-
def draw(self, camera) -> bool:
|
98
|
-
camera.surface.fblits(
|
99
|
-
[(p.surface, camera.world_to_screen(p.rect).center) for p in self.particles]
|
100
|
-
)
|
101
|
-
return len(self.particles)
|
batFramework/renderGroup.py
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
import pygame
|
3
|
-
from typing import Self, Iterator, Callable
|
4
|
-
|
5
|
-
"""
|
6
|
-
+ same render order
|
7
|
-
+ fblits
|
8
|
-
"""
|
9
|
-
|
10
|
-
class RenderGroup(bf.Entity):
|
11
|
-
def __init__(self, entity_iterator: Callable[[],Iterator[bf.Entity]], blit_flags: int = 0) -> None:
|
12
|
-
super().__init__()
|
13
|
-
self.entity_iterator = entity_iterator
|
14
|
-
self.set_blit_flags(blit_flags)
|
15
|
-
self.set_debug_color("white")
|
16
|
-
|
17
|
-
def get_debug_outlines(self):
|
18
|
-
# yield (self.rect, self.debug_color)
|
19
|
-
for e in self.entity_iterator():
|
20
|
-
yield from e.get_debug_outlines()
|
21
|
-
|
22
|
-
def set_parent_scene(self, scene) -> Self:
|
23
|
-
self.parent_scene = scene
|
24
|
-
for e in self.entity_iterator():
|
25
|
-
e.set_parent_scene(scene)
|
26
|
-
return self
|
27
|
-
|
28
|
-
def process_event(self, event: pygame.Event) -> bool:
|
29
|
-
"""
|
30
|
-
Returns bool : True if the method is blocking (no propagation to next children of the scene)
|
31
|
-
"""
|
32
|
-
self.do_process_actions(event)
|
33
|
-
res = self.do_handle_event(event)
|
34
|
-
if res:
|
35
|
-
return res
|
36
|
-
for e in self.entity_iterator():
|
37
|
-
if e.process_event(event):
|
38
|
-
return True
|
39
|
-
return False
|
40
|
-
|
41
|
-
def update(self, dt: float) -> None:
|
42
|
-
"""
|
43
|
-
Update method to be overriden by subclasses of entity
|
44
|
-
"""
|
45
|
-
for e in self.entity_iterator():
|
46
|
-
e.update(dt)
|
47
|
-
# gen = self.entity_iterator()
|
48
|
-
# self.rect = next(gen).rect.unionall([e.rect for e in gen])
|
49
|
-
|
50
|
-
self.do_update(dt)
|
51
|
-
self.do_reset_actions()
|
52
|
-
|
53
|
-
def draw(self, camera: bf.Camera) -> None:
|
54
|
-
"""
|
55
|
-
Draw the entity onto the camera with coordinate transposing
|
56
|
-
"""
|
57
|
-
if not self.visible:
|
58
|
-
return
|
59
|
-
fblits_data = (
|
60
|
-
(e.surface, (e.rect.x - camera.rect.x,e.rect.y - camera.rect.y)) for e in self.entity_iterator() if camera.rect.colliderect(e.rect)
|
61
|
-
)
|
62
|
-
camera.surface.fblits(fblits_data, self.blit_flags)
|