Skip to content
Permalink
Browse files

[Assets] Reorganized templates

  • Loading branch information
xen2 committed Nov 1, 2018
1 parent ed826ce commit 1f269ac8b8ccdaeca0d94c8ba2555a83df90a1d7
@@ -54,6 +54,18 @@ void RegisterItem(UFile targetFilePath)
generatedItems.Add(generatedItem);
}

void TryCopyDirectory(UDirectory sourceDirectory, UDirectory targetDirectory)
{
var resourceFiles = Directory.EnumerateFiles(sourceDirectory, "*.*", SearchOption.AllDirectories);
foreach (var resourceFile in resourceFiles)
{
var resourceFilePath = (UFile)resourceFile;
var targetFilePath = UPath.Combine(targetDirectory, resourceFilePath.MakeRelative(sourceDirectory));

TryCopyResource(resourceFilePath, targetFilePath);
}
}

void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
{
resourcesSourceToTarget.Add(resourceFilePath, targetFilePath);
@@ -85,14 +97,7 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
if (!Directory.Exists(resourceFolder))
continue;

var resourceFiles = Directory.EnumerateFiles(resourceFolder, "*.*", SearchOption.AllDirectories);
foreach (var resourceFile in resourceFiles)
{
var resourceFilePath = (UFile)resourceFile;
var targetFilePath = UPath.Combine(resourceOutputPath, resourceFilePath.MakeRelative(resourceFolder));

TryCopyResource(resourceFilePath, targetFilePath);
}
TryCopyDirectory(resourceFolder, resourceOutputPath);
}

var assetOutputPath = UPath.Combine(outputPath, (UDirectory)"Assets");
@@ -190,9 +195,34 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
if (package.TemplateFolders.Count > 0)
{
var templateOutputPath = UPath.Combine(outputPath, (UDirectory)"Templates");
result.Error("Packing templates is not implemented yet.");

newPackage.TemplateFolders.Add(new TemplateFolder(templateOutputPath));
var targetFolder = new TemplateFolder(templateOutputPath);

foreach (var templateFolder in package.TemplateFolders)
{
UDirectory target = templateOutputPath;
if (templateFolder.Group != null)
{
target = UPath.Combine(target, templateFolder.Group);
}

TryCopyDirectory(templateFolder.Path, target);

// Add template files
foreach (var templateFile in templateFolder.Files)
{
var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
if (templateFolder.Group != null)
{
newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
}

newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
targetFolder.Files.Add(newTemplateFile);
}
}

newPackage.TemplateFolders.Add(targetFolder);
}

// Save package only if there is any resources and/or assets
@@ -13,6 +13,12 @@ public class TemplateManager
{
private static readonly object ThisLock = new object();
private static readonly List<ITemplateGenerator> Generators = new List<ITemplateGenerator>();
private static readonly PackageCollection ExtraPackages = new PackageCollection();

public static void RegisterPackage(Package package)
{
ExtraPackages.Add(package);
}

/// <summary>
/// Registers the specified factory.
@@ -53,9 +59,9 @@ public static void Unregister(ITemplateGenerator generator)
/// <returns>A sequence containing all registered template descriptions.</returns>
public static IEnumerable<TemplateDescription> FindTemplates(PackageSession session = null)
{
var packages = session?.Packages ?? new PackageCollection();
var packages = session?.Packages.Concat(ExtraPackages) ?? ExtraPackages;
// TODO this will not work if the same package has different versions
return packages.SelectMany(package => package.Templates).OrderBy(tpl => tpl.Order).ThenBy(tpl => tpl.Name);
return packages.SelectMany(package => package.Templates).OrderBy(tpl => tpl.Order).ThenBy(tpl => tpl.Name).ToList();
}

/// <summary>
@@ -51,8 +51,8 @@ public GameTemplateWindow(IEnumerable<SolutionPlatform> availablePlatforms, stri

// Obsolete - this will be replaced by AssetPacks at some point
AssetPackages = new List<AssetPackageViewModel>();
AssetPackages.Add(new AssetPackageViewModel(services, "Animated Models", new UDirectory("mannequinModel/mannequinModel"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Building Blocks", new UDirectory("PrototypingBlocks/PrototypingBlocks"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Animated Models", new UDirectory("mannequinModel"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Building Blocks", new UDirectory("PrototypingBlocks"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Materials Pack", new UDirectory("MaterialPackage"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Particles Pack", new UDirectory("VFXPackage"), false));
AssetPackages.Add(new AssetPackageViewModel(services, "Samples Assets", new UDirectory("SamplesAssetPackage"), false));
@@ -405,10 +405,8 @@ private static void CopyAssetPacks(SessionTemplateGeneratorParameters parameters
{
var logger = parameters.Logger;

var installDir = DirectoryHelper.GetInstallationDirectory("Xenko");
var assetPackagesDir = (DirectoryHelper.IsRootDevDirectory(installDir)) ?
UDirectory.Combine(installDir, @"samples\Templates\Packs") :
UDirectory.Combine(ProjectTemplateGeneratorHelper.GetTemplateDataDirectory(parameters.Description).GetParent(), @"Samples\Templates\Packs");
var presentationPackageFile = PackageStore.Instance.GetPackageFileName("Xenko.Assets.Presentation", new PackageVersionRange(new PackageVersion(XenkoVersion.NuGetVersion)));
var assetPackagesDir = UDirectory.Combine(presentationPackageFile.GetFullDirectory(), @"Templates\Samples\Templates\Packs");
var assetPacks = parameters.TryGetTag(AssetsKey);
if (assetPacks == null)
return;
@@ -1,9 +1,10 @@
<Project>
<Project>
<Import Project="..\..\targets\Xenko.PreSettings.targets" />
<Import Project="Sdk.props" Sdk="MSBuild.Sdk.Extras" Version="1.6.55" />
<PropertyGroup>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<XenkoAssemblyProcessor>true</XenkoAssemblyProcessor>
<XenkoPackAssets>true</XenkoPackAssets>
<TargetFramework>$(TargetFrameworkTool)</TargetFramework>
<XenkoAssemblyProcessorOptions>--auto-module-initializer --serialization --parameter-key</XenkoAssemblyProcessorOptions>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\build\</SolutionDir>
@@ -0,0 +1,102 @@
!Package
SerializedVersion: {Assets: 3.1.0.0}
TemplateFolders:
- Path: !dir Templates/Core
Group: Core
Exclude: "**/*.cs;**/*.xaml"
Files:
- !file Templates/Core/ProjectExecutable.xktpl
- !file Templates/Core/ProjectLibrary.xktpl
- !file Templates/Core/UpdatePlatforms.xktpl
- Path: !dir ../../data/XenkoPackage/Templates/Core
Group: Core
Exclude: "**/*.psd;**/*.md"
- Path: !dir Templates/Assets
Group: Assets
Files:
- !file Templates/Assets/Animations/DefaultAnimation.xktpl
- !file Templates/Assets/Animations/DefaultSkeleton.xktpl
- !file Templates/Assets/Fonts/OfflineRasterizedSpriteFont.xktpl
- !file Templates/Assets/Fonts/RuntimeRasterizedSpriteFont.xktpl
- !file Templates/Assets/Fonts/SignedDistanceFieldSpriteFont.xktpl
- !file Templates/Assets/Materials/DefaultMaterial.xktpl
- !file Templates/Assets/Materials/DiffuseMaterial.xktpl
- !file Templates/Assets/Materials/PBRMetalnessMaterial.xktpl
- !file Templates/Assets/Materials/PBRSpecularMaterial.xktpl
- !file Templates/Assets/Materials/PBRClearCoatMaterial.xktpl
- !file Templates/Assets/Materials/PBRGlassMaterial.xktpl
- !file Templates/Assets/Media/DefaultSound.xktpl
- !file Templates/Assets/Media/DefaultVideo.xktpl
- !file Templates/Assets/Media/SpatializedSound.xktpl
- !file Templates/Assets/Media/MusicSound.xktpl
- !file Templates/Assets/Misc/DefaultGraphicsCompositorLevel10.xktpl
- !file Templates/Assets/Misc/DefaultGraphicsCompositorLevel9.xktpl
- !file Templates/Assets/Misc/DefaultRawAsset.xktpl
- !file Templates/Assets/Misc/DefaultSkybox.xktpl
- !file Templates/Assets/Models/DefaultModel.xktpl
- !file Templates/Assets/Models/PrefabModel.xktpl
- !file Templates/Assets/Models/ProceduralCapsule.xktpl
- !file Templates/Assets/Models/ProceduralCone.xktpl
- !file Templates/Assets/Models/ProceduralCube.xktpl
- !file Templates/Assets/Models/ProceduralCylinder.xktpl
- !file Templates/Assets/Models/ProceduralGeoSphere.xktpl
- !file Templates/Assets/Models/ProceduralPlane.xktpl
- !file Templates/Assets/Models/ProceduralSphere.xktpl
- !file Templates/Assets/Models/ProceduralTeapot.xktpl
- !file Templates/Assets/Models/ProceduralTorus.xktpl
- !file Templates/Assets/Physics/ColliderShapeBox.xktpl
- !file Templates/Assets/Physics/ColliderShapeCapsule.xktpl
- !file Templates/Assets/Physics/ColliderShapeConvexHull.xktpl
- !file Templates/Assets/Physics/ColliderShapeCylinder.xktpl
- !file Templates/Assets/Physics/ColliderShapePlane.xktpl
- !file Templates/Assets/Physics/ColliderShapeSphere.xktpl
- !file Templates/Assets/Physics/ColliderShapeCone.xktpl
- !file Templates/Assets/Scenes/DefaultPrefab.xktpl
- !file Templates/Assets/Scenes/DefaultNavigationMesh.xktpl
- !file Templates/Assets/Scenes/DefaultScene.xktpl
- !file Templates/Assets/Scripts/Animation/AnimationBlend.xktpl
- !file Templates/Assets/Scripts/Animation/AnimationStart.xktpl
- !file Templates/Assets/Scripts/Camera/BasicCameraController.xktpl
- !file Templates/Assets/Scripts/Camera/SideScrollingCamera.xktpl
- !file Templates/Assets/Scripts/Camera/FpsCamera.xktpl
- !file Templates/Assets/Scripts/Physics/PlayerController.xktpl
- !file Templates/Assets/Scripts/DefaultAsyncScript.xktpl
- !file Templates/Assets/Scripts/DefaultSyncScript.xktpl
- !file Templates/Assets/Scripts/DefaultStartupScript.xktpl
- !file Templates/Assets/Scripts/Events/EventBroadcaster.xktpl
- !file Templates/Assets/Scripts/Events/EventListener.xktpl
- !file Templates/Assets/Scripts/Physics/DebugShapesRender.xktpl
- !file Templates/Assets/Scripts/Prefabs/PrefabInstance.xktpl
- !file Templates/Assets/Scripts/Utility/GameProfiler.xktpl
- !file Templates/Assets/Scripts/Utility/SceneStreaming.xktpl
- !file Templates/Assets/Sprites/SpriteSheetSprites.xktpl
- !file Templates/Assets/Sprites/SpriteSheetUI.xktpl
- !file Templates/Assets/Textures/ColorTexture.xktpl
- !file Templates/Assets/Textures/NormalMapTexture.xktpl
- !file Templates/Assets/Textures/GrayscaleTexture.xktpl
- !file Templates/Assets/Textures/DefaultRenderTexture.xktpl
- !file Templates/Assets/UI/Library.xktpl
- !file Templates/Assets/UI/Page.xktpl
- Path: !dir ../../../samples
Group: Samples
Exclude: "**/Testing/**;**/.git/**;**/_ReSharper.*/**;**/Bin/**;**/obj/**;**/*.sln;**/*.suo;**/*.GhostDoc.xml;**/samples2/readme.md;**/samples2/.gitignore;**/*.psess;**/*.vspx;**/*.userprefs"
Files:
- !file ..\..\..\samples\Audio\SimpleAudio\SimpleAudio.xktpl
- !file ..\..\..\samples\Games\JumpyJet\JumpyJet.xktpl
- !file ..\..\..\samples\Games\SpaceEscape\SpaceEscape.xktpl
- !file ..\..\..\samples\Graphics\AnimatedModel\AnimatedModel.xktpl
- !file ..\..\..\samples\Graphics\CustomEffect\CustomEffect.xktpl
- !file ..\..\..\samples\Graphics\MaterialShader\MaterialShader.xktpl
- !file ..\..\..\samples\Graphics\SpriteFonts\SpriteFonts.xktpl
- !file ..\..\..\samples\Graphics\SpriteStudioDemo\SpriteStudioDemo.xktpl
- !file ..\..\..\samples\Input\TouchInputs\TouchInputs.xktpl
- !file ..\..\..\samples\Input\GravitySensor\GravitySensor.xktpl
- !file ..\..\..\samples\Particles\ParticlesSample\ParticlesSample.xktpl
- !file ..\..\..\samples\Physics\PhysicsSample\PhysicsSample.xktpl
- !file ..\..\..\samples\UI\GameMenu\GameMenu.xktpl
- !file ..\..\..\samples\UI\UIParticles\UIParticles.xktpl
- !file ..\..\..\samples\UI\UIElementLink\UIElementLink.xktpl
- !file ..\..\..\samples\Templates\FirstPersonShooter\FirstPersonShooter\FirstPersonShooter.xktpl
- !file ..\..\..\samples\Templates\ThirdPersonPlatformer\ThirdPersonPlatformer\ThirdPersonPlatformer.xktpl
- !file ..\..\..\samples\Templates\TopDownRPG\TopDownRPG\TopDownRPG.xktpl
- !file ..\..\..\samples\Templates\VRSandbox\VRSandbox\VRSandbox.xktpl
@@ -24,6 +24,7 @@
using Xenko.Assets.Presentation.ViewModel.CopyPasteProcessors;
using Xenko.Editor;
using Xenko.Engine;
using Xenko.Core.Assets.Templates;

namespace Xenko.Assets.Presentation
{
@@ -79,6 +80,14 @@ public XenkoDefaultAssetsPlugin()
{
ProfileSettings.Add(new PackageSettingsEntry(GameUserSettings.Effect.EffectCompilation, TargetPackage.Executable));
ProfileSettings.Add(new PackageSettingsEntry(GameUserSettings.Effect.RecordUsedEffects, TargetPackage.Executable));

var logger = new LoggerResult();
var presentationPackageFile = PackageStore.Instance.GetPackageFileName("Xenko.Assets.Presentation", new PackageVersionRange(new PackageVersion(XenkoVersion.NuGetVersion)));
var presentationPackage = Package.Load(logger, presentationPackageFile);
if (logger.HasErrors)
throw new InvalidOperationException($"Could not load package Xenko.Assets.Presentation:{Environment.NewLine}{logger.ToText()}");

TemplateManager.RegisterPackage(presentationPackage);
}

/// <inheritdoc />
@@ -93,6 +93,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="..\..\assets\Xenko.Core.Assets.CompilerApp\NuGetAssemblyResolver.cs" Link="NuGetAssemblyResolver.cs" />
<Compile Include="..\..\core\Xenko.Core.IO\TemporaryFile.cs">
<Link>Debugging\TemporaryFile.cs</Link>
</Compile>
@@ -24,23 +24,6 @@ public static class ProjectTemplateGeneratorHelper

public static UDirectory GetTemplateDataDirectory(TemplateDescription template)
{
var installDir = DirectoryHelper.GetInstallationDirectory("Xenko");
if (DirectoryHelper.IsRootDevDirectory(installDir))
{
var templateRoot = template.TemplateDirectory;
while (templateRoot.GetDirectoryName() != "Templates")
{
templateRoot = templateRoot.GetParent();
// Should not happen, but let's fail gracefully
if (templateRoot == UDirectory.Empty)
return template.TemplateDirectory;
}

var relativePath = template.TemplateDirectory.MakeRelative(templateRoot);
var devDataPath = UPath.Combine(@"sources\data\XenkoPackage\Templates", relativePath);
var fullPath = UPath.Combine(installDir, devDataPath);
return fullPath;
}
return template.TemplateDirectory;
}

@@ -108,6 +108,10 @@
<Output TaskParameter="AssignedFiles" ItemName="_XenkoNativeLibAssigned"/>
</AssignTargetPath>

<PropertyGroup>
<_XenkoAppendRuntimeIdentifier Condition="'$(AppendRuntimeIdentifierToOutputPath)' == 'true' and '$(RuntimeIdentifier)' != '' and '$(_UsingDefaultRuntimeIdentifier)' != 'true'">true</_XenkoAppendRuntimeIdentifier>
</PropertyGroup>

<!-- Combine into _XenkoDependencyToCopy (and add RelativePath and Type) -->
<ItemGroup>
<_XenkoDependencyToCopy Include="@(_XenkoContentAssigned)">
@@ -125,8 +129,8 @@
<_XenkoDependencyToCopy Remove="@(_XenkoNativeLibAssigned)" Condition=" '$(XenkoPackageBuild)' == 'true' And '%(_XenkoNativeLibAssigned.Extension)' == '.pdb' "/>

<_XenkoDependencyToCopy>
<PackagePath Condition="'$(RuntimeIdentifier)' == ''">lib\$(TargetFramework)\$([System.IO.Path]::GetDirectoryName('%(TargetPath)'))</PackagePath>
<PackagePath Condition="'$(RuntimeIdentifier)' != ''">runtimes\$(RuntimeIdentifier)\lib\$(TargetFramework)\$([System.IO.Path]::GetDirectoryName('%(TargetPath)'))</PackagePath>
<PackagePath Condition="'$(_XenkoAppendRuntimeIdentifier)' != 'true'">lib\$(TargetFramework)\$([System.IO.Path]::GetDirectoryName('%(TargetPath)'))</PackagePath>
<PackagePath Condition="'$(_XenkoAppendRuntimeIdentifier)' == 'true'">runtimes\$(RuntimeIdentifier)\lib\$(TargetFramework)\$([System.IO.Path]::GetDirectoryName('%(TargetPath)'))</PackagePath>
</_XenkoDependencyToCopy>
</ItemGroup>

@@ -149,8 +153,8 @@
<!-- C# -->
<Target Name="_XenkoRegisterDependenciesOutputs" Condition="'$(TargetFramework)' != ''" DependsOnTargets="_XenkoGenerateDependencies">
<ItemGroup Condition="'@(_XenkoDependencyToCopy)' != ''">
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ssdeps" Condition="'$(RuntimeIdentifier)' == ''" PackagePath="lib\$(TargetFramework)" />
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ssdeps" Condition="'$(RuntimeIdentifier)' != ''" PackagePath="runtimes\$(RuntimeIdentifier)\lib\$(TargetFramework)" />
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ssdeps" Condition="'$(_XenkoAppendRuntimeIdentifier)' != 'true'" PackagePath="lib\$(TargetFramework)" />
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ssdeps" Condition="'$(_XenkoAppendRuntimeIdentifier)' == 'true'" PackagePath="runtimes\$(RuntimeIdentifier)\lib\$(TargetFramework)" />
<TfmSpecificPackageFile Include="@(_XenkoDependencyToCopy)" />
</ItemGroup>
</Target>

0 comments on commit 1f269ac

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