Beispiel #1
0
		/// <summary>
		/// Returns the first occurrence of the given search-parameter.
		/// </summary>
		/// <param name="dataType">The type to search through (Schema, Item or Field).</param>
		/// <param name="searchType">If the given String should contain, start/end with or equal the searched entries.</param>
		/// <param name="searchBy">Searches for this String in every entry of given type.</param>
		/// <param name="limitBySchema">Optionally only search through a specific Schema.</param>
		/// <returns></returns>
		public static string Find(GDEDataType dataType, SearchType searchType, string searchBy, string limitBySchema = "")
		{
			foreach(var entry in ListAllBy(dataType))
			{
				switch(searchType)
				{
					case SearchType.Contains:
						if(entry.Contains(searchBy)) return entry;
						break;
					case SearchType.Equals:
						if(entry == searchBy) return entry;
						break;
					case SearchType.DoesNotContain:
						if(!entry.Contains(searchBy)) return entry;
						break;
					case SearchType.DoesNotEqual:
						if(entry != searchBy) return entry;
						break;
					case SearchType.StartsWith:
						if(entry.StartsWith(searchBy)) return entry;
						break;
					case SearchType.EndsWith:
						if(entry.EndsWith(searchBy)) return entry;
						break;
				}
			}

			UnityEngine.Debug.LogWarning("Couldn't find any matching " + searchBy.ToString()
										  + " which " + searchType.ToString() + " \"" + searchBy + "\".");

			return "";
		}
Beispiel #2
0
		/// <summary>
		/// Returns a list of all data by data type.
		/// </summary>
		/// <param name="searchBy">What type of data to list.</param>
		public static List<string> ListAllBy(GDEDataType searchBy, string limitBySchema = "")
		{
			List<string> currList = new List<string>();

			switch(searchBy)
			{
				case GDEDataType.Schema:
					currList = GetAllSchemas();
					break;
				case GDEDataType.Item:
					currList = GetAllItems(limitBySchema);
					break;
				case GDEDataType.FieldName:
					currList = GetAllFieldNames(limitBySchema);
					break;
				case GDEDataType.FieldType:
					currList = GetAllFieldTypes(limitBySchema).ToStringList();
					break;
				case GDEDataType.FieldValue:
					currList = GetAllFieldValues(limitBySchema).ToStringList();
					break;
			}

			if(currList.Count == 0)
			{
				Debug.LogError("Empty List in ListAllBy(" + searchBy + ", " + limitBySchema + ")!");
				return null;
			}

			return currList;
		}
 public override void Reset()
 {
     dataType   = GDEDataType.Item;
     searchType = new SearchType[0];
     searchBy   = new FsmString[0];
     result     = null;
 }
Beispiel #4
0
		/// <summary>
		/// Returns the amount of occurences of the given search-parameter.
		/// </summary>
		/// <param name="searchBy">The type to search through (Schema, Item or Field).</param>
		/// <param name="contains">Searches for this String in every entry of given type.</param>
		/// <returns></returns>
		public static int CountOccurrences(GDEDataType searchBy, string contains, string limitBySchema = "")
		{
			int result = 0;

			foreach(var entry in ListAllBy(searchBy))
			{
				if(entry.Contains(contains)) result++;
			}

			return result;
		}
Beispiel #5
0
		/// <summary>
		/// Returns a random occurence of the given search-parameter.
		/// </summary>
		/// <param name="searchBy">The type to search through (Schema, Item or Field).</param>
		/// <param name="contains">Searches for this String in every entry of given type.</param>
		/// <returns></returns>
		public static string GetRandom(GDEDataType searchBy, string bySchema = "")
		{
			List<string> currList = new List<string>();

			switch(searchBy)
			{
				case GDEDataType.Schema:
					currList = GetAllSchemas();
					break;
				case GDEDataType.Item:
					currList = GetAllItems(bySchema);
					break;
				case GDEDataType.FieldName:
					currList = GetAllFieldNames(bySchema);
					break;
			}

			return currList.Random();
		}
Beispiel #6
0
		/// <summary>
		/// Finds all matching occurrences with given search-parameters.
		/// </summary>
		public static List<string> FindAllMatching(GDEDataType dataType, SearchType[] searchTypes,
												   string[] searchBy, string limitBySchema = "", bool debug = true)
		{
			List<string> result = FindAll(dataType, searchTypes[0], searchBy[0], limitBySchema);

			if(result.Count == 0 && debug)
			{
				UnityEngine.Debug.LogWarning("Couldn't find any matching " + dataType.ToString()
										  + " which " + searchTypes[0].ToString() + " \"" + searchBy[0] + "\".");
				return result;
			}

			for(int i = 1; i < searchTypes.Length; i++)
			{
				List<string> tmpResult = FindAll(dataType, searchTypes[i], searchBy[i], limitBySchema);
				result = result.Matches(tmpResult);
			}

			return result;
		}
Beispiel #7
0
		/// <summary>
		/// Returns all occurrences of the given search-parameter.
		/// </summary>
		/// <param name="dataType">The type to search through (Schema, Item or Field).</param>
		/// <param name="searchType">If the given String should contain, start/end with or equal the searched entries.</param>
		/// <param name="searchBy">Searches for this String in every entry of given type.</param>
		/// <param name="limitBySchema">Optionally only search through a specific Schema.</param>
		/// <returns></returns>
		public static List<string> FindAll(GDEDataType dataType, SearchType searchType,
											  string searchBy, string limitBySchema = "")
		{
			List<string> result = new List<string>();

			foreach(var entry in ListAllBy(dataType))
			{
				switch(searchType)
				{
					case SearchType.Contains:
						if(entry.Contains(searchBy)) result.AddUnique(entry);
						break;
					case SearchType.Equals:
						if(entry == searchBy) result.AddUnique(entry);
						break;
					case SearchType.DoesNotContain:
						if(!entry.Contains(searchBy)) result.AddUnique(entry);
						break;
					case SearchType.DoesNotEqual:
						if(entry != searchBy) result.AddUnique(entry);
						break;
					case SearchType.StartsWith:
						if(entry.StartsWith(searchBy)) result.AddUnique(entry);
						break;
					case SearchType.EndsWith:
						if(entry.EndsWith(searchBy)) result.AddUnique(entry);
						break;
				}
			}

			if(result.Count == 0)
			{
				UnityEngine.Debug.LogWarning("Couldn't find any matching " + dataType.ToString()
										  + " which " + searchType.ToString() + " \"" + searchBy + "\".");
			}

			return result;
		}
Beispiel #8
0
		/// <summary>
		/// Retrieve all available and relevant data, limited by specified parameters.
		/// </summary>
		/// <param name="outputType">Define what type should be returned. Current options: 'Schema', 'Item' and 'Field'.</param>
		/// <param name="limitBySchema">Limit result to only contains entries by given Schema.</param>
		/// <param name="limitByItem">Limit result to only contains entries by given Item Name.</param>
		/// <param name="limitByField">Limit result to only contains entries by given Field Name.</param>
		/// <param name="sort">Sort the list alphanumerically.</param>
		public static List<object> GDEGetAllDataBy(GDEDataType outputType, string limitBySchema = "",
												   string limitByItem = "", string limitByFieldType = "",
												   string limitByFieldName = "", object limitByFieldValue = null,
												   bool sort = false)
		{
			Dictionary<string, object> allGDEData = GetAllGDEData();
			Dictionary<string, object> currentDataSet = new Dictionary<string, object>();
			List<object> result = new List<object>();
			string currentSchema;

			//go through all data pairs to limit the result and list all entries by type
			foreach(KeyValuePair<string, object> pair in allGDEData)
			{
				//skip irrelevant KeyPairs
				if(pair.Key.StartsWith(GDMConstants.SchemaPrefix)) continue;

				currentDataSet = pair.Value as Dictionary<string, object>;

				if(limitBySchema != "")
				{
					//extract current Schema
					currentDataSet.TryGetString(GDMConstants.SchemaKey, out currentSchema);

					//check if current Schema equals specified one
					if(currentSchema != limitBySchema) continue;
				}

				//skip if it doesn't contain the specified ItemName
				if(!string.IsNullOrEmpty(limitByItem) && pair.Key != limitByItem) continue;
				//skip if it doesn't contain the specified FieldType
				if(!string.IsNullOrEmpty(limitByFieldType)
					&& !DataSetContainsFieldType(currentDataSet, limitByFieldType)) continue;
				//skip if it doesn't contain the specified FieldName
				if(!string.IsNullOrEmpty(limitByFieldName)
					&& !DataSetContainsFieldName(currentDataSet, limitByFieldName)) continue;
				//skip if it doesn't contain the specified FieldValue
				if(limitByFieldValue != null
					&& !DataSetContainsFieldValue(currentDataSet, limitByFieldValue)) continue;

				//only add entries of given type
				switch(outputType)
				{
					case GDEDataType.Schema:
						currentDataSet.TryGetString(GDMConstants.SchemaKey, out currentSchema);
						result.AddUnique(currentSchema);
						break;
					case GDEDataType.Item:
						result.AddUnique(pair.Key);
						break;
					case GDEDataType.FieldName:
						foreach(var subPair in currentDataSet)
						{
							if(IsRelevant(subPair.Key)) result.AddUnique(subPair.Key);
						}
						break;
					case GDEDataType.FieldType:
						foreach(var subPair in currentDataSet)
						{
							if(IsRelevant(subPair.Key, true)) result.AddUnique(subPair.Value);
						}
						break;
					case GDEDataType.FieldValue:
						foreach(var subPair in currentDataSet)
						{
							if(IsRelevant(subPair.Key)) result.AddUnique(subPair.Value);
						}
						break;
				}
			}

			//if set, sort the complete list
			if(sort) result.Sort();

			return result;
		}
Beispiel #9
0
 public override void Reset()
 {
     dataType = GDEDataType.Item;
     contains = null;
     result   = null;
 }