module documentation

Functionality related to game and user/system environment, such as locating installation directories and detecting language and codepage.

Note that most functions here rely on caching to avoid repeated filesystem access; if you modify environment variables or configuration files during runtime, you may need to clear the relevant function caches using functools.cache_clear(). This will typically only be necessary during testing, is not considered part of the public API, and will likely change in a future version.

Class Alias No class docstring; 0/43 constant, 1/1 class method documented
Function get_codepage Detect the codepage used by the NWN installation based on the user language.
Function get_install_directory Find the first matching NWN installation directory. Currently only supports searching for Steam installs.
Function get_install_language_directory Get the path to the language data directory inside the NWN installation.
Function get_language Detect the language of the NWN installation based on system locale or configuration inside game settings.
Function get_setting Get a setting from the user's settings.tml file.
Function get_user_directory Find the current user NWN directory.
Function resolve_alias Get the path for a given NWN alias from nwn.ini, or return the default value if not found.
Function _get_aliases Undocumented
Function _get_settings_tml Undocumented
@cache
def get_codepage() -> CodePage: (source)

Detect the codepage used by the NWN installation based on the user language.

The codepage can be overridden by setting the NWN_CODEPAGE environment variable.

Returns
CodePageThe codepage specified in settings.tml, or defaults based on language.
@cache
def get_install_directory() -> Path: (source)

Find the first matching NWN installation directory. Currently only supports searching for Steam installs.

The search can be overridden by setting the NWN_ROOT environment variable.

Returns
PathThe path to the NWN root directory.
Raises
FileNotFoundErrorIf the directory cannot be found.
def get_install_language_directory() -> Path: (source)

Get the path to the language data directory inside the NWN installation.

Returns
PathThe path to the language data directory.
Raises
FileNotFoundErrorIf the installation directory cannot be found.
@cache
def get_language() -> Language: (source)

Detect the language of the NWN installation based on system locale or configuration inside game settings.

Returns
LanguageThe detected Language enum value, or english by default.
@cache
def get_setting(key: str) -> Any: (source)

Get a setting from the user's settings.tml file.

Parameters
key:strThe setting key to look up, in dot notation (e.g. "game.language.override").
Returns
AnyThe setting value, or None if not found.
Raises
FileNotFoundErrorIf the user directory cannot be found. This function requires a user directory set up already.
@cache
def get_user_directory() -> Path: (source)

Find the current user NWN directory.

The search can be overridden by setting the NWN_HOME or NWN_USER_DIRECTORY environment variables.

Returns
PathThe path to the NWN user directory.
Raises
FileNotFoundErrorIf the directory cannot be found.
@cache
def resolve_alias(alias: str | Alias) -> Path: (source)

Get the path for a given NWN alias from nwn.ini, or return the default value if not found.

Parameters
alias:str | AliasThe alias to look up.
Returns
PathThe resolved path for the alias, or the default value.
Raises
FileNotFoundErrorIf the user directory cannot be found. This function requires a user directory set up already.
@cache
def _get_aliases() -> dict: (source)

Undocumented

@cache
def _get_settings_tml() -> dict: (source)

Undocumented