public sealed override bool Run(PackageTemplateGeneratorParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } var logger = parameters.Logger; var name = parameters.Name; var package = parameters.Package; // Generate executable projects for each platform var sharedProfile = package.Profiles.FindSharedProfile(); // TODO: this is not a safe way to get a game project see PDX-1128 var gameProjectRef = FindSharedGameProject(package, sharedProfile, logger); if (gameProjectRef == null) { return(false); } // We need to patch the previous game project in order to regenerate property groups var templateGameLibrary = PrepareTemplate(parameters, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", PlatformType.Shared, null, null, ProjectType.Library); var options = ProjectTemplateGeneratorHelper.GetOptions(parameters); var newGameTargetFrameworks = templateGameLibrary.GeneratePart(@"..\Common.TargetFrameworks.targets.t4", logger, options); PatchGameProject(newGameTargetFrameworks, gameProjectRef.Location.FullPath); // Generate missing platforms bool forceGenerating = parameters.GetTag(ForcePlatformRegenerationKey); ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), gameProjectRef.Id, name, package, forceGenerating); // Save the session after the update // FIXME: Saving like this is not supported anymore - let's not save for now be we should provide a proper way to save! //var result = package.Session.Save(); //result.CopyTo(logger); // Log done ProjectTemplateGeneratorHelper.Progress(logger, "Done", 1, 1); return(true); }
protected override bool Generate(SessionTemplateGeneratorParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } // Structure of files to generate: // $Name$.xkpkg // $Name$.targets // Assets\ // $Name$.Game\ // $Name$.Windows\ // $Name$.Android\ // $Name$.iOS\ var logger = parameters.Logger; var platforms = parameters.GetTag(PlatformsKey); var name = parameters.Name; var outputDirectory = parameters.OutputDirectory; var orientation = parameters.GetTag(OrientationKey); // Generate the package var package = NewPackageTemplateGenerator.GeneratePackage(parameters); // Generate projects for this package var session = parameters.Session; var sharedProfile = package.Profiles.FindSharedProfile(); // Setup the assets folder Directory.CreateDirectory(UPath.Combine(outputDirectory, (UDirectory)"Assets/Shared")); //write gitignore WriteGitIgnore(parameters); var previousCurrent = session.CurrentPackage; session.CurrentPackage = package; var projectGameName = Utilities.BuildValidNamespaceName(name) + ".Game"; var stepIndex = 0; var stepCount = platforms.Count + 1; // Log progress ProjectTemplateGeneratorHelper.Progress(logger, $"Generating {projectGameName}...", stepIndex++, stepCount); // Generate the Game library var projectGameReference = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, platforms, package, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", projectGameName, PlatformType.Shared, null, null, ProjectType.Library, orientation); projectGameReference.Type = ProjectType.Library; sharedProfile.ProjectReferences.Add(projectGameReference); // Add Effects as an asset folder in order to load xksl sharedProfile.AssetFolders.Add(new AssetFolder(projectGameName + "/Effects")); // Generate executable projects for each platform ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, platforms, orientation, projectGameReference.Id, name, package, false); // Add asset packages CopyAssetPacks(parameters); // Load assets from HDD package.LoadTemporaryAssets(logger); // Validate assets package.ValidateAssets(true, false, logger); // Setup GraphicsCompositor using DefaultGraphicsCompositor var graphicsProfile = parameters.GetTag(GraphicsProfileKey); var defaultCompositorUrl = graphicsProfile >= GraphicsProfile.Level_10_0 ? XenkoPackageUpgrader.DefaultGraphicsCompositorLevel10Url : XenkoPackageUpgrader.DefaultGraphicsCompositorLevel9Url; var defaultCompositor = session.FindAsset(defaultCompositorUrl); var graphicsCompositor = new AssetItem("GraphicsCompositor", defaultCompositor.CreateDerivedAsset()); package.Assets.Add(graphicsCompositor); graphicsCompositor.IsDirty = true; // Setup GameSettingsAsset var gameSettingsAsset = GameSettingsFactory.Create(); gameSettingsAsset.GetOrCreate <EditorSettings>().RenderingMode = parameters.GetTag(IsHDRKey) ? RenderingMode.HDR : RenderingMode.LDR; gameSettingsAsset.GraphicsCompositor = AttachedReferenceManager.CreateProxyObject <GraphicsCompositor>(graphicsCompositor.ToReference()); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(); renderingSettings.DefaultGraphicsProfile = parameters.GetTag(GraphicsProfileKey); renderingSettings.DisplayOrientation = (RequiredDisplayOrientation)orientation; var gameSettingsAssetItem = new AssetItem(GameSettingsAsset.GameSettingsLocation, gameSettingsAsset); package.Assets.Add(gameSettingsAssetItem); gameSettingsAssetItem.IsDirty = true; // Add assets to the package AddAssets(parameters, package, projectGameReference, projectGameName); // Log done ProjectTemplateGeneratorHelper.Progress(logger, "Done", stepCount, stepCount); session.CurrentPackage = previousCurrent; return(true); }
protected override bool Generate(SessionTemplateGeneratorParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } // Structure of files to generate: // $Name$.sdpkg // $Name$.targets // Assets\ // $Name$.Game\ // $Name$.Windows\ // $Name$.Android\ // $Name$.iOS\ var logger = parameters.Logger; var platforms = parameters.GetTag(PlatformsKey); var name = parameters.Name; var outputDirectory = parameters.OutputDirectory; var orientation = parameters.GetTag(OrientationKey); // Generate the package //var package = NewPackageTemplateGenerator.GeneratePackage(parameters); // Generate projects for this package var session = parameters.Session; var projectGameName = Utilities.BuildValidNamespaceName(name); var stepIndex = 0; var stepCount = platforms.Count + 1; // Log progress ProjectTemplateGeneratorHelper.Progress(logger, $"Generating {projectGameName}...", stepIndex++, stepCount); // Generate the Game library var project = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, platforms, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", projectGameName, PlatformType.Shared, null, ProjectType.Library, orientation); var package = project.Package; //write gitignore WriteGitIgnore(parameters); // Setup the assets folder //Directory.CreateDirectory(UPath.Combine(package.RootDirectory, (UDirectory)"Assets/Shared")); session.Projects.Add(project); // Load missing references session.LoadMissingDependencies(parameters.Logger); // Load dependency assets (needed for camera script template) session.LoadMissingAssets(parameters.Logger, project.FlattenedDependencies.Select(x => x.Package).NotNull()); // Add Effects as an asset folder in order to load sdsl package.AssetFolders.Add(new AssetFolder("Effects")); var packageParameters = new PackageTemplateGeneratorParameters { Name = package.Meta.Name, OutputDirectory = package.FullPath.GetFullDirectory(), Description = parameters.Description, Package = package, Logger = parameters.Logger, Namespace = parameters.Namespace }; // Generate executable projects for each platform var platformProjects = ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(packageParameters, platforms, orientation, false).ToList(); // Add asset packages CopyAssetPacks(parameters, package); // Create camera script var cameraScriptTemplate = TemplateManager.FindTemplates(package.Session).OfType <TemplateAssetDescription>().FirstOrDefault(x => x.DefaultOutputName == CameraScriptDefaultOutputName); if (cameraScriptTemplate == null) { throw new InvalidOperationException($"Could not find template for script '{CameraScriptDefaultOutputName}'"); } var cameraScriptParameters = new AssetTemplateGeneratorParameters(string.Empty) { Name = cameraScriptTemplate.DefaultOutputName, Description = cameraScriptTemplate, Namespace = parameters.Namespace, Package = package, Logger = logger, Unattended = true, }; ScriptTemplateGenerator.SetClassName(cameraScriptParameters, cameraScriptTemplate.DefaultOutputName); if (!ScriptTemplateGenerator.Default.PrepareForRun(cameraScriptParameters).Result || !ScriptTemplateGenerator.Default.Run(cameraScriptParameters)) { throw new InvalidOperationException($"Could not create script '{CameraScriptDefaultOutputName}'"); } // Force save after having created the script // Note: We do that AFTER GameSettings is dirty, otherwise it would ask for an assembly reload (game settings saved might mean new graphics API) SaveSession(parameters); // Load missing references session.LoadMissingReferences(parameters.Logger); // Setup GraphicsCompositor using DefaultGraphicsCompositor var graphicsProfile = parameters.GetTag(GraphicsProfileKey); var defaultCompositorUrl = graphicsProfile >= GraphicsProfile.Level_10_0 ? StridePackageUpgrader.DefaultGraphicsCompositorLevel10Url : StridePackageUpgrader.DefaultGraphicsCompositorLevel9Url; var defaultCompositor = session.FindAsset(defaultCompositorUrl); var graphicsCompositor = new AssetItem("GraphicsCompositor", defaultCompositor.CreateDerivedAsset()); package.Assets.Add(graphicsCompositor); graphicsCompositor.IsDirty = true; // Setup GameSettingsAsset var gameSettingsAsset = GameSettingsFactory.Create(); gameSettingsAsset.GetOrCreate <EditorSettings>().RenderingMode = parameters.GetTag(IsHDRKey) ? RenderingMode.HDR : RenderingMode.LDR; gameSettingsAsset.GraphicsCompositor = AttachedReferenceManager.CreateProxyObject <GraphicsCompositor>(graphicsCompositor.ToReference()); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(); renderingSettings.DefaultGraphicsProfile = parameters.GetTag(GraphicsProfileKey); renderingSettings.DisplayOrientation = (RequiredDisplayOrientation)orientation; var gameSettingsAssetItem = new AssetItem(GameSettingsAsset.GameSettingsLocation, gameSettingsAsset); package.Assets.Add(gameSettingsAssetItem); gameSettingsAssetItem.IsDirty = true; // Add assets to the package AddAssets(parameters, package, projectGameName); // Log done ProjectTemplateGeneratorHelper.Progress(logger, "Done", stepCount, stepCount); // Set current project session.CurrentProject = platformProjects.FirstOrDefault(x => x.Platform == PlatformType.Windows) ?? project; return(true); }