示例#1
0
        public void GetNestedTypes_returns_direct_children_only()
        {
            var parentFqn = "improbable.gdk.tests.TypeName";

            var nestedTypes = store.GetNestedTypes(parentFqn);

            Assert.AreEqual(1, nestedTypes.Count);
            Assert.IsTrue(nestedTypes.Contains("improbable.gdk.tests.TypeName.Other"));
        }
示例#2
0
        public void GetNestedTypes_returns_direct_children_only()
        {
            var parentIdentifier = CommonDetailsUtils.CreateIdentifier("improbable.gdk.tests.TypeName");

            var nestedTypes = store.GetNestedTypes(parentIdentifier);

            Assert.AreEqual(1, nestedTypes.Count);
            Assert.IsTrue(nestedTypes.Contains(CommonDetailsUtils.CreateIdentifier("improbable.gdk.tests.TypeName.Other")));
        }
示例#3
0
        public CoreCodegenJob(string outputDir, IFileSystem fileSystem, DetailsStore store) : base(
                outputDir, fileSystem, store)
        {
            InputFiles  = store.SchemaFiles.ToList();
            OutputFiles = new List <string>();

            var allNestedTypes = store.Types
                                 .SelectMany(kv => store.GetNestedTypes(kv.Key))
                                 .ToHashSet();

            typesToGenerate = store.Types
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityTypeDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            enumsToGenerate = store.Enums
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityEnumDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            componentsToGenerate = store.Components
                                   .Select(kv => new GenerationTarget <UnityComponentDetails>(kv.Value, kv.Value.Package))
                                   .ToList();

            foreach (var typeTarget in typesToGenerate)
            {
                var fileName = Path.ChangeExtension(typeTarget.Content.CapitalisedName, FileExtension);
                OutputFiles.Add(Path.Combine(typeTarget.OutputPath, fileName));
            }

            foreach (var componentTarget in componentsToGenerate)
            {
                var relativeOutputPath = componentTarget.OutputPath;
                var componentName      = componentTarget.Content.ComponentName;

                OutputFiles.Add(Path.Combine(relativeOutputPath, Path.ChangeExtension(componentTarget.Content.ComponentName, FileExtension)));

                if (componentTarget.Content.CommandDetails.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandPayloads", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandComponents", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandDiffDeserializer", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandDiffStorage", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandMetaDataStorage", FileExtension)));
                }

                if (componentTarget.Content.EventDetails.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}Events", FileExtension)));
                }

                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}UpdateSender", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}EcsViewManager", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ComponentDiffStorage", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ComponentDiffDeserializer", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}Providers", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ViewStorage", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath, Path.ChangeExtension($"{componentName}Metaclass", FileExtension)));
            }

            foreach (var enumTarget in enumsToGenerate)
            {
                var fileName = Path.ChangeExtension(enumTarget.Content.TypeName, FileExtension);
                OutputFiles.Add(Path.Combine(enumTarget.OutputPath, fileName));
            }
        }
示例#4
0
        public CoreCodegenJob(CodegenJobOptions options, IFileSystem fileSystem, DetailsStore store)
            : base(options, fileSystem, store)
        {
            const string jobName = nameof(CoreCodegenJob);

            Logger.Trace($"Initialising {jobName}.");

            AddInputFiles(store.SchemaFiles);

            // Types
            Logger.Trace("Gathering nested types.");
            var allNestedTypes = store.Types
                                 .SelectMany(kv => store.GetNestedTypes(kv.Key))
                                 .ToHashSet();

            Logger.Trace("Gathering types details.");
            var typesToGenerate = store.Types
                                  .Where(kv => !allNestedTypes.Contains(kv.Key))
                                  .Select(kv => kv.Value)
                                  .ToList();

            Logger.Trace("Adding job targets for types.");
            AddGenerators(typesToGenerate, t => ($"{t.Name}.cs", UnityTypeGenerator.Generate));

            Logger.Trace($"Added job targets for {typesToGenerate.Count} types.");

            // Enums
            Logger.Trace("Gathering enum details.");
            var enumsToGenerate = store.Enums
                                  .Where(kv => !allNestedTypes.Contains(kv.Key))
                                  .Select(kv => kv.Value)
                                  .ToList();

            Logger.Trace("Adding job targets for enums.");
            AddGenerators(enumsToGenerate,
                          e => ($"{e.Name}.cs", UnityEnumGenerator.Generate));

            Logger.Trace($"Added job targets for {enumsToGenerate.Count} enums.");

            // Components
            Logger.Trace("Gathering component details.");
            var componentsToGenerate = store.Components.Values.ToList();

            Logger.Trace("Adding job targets for components.");
            AddGenerators(componentsToGenerate,
                          c => ($"{c.Name}.cs", UnityComponentDataGenerator.Generate),
                          c => ($"{c.Name}ReplicationSystem.cs", UnityComponentReplicationSystemGenerator.Generate),
                          c => ($"{c.Name}EcsViewManager.cs", UnityEcsViewManagerGenerator.Generate),
                          c => ($"{c.Name}ComponentDiffStorage.cs", ComponentDiffStorageGenerator.Generate),
                          c => ($"{c.Name}ComponentDiffDeserializer.cs", ComponentDiffDeserializerGenerator.Generate),
                          c => ($"{c.Name}Metaclass.cs", MetaclassGenerator.Generate));

            Logger.Trace("Adding job targets for commands.");
            AddGenerators(componentsToGenerate.Where(c => c.CommandDetails.Count > 0),
                          c => ($"{c.Name}CommandPayloads.cs", UnityCommandPayloadGenerator.Generate),
                          c => ($"{c.Name}CommandDiffDeserializer.cs", CommandDiffDeserializerGenerator.Generate),
                          c => ($"{c.Name}CommandDiffStorage.cs", CommandDiffStorageGenerator.Generate),
                          c => ($"{c.Name}CommandMetaDataStorage.cs", CommandMetaDataStorageGenerator.Generate));

            Logger.Trace("Adding job targets for events.");
            AddGenerators(componentsToGenerate.Where(c => c.EventDetails.Count > 0),
                          c => ($"{c.Name}Events.cs", UnityEventGenerator.Generate));

            Logger.Trace($"Added job targets for {componentsToGenerate.Count} components.");

            Logger.Trace($"Finished initialising {jobName}.");
        }
示例#5
0
        public CoreCodegenJob(string outputDir, IFileSystem fileSystem, DetailsStore store)
            : base(outputDir, fileSystem, store)
        {
            var jobName = nameof(CoreCodegenJob);

            logger.Info($"Initialising {jobName}.");

            AddInputFiles(store.SchemaFiles.ToList());

            logger.Info("Gathering nested types.");
            var allNestedTypes = store.Types
                                 .SelectMany(kv => store.GetNestedTypes(kv.Key))
                                 .ToHashSet();

            logger.Info("Gathering types details.");
            typesToGenerate = store.Types
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityTypeDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            logger.Info("Gathering enum details.");
            enumsToGenerate = store.Enums
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityEnumDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            logger.Info("Gathering component details.");
            componentsToGenerate = store.Components
                                   .Select(kv => new GenerationTarget <UnityComponentDetails>(kv.Value, kv.Value.Package))
                                   .ToList();

            logger.Trace("Adding job output files for types.");
            foreach (var typeTarget in typesToGenerate)
            {
                logger.Trace($"Adding output file for type {typeTarget.Content.QualifiedName}.");

                var fileName = Path.ChangeExtension(typeTarget.Content.CapitalisedName, FileExtension);
                AddOutputFile(Path.Combine(typeTarget.OutputPath, fileName));
            }
            logger.Info($"Added output files for {typesToGenerate.Count} types.");

            logger.Trace("Adding job output files for components.");
            foreach (var componentTarget in componentsToGenerate)
            {
                var relativeOutputPath = componentTarget.OutputPath;
                var componentName      = componentTarget.Content.ComponentName;

                logger.Trace($"Adding job output files for component {componentTarget.Content.QualifiedName}.");

                AddOutputFile(Path.Combine(relativeOutputPath, Path.ChangeExtension(componentTarget.Content.ComponentName, FileExtension)));

                if (componentTarget.Content.CommandDetails.Count > 0)
                {
                    logger.Trace("Adding job output files for commands.");

                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}CommandPayloads", FileExtension)));
                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}CommandComponents", FileExtension)));
                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}CommandDiffDeserializer", FileExtension)));
                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}CommandDiffStorage", FileExtension)));
                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}CommandMetaDataStorage", FileExtension)));
                }

                if (componentTarget.Content.EventDetails.Count > 0)
                {
                    logger.Trace("Adding job output file for events.");

                    AddOutputFile(Path.Combine(relativeOutputPath,
                                               Path.ChangeExtension($"{componentName}Events", FileExtension)));
                }

                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}UpdateSender", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}EcsViewManager", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}ComponentDiffStorage", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}ComponentDiffDeserializer", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}Providers", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}ViewStorage", FileExtension)));
                AddOutputFile(Path.Combine(relativeOutputPath,
                                           Path.ChangeExtension($"{componentName}Metaclass", FileExtension)));
            }
            logger.Info($"Added output files for {componentsToGenerate.Count} components.");

            logger.Trace("Adding job output files for enums.");
            foreach (var enumTarget in enumsToGenerate)
            {
                logger.Trace($"Adding job output file for enum {enumTarget.Content.QualifiedName}.");

                var fileName = Path.ChangeExtension(enumTarget.Content.TypeName, FileExtension);
                AddOutputFile(Path.Combine(enumTarget.OutputPath, fileName));
            }
            logger.Info($"Added output files for {enumsToGenerate.Count} enums.");

            logger.Info($"Finished initialising {jobName}.");
        }