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

Input<T>.HasChanged #16

Open
Fydar opened this issue Jan 29, 2020 · 0 comments
Open

Input<T>.HasChanged #16

Fydar opened this issue Jan 29, 2020 · 0 comments
Assignees
Labels
📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package New feature or request

Comments

@Fydar
Copy link
Owner

Fydar commented Jan 29, 2020

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 Fydar added New feature or request 🔌 API labels Jan 29, 2020
@Fydar Fydar added 📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package and removed 🔌 API labels Feb 19, 2020
@Fydar Fydar self-assigned this May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package New feature or request
Projects
Development

No branches or pull requests

1 participant