Config
The Config module provides a flexible configuration file management system that supports game version-based configuration loading, caching mechanisms and factory pattern configuration instance creation. The module is suitable for game applications that need to manage multiple versions of configurations.
Main Interface
Detectors
@register_config(name: str, config_dir: str = "../../conf/sys")
Decorator for automatic configuration class registration.
Parameters:
name: Configuration nameconfig_dir: Configuration file directory path (optional)
Usage Example:
@register_config("game_settings") # Make sure that the file conf/sys/_game_settings.json exists
class GameConfig(BaseConfig):
passThe configuration file /conf/sys/_{name}.json will be automatically bundled to the corresponding registration class.
@register_config_with_dir(name: str, config_dir: str)
Register configuration in a specified directory.
Parameters:
name: Configuration nameconfig_dir: Configuration file directory path
We do not recommend customizing the path of the file, which may cause difficult problems in subsequent interfaces.
BaseConfig Class
Base configuration class that all configuration classes should inherit from.
load_config(game_ver: str) -> Dict[str, Any]
Load configuration for the specified game version.
Parameters:
game_ver: Game version identifier.
Returns:
Configuration data dictionary.
get_config_info(game_ver: str) -> Dict[str, Any]
Get configuration information.
Returns:
Dictionary containing configuration name, file path, and other information.
clear_cache() -> None
Clear configuration cache.
get_config_path() -> str
Get the full path to the configuration file.
Returns:
Full file path.
ConfigFactory Class
Configuration factory class for creating and managing configuration instances.
create(config_type: str) -> BaseConfig
Create a configuration instance.
Parameters:
config_type: Configuration name. (The registered name by detector.)
Returns:
Configuration instance.
register(name: str, config_class: Type[BaseConfig]) -> None
Register a new configuration type.
Parameters:
name: Configuration name.config_class: Configuration class.
get_registered_configs() -> Dict[str, Dict[str, any]]
Get information about all registered configurations.
Returns:
Configuration information dictionary.
is_registered(config_type: str) -> bool
Check if a configuration type is registered.
Parameters:
config_type : Configuration name.
Returns:
Boolean indicating if registered.
unregister(config_type: str) -> bool
Unregister a configuration type.
Parameters:
config_type : Configuration name.
Returns:
Boolean indicating success.
Last updated
