Earewien / godot-traits

Traits made easy in Godot 4
MIT License
92 stars 5 forks source link

Nodes and Scenes as trait #6

Closed Earewien closed 10 months ago

Earewien commented 10 months ago

In many languages, traits are just sharable pieces of code. But in Godot, it may also be a Node. Why not share a hitbox as an Area2D as a trait ?

If a trait is a Node (it extends Node or a sub-class of Node), it should be added as a child of the receiver, to allow the trait to use methods like _process and all. It allows it to access the scene tree too.

Second thing is, only objects and ref counted are traits. By doing this feature, if a Node script becomes a trait, if it has an associated scene (a scene where the root element has this script attached), the scene should be instantiated as the trait instead of the script itself.