godot icon indicating copy to clipboard operation
godot copied to clipboard

Make `EditorInterface.get_editor_scale()` static

Open Zylann opened this issue 3 years ago • 3 comments

To avoid having to do workarounds like this https://github.com/Zylann/godot_voxel/blob/41e364624fd5b038ad296eefeb7bfddebea9c697/util/godot/editor_scale.cpp#L10

EditorInterface is internally a singleton though, so if it is desired to expose it entirely as a singleton, it could be changed.

Zylann avatar Sep 19 '22 14:09 Zylann

if it is desired to expose it entirely as a singleton, it could be changed.

I had to use a similar workaround to pass the EditorInterface.get_base_control() between scripts, to access theming properties. I feel that turning the EditorInterface into a singleton would simplify access a lot.

RedMser avatar Sep 19 '22 16:09 RedMser

EditorInterface is internally a singleton though, so if it is desired to expose it entirely as a singleton, it could be changed.

Yes, I think this is the way to go.

Ideally, we'd expose some kind of Editor singleton (probably pointing to EditorNode) and pass everything through it. But for now we can just use EditorPlugin and make the get_editor_interface() method static. This will affect user code, and it seems that calling static methods on instances is not currently handled well in GDScript, but that's the case with the current state of the PR as well.

YuriSizov avatar Sep 19 '22 17:09 YuriSizov

I had to use a similar workaround to pass the EditorInterface.get_base_control() between scripts, to access theming properties. I feel that turning the EditorInterface into a singleton would simplify access a lot.

You don't need to do that, your control already has access to the editor theme as long as it's inside of the tree (and if it's not, then theming doesn't really matter).

YuriSizov avatar Sep 19 '22 17:09 YuriSizov

This will affect user code, and it seems that calling static methods on instances is not currently handled well in GDScript, but that's the case with the current state of the PR as well.

Calling static methods on instances should work fine. It's the fact that it works fine which can be problematic for some static methods which we don't want to allow calling on instances (typically static methods that return an instance).

akien-mga avatar Sep 20 '22 07:09 akien-mga

Ah, okay then. Even more reason to do it properly and not just for one use case.

YuriSizov avatar Sep 20 '22 08:09 YuriSizov

Is it really possible to make a node also an API singleton? It's in the editor's scene tree, that also means there is a particular place it should be registered I guess, as the lifetime of the object isn't bound by register_types and the like. It has no member variables though, so... it could be changed to an Object maybe like other singletons, but then its functions might need to check for existence of EditorNode to be sure no mistake happens (unlike EDSCALE which is just a global float there was no risk)

Zylann avatar Sep 21 '22 20:09 Zylann

Superseded by #75694.

akien-mga avatar Apr 25 '23 14:04 akien-mga