// No 9. OverflowedAnyNode. private static bool ValidateOverflowedAnyNode(MissionRule rule, GraphGrammar graphGrammar) { // Sort nodes in ordering. GraphGrammarNode[] sourceNodes = rule.SourceRule.Nodes.OrderBy(n => n.Ordering).ToArray(); // if replaceRule have any node that dont match the source ordering. return(!rule.ReplacementRule.Nodes.Exists(n => (Alphabet.IsAnyNode(n.AlphabetID) && (n.Ordering > sourceNodes.Length ? true : !Alphabet.IsAnyNode(sourceNodes[n.Ordering - 1].AlphabetID))))); }
// Buttons about adding new symbol, modifying and deleting. void LayoutEditingModeButtonGroup() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(Languages.GetText("MissionAlphabet-AddNew"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Left, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight)) { // Switch the mode. _editingMode = EditingMode.Create; // Initial the preview node and connection. _node = new GraphGrammarNode(); _connection = new GraphGrammarConnection(); // Initial all fields and repaint. Alphabet.RevokeAllSelected(); InitFields(); Repaint(); } switch (_currentTab) { case AlphabetWindowTab.Nodes: EditorGUI.BeginDisabledGroup(Alphabet.SelectedNode == null || Alphabet.IsAnyNode(Alphabet.SelectedNode.AlphabetID)); break; case AlphabetWindowTab.Connections: EditorGUI.BeginDisabledGroup(Alphabet.SelectedConnection == null); break; } if (GUILayout.Button(Languages.GetText("MissionAlphabet-Modify"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Mid, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight)) { // Switch the mode. _editingMode = EditingMode.Modify; } if (GUILayout.Button(Languages.GetText("MissionAlphabet-Delete"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Right, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight)) { // Switch the mode. _editingMode = EditingMode.Delete; // Remove the node or connection from alphabet and repaint. switch (_currentTab) { case AlphabetWindowTab.Nodes: Alphabet.RemoveNode(Alphabet.SelectedNode); break; case AlphabetWindowTab.Connections: Alphabet.RemoveConnection(Alphabet.SelectedConnection); break; } Repaint(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); }
// Step 3: Remove connections from replacement rule. private static void ReplaceNodes(Rule matchedRule) { // Replace the node from matched rule. foreach (Node node in _relatedNodes) { Node replaceNode = matchedRule.FindReplacementByIndex(node.Index); if (replaceNode == null) { break; } // If any node then keep origin node. if (Alphabet.IsAnyNode(replaceNode.AlphabetID)) { continue; } node.Update(replaceNode); } }