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: dict | None = 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 and return the system default configuration.

load_from_file

load_from_file(path: Path | str) -> Svan2DConfig

Load configuration from a TOML file

Parameters

path
Path to TOML configuration file
Raises
FileNotFoundError
If config file doesn't exist
tomllib.TOMLDecodeError
If TOML is invalid

load_with_overrides

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

Load defaults and override with user config if provided

Parameters

user_config_path
Optional path to user config file

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()

Return a deep copy of the entire configuration dictionary.