Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Add user profiles #214

Merged

Conversation

KANAjetzt
Copy link
Member

@KANAjetzt KANAjetzt commented Apr 12, 2023

Add User Profiles - ModLoaderUserProfile

Inner Class Profile

Stores the data for each User Profile

	var name := ""
	var mod_list := {}

New API Methods

  • enable_mod(mod_id: String, profile_name := ModLoaderStore.current_user_profile)
    Enables a mod - it will be loaded on the next game start

  • disable_mod(mod_id: String, profile_name := ModLoaderStore.current_user_profile)
    Disables a mod - it will not be loaded on the next game start

  • delete_mod(mod_id: String, profile_name := ModLoaderStore.current_user_profile)
    Delete a mod from a user profiles mod_list

  • create(profile_name: String)
    Creates a new user profile with the given name, using the currently loaded mods as the mod list.

  • set_profile(profile_name: String)
    Sets the current user profile to the specified profile_name.

  • delete(profile_name: String)
    Deletes a user profile with the given profile_name.

  • get_current()
    Returns the current user profile

  • get_profile(profile_name: String)
    Return the user profile with the given name

  • get_all_as_array()
    Returns an array containing all user profiles stored in ModLoaderStore

New Internal Methods

  • _update_disabled_mods()
    Update the global list of disabled mods based on the current user profile. The user profile will override the disabled_mods property that can be set via the options resource in the editor.
    Example: If Mod-TestMod is set in disabled_mods via the editor, the mod will appear disabled in the user profile. If the user then enables the mod in the profile the entry in disabled_mods will be removed.
    Used in mod_loader.gd _init() before loading mods.

  • _update_mod_lists()
    This function updates the mod lists of all user profiles with newly loaded mods that are not already present. It does so by comparing the current set of loaded mods with the mod list of each user profile, and adding any missing mods.
    Used in mod_loader.gd _ready() after all mods are loaded.

  • _handle_mod_state(mod_id: String, profile_name: String, activate: bool)
    Handles the activation or deactivation of a mod in a user profile.

  • _is_mod_id_in_mod_list(mod_id: String, profile_name: String)
    Checks whether a given mod_id is present in the mod_list of the specified user profile.
    Returns True if the mod_id is present, False otherwise.

  • _create_new_profile(profile_name: String, mod_list: Dictionary)
    Creates a new Profile with the given name and mod list.
    Returns the newly created Profile object.

  • _load()
    Loads user profiles from the JSON file and adds them to ModLoaderStore.
    Path to JSON file stored in const FILE_PATH_USER_PROFILES

  • _save()
    Saves the user profiles in the ModLoaderStore to the user profiles JSON file.
    Path to JSON file stored in const FILE_PATH_USER_PROFILES

Locked mods

Renamed from mandatory_mods

  • Added a new property to ModData - is_locked
    The is_locked flag indicates whether a mod's active state can be changed in a user profile, effectively preventing the user from disabling or enabling the mod.
  • Added locked_mods to options_profile.gd
  • Added locked_mods to ModLoaderStore.ml_options

Test / Example Mod:

image

Download KANA-UserProfile.zip




closes #109

@KANAjetzt KANAjetzt added the enhancement New feature or request label Apr 12, 2023
@KANAjetzt KANAjetzt added this to the v6.0.0 milestone Apr 12, 2023
@KANAjetzt KANAjetzt self-assigned this Apr 12, 2023
Updates the mod lists of all user profiles with newly loaded mods that are not already present.
Deletes a mod from a user profiles mod_list. Also added `_is_mod_id_in_mod_list()` to keep things dry.
Update the global list of disabled mods based on the current user profile
Returns an array containing all user profiles stored in ModLoaderStore
An error was caused in the `_update_disabled_mods()` function due to the potential non-existence of the `default` profile at this stage.
Allows to specify mandatory mods in the `ml_options`
@KANAjetzt KANAjetzt requested review from ithinkandicode, Qubus0, otDan and a team April 18, 2023 14:48
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice stuff, good work 👍
i think the user profiles mod is such a central thing that we might want to pick it up as an organisation repo
also: This seems awesome for implementing mod packs in the future. just create a profile and provide an api to download all of those from the steam workshop

addons/mod_loader/api/profile.gd Outdated Show resolved Hide resolved
addons/mod_loader/api/profile.gd Outdated Show resolved Hide resolved
addons/mod_loader/api/profile.gd Outdated Show resolved Hide resolved
addons/mod_loader/api/profile.gd Outdated Show resolved Hide resolved
addons/mod_loader/api/profile.gd Show resolved Hide resolved
KANAjetzt and others added 9 commits April 21, 2023 11:02
I integrated it into the `_update_mod_lists()` function, so that any mods that are no longer installed will automatically be deleted from the user's profile mod lists.
`create()` -> `create_profile()` | `delete()` -> `delete_profile()`
With this a mod can be locked in the current profile state and can't be disabled or enabled.
@KANAjetzt KANAjetzt requested a review from Qubus0 April 21, 2023 20:37
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@KANAjetzt KANAjetzt added this pull request to the merge queue Apr 22, 2023
Merged via the queue into GodotModding:development with commit b9ad9a5 Apr 22, 2023
@KANAjetzt KANAjetzt deleted the feat_profiles_mod_disable branch April 22, 2023 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants