/// <summary> /// deleted UI node and associated connections /// </summary> /// <param name="node"></param> /// <param name="nodeGraph"></param> private static void DeleteElement(Node node, ref NodeGraph nodeGraph) { // TODO fix special moves still showing up when the attached resource is deleted for (int i = node.ConnectedNodes.Count - 1; i >= 0; i--) { int connectedID = node.ConnectedNodes[i]; nodeGraph.Delete(connectedID); } nodeGraph.Delete(nodeGraph.GetIdFromNode(node)); }
/// <summary> /// applies a single node graph translation where a matching precept from the left hand side, found in the graph <paramref name="nodeGraph"/> is applied according to the <paramref name="nodeGraph"/> e.g. the tranlsation table has an entry [1,5] thus the node with ID 5 in <paramref name="nodeGraph"/> matches ID 1 in <paramref name="rule"/>.LeftHand and will thus be replace by the node linked to by ID 5 of <paramref name="rule"/>.RightHand /// </summary> /// <param name="rule"></param> /// <param name="nodeGraph"></param> /// <param name="translationTable"></param> private static void ApplyNodeRule(NodeGrammar rule, ref NodeGraph nodeGraph, ref OrderedDictionary <int, int> translationTable) { // nodes existing in the replacement but not in the translation table are added AddMissingNodes(rule, ref nodeGraph, ref translationTable); foreach (var translation in translationTable) { // the node that is to be transformed var node = nodeGraph.NodeDict[translation.Value]; // the Key indicates the LeftHand node that matched with this one, we thus want the matching righthand to replace it if (rule.RightHand.NodeDict.TryGetValue(translation.Key, out Node replacementNode)) { // * nodes won't have their values changed, only their connections are modified if (replacementNode.Node_text != "*") { node.Node_text = replacementNode.Node_text; node.Value = replacementNode.Value; } List <int> newConnections = new List <int>(); // maintain the connections this node had and translate them to the new IDs foreach (var connection in node.ConnectedNodes) { if (!translationTable.Values.Contains(connection)) { newConnections.Add(connection); } } // add new connections as described in the grammar foreach (var connection in replacementNode.ConnectedNodes) { if (translationTable.TryGetValue(connection, out int index)) { newConnections.Add(index); } } node.ConnectedNodes = newConnections; } else { // this node doesn't exist in the right hand thus is indicates a deletion nodeGraph.Delete(node); } } }