Beispiel #1
0
    public static GraphicsBackend DefaultBackend(GraphicsPlatform?platform = null)
    {
        var platform1 = platform ?? Platform;

        return(platform1 switch
        {
            GraphicsPlatform.Windows => GraphicsBackend.Direct3D11,
            GraphicsPlatform.macOS => GraphicsBackend.Metal,
            GraphicsPlatform.Linux => GraphicsBackend.OpenGL,
            GraphicsPlatform.Unknown => throw new NotImplementedException(),
            _ => throw new ArgumentOutOfRangeException(nameof(platform), platform, null)
        });
        private static ProjectTemplate PrepareTemplate(PackageTemplateGeneratorParameters parameters, UFile templateRelativePath, PlatformType platformType, string currentProfile, GraphicsPlatform?graphicsPlatform, ProjectType projectType)
        {
            ProjectTemplateGeneratorHelper.AddOption(parameters, "Platforms", parameters.GetTag(PlatformsKey).Select(x => x.Platform).ToList());
            ProjectTemplateGeneratorHelper.AddOption(parameters, "CurrentPlatform", platformType);
            ProjectTemplateGeneratorHelper.AddOption(parameters, "CurrentProfile", currentProfile);
            ProjectTemplateGeneratorHelper.AddOption(parameters, "Orientation", parameters.GetTag(OrientationKey));
            var package = parameters.Package;

            return(ProjectTemplateGeneratorHelper.PrepareTemplate(parameters, package, templateRelativePath, platformType, graphicsPlatform, projectType));
        }
Beispiel #3
0
        public static ProjectTemplate PrepareTemplate(TemplateGeneratorParameters parameters, Package package, UFile templateRelativePath, PlatformType platformType, GraphicsPlatform?graphicsPlatform, ProjectType projectType)
        {
            if (platformType != PlatformType.Shared && !graphicsPlatform.HasValue)
            {
                throw new ArgumentException(@"Expecting a value for GraphicsPlatform when platformType is specified", nameof(graphicsPlatform));
            }

            var rootTemplateDir = parameters.Description.TemplateDirectory;

            var templateFilePath = UPath.Combine(rootTemplateDir, templateRelativePath);
            var projectTemplate  = ProjectTemplate.Load(templateFilePath);

            // TODO assemblies are not configurable from the outside
            projectTemplate.Assemblies.Add(typeof(ProjectType).Assembly.FullName);
            projectTemplate.Assemblies.Add(typeof(StrideConfig).Assembly.FullName);
            projectTemplate.Assemblies.Add(typeof(GraphicsPlatform).Assembly.FullName);
            projectTemplate.Assemblies.Add(typeof(DisplayOrientation).Assembly.FullName);

            AddOption(parameters, "Package", package);
            AddOption(parameters, "PackageName", package.Meta.Name);

            // PackageNameCode, same as PackageName without '.' and ' '.
            AddOption(parameters, "PackageNameCode", package.Meta.Name.Replace(" ", string.Empty).Replace(".", string.Empty));

            AddOption(parameters, "PackageDisplayName", package.Meta.Title ?? package.Meta.Name);
            // Escape illegal characters for the short name
            AddOption(parameters, "PackageNameShort", Utilities.BuildValidClassName(package.Meta.Name.Replace(" ", string.Empty)));

            AddOption(parameters, "CurrentPlatform", platformType);
            if (platformType != PlatformType.Shared)
            {
                AddOption(parameters, "CurrentGraphicsPlatform", graphicsPlatform);
            }

            AddOption(parameters, "ProjectType", projectType);
            AddOption(parameters, "Namespace", parameters.Namespace ?? Utilities.BuildValidNamespaceName(package.Meta.Name));

            return(projectTemplate);
        }
Beispiel #4
0
        public static SolutionProject GenerateTemplate(TemplateGeneratorParameters parameters, UFile templateRelativePath, string projectName, PlatformType platformType, GraphicsPlatform?graphicsPlatform, ProjectType projectType, out List <string> generatedFiles, Guid?projectGuidArg = null)
        {
            var options             = GetOptions(parameters);
            var outputDirectoryPath = UPath.Combine(parameters.OutputDirectory, (UDirectory)projectName);

            Directory.CreateDirectory(outputDirectoryPath);

            generatedFiles = new List <string>();
            parameters.Logger.Verbose($"Generating {projectName}...");

            var projectGuid     = projectGuidArg ?? Guid.NewGuid();
            var packagePath     = UPath.Combine(outputDirectoryPath, (UFile)(projectName + Package.PackageFileExtension));
            var projectFullPath = UPath.Combine(outputDirectoryPath, (UFile)(projectName + ".csproj"));

            var package = new Package
            {
                Meta =
                {
                    Name    = projectName,
                    Version = new PackageVersion("1.0.0.0")
                },
                FullPath = packagePath,
                IsDirty  = true,
            };

            package.AssetFolders.Add(new AssetFolder("Assets"));
            package.ResourceFolders.Add("Resources");

            var projectTemplate = PrepareTemplate(parameters, package, templateRelativePath, platformType, graphicsPlatform, projectType);

            projectTemplate.Generate(outputDirectoryPath, projectName, projectGuid, parameters.Logger, options, generatedFiles);

            var project = new SolutionProject(package, projectGuid, projectFullPath);

            project.Type     = projectType;
            project.Platform = platformType;

            return(project);
        }
Beispiel #5
0
        public static SolutionProject GenerateTemplate(TemplateGeneratorParameters parameters, ICollection <SelectedSolutionPlatform> platforms, UFile templateRelativePath, string projectName, PlatformType platformType, GraphicsPlatform?graphicsPlatform, ProjectType projectType, DisplayOrientation orientation, Guid?projectGuid = null)
        {
            AddOption(parameters, "Platforms", platforms.Select(x => x.Platform).ToList());
            AddOption(parameters, "CurrentPlatform", platformType);
            AddOption(parameters, "Orientation", orientation);

            List <string> generatedFiles;
            var           project = GenerateTemplate(parameters, templateRelativePath, projectName, platformType, graphicsPlatform, projectType, out generatedFiles, projectGuid);

            // Special case for sdfx files
            foreach (var file in generatedFiles)
            {
                if (file.EndsWith(".sdfx"))
                {
                    ConvertXkfxToCSharp(file);
                }
            }

            return(project);
        }
Beispiel #6
0
        public static ProjectReference GenerateTemplate(TemplateGeneratorParameters parameters, Package package, UFile templateRelativePath, string projectName, PlatformType platformType, GraphicsPlatform?graphicsPlatform, ProjectType projectType, out List <string> generatedFiles, Guid?projectGuidArg = null)
        {
            var options             = GetOptions(parameters);
            var projectTemplate     = PrepareTemplate(parameters, package, templateRelativePath, platformType, graphicsPlatform, projectType);
            var outputDirectoryPath = UPath.Combine(parameters.OutputDirectory, (UDirectory)projectName);

            Directory.CreateDirectory(outputDirectoryPath);

            generatedFiles = new List <string>();
            parameters.Logger.Verbose($"Generating {projectName}...");

            var projectGuid = projectGuidArg ?? Guid.NewGuid();

            projectTemplate.Generate(outputDirectoryPath, projectName, projectGuid, parameters.Logger, options, generatedFiles);

            // Mark the package as dirty
            package.IsDirty = true;

            return(new ProjectReference(projectGuid, UPath.Combine(outputDirectoryPath, (UFile)(projectName + ".csproj")), ProjectType.Library));
        }