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

The ability to get class icon from GDScript #2270

Closed
Shatur opened this issue Feb 10, 2021 · 2 comments
Closed

The ability to get class icon from GDScript #2270

Shatur opened this issue Feb 10, 2021 · 2 comments

Comments

@Shatur
Copy link

Shatur commented Feb 10, 2021

Describe the project you are working on

I working on third person shooter.

Describe the problem or limitation you are having in your project

In my game, characters have abilities. I want to add icons to them. GDScript has the ability to add an icon to class:
image
And I want to reuse such icons in game, but I need to specify the path to the icon a second time separately.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It would be nice to have the ability to get script icon. NariveScript already have script_class_icon_path property, but GDScript do not have any method to access used icon. I suppose this is becase the feature to specify an icon appeared relatively recently (in version 3.1).

If this enhancement will not be used often, can it be worked around with a few lines of script?

I can access source_code of Script and parse icon myself. But this is a bit hacky.

Is there a reason why this should be core and not an add-on in the asset library?

I think this is impossible without a corresponding API in the engine :)

@SIsilicon
Copy link

SIsilicon commented Feb 11, 2021

Another alternative would be to read the project settings.

ProjectSettings.get("_global_script_class_icons") # a Dictionary of class names mapped to icon paths

@Shatur
Copy link
Author

Shatur commented Feb 11, 2021

ProjectSettings.get("_global_script_class_icons") # a Dictionary of class names mapped to icon paths

Did non know about it, thanks! But there is no way to get the class_name from the script to access the icon from the dictionary :(

A bit hacky, but possible:

var filepath := get_from_somewhere()
var name := ""
var script_classes := ProjectSettings.get_setting("_global_script_classes") as Array
for a_class in script_classes:
    if a_class.path == filepath:
        name = a_class.class
        break
var script_class_icons := ProjectSettings.get_setting("_global_script_class_icons") as Dictionary
var script_icon := script_class_icons[name] as Texture

I found it in #103 that supersedes this.

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

No branches or pull requests

3 participants