SuperNodes icon indicating copy to clipboard operation
SuperNodes copied to clipboard

SuperNodes Generated with Explicit Interface Definitions

Open CoreyAlexander opened this issue 1 year ago • 2 comments

When using explicit interface definitions like below, the SuperNode generated fails to generate correctly for the following case.

For example:

The given interface.

public interface IHaveAutoload<T> {
    T Instance { get; }
}

The given class.

[GlobalClass, SuperNode(typeof(Dependent))]
public partial class Component: Node2D, IHaveAutoload<SignalAutoload>, IHaveAutoload<AnotherAutoload> {
    protected AnotherAutoload anotherAutoload = null!;
    AnotherAutoload IHaveAutoload<AnotherAutoload>.Instance => this.anotherAutoload;

    protected SignalAutoload signalAutoload = null!;
    SignalAutoload IHaveAutoload<SignalAutoload>.Instance => this.signalAutoload;

    public override void _Ready() {
        this.anotherAutoload = this.GetNode<AnotherAutoload>(
            "/root/AnotherAutoload"
        );

        this.signalAutoload = this.GetNode<SignalAutoload>(
            "/root/SignalAutoload"
        );
    }
}

Produces inside of the generated SuperNode:

    public static TResult ReceiveScriptPropertyOrFieldType<TResult>(
      string scriptProperty, ITypeReceiver<TResult> receiver
    ) {
      switch (scriptProperty) {
        case "Instance":
          return receiver.Receive<NameSpaceOfAutoloadClass>();
        case "Instance":
          return receiver.Receive<NameSpaceOfAutoloadClass>();
    }
}

    public dynamic? GetScriptPropertyOrField(string scriptProperty) {
      switch (scriptProperty) {
        case "Instance":
          return (()this).Instance;
        case "Instance":
          return (()this).Instance;
    }
}

CoreyAlexander avatar Jan 15 '24 00:01 CoreyAlexander

After thinking about this a little more, I poked around how the IProvide<> interface worked. If I switch over to an interface like:

public interface IHaveAutoload<T> {
    T Instance();
}

Things appear to build correctly. I think it is because it's a method now and not an Auto-Property but I'm not sure.

CoreyAlexander avatar Jan 15 '24 01:01 CoreyAlexander

Ah, thank you for filing this issue. Seems the method can be used as a workaround in the meantime. I have some ideas on how this might be fixed, will try when I get a chance.

jolexxa avatar Jan 16 '24 04:01 jolexxa