public string ProcessBeforeLambda(SystemsGraph systemsGraph, SystemNode system, string template) { var queryFields = system.Lambdas.Where(l => l.HasQueryField).Select(l => l.QueryFieldName).ToArray(); if (!queryFields.Any()) { return(s_queryFieldsRegex.Replace(template, "")); } StringBuilder fieldsBuilder = new StringBuilder(); foreach (var field in queryFields) { fieldsBuilder.Append("private EntityQuery "); fieldsBuilder.Append(field); fieldsBuilder.AppendLine(";"); } return(s_queryFieldsRegex.Replace(template, fieldsBuilder.ToString())); }
public string ProcessBeforeLambda(SystemsGraph systemsGraph, SystemNode system, string template) { string namespaceName = systemsGraph.Namespace; // Namespaces var usingNamespaces = system.AllComponents .Where(c => c.TypeReference != null) .Select(c => c.TypeReference.Namespace) .Distinct() .Where(c => !string.IsNullOrWhiteSpace(c)); StringBuilder usingsBuilder = new StringBuilder(); foreach (var usingNamespace in usingNamespaces) { usingsBuilder.Append("using "); usingsBuilder.Append(usingNamespace); usingsBuilder.AppendLine(";"); } if (system.AllComponents.Any(c => c.IsHandWrited)) { usingsBuilder.AppendLine($"using {namespaceName}.Components;"); } template = s_usingsRegex.Replace(template, usingsBuilder.ToString()); return(template); }
private static void GenerateSystems(SystemsGraph systemsGraph) { var states = systemsGraph.nodes.OfType <SystemNode>().Where(s => s.Editable).ToList(); var systemsPath = systemsGraph.CodeGenerationPath; if (systemsPath.EndsWith("Systems")) { systemsPath = PathExtension.SystemPath(systemsPath); } else { systemsPath = PathExtension.SystemPath(Path.Combine(systemsPath, "Systems")); } if (!Directory.Exists(systemsPath)) { Directory.CreateDirectory(systemsPath); } var loadedTemplate = CodeGeneratorUtils.LoadTemplate("System"); foreach (var system in states) { var template = loadedTemplate; var systemName = system.StateName; // ICodeGeneratorSystemProcessorBeforeLambda var beforeLambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorBeforeLambda>(); foreach (var processor in beforeLambdaProcessors) { template = processor.ProcessBeforeLambda(systemsGraph, system, template); } // Process lambdas var lambdaTemplate = s_lambdaRegex.Match(template).Groups[2].Value; StringBuilder lambdaTemplateBuilder = new StringBuilder(); foreach (var lambda in system.Lambdas) { var currentTemplate = lambdaTemplate; // ICodeGeneratorSystemProcessorLambda var lambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorLambda>(); foreach (var processor in lambdaProcessors) { currentTemplate = processor.ProcessLambda(system, lambda, currentTemplate); } // Add lambda to others lambdaTemplateBuilder.AppendLine(currentTemplate); } template = CodeGeneratorUtils.ConditionalText(system.HasStructuralChanges, "STRUCTURAL_CHANGES", template); template = s_lambdaRegex.Replace(template, lambdaTemplateBuilder.ToString()); // ICodeGeneratorSystemProcessorAfterLambda var afterLambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorAfterLambda>(); foreach (var processor in afterLambdaProcessors) { template = processor.ProcessAfterLambda(systemsGraph, system, template); } // Generate file var systemPath = Path.Combine(systemsPath, $"{systemName}.cs"); GenerateSystemFile(systemName, systemPath, template); } }
public static void Generate(SystemsGraph systemsGraph) { GenerateSystems(systemsGraph); AssetDatabase.Refresh(); }
public string ProcessAfterLambda(SystemsGraph systemsGraph, SystemNode system, string template) => s_nameRegex.Replace(template, system.StateName);
public string ProcessAfterLambda(SystemsGraph systemsGraph, SystemNode system, string template) => s_emptyLinesRegex.Replace(template, string.Empty);