Skip to content

Commit

Permalink
[v0.0.2] Comment node; Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed May 12, 2024
1 parent f0d0c9b commit 58604d5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
60 changes: 30 additions & 30 deletions Editor/View/CodeGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public void Create(CodeGraphNode node)
Bind();
}

internal void RemoveNode(CodeGraphEditorNode editorNode)
{
Undo.RecordObject(_serializedObject.targetObject, "Removed Node");

_nodes.Remove(editorNode);
_tree.Nodes.Remove(editorNode.Node);
_nodeLookup.Remove(editorNode.Node.Guid);
_serializedObject.Update();
}

private void PopulateNodes(IEnumerable<CodeGraphNode> graphNodes)
{
foreach (var node in graphNodes)
Expand All @@ -95,6 +105,26 @@ private void PopulateNodes(IEnumerable<CodeGraphNode> graphNodes)
}
}

internal void RemoveConnection(Edge edge)
{
if (_edgeLookup.Remove(edge, out var connection))
{
_tree.Connections.Remove(connection);
}
}

internal void CreateEdge(Edge edge)
{
var inputNode = (CodeGraphEditorNode) edge.input.node;
var outputNode = (CodeGraphEditorNode) edge.output.node;

var inputIndex = inputNode.Ports.IndexOf(edge.input);
var outputIndex = outputNode.Ports.IndexOf(edge.output);

var connection = new CodeGraphConnection(inputNode.Id, inputIndex, outputNode.Id, outputIndex);
_tree.Connections.Add(connection);
}

private void PopulateConnections(IEnumerable<CodeGraphConnection> connections)
{
foreach (var connection in connections)
Expand Down Expand Up @@ -133,24 +163,6 @@ private void AddNode(CodeGraphNode node)
AddElement(editorNode);
}

internal void RemoveNode(CodeGraphEditorNode editorNode)
{
Undo.RecordObject(_serializedObject.targetObject, "Removed Node");

_nodes.Remove(editorNode);
_tree.Nodes.Remove(editorNode.Node);
_nodeLookup.Remove(editorNode.Node.Guid);
_serializedObject.Update();
}

internal void RemoveConnection(Edge edge)
{
if (_edgeLookup.Remove(edge, out var connection))
{
_tree.Connections.Remove(connection);
}
}

private void AddGridBackground()
{
var grid = new GridBackground();
Expand All @@ -167,18 +179,6 @@ private void AddStyles()
styleSheets.Add(styleSheet);
}

internal void CreateEdge(Edge edge)
{
var inputNode = (CodeGraphEditorNode) edge.input.node;
var outputNode = (CodeGraphEditorNode) edge.output.node;

var inputIndex = inputNode.Ports.IndexOf(edge.input);
var outputIndex = outputNode.Ports.IndexOf(edge.output);

var connection = new CodeGraphConnection(inputNode.Id, inputIndex, outputNode.Id, outputIndex);
_tree.Connections.Add(connection);
}

private void Bind()
{
_serializedObject.Update();
Expand Down
14 changes: 14 additions & 0 deletions Runtime/Nodes/CommentNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Depra.CodeGraph.Attributes;
using UnityEngine;

namespace Depra.CodeGraph
{
[Serializable]
[NodeTitle("Comment")]
[NodeMenuPath("Comment")]
internal sealed class CommentNode : CodeGraphNode
{
[SerializeField] private string _text;
}
}
3 changes: 3 additions & 0 deletions Runtime/Nodes/CommentNode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Runtime/Nodes/StartNode.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// © 2024 Nikolay Melnikov <n.melnikov@depra.org>

using System;
using Depra.CodeGraph.Attributes;

namespace Depra.CodeGraph
{
[Serializable]
[HasFlowOutput]
[NodeTitle("Start")]
[NodeMenuPath("Process/Start")]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.depra.code-graph",
"version": "0.0.1",
"version": "0.0.2",
"displayName": "Depra.CodeGraph",
"description": "",
"unity": "2022.3",
Expand Down

0 comments on commit 58604d5

Please sign in to comment.