Skip to content
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion samples/Tests/SampleTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static void CompileSample(LoggerResult logger, string sampleName, Packag
{
var project = session.Projects.OfType<SolutionProject>().First(x => x.Platform == Core.PlatformType.Windows);

var buildResult = VSProjectHelper.CompileProjectAssemblyAsync(null, project.FullPath, logger, extraProperties: new Dictionary<string, string> { { "StrideAutoTesting", "true" } }).BuildTask.Result;
var buildResult = VSProjectHelper.CompileProjectAssemblyAsync(project.FullPath, logger, extraProperties: new Dictionary<string, string> { { "StrideAutoTesting", "true" } }).BuildTask.Result;
if (logger.HasErrors)
{
throw new InvalidOperationException($"Error compiling sample {sampleName}:\r\n{logger.ToText()}");
Expand Down
2 changes: 2 additions & 0 deletions samples/Tests/Stride.Samples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
<StrideAssemblyProcessorOptions>--auto-module-initializer</StrideAssemblyProcessorOptions>
<StrideSkipAutoPack>false</StrideSkipAutoPack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
}

var assetOutputPath = UPath.Combine(outputPath, (UDirectory)"Assets");
var assets = Package.ListAssetFiles(logger, package, true, true, null);
var assets = Package.ListAssetFiles(package, true, true);
if (assets.Count > 0)
{
newPackage.AssetFolders.Add(new AssetFolder(assetOutputPath));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,76 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
using Stride.Core.Assets.Tests.Helpers;
using Stride.Core.Extensions;

namespace Stride.Core.Assets.Quantum.Tests.Helpers
namespace Stride.Core.Assets.Quantum.Tests.Helpers;

public static class AssetHierarchyHelper
{
public static class AssetHierarchyHelper
public static string PrintHierarchy(AssetCompositeHierarchy<Types.MyPartDesign, Types.MyPart> asset)
{
public static string PrintHierarchy(AssetCompositeHierarchy<Types.MyPartDesign, Types.MyPart> asset)
var stack = new Stack<Tuple<Types.MyPartDesign, int>>();
asset.Hierarchy.RootParts.Select(x => asset.Hierarchy.Parts[x.Id]).Reverse().ForEach(x => stack.Push(Tuple.Create(x, 0)));
var sb = new StringBuilder();
while (stack.Count > 0)
{
var stack = new Stack<Tuple<Types.MyPartDesign, int>>();
asset.Hierarchy.RootParts.Select(x => asset.Hierarchy.Parts[x.Id]).Reverse().ForEach(x => stack.Push(Tuple.Create(x, 0)));
var sb = new StringBuilder();
while (stack.Count > 0)
var current = stack.Pop();
sb.Append("".PadLeft(current.Item2 * 2));
sb.AppendLine($"- {current.Item1.Part.Name} [{current.Item1.Part.Id}]");
foreach (var child in asset.EnumerateChildPartDesigns(current.Item1, asset.Hierarchy, false).Reverse())
{
var current = stack.Pop();
sb.Append("".PadLeft(current.Item2 * 2));
sb.AppendLine($"- {current.Item1.Part.Name} [{current.Item1.Part.Id}]");
foreach (var child in asset.EnumerateChildPartDesigns(current.Item1, asset.Hierarchy, false).Reverse())
{
stack.Push(Tuple.Create(child, current.Item2 + 1));
}
stack.Push(Tuple.Create(child, current.Item2 + 1));
}
var str = sb.ToString();
return str;
}
var str = sb.ToString();
return str;
}

public static Types.MyAssetHierarchyPropertyGraph BuildAssetAndGraph(int rootCount, int depth, int childPerPart, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
{
var container = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var asset = BuildHierarchy(rootCount, depth, childPerPart);
var assetItem = new AssetItem("MyAsset", asset);
initializeProperties?.Invoke(asset.Hierarchy);
var graph = (Types.MyAssetHierarchyPropertyGraph)AssetQuantumRegistry.ConstructPropertyGraph(container, assetItem, null);
return graph;
}
public static Types.MyAssetHierarchyPropertyGraph BuildAssetAndGraph(int rootCount, int depth, int childPerPart, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
{
var container = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var asset = BuildHierarchy(rootCount, depth, childPerPart);
var assetItem = new AssetItem("MyAsset", asset);
initializeProperties?.Invoke(asset.Hierarchy);
return (Types.MyAssetHierarchyPropertyGraph)AssetQuantumRegistry.ConstructPropertyGraph(container, assetItem, null);
}

public static AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph> BuildAssetContainer(int rootCount, int depth, int childPerPart, AssetPropertyGraphContainer graphContainer = null, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
{
graphContainer = graphContainer ?? new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var asset = BuildHierarchy(rootCount, depth, childPerPart);
initializeProperties?.Invoke(asset.Hierarchy);
var container = new AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph>(graphContainer, asset);
container.BuildGraph();
return container;
}
public static AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph> BuildAssetContainer(int rootCount, int depth, int childPerPart, AssetPropertyGraphContainer graphContainer = null, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
{
graphContainer ??= new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var asset = BuildHierarchy(rootCount, depth, childPerPart);
initializeProperties?.Invoke(asset.Hierarchy);
var container = new AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph>(graphContainer, asset);
container.BuildGraph();
return container;
}

private static Types.MyAssetHierarchy BuildHierarchy(int rootCount, int depth, int childPerPart)
private static Types.MyAssetHierarchy BuildHierarchy(int rootCount, int depth, int childPerPart)
{
var asset = new Types.MyAssetHierarchy();
var guid = 0;
for (var i = 0; i < rootCount; ++i)
{
var asset = new Types.MyAssetHierarchy();
var guid = 0;
for (var i = 0; i < rootCount; ++i)
{
var rootPart = BuildPart(asset, $"Part{i + 1}", depth - 1, childPerPart, ref guid);
asset.Hierarchy.RootParts.Add(rootPart.Part);
}
return asset;
var rootPart = BuildPart(asset, $"Part{i + 1}", depth - 1, childPerPart, ref guid);
asset.Hierarchy.RootParts.Add(rootPart.Part);
}
return asset;
}

private static Types.MyPartDesign BuildPart(Types.MyAssetHierarchy asset, string name, int depth, int childPerPart, ref int guidCount)
{
var part = new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(++guidCount), Name = name } };
asset.Hierarchy.Parts.Add(part);
if (depth <= 0)
return part;

for (var i = 0; i < childPerPart; ++i)
{
var child = BuildPart(asset, name + $"-{i + 1}", depth - 1, childPerPart, ref guidCount);
part.Part.AddChild(child.Part);
}
private static Types.MyPartDesign BuildPart(Types.MyAssetHierarchy asset, string name, int depth, int childPerPart, ref int guidCount)
{
var part = new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(++guidCount), Name = name } };
asset.Hierarchy.Parts.Add(part);
if (depth <= 0)
return part;

for (var i = 0; i < childPerPart; ++i)
{
var child = BuildPart(asset, name + $"-{i + 1}", depth - 1, childPerPart, ref guidCount);
part.Part.AddChild(child.Part);
}
return part;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Stride.Core.Assets.Quantum.Internal;
using Stride.Core.Reflection;
using Stride.Core.Quantum;

namespace Stride.Core.Assets.Quantum.Tests.Helpers
namespace Stride.Core.Assets.Quantum.Tests.Helpers;

public static class AssetNodeInternalExtensions
{
public static class AssetNodeInternalExtensions
public static OverrideType GetItemOverride(this IAssetNode node, NodeIndex index)
{
public static OverrideType GetItemOverride(this IAssetNode node, NodeIndex index)
{
return ((IAssetObjectNodeInternal)node).GetItemOverride(index);
}
return ((IAssetObjectNodeInternal)node).GetItemOverride(index);
}

public static OverrideType GetKeyOverride(this IAssetNode node, NodeIndex index)
{
return ((IAssetObjectNodeInternal)node).GetKeyOverride(index);
}
public static OverrideType GetKeyOverride(this IAssetNode node, NodeIndex index)
{
return ((IAssetObjectNodeInternal)node).GetKeyOverride(index);
}
}
Original file line number Diff line number Diff line change
@@ -1,79 +1,77 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.IO;

using Xunit;
using Stride.Core.Annotations;
using Stride.Core.Diagnostics;

namespace Stride.Core.Assets.Quantum.Tests.Helpers
namespace Stride.Core.Assets.Quantum.Tests.Helpers;

public class AssetTestContainer
{
public class AssetTestContainer
public AssetTestContainer(AssetPropertyGraphContainer container, Asset asset)
{
public AssetTestContainer(AssetPropertyGraphContainer container, Asset asset)
{
Container = container;
AssetItem = new AssetItem("MyAsset", asset);
}

public AssetPropertyGraphContainer Container { get; }
Container = container;
AssetItem = new AssetItem("MyAsset", asset);
}

public AssetItem AssetItem { get; }
public AssetPropertyGraphContainer Container { get; }

public AssetItem AssetItem { get; }

[NotNull]
public static Stream ToStream(string str)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(str);
writer.Flush();
stream.Position = 0;
return stream;
}
public static Stream ToStream(string str)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(str);
writer.Flush();
stream.Position = 0;
return stream;
}
}

public class AssetTestContainer<TAsset, TAssetPropertyGraph> : AssetTestContainer where TAsset : Asset where TAssetPropertyGraph : AssetPropertyGraph
{
private readonly LoggerResult logger = new LoggerResult();
public class AssetTestContainer<TAsset, TAssetPropertyGraph> : AssetTestContainer
where TAsset : Asset
where TAssetPropertyGraph : AssetPropertyGraph
{
private readonly LoggerResult logger = new();

public AssetTestContainer(AssetPropertyGraphContainer container, TAsset asset)
: base(container, asset)
{
}
public AssetTestContainer(AssetPropertyGraphContainer container, TAsset asset)
: base(container, asset)
{
}

public AssetTestContainer(TAsset asset)
: base(new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } }), asset)
{
}
public AssetTestContainer(TAsset asset)
: base(new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } }), asset)
{
}

public TAsset Asset => (TAsset)AssetItem.Asset;
public TAsset Asset => (TAsset)AssetItem.Asset;

public TAssetPropertyGraph Graph { get; private set; }
public TAssetPropertyGraph Graph { get; private set; }

public void BuildGraph()
{
var baseGraph = AssetQuantumRegistry.ConstructPropertyGraph(Container, AssetItem, logger);
Container.RegisterGraph(baseGraph);
Assert.True(baseGraph is TAssetPropertyGraph);
Graph = (TAssetPropertyGraph)baseGraph;
}
public void BuildGraph()
{
var baseGraph = AssetQuantumRegistry.ConstructPropertyGraph(Container, AssetItem, logger);
Container.RegisterGraph(baseGraph);
Assert.True(baseGraph is TAssetPropertyGraph);
Graph = (TAssetPropertyGraph)baseGraph;
}

public AssetTestContainer<TAsset, TAssetPropertyGraph> DeriveAsset()
{
var derivedAsset = (TAsset)Asset.CreateDerivedAsset("MyAsset");
var result = new AssetTestContainer<TAsset, TAssetPropertyGraph>(Container, derivedAsset);
result.BuildGraph();
return result;
}
public AssetTestContainer<TAsset, TAssetPropertyGraph> DeriveAsset()
{
var derivedAsset = (TAsset)Asset.CreateDerivedAsset("MyAsset");
var result = new AssetTestContainer<TAsset, TAssetPropertyGraph>(Container, derivedAsset);
result.BuildGraph();
return result;
}

public static AssetTestContainer<TAsset, TAssetPropertyGraph> LoadFromYaml(string yaml)
{
var asset = AssetFileSerializer.Load<TAsset>(ToStream(yaml), $"MyAsset{Types.FileExtension}");
var graphContainer = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var assetContainer = new AssetTestContainer<TAsset, TAssetPropertyGraph>(graphContainer, asset.Asset);
asset.YamlMetadata.CopyInto(assetContainer.AssetItem.YamlMetadata);
assetContainer.BuildGraph();
return assetContainer;
}
public static AssetTestContainer<TAsset, TAssetPropertyGraph> LoadFromYaml(string yaml)
{
var asset = AssetFileSerializer.Load<TAsset>(ToStream(yaml), $"MyAsset{Types.FileExtension}");
var graphContainer = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
var assetContainer = new AssetTestContainer<TAsset, TAssetPropertyGraph>(graphContainer, asset.Asset);
asset.YamlMetadata.CopyInto(assetContainer.AssetItem.YamlMetadata);
assetContainer.BuildGraph();
return assetContainer;
}
}
Loading