Preforms in editor checking for interfaces.
Godot (currently) does not support interfaces or traits or multi-inherence - which would all solve the same issue more or less.
But with not we are forced to usehas_method or excessive composition - both which arent great.
This bothered me enough to create this - which lets you:
- define interfaces
- then get error (without even running the game) to see what you need to fix to correctly implement the give interface.
- place the
plugin.cfg, theplugin.gd, and theqinterface.gdin a folder in the godot project (recomenededres://addons/qinterface/) - Project > Project Settings > Plugins > QInterface > Enabled
why is this not on the asset library?
cause dispite doing everything I set out for it to do, it could use some more upgrades before I feel like submitting it for review.
IDK if I will improve it further - probably will.
File should start with
@abstract # @interface
class_name InterfaceNamewhere InterfaceName can be whatever you want
you can optionally put commonets above it and change the white space a bit
then this file is an interface - anything that implements it will need to also define those
create the varrible in the script as follows
var implements = [InterfaceName1, InterfaceName2]
or
var implements: Array = [
InterfaceName1,
InterfaceName2,
](dont place comments between the [ ]) (you can type it Array but dont give it a further type (like Array[Foo]))
now whenever you:
- save this script
- navigate to this script
- naviage away from this script
- open the project
the output will log error messages telling you if you have implemented the interface incorrectly
this way you can garentee that you have it implemented correctly everywhere
Check if enemy has the interface Hittable with QInterface.implements(enemy, Hittable)
Have an array of objects that implement a given inteface: sorry there isnt a good way to do it - just use an Array[Object] or Array[Varient] or Array - then just check every element before you add it to the array
You might want to consider a naming convention
naming interfaces starting with I_ - will make it so that you can autocomplete them easier but otherwise stay out of the way
naming properties and methods and signals within a given interface starting with i_interface_name_property_name will help you know what belongs to what and if something should be removed if you remove the interface
Does not support:
- static properties
- nested types
- difference between void/Nil and Varient (in both cases will leave untyped)