Skip to content
Permalink
Browse files

[Assets] Rearranged templates for the new xkpkg = csproj change (note…

…: project delete is broken)
  • Loading branch information
xen2 committed Sep 14, 2018
1 parent 598f465 commit bf975595c09efc63fc0d9514c502cc510a7811ef
Showing with 121 additions and 234 deletions.
  1. +0 −1 Xenko.xkpkg
  2. +3 −3 sources/assets/Xenko.Core.Assets/Package.cs
  3. +1 −1 sources/assets/Xenko.Core.Assets/PackageLoadParameters.cs
  4. +1 −1 sources/assets/Xenko.Core.Assets/PackageSession.cs
  5. +2 −2 sources/assets/Xenko.Core.Assets/SourceCodeAsset.cs
  6. +5 −0 sources/core/Xenko.Core/Storage/ObjectId.cs
  7. +0 −10 sources/editor/Xenko.Assets.Presentation/Templates/Core/NewPackage.xktpl
  8. +3 −3 sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectLibrary.xktpl
  9. +0 −1 sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectLibrary/ProjectLibrary.ttproj
  10. +0 −29 sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectLibrary/Properties/AssemblyInfo.cs.t4
  11. +0 −86 sources/editor/Xenko.Assets.Presentation/Templates/NewPackageTemplateGenerator.cs
  12. +15 −12 sources/editor/Xenko.Assets.Presentation/Templates/ProjectLibraryTemplateGenerator.cs
  13. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/ScriptTemplateGenerator.cs
  14. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/TemplateSampleGenerator.cs
  15. +0 −1 sources/editor/Xenko.Assets.Presentation/Templates/XenkoTemplates.cs
  16. +23 −0 sources/editor/Xenko.Assets.Presentation/ViewModel/CodeViewModel.cs
  17. +20 −13 sources/editor/Xenko.Assets.Presentation/ViewModel/ScriptSourceFileAssetViewModel.cs
  18. +5 −4 .../ViewModels/{NewPackageTemplateCollectionViewModel.cs → NewProjectTemplateCollectionViewModel.cs}
  19. +2 −2 ...sets.Editor/Components/TemplateDescriptions/Views/{NewPackageWindow.xaml → NewProjectWindow.xaml}
  20. +3 −3 ...ditor/Components/TemplateDescriptions/Views/{NewPackageWindow.xaml.cs → NewProjectWindow.xaml.cs}
  21. +2 −2 sources/editor/Xenko.Core.Assets.Editor/Services/IEditorDialogService.cs
  22. +1 −1 sources/editor/Xenko.Core.Assets.Editor/Services/{INewPackageDialog.cs → INewProjectDialog.cs}
  23. +3 −3 sources/editor/Xenko.Core.Assets.Editor/View/EditorDialogService.cs
  24. +2 −2 sources/editor/Xenko.Core.Assets.Editor/ViewModel/PackageViewModel.cs
  25. +18 −34 sources/editor/Xenko.Core.Assets.Editor/ViewModel/SessionViewModel.cs
  26. +3 −3 sources/editor/Xenko.Core.Assets.Editor/Xenko.Core.Assets.Editor.csproj
  27. +6 −8 sources/editor/Xenko.GameStudio/GameStudioWindow.xaml
  28. +1 −7 sources/localization/ja/Xenko.GameStudio.ja.po
@@ -28,7 +28,6 @@ TemplateFolders:
Group: Core
Exclude: "**/*.cs;**/*.xaml"
Files:
- sources/editor/Xenko.Assets.Presentation/Templates/Core/NewPackage.xktpl
- sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.xktpl
- sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectLibrary.xktpl
- sources/editor/Xenko.Assets.Presentation/Templates/Core/UpdatePlatforms.xktpl
@@ -1051,7 +1051,7 @@ private void LoadAsset(AssetMigrationContext context, PackageLoadingAssetFile as

bool aliasOccurred;
AttachedYamlAssetMetadata yamlMetadata;
var asset = LoadAsset(context.Log, assetFullPath, assetPath.ToWindowsPath(), assetContent, out aliasOccurred, out yamlMetadata);
var asset = LoadAsset(context.Log, ref id, assetFullPath, assetPath.ToWindowsPath(), assetContent, out aliasOccurred, out yamlMetadata);

// Create asset item
var assetItem = new AssetItem(assetPath, asset, this)
@@ -1117,7 +1117,7 @@ public void RestoreNugetPackages(ILogger log)
}
}

private static Asset LoadAsset(ILogger log, string assetFullPath, string assetPath, byte[] assetContent, out bool assetDirty, out AttachedYamlAssetMetadata yamlMetadata)
private static Asset LoadAsset(ILogger log, ref Guid packageId, string assetFullPath, string assetPath, byte[] assetContent, out bool assetDirty, out AttachedYamlAssetMetadata yamlMetadata)
{
var loadResult = assetContent != null
? AssetFileSerializer.Load<Asset>(new MemoryStream(assetContent), assetFullPath, log)
@@ -1131,7 +1131,7 @@ private static Asset LoadAsset(ILogger log, string assetFullPath, string assetPa
if (sourceCodeAsset != null)
{
// Use an id generated from the location instead of the default id
sourceCodeAsset.Id = SourceCodeAsset.GenerateIdFromLocation(assetPath);
sourceCodeAsset.Id = SourceCodeAsset.GenerateIdFromLocation(packageId, assetPath);
}

return loadResult.Asset;
@@ -128,7 +128,7 @@ public PackageLoadParameters()
/// Gets or sets the generate new asset ids.
/// </summary>
/// <value>The generate new asset ids.</value>
/// <remarks>Only makes sense for <see cref="PackageSession.AddExistingPackage(UFile, ILogger, PackageLoadParameters)"/>.</remarks>
/// <remarks>Only makes sense for <see cref="PackageSession.AddExistingProject(UFile, ILogger, PackageLoadParameters)"/>.</remarks>
public bool GenerateNewAssetIds { get; set; }

/// <summary>
@@ -376,7 +376,7 @@ public AssetSourceTracker SourceTracker
/// <exception cref="System.ArgumentNullException">packagePath</exception>
/// <exception cref="System.ArgumentException">Invalid relative path. Expecting an absolute package path;packagePath</exception>
/// <exception cref="System.IO.FileNotFoundException">Unable to find package</exception>
public PackageContainer AddExistingPackage(UFile projectPath, ILogger logger, PackageLoadParameters loadParametersArg = null)
public PackageContainer AddExistingProject(UFile projectPath, ILogger logger, PackageLoadParameters loadParametersArg = null)
{
if (projectPath == null) throw new ArgumentNullException(nameof(projectPath));
if (logger == null) throw new ArgumentNullException(nameof(logger));
@@ -66,10 +66,10 @@ public virtual void Save(Stream stream)
/// </summary>
/// <param name="location">The location.</param>
/// <returns>Guid.</returns>
public static AssetId GenerateIdFromLocation(string location)
public static AssetId GenerateIdFromLocation(Guid packageId, string location)
{
if (location == null) throw new ArgumentNullException(nameof(location));
return (AssetId)ObjectId.FromBytes(Encoding.UTF8.GetBytes(location)).ToGuid();
return (AssetId)ObjectId.Combine((ObjectId)packageId, ObjectId.FromBytes(Encoding.UTF8.GetBytes(location))).ToGuid();
}
}
}
@@ -65,6 +65,11 @@ public ObjectId(uint hash1, uint hash2, uint hash3, uint hash4)
this.hash4 = hash4;
}

public static unsafe explicit operator ObjectId(Guid guid)
{
return *(ObjectId*)&guid;
}

public static ObjectId Combine(ObjectId left, ObjectId right)
{
// Note: we don't carry (probably not worth the performance hit)

This file was deleted.

@@ -1,8 +1,8 @@
!Template
Id: e12246ff-41a1-49d4-90e4-e72a4eb4a3e9
Name: Add code library
Scope: Package
Description: Create a new library that can target multiple platforms and add it to the package
Scope: Session
Description: Create a new library that can target multiple platforms and add it to the solution
Group: General
Icon: .xktpl\NewCode.png
DefaultOutputName: MyLibrary
DefaultOutputName: MyLibrary
@@ -2,4 +2,3 @@
Files:
- {Source: $ProjectName$.csproj.t4, Target: $ProjectName$.csproj, IsTemplate: true}
- {Source: Class1.cs.t4, Target: Class1.cs, IsTemplate: true}
- {Source: Properties\AssemblyInfo.cs.t4, Target: Properties\AssemblyInfo.cs, IsTemplate: true}

This file was deleted.

This file was deleted.

@@ -14,23 +14,24 @@
using Xenko.Core.Presentation.Services;
using Xenko.Core.Presentation.Windows;
using Xenko.Assets.Templates;
using Xenko.Core.Assets.Editor.Components.TemplateDescriptions;

namespace Xenko.Assets.Presentation.Templates
{
/// <summary>
/// Generator to create a library and add it to the selected package.
/// </summary>
public class ProjectLibraryTemplateGenerator : TemplateGeneratorBase<PackageTemplateGeneratorParameters>
public class ProjectLibraryTemplateGenerator : SessionTemplateGenerator
{
public static readonly ProjectLibraryTemplateGenerator Default = new ProjectLibraryTemplateGenerator();

public static readonly Guid TemplateId = new Guid("e12246ff-41a1-49d4-90e4-e72a4eb4a3e9");

private static List<string> ExtractReferencesList(PackageTemplateGeneratorParameters parameters)
private static List<string> ExtractReferencesList(SessionTemplateGeneratorParameters parameters)
{
// libraries and executables
var referencedBinaryNames = new List<string>();
referencedBinaryNames.AddRange(parameters.Package.Session.Projects.OfType<SolutionProject>().Where(x => x.FullPath != null).Select(x => x.FullPath.GetFileNameWithoutExtension()));
referencedBinaryNames.AddRange(parameters.Session.Projects.OfType<SolutionProject>().Where(x => x.FullPath != null).Select(x => x.FullPath.GetFileNameWithoutExtension()));
return referencedBinaryNames;
}

@@ -45,12 +46,12 @@ public override bool IsSupportingTemplate(TemplateDescription templateDescriptio
return templateDescription.Id == TemplateId;
}

public override async Task<bool> PrepareForRun(PackageTemplateGeneratorParameters parameters)
public override async Task<bool> PrepareForRun(SessionTemplateGeneratorParameters parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
parameters.Validate();

var initialName = parameters.Name + ".MyLibrary";
var initialName = parameters.Name;
var existingNames = ExtractReferencesList(parameters);

initialName = NamingHelper.ComputeNewName(initialName, (Core.IO.UFile uf) => IsNameColliding(existingNames, uf), "{0}{1}");
@@ -69,17 +70,14 @@ public override async Task<bool> PrepareForRun(PackageTemplateGeneratorParameter
return !collision; // we cannot allow to flow the creation request in case of name collision, because the underlying viewmodel system does not have protection against it.
}

public sealed override bool Run(PackageTemplateGeneratorParameters parameters)
protected sealed override bool Generate(SessionTemplateGeneratorParameters parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
parameters.Validate();

var logger = parameters.Logger;
var name = parameters.Name;
var package = parameters.Package;

// Make sure we have a shared profile
var sharedProfile = package.Profile;
var session = parameters.Session;

// Log progress
var projectName = name;
@@ -88,9 +86,14 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)
// Generate the library
List<string> generatedFiles;
ProjectTemplateGeneratorHelper.AddOption(parameters, "Platforms", AssetRegistry.SupportedPlatforms);
var projectGameRef = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, "ProjectLibrary/ProjectLibrary.ttproj", projectName, PlatformType.Shared, null, ProjectType.Library, out generatedFiles);
var project = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, "ProjectLibrary/ProjectLibrary.ttproj", projectName, PlatformType.Shared, null, ProjectType.Library, out generatedFiles);

session.Projects.Add(project);

package.Session.Projects.Add(projectGameRef);
// Load missing references
session.LoadMissingDependencies(parameters.Logger);
// Load dependency assets (needed for camera script template)
session.LoadMissingAssets(parameters.Logger, project.LoadedDependencies);

// Log done
ProjectTemplateGeneratorHelper.Progress(logger, "Done", 1, 1);
@@ -97,7 +97,7 @@ protected override IEnumerable<AssetItem> CreateAssets(AssetTemplateGeneratorPar
scriptContent = scriptContent.Replace("##Scriptname##", location.GetFileNameWithoutExtension());

var asset = (ScriptSourceFileAsset)ObjectFactoryRegistry.NewInstance(typeof(ScriptSourceFileAsset));
asset.Id = SourceCodeAsset.GenerateIdFromLocation(location);
asset.Id = SourceCodeAsset.GenerateIdFromLocation(parameters.Package.Id, location);
asset.Text = scriptContent;
yield return new AssetItem(location, asset);
}
@@ -263,7 +263,7 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
loadParams.LoadMissingDependencies = false;
var session = parameters.Session;
// We should switch to loading .csproj once all samples are upgraded
var loadedProject = session.AddExistingPackage(packageOutputFile, log, loadParams);
var loadedProject = session.AddExistingProject(packageOutputFile, log, loadParams);

RemoveUnusedAssets(loadedProject.Package, session);

@@ -10,7 +10,6 @@ public static void Register()
{
// TODO: Attribute-based auto registration would be better I guess
TemplateManager.Register(TemplateSampleGenerator.Default);
TemplateManager.Register(NewPackageTemplateGenerator.Default);
TemplateManager.Register(NewGameTemplateGenerator.Default);
TemplateManager.Register(ProjectLibraryTemplateGenerator.Default);
TemplateManager.Register(UpdatePlatformsTemplateGenerator.Default);
@@ -24,6 +24,7 @@
using Xenko.Core.Presentation.Dirtiables;
using Xenko.Core.Translation;
using Xenko.Assets.Scripts;
using System.Collections.Specialized;

namespace Xenko.Assets.Presentation.ViewModel
{
@@ -73,6 +74,28 @@ public CodeViewModel(XenkoAssetsViewModel xenkoAssetsViewModel) : base(xenkoAsse
workspace.AddOrUpdateProject(project);
}

void TrackedAssemblies_CollectionChanged(object sender, Core.Collections.TrackingCollectionChangedEventArgs e)
{
var project = ((ProjectWatcher.TrackedAssembly)e.Item).Project;
if (project != null)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
{
workspace.AddOrUpdateProject(project);
break;
}
case NotifyCollectionChangedAction.Remove:
{
workspace.RemoveProject(project.Id);
break;
}
}
}
}
projectWatcher.TrackedAssemblies.CollectionChanged += TrackedAssemblies_CollectionChanged;

// TODO: Right now, we simply replace the solution with newly loaded one
// Ideally, we should keep our existing solution and update it to follow external changes after initial loading (similar to VisualStudioWorkspace)
// This should provide better integration with background changes and local changes

0 comments on commit bf97559

Please sign in to comment.
You can’t perform that action at this time.