Godot-proposals: Differentiate Image's get_data() and Texture's get_data()

Created on 24 Feb 2020  路  3Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:
Projects that deal with the Image and Texture classes.
Describe the problem or limitation you are having in your project:
Poor clarity in GDScript. I was helping someone with their code earlier today and I got them mixed up again for the 3rd time.
Your code can even look like this: variable.get_data().get_data() which is just crazy. You will often be handling both classes in the same script and both classes are calling what appears to be the same function. Knowing about the difference between a "texture" and "image" in Godot is already another point of confusion in itself.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Rename one of them and clarity will be improved. Now may be the best time to ask, considering other things are being renamed: https://github.com/godotengine/godot/issues/30736
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Any kind of rename, I don't mind how they are differentiated.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
It will be used often.
Is there a reason why this should be core and not an add-on in the asset library?:
This is about GDScript.

core

Most helpful comment

I figured I'd leave it to the experts, the most important thing was seeing if others felt the same way. But as a starting point:

Texture class's function could become get_image(), since the Image class is the one that has much more to do with "data".

In the docs the create_from_data() function says it "Fills the image with the given raw data." so Image class's function could potentially become get_raw_data(), but this may be unnecessary if the other rename is implemented.

Interestingly OpenSimplexNoise has a function named get_image() which returns an Image, so that would line up well with renaming Texture class's function to be get_image() as well.
One of big the issues with both these get_data() functions having the same name is that they each return different data (PoolByteArray and Image) which causes confusion and errors.

All 3 comments

This sounds like a good idea. Do you have a better name in mind?

I figured I'd leave it to the experts, the most important thing was seeing if others felt the same way. But as a starting point:

Texture class's function could become get_image(), since the Image class is the one that has much more to do with "data".

In the docs the create_from_data() function says it "Fills the image with the given raw data." so Image class's function could potentially become get_raw_data(), but this may be unnecessary if the other rename is implemented.

Interestingly OpenSimplexNoise has a function named get_image() which returns an Image, so that would line up well with renaming Texture class's function to be get_image() as well.
One of big the issues with both these get_data() functions having the same name is that they each return different data (PoolByteArray and Image) which causes confusion and errors.

Functions like these (and I'm sure these are not the only two instances) should be renamed ala get_image_data/get_texture_data, i.e. make it more explicit (along the pattern of get_nameofnodetypehere_data).

Was this page helpful?
0 / 5 - 0 ratings