Svan2DConfig

Configuration manager for svan2d

Loads configuration from TOML files and provides access to config values with proper type conversion and color normalization. Configuration priority (highest to lowest): 1. User config file (if provided) 2. System defaults (defaults.toml)

Constructor

Svan2DConfig(config_dict: Optional[dict] = None)

Initialize configuration

Parameters

config_dict
Optional pre-loaded configuration dictionary

Methods

get

get(key: ConfigKey, default: Any = None) -> Any

Get configuration value by config key enum

Parameters

key
ConfigKey enum value (e.g., ConfigKey.SCENE_WIDTH)
default
Default value if key not found

Returns

Configuration value with appropriate type conversion

load_defaults

load_defaults()

Load system default configuration

Returns

Svan2DConfig instance with system defaults

load_from_file

load_from_file(path: Path | str) -> Svan2DConfig

Load configuration from a TOML file

Parameters

path
Path to TOML configuration file

Returns

Svan2DConfig instance Raises: FileNotFoundError: If config file doesn't exist tomllib.TOMLDecodeError: If TOML is invalid

load_with_overrides

load_with_overrides(
    user_config_path: Optional[Path | str] = None
) -> Svan2DConfig

Load defaults and override with user config if provided

Parameters

user_config_path
Optional path to user config file

Returns

Svan2DConfig with defaults and user overrides applied

set

set(key: ConfigKey, value: Any)

Set configuration value by config key enum

Parameters

key
ConfigKey enum value (e.g., ConfigKey.SCENE_WIDTH)
value
Value to set

to_dict

to_dict()

Get the entire configuration as a dictionary

Returns

Deep copy of configuration dictionary