McManning / BlueGraph

Visual Scripting Framework for Unity
MIT License
237 stars 30 forks source link

Remove Port.fieldName #17

Closed McManning closed 3 years ago

McManning commented 3 years ago

This isn't used at runtime and is only used in the editor for creating a UIElement editable and binding it to the field. Any changes to field names ends up breaking this behavior since during deserialization we expect to map existing ports back to named fields.

Instead - this should be stored on the reflection code to associate named ports to their fields while in the editor. Doing it in reflection should help forward compatibility too if we have some sort of "FormerlyNamed" attribute we can attach to gracefully handle changes.

E.g. to support the following scenario:

[Node]
public class Foo : AbstractNode
{
    [Input] public int bar;
}

// Later, I want to refactor my code to make bar -> buzz

[Node]
public class Foo : AbstractNode
{
    [FormerlyNamed("Bar")]
    [Input] public int buzz;
}

In this hypothetical - the input port named "Bar" can automatically upgrade to "Buzz" and keep the association to the same field and value. It should be able to work alongside Unity's FormerlySerializedAs.

McManning commented 3 years ago

NodeView.AddInputPort would be the primary place to refactor here. Add some methods onto NodeReflection to pull out metadata about what ports should be associated with what fields

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: