e2D 1.4.19__py3-none-any.whl → 1.4.21__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.
- e2D/__init__.py +58 -7
- e2D/__init__.pyi +294 -5
- e2D/colors.py +53 -23
- e2D/envs.py +71 -23
- e2D/utils.py +437 -51
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/METADATA +3 -2
- e2d-1.4.21.dist-info/RECORD +13 -0
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/WHEEL +1 -1
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info/licenses}/LICENSE +21 -21
- e2d-1.4.19.dist-info/RECORD +0 -13
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/top_level.txt +0 -0
e2D/envs.py
CHANGED
|
@@ -42,13 +42,15 @@ class RootEnv:
|
|
|
42
42
|
quit_on_key_pressed : None|int = pg.K_x,
|
|
43
43
|
vsync : bool = True,
|
|
44
44
|
window_flags : int = pg.DOUBLEBUF,
|
|
45
|
+
display_index : int = 0,
|
|
45
46
|
clear_screen_each_frame : bool = True) -> None:
|
|
46
47
|
self.quit = False
|
|
47
48
|
self.__screen_size__ :Vector2D= screen_size
|
|
48
49
|
|
|
49
50
|
self.__vsync__ = vsync
|
|
50
51
|
self.__flags__ = window_flags
|
|
51
|
-
self.
|
|
52
|
+
self.__display_index__ = display_index
|
|
53
|
+
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__, display=self.__display_index__)
|
|
52
54
|
|
|
53
55
|
self.clock = pg.time.Clock()
|
|
54
56
|
self.keyboard = Keyboard()
|
|
@@ -56,15 +58,32 @@ class RootEnv:
|
|
|
56
58
|
|
|
57
59
|
self.target_fps = target_fps
|
|
58
60
|
self.current_fps = self.target_fps if self.target_fps != 0 else 1
|
|
61
|
+
self.__dt__ = 1 / self.current_fps
|
|
59
62
|
self.current_frame = 0
|
|
60
63
|
self.show_fps = show_fps
|
|
61
64
|
self.events :list[pg.event.Event]= []
|
|
62
|
-
|
|
65
|
+
|
|
66
|
+
self.__background_color__ :Color= BLACK_COLOR_PYG
|
|
67
|
+
|
|
63
68
|
self.clear_screen_each_frame = clear_screen_each_frame
|
|
64
69
|
self.utils :dict[int|str, Util]= {}
|
|
65
70
|
self.selected_util :Util|None = None
|
|
66
71
|
self.__quit_on_key_pressed__ = quit_on_key_pressed
|
|
67
72
|
|
|
73
|
+
self.fps_label = Label(str(round(self.current_fps,2)), self.screen_size * .01, V2(250, 50), BLACK_COLOR_PYG, TRANSPARENT_COLOR_PYG, WHITE_COLOR_PYG, border_width=0, starting_hidden=(not self.show_fps), pivot_position="top_left", font=FONT_ARIAL_32)
|
|
74
|
+
self.add_utils(self.fps_label)
|
|
75
|
+
|
|
76
|
+
def init_rec(self, fps:int=30, path:str='output.mp4') -> None:
|
|
77
|
+
from .winrec import WinRec
|
|
78
|
+
self.__winrecorder__ = WinRec(self, fps=fps, path=path)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def background_color(self) -> Color:
|
|
82
|
+
return unpygamize_color(self.__background_color__)
|
|
83
|
+
@background_color.setter
|
|
84
|
+
def background_color(self, color: Color|pg.Color) -> None:
|
|
85
|
+
self.__background_color__ = pygamize_color(color)
|
|
86
|
+
|
|
68
87
|
@property
|
|
69
88
|
def screen_size(self) -> Vector2D:
|
|
70
89
|
return self.__screen_size__
|
|
@@ -72,19 +91,24 @@ class RootEnv:
|
|
|
72
91
|
@screen_size.setter
|
|
73
92
|
def screen_size(self, new_size:Vector2D) -> None:
|
|
74
93
|
self.__screen_size__ = new_size
|
|
75
|
-
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__)
|
|
94
|
+
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__, display=self.__display_index__)
|
|
95
|
+
|
|
96
|
+
def update_screen_to_new_size(self) -> None:
|
|
97
|
+
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__, display=self.__display_index__)
|
|
76
98
|
|
|
77
99
|
@property
|
|
78
100
|
def delta(self) -> int:
|
|
79
|
-
return self.
|
|
101
|
+
return self.__dt__
|
|
80
102
|
|
|
81
103
|
def get_teoric_max_fps(self) -> float:
|
|
82
104
|
rawdelta = self.clock.get_rawtime()
|
|
83
105
|
return (1000 / rawdelta) if rawdelta != 0 else 1
|
|
84
106
|
|
|
85
|
-
def update_screen_mode(self, vsync:None|bool=None, flags=None) -> None:
|
|
107
|
+
def update_screen_mode(self, vsync:None|bool=None, flags=None, display_index=None) -> None:
|
|
86
108
|
self.__vsync__ = vsync
|
|
87
109
|
self.__flags__ = flags
|
|
110
|
+
self.__display_index__ = display_index
|
|
111
|
+
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__, display=self.__display_index__)
|
|
88
112
|
|
|
89
113
|
def sleep(self, seconds:int|float, precise_delay=False) -> None:
|
|
90
114
|
if precise_delay:
|
|
@@ -96,6 +120,8 @@ class RootEnv:
|
|
|
96
120
|
for util in utils:
|
|
97
121
|
if util.surface == None: util.surface = self.screen
|
|
98
122
|
util.rootEnv = self
|
|
123
|
+
util.id = self.__new_util_id__()
|
|
124
|
+
util.__render__()
|
|
99
125
|
self.utils[util.id] = util
|
|
100
126
|
|
|
101
127
|
def remove_utils(self, *utils:int|str|Util) -> None:
|
|
@@ -106,6 +132,18 @@ class RootEnv:
|
|
|
106
132
|
del self.utils[uid.id]
|
|
107
133
|
else:
|
|
108
134
|
raise Exception(f"Unknown util type: {uid}")
|
|
135
|
+
|
|
136
|
+
def __new_util_id__(self) -> int:
|
|
137
|
+
if not self.utils: return 0
|
|
138
|
+
else: return max(self.utils.keys()) + 1
|
|
139
|
+
|
|
140
|
+
def get_util(self, uid:int|str) -> Util|None:
|
|
141
|
+
if isinstance(uid, Util):
|
|
142
|
+
return self.utils.get(uid.id)
|
|
143
|
+
elif isinstance(uid, int) or isinstance(uid, str):
|
|
144
|
+
return self.utils.get(uid)
|
|
145
|
+
else:
|
|
146
|
+
raise Exception(f"Unknown util type: {uid}")
|
|
109
147
|
|
|
110
148
|
@property
|
|
111
149
|
def runtime_seconds(self) -> float:
|
|
@@ -115,24 +153,25 @@ class RootEnv:
|
|
|
115
153
|
self.env = sub_env
|
|
116
154
|
|
|
117
155
|
def clear(self) -> None:
|
|
118
|
-
self.screen.fill(self.
|
|
156
|
+
self.screen.fill(self.__background_color__)
|
|
119
157
|
|
|
120
158
|
def clear_rect(self, position:Vector2D, size:Vector2D) -> None:
|
|
121
|
-
self.screen.fill(self.
|
|
159
|
+
self.screen.fill(self.__background_color__, position() + size())
|
|
122
160
|
|
|
123
161
|
def print(self,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
162
|
+
text : str,
|
|
163
|
+
position : Vector2D,
|
|
164
|
+
color : pg.color.Color = WHITE_COLOR_PYG,
|
|
165
|
+
pivot_position : __LITERAL_PIVOT_POSITIONS__ = "top_left",
|
|
166
|
+
font : pg.font.Font = FONT_ARIAL_32,
|
|
167
|
+
bg_color : None|pg.color.Color = None,
|
|
168
|
+
border_color : pg.color.Color = WHITE_COLOR_PYG,
|
|
169
|
+
border_width : float = 0.0,
|
|
170
|
+
border_radius : int|list[int]|tuple[int,int,int,int] = -1,
|
|
171
|
+
margin : Vector2D = Vector2D.zero(),
|
|
172
|
+
personalized_surface : pg.Surface|None = None
|
|
135
173
|
) -> None:
|
|
174
|
+
|
|
136
175
|
text_box = font.render(text, True, color)
|
|
137
176
|
size = Vector2D(*text_box.get_size()) + margin * 2
|
|
138
177
|
pivotted_position = position - size * __PIVOT_POSITIONS_MULTIPLIER__[pivot_position] + margin
|
|
@@ -145,24 +184,32 @@ class RootEnv:
|
|
|
145
184
|
surface.blit(text_box, pivotted_position())
|
|
146
185
|
|
|
147
186
|
def __draw__(self) -> None:
|
|
148
|
-
self.clock.tick(self.target_fps)
|
|
187
|
+
self.__dt__ = self.clock.tick(self.target_fps) / 1000.0
|
|
149
188
|
self.current_fps = self.clock.get_fps()
|
|
189
|
+
self.fps_label.text = str(round(self.current_fps, 2))
|
|
190
|
+
|
|
150
191
|
if self.clear_screen_each_frame: self.clear()
|
|
151
192
|
|
|
152
193
|
self.env.draw()
|
|
153
|
-
for util in self.utils.values(): util.
|
|
194
|
+
for util in self.utils.values(): util.__draw__()
|
|
154
195
|
|
|
155
|
-
if self.show_fps: self.print(str(round(self.current_fps,2)), self.screen_size * .01, bg_color=BLACK_COLOR_PYG)
|
|
156
196
|
pg.display.flip()
|
|
157
197
|
|
|
158
198
|
def __update__(self) -> None:
|
|
159
199
|
self.mouse.update()
|
|
160
200
|
self.keyboard.update()
|
|
161
201
|
self.env.update()
|
|
162
|
-
for util in self.utils.values(): util.
|
|
202
|
+
for util in self.utils.values(): util.__update__()
|
|
203
|
+
|
|
204
|
+
if hasattr(self, "__winrecorder__"):
|
|
205
|
+
self.__winrecorder__.update()
|
|
206
|
+
self.__winrecorder__.draw()
|
|
163
207
|
|
|
164
208
|
def frame(self) -> None:
|
|
165
|
-
|
|
209
|
+
try:
|
|
210
|
+
self.events = pg.event.get()
|
|
211
|
+
except SystemError:
|
|
212
|
+
raise Warning(f"Pygame error with event drivers. Try restarting the program. If the error persists, try restarting your computer.")
|
|
166
213
|
self.current_frame += 1
|
|
167
214
|
self.__update__()
|
|
168
215
|
self.__draw__()
|
|
@@ -170,4 +217,5 @@ class RootEnv:
|
|
|
170
217
|
for event in self.events:
|
|
171
218
|
if event.type == pg.QUIT or ((event.type == pg.KEYDOWN and event.key == self.__quit_on_key_pressed__ and self.selected_util == None) if self.__quit_on_key_pressed__ != None else False):
|
|
172
219
|
pg.quit()
|
|
220
|
+
if hasattr(self, "__winrecorder__"): self.__winrecorder__.quit()
|
|
173
221
|
self.quit = True
|