<commit_before>using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Fungus
{
	/**
	 * Visual scripting controller for the Flowchart programming language.
	 * Flowchart objects may be edited visually using the Flowchart editor window.
	 */
	[ExecuteInEditMode]
	public class Flowchart : MonoBehaviour 
	{
		/**
		 * Scroll position of Flowchart editor window.
		 */
		[HideInInspector]
		public Vector2 scrollPos;

		/**
		 * Scroll position of Flowchart variables window.
		 */
		[HideInInspector]
		public Vector2 variablesScrollPos;

		/**
		 * Show the variables pane.
		 */
		[HideInInspector]
		public bool variablesExpanded = true;

		/**
		 * Height of command block view in inspector.
		 */
		[HideInInspector]
		public float blockViewHeight = 400;

		/**
		 * Zoom level of Flowchart editor window
		 */
		[HideInInspector]
		public float zoom = 1f;

		/**
		 * Scrollable area for Flowchart editor window.
		 */
		[HideInInspector]
		public Rect scrollViewRect;

		/**
		 * Currently selected block in the Flowchart editor.
		 */
		[HideInInspector]
		[FormerlySerializedAs("selectedSequence")]
		public Block selectedBlock;
		
		/**
		 * Currently selected command in the Flowchart editor.
		 */
		[HideInInspector]
		public List<Command> selectedCommands = new List<Command>();

		/**
		 * The list of variables that can be accessed by the Flowchart.
		 */
		[HideInInspector]
		public List<Variable> variables = new List<Variable>();

		[TextArea(3, 5)]
		[Tooltip("Description text displayed in the Flowchart editor window")]
		public string description = "";

		/**
	 	 * Slow down execution in the editor to make it easier to visualise program flow.
	 	 */
		[Range(0f, 5f)]
		[Tooltip("Adds a pause after each execution step to make it easier to visualise program flow. Editor only, has no effect in platform builds.")]
		public float stepPause = 0f;

		/**
		 * Use command color when displaying the command list in the inspector.
		 */
		[Tooltip("Use command color when displaying the command list in the Fungus Editor window")]
		public bool colorCommands = true;
		
		/**
		 * Hides the Flowchart block and command components in the inspector.
		 * Deselect to inspect the block and command components that make up the Flowchart.
		 */
		[Tooltip("Hides the Flowchart block and command components in the inspector")]
		public bool hideComponents = true;

		/**
		 * Saves the selected block and commands when saving the scene.
		 * Helps avoid version control conflicts if you've only changed the active selection.
		 */
		[Tooltip("Saves the selected block and commands when saving the scene.")]
		public bool saveSelection = true;

		/**
		 * Unique identifier for identifying this flowchart in localized string keys.
		 */
		[Tooltip("Unique identifier for this flowchart in localized string keys. If no id is specified then the name of the Flowchart object will be used.")]
		public string localizationId = "";

		/**
		 * Cached list of flowchart objects in the scene for fast lookup
		 */
		public static List<Flowchart> cachedFlowcharts = new List<Flowchart>();

		/**
		 * Returns the next id to assign to a new flowchart item.
		 * Item ids increase monotically so they are guaranteed to
		 * be unique within a Flowchart.
		 */
		public int NextItemId()
		{
			int maxId = -1;
			Block[] blocks = GetComponentsInChildren<Block>();
			foreach (Block block in blocks)
			{
				maxId = Math.Max(maxId, block.itemId);
			}
			
			Command[] commands = GetComponentsInChildren<Command>();
			foreach (Command command in commands)
			{
				maxId = Math.Max(maxId, command.itemId);
			}
			return maxId + 1;
		}

		public virtual void OnEnable()
		{
			if (!cachedFlowcharts.Contains(this))
			{
				cachedFlowcharts.Add(this);
			}

			// Assign an item id to any block or command that doesn't have one yet, or
			// that has an already assigned item id.
			// This should only happen after loading a legacy Flowchart.
			List<int> usedIds = new List<int>();
			Block[] blocks = GetComponentsInChildren<Block>();
			foreach (Block block in blocks)
			{
				if (block.itemId == -1 ||
				    usedIds.Contains(block.itemId))
				{
					block.itemId = NextItemId();
				}
			}

			Command[] commands = GetComponentsInChildren<Command>();
			foreach (Command command in commands)
			{
				if (command.itemId == -1 ||
				    usedIds.Contains(command.itemId))
				{
					command.itemId = NextItemId();
				}
			}
		}

		public virtual void OnDisable()
		{
			cachedFlowcharts.Remove(this);
		}

		protected virtual Block CreateBlockComponent(GameObject parent)
		{
			Block block = parent.AddComponent<Block>();
			return block;
		}

		/**<commit_msg>Block & command item ids can sometime conflict #110<commit_after>using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Fungus
{
	/**
	 * Visual scripting controller for the Flowchart programming language.
	 * Flowchart objects may be edited visually using the Flowchart editor window.
	 */
	[ExecuteInEditMode]
	public class Flowchart : MonoBehaviour 
	{
		/**
		 * Scroll position of Flowchart editor window.
		 */
		[HideInInspector]
		public Vector2 scrollPos;

		/**
		 * Scroll position of Flowchart variables window.
		 */
		[HideInInspector]
		public Vector2 variablesScrollPos;

		/**
		 * Show the variables pane.
		 */
		[HideInInspector]
		public bool variablesExpanded = true;

		/**
		 * Height of command block view in inspector.
		 */
		[HideInInspector]
		public float blockViewHeight = 400;

		/**
		 * Zoom level of Flowchart editor window
		 */
		[HideInInspector]
		public float zoom = 1f;

		/**
		 * Scrollable area for Flowchart editor window.
		 */
		[HideInInspector]
		public Rect scrollViewRect;

		/**
		 * Currently selected block in the Flowchart editor.
		 */
		[HideInInspector]
		[FormerlySerializedAs("selectedSequence")]
		public Block selectedBlock;
		
		/**
		 * Currently selected command in the Flowchart editor.
		 */
		[HideInInspector]
		public List<Command> selectedCommands = new List<Command>();

		/**
		 * The list of variables that can be accessed by the Flowchart.
		 */
		[HideInInspector]
		public List<Variable> variables = new List<Variable>();

		[TextArea(3, 5)]
		[Tooltip("Description text displayed in the Flowchart editor window")]
		public string description = "";

		/**
	 	 * Slow down execution in the editor to make it easier to visualise program flow.
	 	 */
		[Range(0f, 5f)]
		[Tooltip("Adds a pause after each execution step to make it easier to visualise program flow. Editor only, has no effect in platform builds.")]
		public float stepPause = 0f;

		/**
		 * Use command color when displaying the command list in the inspector.
		 */
		[Tooltip("Use command color when displaying the command list in the Fungus Editor window")]
		public bool colorCommands = true;
		
		/**
		 * Hides the Flowchart block and command components in the inspector.
		 * Deselect to inspect the block and command components that make up the Flowchart.
		 */
		[Tooltip("Hides the Flowchart block and command components in the inspector")]
		public bool hideComponents = true;

		/**
		 * Saves the selected block and commands when saving the scene.
		 * Helps avoid version control conflicts if you've only changed the active selection.
		 */
		[Tooltip("Saves the selected block and commands when saving the scene.")]
		public bool saveSelection = true;

		/**
		 * Unique identifier for identifying this flowchart in localized string keys.
		 */
		[Tooltip("Unique identifier for this flowchart in localized string keys. If no id is specified then the name of the Flowchart object will be used.")]
		public string localizationId = "";

		/**
		 * Cached list of flowchart objects in the scene for fast lookup
		 */
		public static List<Flowchart> cachedFlowcharts = new List<Flowchart>();

		/**
		 * Returns the next id to assign to a new flowchart item.
		 * Item ids increase monotically so they are guaranteed to
		 * be unique within a Flowchart.
		 */
		public int NextItemId()
		{
			int maxId = -1;
			Block[] blocks = GetComponentsInChildren<Block>();
			foreach (Block block in blocks)
			{
				maxId = Math.Max(maxId, block.itemId);
			}
			
			Command[] commands = GetComponentsInChildren<Command>();
			foreach (Command command in commands)
			{
				maxId = Math.Max(maxId, command.itemId);
			}
			return maxId + 1;
		}

		public virtual void OnEnable()
		{
			if (!cachedFlowcharts.Contains(this))
			{
				cachedFlowcharts.Add(this);
			}

			// Assign an item id to any block or command that doesn't have one yet, or
			// that has an already assigned item id.
			// This should only happen after loading a legacy Flowchart.
			List<int> usedIds = new List<int>();
			Block[] blocks = GetComponentsInChildren<Block>();
			foreach (Block block in blocks)
			{
				if (block.itemId == -1 ||
				    usedIds.Contains(block.itemId))
				{
					block.itemId = NextItemId();
				}
				usedIds.Add(block.itemId);
			}

			Command[] commands = GetComponentsInChildren<Command>();
			foreach (Command command in commands)
			{
				if (command.itemId == -1 ||
				    usedIds.Contains(command.itemId))
				{
					command.itemId = NextItemId();
				}
				usedIds.Add(command.itemId);
			}
		}

		public virtual void OnDisable()
		{
			cachedFlowcharts.Remove(this);
		}

		protected virtual Block CreateBlockComponent(GameObject parent)
		{
			Block block = parent.AddComponent<Block>();
			return block;
		}

		/**
{'fraction_non_alphanumeric': 0.0919185687847008, 'fraction_numerical': 0.003392967304133251, 'mean_word_length': 3.2718489240228372, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7381383', 'n_tokens_mistral': 3212, 'n_tokens_neox': 2627, 'n_words': 1001}