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

Swap arguments of ResourceSaver.save() #61647

Merged
merged 1 commit into from
Jul 29, 2022

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Jun 2, 2022

Whenever I use ResourceSaver.save(), I intuitively try to put the Resource as first argument and path as second, only to discover that the actual order is reversed. So I reversed that order. IMO it makes sense to put resource first, as it's more important. This also allows making the path an optional argument and saving will default to the resource's own path.

core/core_bind.cpp Outdated Show resolved Hide resolved
core/core_bind.cpp Outdated Show resolved Hide resolved
@akien-mga
Copy link
Member

Another thing that could be considered would be adding something like Resource.save() for the use case where you just want to re-save a resource to the path it was already saved to.

One concern I have with the default value for path is that for a new Resource which hasn't been saved yet, the default output of calling ResourceSaver.save(res) will result in an error (since it can't infer a path and that's then invalid). Feels a bit weird that the default API usage errors out.

No strong opinion either way, would be good to get @reduz's input on this too.

@KoBeWi
Copy link
Member Author

KoBeWi commented Jun 7, 2022

One concern I have with the default value for path is that for a new Resource which hasn't been saved yet, the default output of calling ResourceSaver.save(res) will result in an error (since it can't infer a path and that's then invalid). Feels a bit weird that the default API usage errors out.

Maybe the error message could just be clearer, to say that you either need to provide path or the Resource itself needs a path.

@KoBeWi KoBeWi force-pushed the SaverResource branch 2 times, most recently from b3d8cf3 to f1d0043 Compare June 29, 2022 14:58
@KoBeWi KoBeWi requested review from a team as code owners June 29, 2022 14:58
@neikeq
Copy link
Contributor

neikeq commented Jun 29, 2022

The most natural for me has always been the path as first parameter. I don't mind that too much though. What I really think is bad is the path as an optional parameter with a default value.

@KoBeWi KoBeWi requested a review from a team as a code owner June 29, 2022 16:07
@YuriSizov
Copy link
Contributor

@reduz approved this during the PR meeting without a strong opinion either way.

@@ -174,7 +174,7 @@ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_form
ResourceSaver *ResourceSaver::singleton = nullptr;

void ResourceSaver::_bind_methods() {
ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL((uint32_t)FLAG_NONE));
ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE));
Copy link
Member

Choose a reason for hiding this comment

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

What was the decision on @neikeq's suggestion to not have a default value for the path?

Copy link
Member

Choose a reason for hiding this comment

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

I think its expected that it has a default value, it makes it clear that if you already specified a path it will re-use it.

@akien-mga
Copy link
Member

Needs a rebase, otherwise I think this can be merged now.

@KoBeWi KoBeWi requested a review from a team as a code owner July 28, 2022 08:53
@akien-mga akien-mga merged commit 15a02c4 into godotengine:master Jul 29, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants