Ejemplo n.º 1
0
 private static string GetTypeFromTypeReference(TypeReferenceRaw typeReference, string packagePrefix)
 {
     return(typeReference.IsBuiltInType
         ? UnityTypeMappings.BuiltInSchemaTypeToUnityNativeType[typeReference.TypeName]
         : string.Format("global::{0}{1}", packagePrefix,
                         Formatting.CapitaliseQualifiedNameParts(typeReference.TypeName)));
 }
Ejemplo n.º 2
0
 public UnityTypeDetails(UnityTypeDefinition typeDefinition)
 {
     CapitalisedName = Formatting.SnakeCaseToCapitalisedCamelCase(typeDefinition.Name);
     CamelCaseName   = Formatting.SnakeCaseToCamelCase(typeDefinition.Name);
     FullyQualifiedSpatialTypeName =
         "global::" + Formatting.CapitaliseQualifiedNameParts(typeDefinition.QualifiedName);
     FullyQualifiedTypeName = "global::" + Formatting.CapitaliseQualifiedNameParts(typeDefinition.QualifiedName);
 }
Ejemplo n.º 3
0
        protected GeneratorInputDetails(string package, QualifiedDefinition qualifiedDefinition) : base(qualifiedDefinition)
        {
            Namespace     = Formatting.CapitaliseQualifiedNameParts(package);
            NamespacePath = Formatting.GetNamespacePath(package);

            QualifiedName      = qualifiedDefinition.QualifiedName;
            FullyQualifiedName = DetailsUtils.GetCapitalisedFqnTypename(qualifiedDefinition.QualifiedName);
        }
Ejemplo n.º 4
0
 public UnityCommandDetails(UnityComponentDefinition.UnityCommandDefinition commandDefinition)
 {
     CommandName       = Formatting.SnakeCaseToCapitalisedCamelCase(commandDefinition.Name);
     CamelCaseTypeName = "spatialOS" + Formatting.QualifiedNameToCapitalisedCamelCase(commandDefinition.Name);
     RequestType       = "global::" + UnityTypeMappings.PackagePrefix +
                         Formatting.CapitaliseQualifiedNameParts(commandDefinition.RequestType.typeDefinition.QualifiedName);
     ResponseType = "global::" + UnityTypeMappings.PackagePrefix +
                    Formatting.CapitaliseQualifiedNameParts(commandDefinition.ResponseType.typeDefinition.QualifiedName);
 }
Ejemplo n.º 5
0
        public UnityEventDetails(UnityComponentDefinition.UnityEventDefinition eventDefinition)
        {
            EventName         = Formatting.SnakeCaseToCapitalisedCamelCase(eventDefinition.Name);
            CamelCaseTypeName = Formatting.SnakeCaseToCamelCase(eventDefinition.Name);
            var payloadTypeName = eventDefinition.RawType.TypeName;

            FullyQualifiedPayloadTypeName = "global::" + UnityTypeMappings.PackagePrefix +
                                            Formatting.CapitaliseQualifiedNameParts(payloadTypeName);
        }
Ejemplo n.º 6
0
 public UnityComponentDetails(UnityComponentDefinition componentDefinition)
 {
     ComponentName                 = Formatting.QualifiedNameToCapitalisedCamelCase(componentDefinition.Name);
     TypeName                      = "SpatialOS" + ComponentName;
     CamelCaseTypeName             = "spatialOS" + ComponentName;
     FullyQualifiedSpatialTypeName =
         "global::" + Formatting.CapitaliseQualifiedNameParts(componentDefinition.QualifiedName);
     IsBlittable = componentDefinition.IsBlittable;
 }
Ejemplo n.º 7
0
        public UnityTypeDetails(string package, TypeDefinition typeDefinitionRaw)
        {
            Package                = package;
            CapitalisedName        = typeDefinitionRaw.Name;
            CamelCaseName          = Formatting.PascalCaseToCamelCase(CapitalisedName);
            FullyQualifiedTypeName = $"global::{Formatting.CapitaliseQualifiedNameParts(typeDefinitionRaw.QualifiedName)}";

            raw = typeDefinitionRaw;
        }
Ejemplo n.º 8
0
 public UnityEnumDetails(EnumDefinitionRaw enumDefinition)
 {
     PascalCaseName = Formatting.SnakeCaseToCapitalisedCamelCase(enumDefinition.name);
     CamelCaseName  = Formatting.SnakeCaseToCamelCase(enumDefinition.name);
     FullyQualifiedSpatialTypeName =
         "global::" + Formatting.CapitaliseQualifiedNameParts(enumDefinition.qualifiedName);
     FullyQualifiedTypeName = "global::" + UnityTypeMappings.PackagePrefix +
                              Formatting.CapitaliseQualifiedNameParts(enumDefinition.qualifiedName);
 }
Ejemplo n.º 9
0
        public UnityTypeDetails(TypeDefinitionRaw typeDefinitionRaw)
        {
            CapitalisedName        = typeDefinitionRaw.Identifier.Name;
            CamelCaseName          = Formatting.PascalCaseToCamelCase(CapitalisedName);
            FullyQualifiedTypeName =
                $"global::{Formatting.CapitaliseQualifiedNameParts(typeDefinitionRaw.Identifier.QualifiedName)}";

            Identifier = typeDefinitionRaw.Identifier;
            raw        = typeDefinitionRaw;
        }
Ejemplo n.º 10
0
        public static string GetCapitalisedFqnTypename(string qualifiedTypeName)
        {
            if (UnityTypeMappings.BuiltInSchemaTypeToUnityNativeType.TryGetValue(qualifiedTypeName, out var fqn))
            {
                return(fqn);
            }

            return
                ($"global::{Formatting.CapitaliseQualifiedNameParts(qualifiedTypeName)}");
        }
Ejemplo n.º 11
0
        public SingleGenerationJob(string outputDir, UnitySchemaFile schemaFile, IFileSystem fileSystem,
                                   HashSet <string> enumSet) : base(
                outputDir, fileSystem)
        {
            InputFiles = new List <string> {
                schemaFile.CompletePath
            };
            OutputFiles = new List <string>();

            relativeOutputPath = Formatting.GetNamespacePath(schemaFile.Package);
            package            = Formatting.CapitaliseQualifiedNameParts(schemaFile.Package);

            // Filter out the data types like PositionData or TransformData. We don't want to generate these.
            typesToGenerate = schemaFile.TypeDefinitions.Where(type =>
                                                               schemaFile.ComponentDefinitions.Select(component => component.DataDefinition.typeDefinition.Name)
                                                               .All(componentDataName => componentDataName != type.Name)).ToList();

            foreach (var unityTypeDefinition in typesToGenerate)
            {
                var fileName = Path.ChangeExtension(unityTypeDefinition.Name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            componentsToGenerate = schemaFile.ComponentDefinitions;
            foreach (var unityComponentDefinition in componentsToGenerate)
            {
                var fileName = Path.ChangeExtension(unityComponentDefinition.Name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));

                fileName = Path.ChangeExtension(unityComponentDefinition.Name + "Translation", fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            enumsToGenerate = new List <EnumDefinitionRaw>();
            enumsToGenerate.AddRange(schemaFile.EnumDefinitions);
            foreach (var unityEnum in enumsToGenerate)
            {
                var fileName = Path.ChangeExtension(unityEnum.name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            this.enumSet = enumSet;
        }
Ejemplo n.º 12
0
        public SingleGenerationJob(string outputDir, UnitySchemaFile schemaFile, IFileSystem fileSystem,
                                   HashSet <string> enumSet) : base(
                outputDir, fileSystem)
        {
            InputFiles = new List <string> {
                schemaFile.CompletePath
            };
            OutputFiles = new List <string>();

            relativeOutputPath = Formatting.GetNamespacePath(schemaFile.Package);
            package            = Formatting.CapitaliseQualifiedNameParts(schemaFile.Package);

            typesToGenerate = SelectTypesToGenerate(schemaFile);

            foreach (var unityTypeDefinition in typesToGenerate)
            {
                var fileName = Path.ChangeExtension(unityTypeDefinition.Name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            componentsToGenerate = schemaFile.ComponentDefinitions;
            foreach (var unityComponentDefinition in componentsToGenerate)
            {
                var fileName = Path.ChangeExtension(unityComponentDefinition.Name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));

                fileName = Path.ChangeExtension(unityComponentDefinition.Name + "Translation", fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));

                fileName = Path.ChangeExtension($"{unityComponentDefinition.Name}Providers", fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            enumsToGenerate = new List <EnumDefinitionRaw>();
            enumsToGenerate.AddRange(schemaFile.EnumDefinitions);
            foreach (var unityEnum in enumsToGenerate)
            {
                var fileName = Path.ChangeExtension(unityEnum.name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            this.enumSet = enumSet;
        }
Ejemplo n.º 13
0
        public SingleGenerationJob(string outputDir, UnitySchemaFile schemaFile, IFileSystem fileSystem,
                                   HashSet <string> enumSet) : base(
                outputDir, fileSystem)
        {
            InputFiles = new List <string> {
                schemaFile.CompletePath
            };
            OutputFiles = new List <string>();

            relativeOutputPath = Formatting.GetNamespacePath(schemaFile.Package);
            package            = Formatting.CapitaliseQualifiedNameParts(schemaFile.Package);

            typesToGenerate = SelectTypesToGenerate(schemaFile);

            foreach (var unityTypeDefinition in typesToGenerate)
            {
                var fileName = Path.ChangeExtension(unityTypeDefinition.Name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            componentsToGenerate = schemaFile.ComponentDefinitions;
            foreach (var component in componentsToGenerate)
            {
                OutputFiles.Add(Path.Combine(relativeOutputPath, Path.ChangeExtension(component.Name, fileExtension)));

                if (component.CommandDefinitions.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{component.Name}CommandPayloads", fileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{component.Name}CommandComponents", fileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{component.Name}CommandStorage", fileExtension)));
                }

                if (component.EventDefinitions.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{component.Name}Events", fileExtension)));
                }

                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{component.Name}Translation", fileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{component.Name}Providers", fileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{component.Name}GameObjectComponentDispatcher", fileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{component.Name}ReaderWriter", fileExtension)));

                if (component.CommandDefinitions.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{component.Name}MonoBehaviourCommandHandlers", fileExtension)));
                }
            }

            enumsToGenerate = new List <EnumDefinitionRaw>();
            enumsToGenerate.AddRange(schemaFile.EnumDefinitions);
            foreach (var unityEnum in enumsToGenerate)
            {
                var fileName = Path.ChangeExtension(unityEnum.name, fileExtension);
                OutputFiles.Add(Path.Combine(relativeOutputPath, fileName));
            }

            this.enumSet = enumSet;
        }
Ejemplo n.º 14
0
 private static string GetFullyQualifiedSpatialTypeName(string typeName)
 {
     return("global::" + Formatting.CapitaliseQualifiedNameParts(typeName));
 }
Ejemplo n.º 15
0
 private static string GetFullyQualifiedGeneratedTypeName(string typeName)
 {
     return("global::Generated." + Formatting.CapitaliseQualifiedNameParts(typeName));
 }
Ejemplo n.º 16
0
        public void CapitaliseQualifiedNameParts_has_correct_behaviour(string input, string expectedOutput)
        {
            var output = Formatting.CapitaliseQualifiedNameParts(input);

            Assert.AreEqual(expectedOutput, output);
        }
Ejemplo n.º 17
0
 public static string GetCapitalisedFqnTypename(string qualifiedTypeName)
 {
     return($"global::{Formatting.CapitaliseQualifiedNameParts(qualifiedTypeName)}");
 }
Ejemplo n.º 18
0
 public GenerationTarget(T content, string package)
 {
     Content    = content;
     Package    = Formatting.CapitaliseQualifiedNameParts(package);
     OutputPath = Formatting.GetNamespacePath(package);
 }