profile_manager module

class data.profile.profile_manager.UserProfile(name, profile_version, data=None)

Bases: object

Represents a user profile containing character data and preferences.

Variables:
  • VERSION (int) – The current version of the user profile schema.

  • name (str) – The name of the user profile.

  • profile_version (int) – The version of the profile data.

  • data (dict) – The profile data, including characters, current character, and preferences.

VERSION = 1
static from_dict(data: dict)

Instantiate a UserProfile from a dict loaded from JSON.

Assumes data["version"] is the profile version. The name field isn’t stored in the JSON, so we leave it as None.

Parameters:

data (dict) – The dictionary containing profile data.

Returns:

The instantiated user profile.

Return type:

UserProfile

get_characters()

Get the list of characters in the profile.

Returns:

A list of character data.

Return type:

list

get_current_character()

Get the currently selected character.

Returns:

The current character, or None if not set.

Return type:

object or None

get_preference(key, default=None)

Get a user preference.

Parameters:
  • key (str) – The preference key.

  • default (object, optional) – The value to return if the preference is not set.

Returns:

The value of the preference, or the default if not set.

Return type:

object

static load(path, name)

Load a user profile from a file with a given name.

Parameters:
  • path (str) – The file path to load the profile from.

  • name (str) – The name to assign to the loaded profile.

Returns:

The loaded user profile.

Return type:

UserProfile

static load_user_profile(path)

Load a user profile from a file, updating if necessary.

Parameters:

path (str) – The file path to load the profile from.

Returns:

The loaded (and possibly updated) user profile.

Return type:

UserProfile

save(path)

Save the profile data to a file.

Parameters:

path (str) – The file path to save the profile data.

set_preference(key, value)

Set a user preference.

Parameters:
  • key (str) – The preference key.

  • value (object) – The value to set for the preference.