using System.Collections.Generic; using System.IO; using Gum.Composer.CodeGen.Config; namespace Gum.Composer.CodeGen.Internal { internal static class AspectFileReader { private const string SEARCH_PATTERN = "*.gum"; public static IEnumerable ReadAspects() { string[] files = Directory.GetFiles(PathConfig.GetAspectsDirectoryPath(), SEARCH_PATTERN, SearchOption.AllDirectories); List aspectPrototypes = new List(); for (int index = 0; index < files.Length; index++) { string text = File.ReadAllText(files[index]); if (ResolveText(text, out AspectPrototype aspectPrototype)) { aspectPrototypes.Add(aspectPrototype); } } return aspectPrototypes; } private static bool ResolveText(string text, out AspectPrototype aspectPrototype) { aspectPrototype = default; if (!text.StartsWith(Keywords.ASPECT_FILE)) { return false; } string[] splitText = text.Split(Keywords.BOF); string name = splitText[0].Replace(Keywords.ASPECT_FILE, "").Trim(); Dictionary fields = new Dictionary(); char[] chars = splitText[1].ToCharArray(); bool isReadingField = false; bool isReadingFieldName = false; bool isReadingTypeName = false; string fieldName = string.Empty; string typeName = string.Empty; for (int index = 0; index < chars.Length; index++) { char currentChar = chars[index]; if (currentChar == Keywords.EOF) { break; } if (char.IsWhiteSpace(currentChar)) { if (!isReadingField) { continue; } if (isReadingFieldName) { isReadingFieldName = false; isReadingTypeName = true; } } else { isReadingField = true; if (!isReadingFieldName && !isReadingTypeName) { isReadingFieldName = true; } if (currentChar == Keywords.EOL) { fields.Add(fieldName, typeName); isReadingField = false; isReadingFieldName = false; isReadingTypeName = false; fieldName = string.Empty; typeName = string.Empty; continue; } if (isReadingFieldName) { typeName += currentChar; } else { fieldName += currentChar; } } } aspectPrototype = new AspectPrototype(name, fields); return true; } } }