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

Support abstract classes #339

Merged
merged 6 commits into from
Jul 15, 2022
Merged

Conversation

chippmann
Copy link
Contributor

This adds support for member registration in abstract classes.

Now one can define abstract classes which inherit from a godot type and register default members in it.
Upon registration of inheriting classes, the inheriting class registers the member of the abstract class as well.

To godot, the abstract class does not exist as it's not registered. But on the jvm side, it exists and all calls to the default members are properly propagated through normal inheritance.

Example:

// register class annotation is optional for abstract classes
abstract class AbstractClassInheritanceParent: Node() {

    @Export
    @RegisterProperty
    var registeredExportedPropertyInAbstractClass = false

    @RegisterSignal
    val signalInAbstractClass by signal<String>("blubb")

    @RegisterFunction
    fun functionInAbstractClassWithDefaultImplementation() {
        // some implementation
    }

    @RegisterFunction
    abstract fun abstractFunction()
}
@RegisterClass
class AbstractClassInheritanceChild: AbstractClassInheritanceParent() {
    @RegisterFunction
    override fun abstractFunction() {
        // some implementation
    }
}

Limitations:
Currently a user must explicitly register any member he overrides even if that member is marked as registered in the abstract class.
This could be changed though in the future, but personally i would opt against it, to force users to be explicit about what is exported and what not.

Note to self: If this PR is accepted, it needs to be cherry picked to the 4.0 branches

@piiertho piiertho merged commit 751fee4 into develop Jul 15, 2022
@piiertho piiertho deleted the feature/support_abstract_classes branch July 15, 2022 13:45
piiertho added a commit that referenced this pull request Jul 15, 2022
* Implement support for abstract classes

* Add abstract classes documentation

* Ignore default parameters in detekt config for too many function parameters

* Add IDE check for not registered overridden abstract functions which were registered in the abstract class

Co-authored-by: Cedric Hippmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants