Beispiel #1
0
    def load_config(self, mod=None):
        """ Loads config :-) May be called without mod argument to set up
         initial settings"""
        pre_config = copy(self.config_defaults)
        #if mod is defined update pre_config with mod specific settings
        if mod:
            mod_specific_config = ConfigParser()
            if not mod_specific_config.read(
                    os.path.join(self.data_path(mod), 'settings.ini')):
                self.log.warning(
                    "Config file '%s' not found, using default settings" %
                    os.path.join(self.data_path(mod), 'settings.ini'))
            mod_specific_config = config_to_dict(mod_specific_config)
            pre_config.update(mod_specific_config.get('main', {}))

        # Parsing config
        pre_config = parse_dict(pre_config, self.config_parser, self.log)

        # Other mod options (already parsed by mod)
        if mod:
            mod_config = mod.get_config()
            try:
                pre_config['board-size'] = mod_config['board']['size']
            except KeyError:
                self.log.critical(
                    "Attribute 'size' in section 'board' of mod config"
                    "not found, using default. Weird things may happen")

        self.config = pre_config
        self.log.debug("Configuration loaded")
Beispiel #2
0
 def parse_players_conifg(self, n):
     #Load config should be called before this
     result = []
     for i in range(1,n+1):
         key = 'player%i' % i
         player_config = {}
         player_config = copy(self.player_config_default)
         player_config.update(self.config.get(key, {}))
         player_config = parse_dict(player_config, self.player_config_parser)
         result.append(player_config)
     
     return result
Beispiel #3
0
    def load_anim_config(self, path_to_file):
        """ Returns a readymade, parsed config dict loaded from path_to_file """
        self.log.debug("\tLoading configuration...")
        #TODO: Generating sprite classes on the fly from config ?
        #Loading config from file
        configParser = ConfigParser()
        configParser.read(path_to_file)
        #Making it a dictionary
        dicted = config_to_dict(configParser)
        # Setting up result config dict
        config = {}
        for action, options in dicted.items():
            # each action's options are made a copy of default ones 
            config[action] = copy(self.anim_defaults)
            # then we update it with values from loaded config file
            config[action].update(options)
            # parsing options
            config[action] = parse_dict(config[action], self.anim_parser, self.log)

        return config