RPGCore icon indicating copy to clipboard operation
RPGCore copied to clipboard

Input<T>.HasChanged

Open fydar opened this issue 6 years ago • 0 comments

Currently, to detect changes to an individual input, you have to subscribe to a delegate. You can also receive a callback whenever any of the inputted values change.

This API proposal adds a Boolean property to the inputs to a node that can be acted on in the OnInputChanged() callback.

Example

public class DemoNode : Node
{
    public InputSocket Target;
    public InputSocket StatIncrease;

    public INodeInstance Create()
    {
        return new DemoNodeInstance();
    }

    public class DemoNodeInstance : Instance
    {
        public Input<Character> Target;
        public Input<int> StatIncrease;

        public override InputMap[] Inputs(GraphConnector connections) = new[]
        {
            connections.Create(ref Node.Target, ref Target)
        }

        public override void Setup()
        {
            // Subscribe to events, setup variables...
        }

        public override void OnInputChanged()
        {
            if (StatIncrease.HasChanged)
            {
                Console.WriteLine($"New Stat Value: {StatIncrease.Value}.");
            }
            if (Target.HasChanged)
            {
                Console.WriteLine($"New Target Value: {Target.Value}.");
            }
        }

        public override void Remove()
        {
            // Unsubscribe from events, dispose members...
        }
    }
}

Implementation

This Boolean flag indicating whether the value of the connection has changed should live on the connection itself.

Buffering events will allow this API to be much more useful.

fydar avatar Jan 29 '20 08:01 fydar