Beispiel #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);
        }
Beispiel #2
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);
            }
        }