Bläddra i källkod

set_caption() and _predefined_attributes_allowed added to videogame.

Zero! Studio 1 år sedan
förälder
incheckning
31d5d59931
2 ändrade filer med 30 tillägg och 10 borttagningar
  1. 2 2
      data/02.yaml
  2. 28 8
      jogai/videogame.py

+ 2 - 2
data/02.yaml

@@ -1,5 +1,5 @@
-attributes:
-  gravity: 5
+caption: Test Videogame
+gravity: 5
 scene: test_large.png
 characters:
   protagonist:

+ 28 - 8
jogai/videogame.py

@@ -17,6 +17,10 @@ from jogai.utils import _get_events, _get_keys
 # --------------- #
 
 running = True
+_predefined_attributes_allowed = [
+    _('caption'),
+    _('gravity'),
+]
 
 # ------------------ #
 #    FUNCTIONS       #
@@ -49,14 +53,15 @@ def _load_attributes(data: dict):
     Parameters:
         data: input schema
     """
-    if _('attributes') in data:
-        attributes = data[_('attributes')]
-        if not isinstance(attributes, dict):
-            raise TypeError(
-                _('The attributes in the input schema must be a dict.')
-            )
-        if _('gravity') in attributes:
-            set_gravity(attributes[_('gravity')])
+
+    if not isinstance(data, dict):
+        raise TypeError(
+            _('The attributes in the input schema must be a dict.')
+        )
+    for attribute in data:
+        # utils._convert_function_arguments_to_string()
+        if attribute in _predefined_attributes_allowed:
+            eval(f'set_{attribute}(data["{attribute}"])')
 
 
 def _load_characters(data: dict) -> list:
@@ -252,6 +257,21 @@ def paint_group(group: Type['group.SquareGroup']):
     group.draw(_globals._window)
 
 
+def set_caption(caption: str):
+    """
+    Set the caption for the videogame.
+
+    Parameters:
+        caption: Caption to be setted
+
+    Examples:
+        >>> set_caption('My videogame')
+    """
+    if not isinstance(caption, str):
+        raise TypeError(_('The caption for the videogame must be a string.'))
+    pygame.display.set_caption(caption)
+
+
 def set_gravity(gravity: int):
     """
     Set the gravity in the videogame.