Ejemplo n.º 1
0
        private static void GenerateComponent(ComponentDefinition componentDefinition)
        {
            // Paths
            var componentsPath = componentDefinition.Directory;

            if (componentsPath.EndsWith("Components"))
            {
                componentsPath = PathExtension.SystemPath(componentsPath);
            }
            else
            {
                componentsPath = PathExtension.SystemPath(Path.Combine(componentsPath, "Components"));
            }
            if (!Directory.Exists(componentsPath))
            {
                Directory.CreateDirectory(componentsPath);
            }

            var template = CodeGeneratorUtils.LoadTemplate("Component");

            var processors = ProcessorsSelector.Selectors <ICodeGeneratorComponentProcessors>();

            foreach (var processor in processors)
            {
                template = processor.Process(componentDefinition, template);
            }

            var upperedComponentName = componentDefinition.ComponentName.ToUpperFirstChar();
            var componentPath        = Path.Combine(componentsPath, $"{upperedComponentName}.cs");

            GenerateComponentFile(upperedComponentName, componentPath, template);
        }
Ejemplo n.º 2
0
        public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate)
        {
            var    transitions      = system.TransitionTo(lambda).ToArray();
            bool   hasTransition    = (transitions?.Count() ?? -1) > 0;
            string transitionsNames = "";

            if (hasTransition)
            {
                transitionsNames = string.Join(", ", transitions.Select(t => t.Name));
            }

            currentTemplate = CodeGeneratorUtils.ConditionalText(hasTransition, "TRANSITION", currentTemplate);
            return(s_transitionToRegex.Replace(currentTemplate, transitionsNames));
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate) =>
 CodeGeneratorUtils.ConditionalText(lambda.Parallel, "PARALLEL", currentTemplate);
Ejemplo n.º 5
0
 public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate)
 {
     currentTemplate = CodeGeneratorUtils.ConditionalText(lambda.HasSharedComponent, "HAS_SHARED", currentTemplate);
     return(CodeGeneratorUtils.ConditionalText(lambda.HasStructuralChanges, "STRUCTURAL_CHANGES", currentTemplate));
 }