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 rename_profile() to ModLoaderUserProfile #352

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

kyooosukedn
Copy link

closes #287

Hi, for this change I modified and reference myself to method create_profile as @KANAjetzt in https://github.com/GodotModding/godot-mod-loader/blob/development/addons/mod_loader/api/profile.gd :)

@KANAjetzt KANAjetzt added the enhancement New feature or request label Oct 25, 2023
@KANAjetzt KANAjetzt added this to the v6.4.0 milestone Oct 25, 2023
@KANAjetzt KANAjetzt requested a review from a team October 25, 2023 08:01
Copy link
Collaborator

@KANAjetzt KANAjetzt left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! Let me know if you have any questions or if something is unclear.

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
@KANAjetzt KANAjetzt changed the title feat: Add a method to rename a user profile to ModLoaderUserProfile #287 feat: Add rename_profile() to ModLoaderUserProfile Oct 25, 2023
@KANAjetzt KANAjetzt changed the base branch from main to development October 25, 2023 08:30
@kyooosukedn
Copy link
Author

@KANAjetzt Thank you very much for your review, now I think I have corrected the changes the way you suggested. Question for "running modloader in godot" do I need to take the mod developer route to test it?

@KANAjetzt
Copy link
Collaborator

For starters, you can create an empty Godot Project and follow the steps on this page.

If you get this working, you can look into symlinking the addons directory into this project.

That will allow you to edit the code inside Godot, where you will get some syntax errors to fix.

If no compile errors show up anymore, you can look into the mod developer route and add the rename functionality to the example user profile UI mod.

This would be ideal, but it might be a bit overwhelming if you've never used Godot. So feel free to just edit your code inside Godot to get the syntax error messages, and I will review your code again.

@kyooosukedn
Copy link
Author

Hi @KANAjetzt sorry that it took so long, i corrected some changes as I am able to get the syntax error now

Copy link
Collaborator

@KANAjetzt KANAjetzt left a comment

Choose a reason for hiding this comment

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

Almost there - thanks for your work! 👍
As I said in the review, it's important to test things in practice. I added the rename feature to the example UI mod and found the mentioned issues.

addons/mod_loader/api/profile.gd Show resolved Hide resolved
return false

# Rename user profile
var profile_to_rename = ModLoaderStore.user_profiles[old_profile_name].duplicate(true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var profile_to_rename = ModLoaderStore.user_profiles[old_profile_name].duplicate(true)
var profile_renamed := ModLoaderStore.user_profiles[old_profile_name].duplicate() as ModUserProfile

I only figured this out because I implemented this function in the UserProfileUI mod - so its always a good idea to test your code in practice 😃

Copy link
Collaborator

Choose a reason for hiding this comment

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

I renamed it from profile_to_rename -> profile_renamed - I feel like this is more clear because it is the reference to the renamed profile.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also realized that we are duplicating a Resource here, and that comes with some caveats (here are the Docs).

I added the as ModUserProfile to cast the type. Without that, it's just a generic Resource, and set_profile(profile_renamed) will not work. In addition, I had to change mod_user_profile.gd. As described in the docs, only exported properties are duplicated, so I added the two export to the file:

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

Comment on lines 123 to 125
# Set it as the current profile
if ModLoaderStore.current_user_profile == ModLoaderStore.user_profiles[old_profile_name]:
ModLoaderStore.current_user_profile[new_profile_name]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Set it as the current profile
if ModLoaderStore.current_user_profile == ModLoaderStore.user_profiles[old_profile_name]:
ModLoaderStore.current_user_profile[new_profile_name]
# Set it as the current profile if it was the current profile
if ModLoaderStore.current_user_profile.name == old_profile_name:
set_profile(profile_renamed)

We can't check for ModLoaderStore.user_profiles[old_profile_name] because it got erased a few lines above.

@kyooosukedn
Copy link
Author

Thank you again :) I'm sorry I don't have the chance yet to really dive deep into it..

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.

Add a method to rename a user profile to ModLoaderUserProfile
2 participants