-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Create a field when Ctrl-dropping a resource into the code editor #81708
Create a field when Ctrl-dropping a resource into the code editor #81708
Conversation
2ec5f5f
to
cddf8d6
Compare
68d1d21
to
894a38d
Compare
Fixed the variable name error and restored the previous behavior (no variable, comma separated elements) for non-empty, non-whitespace lines only. This should address the use case of filling an array as described by @mieldepoche |
894a38d
to
522b809
Compare
8606824
to
d842173
Compare
I tested the pr and everything works as expected now! (at least I didn't find any bug). One thing I stumbled upon is that you can drag an internal resource before saving the scene (just after creating it), so it ends up with no valid path (either simplescreenrecorder-2023-09-19_10.46.10.webm |
d842173
to
d00cc43
Compare
I think it should be fixed now. Thanks @mieldepoche for your very detailed testing! |
I don't know. |
Should a |
If that's desirable then sure, I can implement it. A couple questions though: |
it prevents you from changing it by accident (at least it should), but I'm sure you know that :p
I think that this is a niche case. Most of the time, you'll preload your resource and that's it.
You can't. The question of casing arises though:
|
I feel preloading classes has become pretty much redundant with class_name. I'm not sure it warrants an special case. I also dislike the uppercase naming. At any rate it should be controllable by a setting. I agree with switching to const though, it encourages good practices |
I never use it myself, but I think ideally it would be nice to comply with the style guide. I think people use it to load a type locally, to avoid global namespace pollution (at least that's what I remember being cited). |
I think it would be good to have some input from the editor team to see if the extra complexity is warranted. Also, as I said in the proposal:
Any opinions @Calinou @YuriSizov @KoBeWi ? |
I think preloading a script as PascalCase const is a nice feature. I actually thought about implementing it recently. Note that this is the only way to use it as an actual type, as
This. I have an addon that has 7 preloaded "classes", because they don't need to be global. |
For this particular case, should we still respect type hints setting? |
3e2b500
to
37a4b9a
Compare
Updated OP to reflect the new cases. |
You need to rebase the PR. When doing force-push, always try to be up-to-date with master. |
7fd5ff7
to
313be20
Compare
I tested the last changes a bit and everything seem to work as expected! and I didn't find any bug. nitpicking: one last thing about `const`After testing a bit, I'm actually even more convinced it's better to
It could also be an editor setting. |
Re: const vs var: I don't think this warrants the extra complexity of a setting. If using const is preferred and has no obvious drawbacks, I will just make it so. It is the official style, after all. I can keep the actual behavior behind the shift key. |
If we were to keep the "var" option behind the shift key, would someone prefer to also use "load" instead of "preload"? That was the only real use case where var is actually needed but I don't know if there's any demand for this. |
I think it's really an edge case, most of the time you want to preload the resource. so like if I get things correctly: # resource.gd
extends Resource
const preloaded_member = preload("...") # will be loaded when you `const MyResource = preload("resource.gd")`
var loaded_member = load("...") # will be loaded when you `var instance := MyResource.new()` but postponing the loading to instantiation time is like an edge case I think, if ever done at all willingly. To sum it up:
|
5ca8e11
to
e233346
Compare
Ok, I switched to The PR is tested, rebased and ready to go now. |
e233346
to
3fcbc67
Compare
Applied reviews and simplified the changes significantly since there's no need to support type hints nor internal resources. |
… CRTL is held, and fix some inconsistencies
3fcbc67
to
a93c19f
Compare
Thanks! |
Awesome! Thank you very much for implementing this feature. :) |
The code editor now creates a
const
field when dropping a resource into the code editor while CTRL/CMD is held, similar to what it does for nodes.Closes godotengine/godot-proposals#7673
Additionally, it fixes some inconsistencies that I found while testing the different cases (see the snippet below)