Skip to content
This repository was archived by the owner on May 16, 2021. It is now read-only.

Commit e598d68

Browse files
committed
Fix issue with groups not being saved internally properly
1 parent 46a692d commit e598d68

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CodeGraph_Unity/Assets/CodeGraph/CodeGraph/Editor/CodeGraphView.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void GroupSelection() {
142142

143143
editorWindow.InvalidateSaveButton();
144144
var group = new Group {title = "New Group"};
145-
var groupData = new GroupData("New Group", new Vector2(10f, 10f), group);
145+
var groupData = new GroupData("New Group", group);
146146
editorWindow.GraphObject.CodeGraphData.AddGroup(groupData);
147147
foreach (var node in validSelection) {
148148
if (node.GetContainingScope() is Group previousGroup) {
@@ -164,6 +164,7 @@ public void UngroupSelection() {
164164
if (!(selectable is Node node) || !(node.GetContainingScope() is Group group))
165165
continue;
166166

167+
((IGroupItem) node).GroupGuid = Guid.Empty;
167168
group.RemoveElement(node);
168169
if (!group.containedElements.Any())
169170
RemoveGroup(group);

CodeGraph_Unity/Assets/CodeGraph/CodeGraph/Editor/GroupData.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ public string Title {
2727
set => title = value;
2828
}
2929

30-
[SerializeField]
31-
private Vector2 position;
32-
33-
public Vector2 Position {
34-
get => position;
35-
set => position = value;
36-
}
3730

38-
public GroupData(string title, Vector2 position, Group groupReference) {
31+
public GroupData(string title, Group groupReference) {
3932
guid = Guid.NewGuid();
4033
this.title = title;
41-
this.position = position;
4234
GroupReference = groupReference;
4335
}
4436

CodeGraph_Unity/Assets/CodeGraph/CodeGraph/Editor/SaveUtility.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ public CodeGraphObject Save(string fileName, bool shouldRefreshAssets = true) {
2323
graphObject.CodeGraphData.Edges.AddRange(SerializationHelper.SerializeEdges(connectedEdges));
2424
graphObject.CodeGraphData.Nodes.AddRange(SerializationHelper.SerializeNodes(Nodes));
2525
graphObject.CodeGraphData.LastEditedAt = DateTime.Now.ToString(CultureInfo.InvariantCulture);
26-
graphObject.CodeGraphData.Groups = CodeGraph.Instance.GraphObject.CodeGraphData.Groups;
26+
graphObject.CodeGraphData.Groups = new List<GroupData>(CodeGraph.Instance.GraphObject.CodeGraphData.Groups);
2727
graphObject.CodeGraphData.Groups.ForEach(group => { group.Title = group.GroupReference.title; });
28+
foreach (var groupItem in CodeGraph.Instance.GraphObject.CodeGraphData.GroupItems) {
29+
graphObject.CodeGraphData.GroupItems.Add(groupItem.Key, CodeGraph.Instance.GraphObject.CodeGraphData.GroupItems[groupItem.Key]);
30+
}
2831
graphObject.CodeGraphData.GraphName = CodeGraph.Instance.GraphObject.CodeGraphData.GraphName;
2932
graphObject.CodeGraphData.SchemaVersion = CodeGraph.Instance.GraphObject.CodeGraphData.SchemaVersion;
3033
graphObject.CodeGraphData.IsMonoBehaviour = CodeGraph.Instance.GraphObject.CodeGraphData.IsMonoBehaviour;
@@ -39,6 +42,7 @@ public void LoadGraph(CodeGraphObject graphObject) {
3942
ClearGraph();
4043
CreateGroups();
4144
GenerateNodes();
45+
ClearEmptyGroups();
4246
ConnectNodes();
4347
PostInitNodes();
4448
}
@@ -84,6 +88,18 @@ private void GenerateNodes() {
8488
});
8589
}
8690

91+
private void ClearEmptyGroups() {
92+
foreach (var group in graphView.GroupDictionary.ToDictionary(pair => pair.Key, pair => pair.Value)) {
93+
if (graphObject.CodeGraphData.GroupItems[group.Value.Guid].Count == 0) {
94+
graphView.RemoveElement(group.Key);
95+
graphObject.CodeGraphData.Groups.Remove(group.Value);
96+
graphObject.CodeGraphData.GroupItems.Remove(group.Value.Guid);
97+
graphView.GroupGuidDictionary.Remove(group.Value.Guid);
98+
graphView.GroupDictionary.Remove(group.Key);
99+
}
100+
}
101+
}
102+
87103
private void ConnectNodes() {
88104
SerializationHelper.DeserializeAndLinkEdges(graphObject.CodeGraphData.Edges, Nodes).ForEach(graphView.Add);
89105
}

CodeGraph_Unity/Assets/CodeGraph/CodeGraph/Runtime/CodeGraphData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public void AddGroup(GroupData groupData) {
2727
public void SetGroup(IGroupItem node, GroupData group) {
2828
var groupGuid = group?.Guid ?? Guid.Empty;
2929
if (node.GroupGuid != Guid.Empty) {
30-
Debug.Log(groupGuid);
3130
var oldGroupNodes = GroupItems[groupGuid];
3231
oldGroupNodes.Remove(node);
3332
}

0 commit comments

Comments
 (0)