Browse Source

replace Config object: adapt code

Bastien Sevajol 6 years ago
parent
commit
74e384b43c
3 changed files with 9 additions and 3 deletions
  1. 2 2
      sandbox/tile/run.py
  2. 6 0
      synergine2/config.py
  3. 1 1
      synergine2_cocos2d/gui.py

+ 2 - 2
sandbox/tile/run.py View File

@@ -24,7 +24,7 @@ def main(map_dir_path: str, seed_value: int=42):
24 24
     seed(seed_value)
25 25
 
26 26
     config = Config()
27
-    config.load_files(['sandbox/tile/config.yaml'])
27
+    config.load_yaml('sandbox/tile/config.yaml')
28 28
     logger = get_default_logger(level=logging.ERROR)
29 29
 
30 30
     map_file_path = 'sandbox/tile/{}.tmx'.format(os.path.join(map_dir_path, os.path.basename(map_dir_path)))
@@ -61,7 +61,7 @@ def main(map_dir_path: str, seed_value: int=42):
61 61
                 map_dir_path=map_dir_path,
62 62
             )]
63 63
         ),
64
-        cycles_per_seconds=1 / config.core.cycle_duration,
64
+        cycles_per_seconds=1 / config.resolve('core.cycle_duration'),
65 65
     )
66 66
     core.run()
67 67
 

+ 6 - 0
synergine2/config.py View File

@@ -3,6 +3,8 @@ import typing
3 3
 
4 4
 import re
5 5
 
6
+import yaml
7
+
6 8
 from synergine2.exceptions import SynergineException
7 9
 
8 10
 DEFAULT_VALUE = '__DEFAULT_VALUE__'
@@ -86,3 +88,7 @@ class Config(dict):
86 88
                 return None
87 89
 
88 90
             return value
91
+
92
+    def load_yaml(self, yaml_file_path) -> None:
93
+        with open(yaml_file_path, 'r') as yaml_file:
94
+            self.update(yaml.load(yaml_file))

+ 1 - 1
synergine2_cocos2d/gui.py View File

@@ -669,7 +669,7 @@ class Gui(object):
669 669
         self.logger = logger
670 670
         self._read_queue_interval = read_queue_interval
671 671
         self.terminal = terminal
672
-        self.cycle_duration = self.config.core.cycle_duration
672
+        self.cycle_duration = self.config.resolve('core.cycle_duration')
673 673
 
674 674
         cocos.director.director.init(
675 675
             width=640,