diff --git a/src/RPGCore.Behaviour/Core/SerializedNode.cs b/src/RPGCore.Behaviour/Core/SerializedNode.cs index 4d799565..fdb28ce9 100644 --- a/src/RPGCore.Behaviour/Core/SerializedNode.cs +++ b/src/RPGCore.Behaviour/Core/SerializedNode.cs @@ -24,6 +24,7 @@ public NodeTemplate UnpackNodeAndInputs(Type nodeType, LocalId id, HashSet validOutputs, List mappedInputs) @@ -97,4 +98,62 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return new InputSocket(connectionId); } } + + internal sealed class InputSocketArrayConverter : JsonConverter + { + private readonly HashSet validOutputs; + private readonly List mappedInputs; + + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) + { + if (!objectType.IsArray) + { + return false; + } + + return objectType.IsArray && objectType.GetElementType() == typeof(InputSocket); + } + + public InputSocketArrayConverter(HashSet validOutputs, List mappedInputs) + { + this.validOutputs = validOutputs; + this.mappedInputs = mappedInputs; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new InvalidOperationException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var array = JArray.Load(reader); + + var inputSockets = new InputSocket[array.Count]; + for (int i = 0; i < array.Count; i++) + { + var arrayElement = array[i]; + + var inputSource = new LocalPropertyId(arrayElement.ToObject()); + + if (!validOutputs.Contains(inputSource)) + { + Console.WriteLine($"Ignoring desired input of \"{inputSource}\" as it is not valid."); + return new InputSocket[0]; + } + + int connectionId = mappedInputs.IndexOf(inputSource); + if (connectionId == -1) + { + connectionId = mappedInputs.Count; + mappedInputs.Add(inputSource); + } + inputSockets[i] = new InputSocket(connectionId); + } + + return inputSockets; + } + } } diff --git a/src/RPGCore.Behaviour/Manifest/BehaviourManifest.cs b/src/RPGCore.Behaviour/Manifest/BehaviourManifest.cs index aedf6c1f..e62edeea 100644 --- a/src/RPGCore.Behaviour/Manifest/BehaviourManifest.cs +++ b/src/RPGCore.Behaviour/Manifest/BehaviourManifest.cs @@ -31,7 +31,7 @@ public sealed class BehaviourManifest private static IEnumerable GetDependentAssemblies(AppDomain appDomain, Assembly analyzedAssembly) { return appDomain.GetAssemblies() - .Where(assembly => GetNamesOfAssembliesReferencedBy(assembly) + .Where(assembly => assembly == analyzedAssembly || GetNamesOfAssembliesReferencedBy(assembly) .Contains(analyzedAssembly.FullName)); } @@ -75,7 +75,7 @@ public static BehaviourManifest CreateFromAppDomain(AppDomain appDomain) if (typeof(NodeTemplate).IsAssignableFrom(type)) { - nodeTypes.Add(type.Name, NodeInformation.Construct(type)); + nodeTypes.Add(type.FullName, NodeInformation.Construct(type)); } } } diff --git a/src/RPGCore.Demo.Inventory/Nodes/AddNode.cs b/src/RPGCore.Demo.Inventory/Nodes/AddNode.cs index 5f37b82a..2ba135c2 100644 --- a/src/RPGCore.Demo.Inventory/Nodes/AddNode.cs +++ b/src/RPGCore.Demo.Inventory/Nodes/AddNode.cs @@ -20,13 +20,13 @@ public class AddInstance : Instance public override InputMap[] Inputs(ConnectionMapper connections) => new[] { - connections.Connect (ref Template.ValueA, ref ValueA), - connections.Connect (ref Template.ValueB, ref ValueB) + connections.Connect(ref Template.ValueA, ref ValueA), + connections.Connect(ref Template.ValueB, ref ValueB) }; public override OutputMap[] Outputs(ConnectionMapper connections) => new[] { - connections.Connect (ref Template.Output, ref Output) + connections.Connect(ref Template.Output, ref Output) }; public override void Setup() diff --git a/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.dll b/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.dll index b53c376b..85718e1f 100644 Binary files a/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.dll and b/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.dll differ diff --git a/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.pdb b/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.pdb index b42345a2..309361a1 100644 Binary files a/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.pdb and b/src/RPGCoreUnity/Assets/Demos/Inventory/Plugins/RPGCore.Demo.Inventory.pdb differ diff --git a/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.dll b/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.dll index 345aef0c..cb9f4b58 100644 Binary files a/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.dll and b/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.dll differ diff --git a/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.pdb b/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.pdb index 15f612eb..d17496a8 100644 Binary files a/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.pdb and b/src/RPGCoreUnity/Assets/RPGCore/Plugins/RPGCore.Behaviour.pdb differ diff --git a/src/RPGCoreUnity/Assets/RPGCore/Scripts/Editors/Behaviour/BehaviourGraphFrame.cs b/src/RPGCoreUnity/Assets/RPGCore/Scripts/Editors/Behaviour/BehaviourGraphFrame.cs index 4596303a..6827a6f1 100644 --- a/src/RPGCoreUnity/Assets/RPGCore/Scripts/Editors/Behaviour/BehaviourGraphFrame.cs +++ b/src/RPGCoreUnity/Assets/RPGCore/Scripts/Editors/Behaviour/BehaviourGraphFrame.cs @@ -72,6 +72,7 @@ private void DrawNodes() { return; } + var graphEditorNodes = View.GraphField["Nodes"]; // Draw Nodes @@ -223,13 +224,35 @@ public void DrawConnections() } } - // Foreach Input - foreach (var childField in nodeData) + IEnumerable InputSocketFields(EditorField nodeDataField) { - if (childField.Field.Type != "InputSocket") + foreach (var childField in nodeDataField) { - continue; + if (childField.Field.Type != "InputSocket") + { + continue; + } + if (childField.Field.Format == FieldFormat.List) + { + foreach (var listElement in childField) + { + yield return listElement; + } + } + else if (childField.Field.Format == FieldFormat.Object) + { + yield return childField; + } + else + { + Debug.LogError($"Unknown InputSocket format. InputSockets cannot be a \"{childField.Field.Format}\"."); + } } + } + + // Foreach Input + foreach (var childField in InputSocketFields(nodeData)) + { var inputFieldFeature = childField.GetOrCreateFeature(); inputFieldFeature.GlobalRenderedPosition = new Rect(