Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PackageUnitTestGenerator.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Assets;
5 using SiliconStudio.Assets.Templates;
6 using SiliconStudio.Core.IO;
7 using SiliconStudio.Paradox.Assets;
8 
9 namespace SiliconStudio.Paradox.ProjectGenerator
10 {
11  /// <summary>
12  /// Create a package.
13  /// </summary>
15  {
16  public static readonly PackageUnitTestGenerator Default = new PackageUnitTestGenerator();
17 
18  public static readonly Guid TemplateId = new Guid("3c4ac35f-4d63-462e-9696-974ebaa9a862");
19 
20  public override bool IsSupportingTemplate(TemplateDescription templateDescription)
21  {
22  if (templateDescription == null) throw new ArgumentNullException("templateDescription");
23  return templateDescription.Id == TemplateId;
24  }
25 
26  public override Action PrepareForRun(TemplateGeneratorParameters parameters)
27  {
28  if (parameters == null) throw new ArgumentNullException("parameters");
29  parameters.Validate();
30 
31  return () => Generate(parameters);
32  }
33 
34  public void Generate(TemplateGeneratorParameters parameters)
35  {
36  if (parameters == null) throw new ArgumentNullException("parameters");
37  parameters.Validate();
38 
39  var name = parameters.Name;
40  var outputDirectory = parameters.OutputDirectory;
41 
42  // Creates the package
43  var package = NewPackage(name);
44 
45  // Setup the default namespace
46  package.Meta.RootNamespace = parameters.Namespace;
47 
48  // Setup the path to save it
49  package.FullPath = UPath.Combine(outputDirectory, new UFile(name + Package.PackageFileExtension));
50 
51  // Set the package
52  parameters.Package = package;
53 
54  // Add it to the current session
55  var session = parameters.Session;
56  session.Packages.Add(package);
57 
58  // Load missing references
59  session.LoadMissingReferences(parameters.Logger);
60  }
61 
62  /// <summary>
63  /// Creates a new Paradox package with the specified name
64  /// </summary>
65  /// <param name="name">Name of the package</param>
66  /// <returns>A new package instance</returns>
67  public static Package NewPackage(string name)
68  {
69  var package = new Package
70  {
71  Meta =
72  {
73  Name = name,
74  Version = new PackageVersion("1.0.0.0")
75  },
76  };
77 
78  // Add dependency to latest Paradox package
79  package.Meta.Dependencies.Add(ParadoxConfig.GetLatestPackageDependency());
80 
81  // Setup the assets folder by default
82  package.Profiles.Add(PackageProfile.NewShared());
83 
84  return package;
85  }
86  }
87 }
Base implementation for ITemplateGenerator.
Parameters used by ITemplateGenerator.PrepareForRun
Description of a template generator that can be displayed in the GameStudio.
const string PackageFileExtension
The file extension used for Package.
Definition: Package.cs:46
override Action PrepareForRun(TemplateGeneratorParameters parameters)
Prepares this generator with the specified parameters and return a runnable action that must be run j...
override bool IsSupportingTemplate(TemplateDescription templateDescription)
Determines whether this generator is supporting the specified template
static Package NewPackage(string name)
Creates a new Paradox package with the specified name
A package managing assets.
Definition: Package.cs:28
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13