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
@@ -1,168 +1,81 @@
1
1
  import batFramework as bf
2
2
  from .widget import Widget
3
- from .constraints.constraints import *
4
- from typing import Self,TYPE_CHECKING
5
- import pygame
6
-
7
- if TYPE_CHECKING:
8
- from .container import Container
3
+ from .constraints import *
4
+ from typing import Self
9
5
 
10
6
  class Layout:
11
- def __init__(self, parent: "Container" = None):
7
+ def __init__(self, parent: Widget=None):
12
8
  self.parent = parent
13
- self.child_constraints: list[Constraint] = []
14
- self.children_rect = pygame.FRect(0, 0, 0, 0)
15
-
16
- def set_child_constraints(self, *constraints) -> Self:
17
- self.child_constraints = list(constraints)
18
- self.notify_parent()
9
+ self.child_constraints : list[Constraint] = []
10
+
11
+ def set_child_constraints(self,*constraints)->Self:
12
+ self.child_constraints = constraints
13
+ self.arrange()
19
14
  return self
20
-
21
- def set_parent(self, parent: Widget):
15
+
16
+ def set_parent(self,parent:Widget):
22
17
  self.parent = parent
23
- self.notify_parent()
24
-
25
- def notify_parent(self) -> None:
26
- if self.parent:self.parent.dirty_children = True
27
-
28
- def arrange(self) -> None:
29
- return
30
-
31
- def clamp_scroll(self)->None:
32
- return
33
-
34
- def get_raw_size(self)->tuple[float,float]:
35
- return self.parent.rect.size if self.parent else 0,0
36
-
37
- def get_auto_size(self)->tuple[float,float]:
38
- return self.parent.rect.size if self.parent else 0,0
39
-
40
- def focus_next_child(self)->None:
41
- l = self.parent.get_interactive_children()
42
- self.parent.focused_index = min(self.parent.focused_index + 1, len(l) - 1)
43
- focused = l[self.parent.focused_index]
44
- focused.get_focus()
45
- self.scroll_to_widget(focused)
46
-
47
- def focus_prev_child(self)->None:
48
- l = self.parent.get_interactive_children()
49
- self.parent.focused_index = max(self.parent.focused_index - 1, 0)
50
- focused = l[self.parent.focused_index]
51
- focused.get_focus()
52
- self.scroll_to_widget(focused)
53
-
54
- def scroll_to_widget(self,widget:Widget)->None:
55
- padded = self.parent.get_padded_rect()
56
- r = widget.rect
57
- if padded.contains(r):return
58
- clamped = r.clamp(padded)
59
- dx,dy = clamped.move(-r.x,-r.y).topleft
60
- self.parent.scroll_by((-dx,-dy))
61
-
18
+ self.arrange()
62
19
 
20
+ def arrange(self)->None:
21
+ raise NotImplementedError("Subclasses must implement arrange method")
63
22
 
64
23
  class Column(Layout):
65
- def __init__(self, gap: int = 0,spacing:bf.spacing = bf.spacing.MANUAL):
24
+ def __init__(self,gap:int=0,shrink:bool=False):
66
25
  super().__init__()
67
26
  self.gap = gap
68
- self.spacing = spacing
69
-
70
- def set_gap(self, value: float) -> Self:
71
- self.gap = value
72
- self.notify_parent()
73
- return self
74
-
75
- def set_spacing(self,spacing: bf.spacing)->Self:
76
- self.spacing = spacing
77
- self.notify_parent()
78
- return self
79
-
80
- def get_raw_size(self)-> tuple[float,float]:
81
- len_children = len(self.parent.children)
82
- if not len_children : return self.parent.rect.size
83
- parent_height = sum(c.get_min_required_size()[1] for c in self.parent.children)
84
- parent_width = max(c.get_min_required_size()[0] for c in self.parent.children)
85
- if self.gap:
86
- parent_height += (len_children - 1) * self.gap
87
- target_rect = self.parent.inflate_rect_by_padding((0,0,parent_width,parent_height))
88
- return target_rect.size
89
-
90
- def get_auto_size(self)-> tuple[float,float]:
91
- target_size = list(self.get_raw_size())
92
- if not self.parent.autoresize_w : target_size[0] = self.parent.rect.w
93
- if not self.parent.autoresize_h : target_size[1] = self.parent.rect.h
94
- return target_size
95
-
96
- def arrange(self) -> None:
97
- if not self.parent or not self.parent.children:
98
- return
99
- if self.child_constraints :
100
- for child in self.parent.children : child.add_constraints(*self.child_constraints)
101
- self.child_rect = self.parent.get_padded_rect()
102
-
103
- if self.parent.autoresize_w or self.parent.autoresize_h:
104
- width,height = self.get_auto_size()
105
- if self.parent.rect.size != (width,height):
106
- self.parent.set_size((width,height))
107
- self.parent.build()
108
- self.arrange()
109
- return
110
- self.child_rect.move_ip(-self.parent.scroll.x,-self.parent.scroll.y)
111
- y = self.child_rect.top
112
- for child in self.parent.children :
113
- child.set_position(self.child_rect.x,y)
114
- y+= child.get_min_required_size()[1] + self.gap
27
+ self.shrink :bool = shrink
28
+
29
+ def arrange(self)->None:
30
+ if not self.parent or not self.parent.children : return
31
+ if self.shrink:
32
+ len_children = len(self.parent.children)
33
+ parent_height = sum(c.rect.h for c in self.parent.children)
34
+ parent_width = max(c.rect.w for c in self.parent.children)
35
+ if self.gap : parent_height += (len_children-1) * self.gap
36
+ # print(self.parent.to_string(),len_children,parent_height)
37
+ c = self.parent.get_constraint("height")
38
+ if not c or c.height != parent_height :
39
+ self.parent.add_constraint(ConstraintHeight(parent_height))
40
+ c = self.parent.get_constraint("width")
41
+ if not c or c.width != parent_width :
42
+ self.parent.add_constraint(ConstraintWidth(parent_width))
43
+ current_y = self.parent.rect.top
115
44
 
45
+ for child in self.parent.children:
46
+ child.set_position(self.parent.rect.x,current_y)
47
+ current_y += child.rect.h + self.gap
48
+ for c in self.child_constraints:
49
+ if not child.has_constraint(c.name):
50
+ child.add_constraint(c)
51
+
116
52
  class Row(Layout):
117
- def __init__(self, gap: int = 0,spacing: bf.spacing=bf.spacing.MANUAL):
53
+ def __init__(self, gap: int = 0, shrink: bool = False):
118
54
  super().__init__()
119
55
  self.gap = gap
120
- self.spacing = spacing
121
-
122
- def set_gap(self, value: float) -> Self:
123
- self.gap = value
124
- self.notify_parent()
125
- return self
126
-
127
- def set_spacing(self,spacing: bf.spacing)->Self:
128
- self.spacing = spacing
129
- self.notify_parent()
130
- return self
131
-
132
-
133
- def get_raw_size(self) -> tuple[float, float]:
134
- len_children = len(self.parent.children)
135
- if not len_children: return self.parent.rect.size
136
- parent_width = sum(c.get_min_required_size()[0] for c in self.parent.children)
137
- parent_height = max(c.get_min_required_size()[1] for c in self.parent.children)
138
- if self.gap:
139
- parent_width += (len_children - 1) * self.gap
140
- target_rect = self.parent.inflate_rect_by_padding((0, 0, parent_width, parent_height))
141
-
142
- return target_rect.size
143
-
144
- def get_auto_size(self) -> tuple[float, float]:
145
- target_size = list(self.get_raw_size())
146
- if not self.parent.autoresize_w: target_size[0] = self.parent.rect.w
147
- if not self.parent.autoresize_h: target_size[1] = self.parent.rect.h
148
- return target_size
56
+ self.shrink = shrink
149
57
 
150
58
  def arrange(self) -> None:
151
- if not self.parent or not self.parent.children:
59
+ if not self.parent:
152
60
  return
153
- if self.child_constraints:
154
- for child in self.parent.children: child.add_constraints(*self.child_constraints)
155
- self.child_rect = self.parent.get_padded_rect()
156
-
157
- if self.parent.autoresize_w or self.parent.autoresize_h:
158
- width, height = self.get_auto_size()
159
- if self.parent.rect.size != (width, height):
160
- self.parent.set_size((width, height))
161
- self.parent.build()
162
- self.arrange()
163
- return
164
- self.child_rect.move_ip(-self.parent.scroll.x, -self.parent.scroll.y)
165
- x = self.child_rect.left
61
+ if self.shrink and self.parent.children:
62
+ len_children = len(self.parent.children)
63
+ parent_width = sum(c.rect.w for c in self.parent.children)
64
+ parent_height = max(c.rect.h for c in self.parent.children)
65
+ if self.gap:
66
+ parent_width += (len_children - 1) * self.gap
67
+
68
+ c = self.parent.get_constraint("width")
69
+ if not c or c.width != parent_width:
70
+ self.parent.add_constraint(ConstraintWidth(parent_width))
71
+ c = self.parent.get_constraint("height")
72
+ if not c or c.height != parent_height:
73
+ self.parent.add_constraint(ConstraintHeight(parent_height))
74
+
75
+ current_x = self.parent.rect.left
166
76
  for child in self.parent.children:
167
- child.set_position(x, self.child_rect.y)
168
- x += child.get_min_required_size()[0] + self.gap
77
+ child.set_position(current_x,self.parent.rect.y)
78
+ current_x += child.rect.w + self.gap
79
+ for c in self.child_constraints:
80
+ if not child.has_constraint(c.name):
81
+ child.add_constraint(c)
batFramework/gui/root.py CHANGED
@@ -3,123 +3,58 @@ from .interactiveWidget import InteractiveWidget
3
3
  from .widget import Widget
4
4
  import pygame
5
5
 
6
-
7
6
  class Root(InteractiveWidget):
8
- def __init__(self, camera) -> None:
7
+ def __init__(self):
9
8
  super().__init__()
10
- self.is_root = True
11
- self.drawing_camera: bf.Camera = camera
12
- self.visible = False
9
+ self.surface = None
10
+ self.set_root()
13
11
  self.rect.size = pygame.display.get_surface().get_size()
14
- self.focused: InteractiveWidget | None = self
15
- self.hovered: Widget | None = self
16
- self.set_debug_color("yellow")
17
- self.set_render_order(999)
18
- self.clip_children = False
12
+ self.focused : InteractiveWidget = self
13
+ self.hovered : Widget|None = self
14
+ self.set_debug_color("purple")
19
15
 
20
- def __str__(self) -> str:
21
- return "Root"
16
+ def to_string(self)->str:
17
+ return "ROOT"
22
18
 
23
- def get_focused(self) -> Widget | None:
19
+ def get_focused(self)->Widget|None:
24
20
  return self.focused
25
21
 
26
- def get_hovered(self) -> Widget | None:
22
+ def get_hovered(self)->Widget|None:
27
23
  return self.hovered
24
+
25
+ def to_string_id(self)->str:
26
+ return "ROOT"
28
27
 
29
- def clear_focused(self) -> None:
30
- self.focus_on(None)
31
-
32
- def clear_hovered(self) -> None:
33
- if isinstance(self.hovered, InteractiveWidget):
34
- self.hovered.on_exit()
35
- self.hovered = None
36
-
37
- def focus_on(self, widget: InteractiveWidget | None) -> None:
38
- if widget == self.focused : return
39
- if widget and not widget.allow_focus_to_self():
40
- return
41
- if self.focused is not None:
28
+ def focus_on(self,widget:InteractiveWidget)->None:
29
+ if self.focused is not None:
42
30
  self.focused.on_lose_focus()
43
- if widget is None:
31
+ if widget is None :
44
32
  self.focused = self
45
33
  return
46
- self.focused = widget
34
+ self.focused= widget
47
35
  self.focused.on_get_focus()
48
36
 
49
- def get_by_tags(self,*tags)->list[Widget]:
50
- res = []
51
- def getter(w:Widget):
52
- nonlocal res
53
- if any(t in w.tags for t in tags):
54
- res.append(w)
55
- self.visit(getter)
56
- return res
57
-
58
- def get_by_uid(self,uid:int)->Widget:
59
- def helper(w: Widget,uid):
60
- if w.uid == uid:
61
- return w
62
- for child in w.children:
63
- res = helper(child,uid)
64
- if res :
65
- return child
66
-
67
- return None
68
- return helper(self,uid)
69
-
70
- def set_size(self, size: tuple[float, float], force: bool = False) -> "Root":
71
- if not force:
72
- return self
73
- self.rect.size = size
74
- # self.build(resolve_constraints=True)
37
+ def set_size(self,width:float,height:float,force:bool=False)->"Root":
38
+ if not force : return self
39
+ self.rect.size = width,height
40
+ self.build(apply_constraints=True)
75
41
  return self
76
-
77
-
78
- def do_handle_event(self, event):
79
- # if event.type == pygame.VIDEORESIZE:
80
- # self.set_size(event.w, event.h, force=True)
81
- # return True
82
- if self.focused:
83
- if event.type == pygame.KEYDOWN:
84
- self.focused.on_key_down(event.key)
85
- if event.type == pygame.KEYUP:
86
- self.focused.on_key_up(event.key)
87
- elif not self.hovered or not isinstance(self.hovered, InteractiveWidget):
88
- return
89
- if event.type == pygame.MOUSEBUTTONDOWN:
90
- self.hovered.on_click_down(event.button)
91
- elif event.type == pygame.MOUSEBUTTONUP:
92
- self.hovered.on_click_up(event.button)
93
-
94
-
95
- def do_on_click_down(self, button: int) -> None:
96
- if button == 1:
97
- self.clear_focused()
98
-
99
- def top_at(self, x: float | int, y: float | int) -> "None|Widget":
100
- if self.children:
101
- for child in reversed(self.children):
102
- r = child.top_at(x, y)
103
- if r is not None:
104
- return r
105
- return self if self.rect.collidepoint(x, y) else None
106
-
107
- def update(self, dt: float) -> None:
42
+
43
+ def build(self,apply_constraints:bool=False)->None:
44
+ if apply_constraints : self.apply_all_constraints()
45
+ for child in self.children :
46
+ child.build()
47
+
48
+ def do_handle_event(self,event):
49
+ if event.type == pygame.VIDEORESIZE:
50
+ self.set_size(event.w,event.h,force=True)
51
+ return True
52
+ return False
53
+
54
+ def update(self,dt:float)->None:
108
55
  super().update(dt)
109
- old = self.hovered
110
- transposed = self.drawing_camera.screen_to_world(pygame.mouse.get_pos())
111
- self.hovered = self.top_at(*transposed) if self.top_at(*transposed) else None
112
- if old == self.hovered and isinstance(self.hovered, InteractiveWidget):
113
- self.hovered.on_mouse_motion(*transposed)
114
- return
115
- if old and isinstance(old, InteractiveWidget):
116
- old.on_exit()
117
- if self.hovered and isinstance(self.hovered, InteractiveWidget):
118
- self.hovered.on_enter()
119
-
120
- def draw(self, camera: bf.Camera) -> int:
121
- super().draw(camera)
122
- if self.focused and self.focused!=self:
123
- self.focused.draw_focused(camera)
56
+ self.hovered = self.top_at(*pygame.mouse.get_pos()) if self.top_at(*pygame.mouse.get_pos()) else None
57
+
124
58
 
125
59
 
60
+