/// <summary> /// Filters out auto-generated types like PositionData from the JSON AST. /// However, we want to keep types that are used as a "data" field in a component. /// </summary> private List <UnityTypeDefinition> SelectTypesToGenerate(UnitySchemaFile schemaFile) { var componentDataTypes = schemaFile.ComponentDefinitions.Select(component => component.RawDataDefinition); // From inspection of the JSON AST you can observe that a type definition is auto-generated if the following // conditions are true: // 1. The FQN type names are the same . // 2. The source references are the same. // Using this information, we can effectively filter out auto-generated types. var filteredTypes = schemaFile.TypeDefinitions.Where(type => componentDataTypes.All(componentData => type.QualifiedName != componentData.TypeName || !SourceReferenceEquals(type.SourceReference, componentData.sourceReference))); return(filteredTypes.ToList()); }
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; }
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; }
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; }