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
     seed(seed_value)
24
     seed(seed_value)
25
 
25
 
26
     config = Config()
26
     config = Config()
27
-    config.load_files(['sandbox/tile/config.yaml'])
27
+    config.load_yaml('sandbox/tile/config.yaml')
28
     logger = get_default_logger(level=logging.ERROR)
28
     logger = get_default_logger(level=logging.ERROR)
29
 
29
 
30
     map_file_path = 'sandbox/tile/{}.tmx'.format(os.path.join(map_dir_path, os.path.basename(map_dir_path)))
30
     map_file_path = 'sandbox/tile/{}.tmx'.format(os.path.join(map_dir_path, os.path.basename(map_dir_path)))
61
                 map_dir_path=map_dir_path,
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
     core.run()
66
     core.run()
67
 
67
 

+ 6 - 0
synergine2/config.py View File

3
 
3
 
4
 import re
4
 import re
5
 
5
 
6
+import yaml
7
+
6
 from synergine2.exceptions import SynergineException
8
 from synergine2.exceptions import SynergineException
7
 
9
 
8
 DEFAULT_VALUE = '__DEFAULT_VALUE__'
10
 DEFAULT_VALUE = '__DEFAULT_VALUE__'
86
                 return None
88
                 return None
87
 
89
 
88
             return value
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
         self.logger = logger
669
         self.logger = logger
670
         self._read_queue_interval = read_queue_interval
670
         self._read_queue_interval = read_queue_interval
671
         self.terminal = terminal
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
         cocos.director.director.init(
674
         cocos.director.director.init(
675
             width=640,
675
             width=640,