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

@interface annotation to work in conjunction with class_name registration. #8943

Open
Chevifier opened this issue Jan 23, 2024 · 3 comments
Open

Comments

@Chevifier
Copy link

Chevifier commented Jan 23, 2024

Describe the project you are working on

This feature would be general purpose for OOP practices.

Describe the problem or limitation you are having in your project

Current you have to override methods from another class without any error checking syntax highlighting for overridden functions. This works fine but in most cases an interface requires all methods to have implementations for whichever script extends them.

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

Have the ability to create interface class by specifying an @interface() annotation where you can optionally pass in callables that require implementations or leave blank to require all functions to be implemented.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This would require a class_name to be registered otherwise the @interface annotation will be ignore.
Heres and example script that's annotated as an interface.

class_name Tool extends Node3D
@interface()

func activate():
>>pass
func deactivate():
>>pass

Now heres a script that extends the Tool script

extends Tool #error here i.e class method(s) implementation required: deactivate

func _ready():
>>pass

#implemented activate but forgot deactivate
func activate():
>>#do stuff
>>pass

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

Currently you can override the functions without but this feature basically enables true interfaces in GDScript.

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

This would be a new annotation such as (@export, @onready, etc) in the core of GDScript.

@Lazy-Rabbit-2001
Copy link

Lazy-Rabbit-2001 commented Jan 23, 2024

I think what you said is perhaps this: #6416, for GDScript
trait in it, as what the thread-poster said, has an extra functionality that it supports extending a class so that you are allowed to define a function in a trait, while in interface you cannot define your functions but to only declare them.

@Chevifier
Copy link
Author

Chevifier commented Jan 23, 2024

What im thinking is that you still can add code to the functions if necessary and call it via super.activate() as it is now. but what im suggesting is to create an artificial error that prevents the code from running without the functions being implemented within any other scripts that extends them. But in addition to that it will also provide syntax highlighting such as when typing func _ready() for example.(technically that could be its own issue/feature)

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