Skip to content

Commit cb520de

Browse files
authored
refactor: Nullable and Modernization for Core Assets projects (#2658)
* [Core.BuildEngine.Common] Modernize code * [Core.Packages] Modernize code * [Core.Assets.Yaml] Modernize code * [Build] Remove obsolete Prefer32Bit * [Core.Assets] Modernize code * [Core.Assets.Tests] Modernize code * [Core.Assets.Quantum] Modernize code * [Core.Assets.Quantum.Tests] Modernize code * [xunit.runner.stride] Modernize code * Code review
1 parent b12c52a commit cb520de

File tree

434 files changed

+33462
-34916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

434 files changed

+33462
-34916
lines changed

samples/Tests/SampleTestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static void CompileSample(LoggerResult logger, string sampleName, Packag
3232
{
3333
var project = session.Projects.OfType<SolutionProject>().First(x => x.Platform == Core.PlatformType.Windows);
3434

35-
var buildResult = VSProjectHelper.CompileProjectAssemblyAsync(null, project.FullPath, logger, extraProperties: new Dictionary<string, string> { { "StrideAutoTesting", "true" } }).BuildTask.Result;
35+
var buildResult = VSProjectHelper.CompileProjectAssemblyAsync(project.FullPath, logger, extraProperties: new Dictionary<string, string> { { "StrideAutoTesting", "true" } }).BuildTask.Result;
3636
if (logger.HasErrors)
3737
{
3838
throw new InvalidOperationException($"Error compiling sample {sampleName}:\r\n{logger.ToText()}");

samples/Tests/Stride.Samples.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
66
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
77
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<LangVersion>latest</LangVersion>
810
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
911
<StrideAssemblyProcessorOptions>--auto-module-initializer</StrideAssemblyProcessorOptions>
1012
<StrideSkipAutoPack>false</StrideSkipAutoPack>

sources/assets/Stride.Core.Assets.CompilerApp/Tasks/PackAssets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
9999
}
100100

101101
var assetOutputPath = UPath.Combine(outputPath, (UDirectory)"Assets");
102-
var assets = Package.ListAssetFiles(logger, package, true, true, null);
102+
var assets = Package.ListAssetFiles(package, true, true);
103103
if (assets.Count > 0)
104104
{
105105
newPackage.AssetFolders.Add(new AssetFolder(assetOutputPath));
Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,76 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
3+
64
using System.Text;
75
using Stride.Core.Assets.Tests.Helpers;
86
using Stride.Core.Extensions;
97

10-
namespace Stride.Core.Assets.Quantum.Tests.Helpers
8+
namespace Stride.Core.Assets.Quantum.Tests.Helpers;
9+
10+
public static class AssetHierarchyHelper
1111
{
12-
public static class AssetHierarchyHelper
12+
public static string PrintHierarchy(AssetCompositeHierarchy<Types.MyPartDesign, Types.MyPart> asset)
1313
{
14-
public static string PrintHierarchy(AssetCompositeHierarchy<Types.MyPartDesign, Types.MyPart> asset)
14+
var stack = new Stack<Tuple<Types.MyPartDesign, int>>();
15+
asset.Hierarchy.RootParts.Select(x => asset.Hierarchy.Parts[x.Id]).Reverse().ForEach(x => stack.Push(Tuple.Create(x, 0)));
16+
var sb = new StringBuilder();
17+
while (stack.Count > 0)
1518
{
16-
var stack = new Stack<Tuple<Types.MyPartDesign, int>>();
17-
asset.Hierarchy.RootParts.Select(x => asset.Hierarchy.Parts[x.Id]).Reverse().ForEach(x => stack.Push(Tuple.Create(x, 0)));
18-
var sb = new StringBuilder();
19-
while (stack.Count > 0)
19+
var current = stack.Pop();
20+
sb.Append("".PadLeft(current.Item2 * 2));
21+
sb.AppendLine($"- {current.Item1.Part.Name} [{current.Item1.Part.Id}]");
22+
foreach (var child in asset.EnumerateChildPartDesigns(current.Item1, asset.Hierarchy, false).Reverse())
2023
{
21-
var current = stack.Pop();
22-
sb.Append("".PadLeft(current.Item2 * 2));
23-
sb.AppendLine($"- {current.Item1.Part.Name} [{current.Item1.Part.Id}]");
24-
foreach (var child in asset.EnumerateChildPartDesigns(current.Item1, asset.Hierarchy, false).Reverse())
25-
{
26-
stack.Push(Tuple.Create(child, current.Item2 + 1));
27-
}
24+
stack.Push(Tuple.Create(child, current.Item2 + 1));
2825
}
29-
var str = sb.ToString();
30-
return str;
3126
}
27+
var str = sb.ToString();
28+
return str;
29+
}
3230

33-
public static Types.MyAssetHierarchyPropertyGraph BuildAssetAndGraph(int rootCount, int depth, int childPerPart, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
34-
{
35-
var container = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
36-
var asset = BuildHierarchy(rootCount, depth, childPerPart);
37-
var assetItem = new AssetItem("MyAsset", asset);
38-
initializeProperties?.Invoke(asset.Hierarchy);
39-
var graph = (Types.MyAssetHierarchyPropertyGraph)AssetQuantumRegistry.ConstructPropertyGraph(container, assetItem, null);
40-
return graph;
41-
}
31+
public static Types.MyAssetHierarchyPropertyGraph BuildAssetAndGraph(int rootCount, int depth, int childPerPart, Action<AssetCompositeHierarchyData<Types.MyPartDesign, Types.MyPart>> initializeProperties = null)
32+
{
33+
var container = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
34+
var asset = BuildHierarchy(rootCount, depth, childPerPart);
35+
var assetItem = new AssetItem("MyAsset", asset);
36+
initializeProperties?.Invoke(asset.Hierarchy);
37+
return (Types.MyAssetHierarchyPropertyGraph)AssetQuantumRegistry.ConstructPropertyGraph(container, assetItem, null);
38+
}
4239

43-
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)
44-
{
45-
graphContainer = graphContainer ?? new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
46-
var asset = BuildHierarchy(rootCount, depth, childPerPart);
47-
initializeProperties?.Invoke(asset.Hierarchy);
48-
var container = new AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph>(graphContainer, asset);
49-
container.BuildGraph();
50-
return container;
51-
}
40+
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)
41+
{
42+
graphContainer ??= new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
43+
var asset = BuildHierarchy(rootCount, depth, childPerPart);
44+
initializeProperties?.Invoke(asset.Hierarchy);
45+
var container = new AssetTestContainer<Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph>(graphContainer, asset);
46+
container.BuildGraph();
47+
return container;
48+
}
5249

53-
private static Types.MyAssetHierarchy BuildHierarchy(int rootCount, int depth, int childPerPart)
50+
private static Types.MyAssetHierarchy BuildHierarchy(int rootCount, int depth, int childPerPart)
51+
{
52+
var asset = new Types.MyAssetHierarchy();
53+
var guid = 0;
54+
for (var i = 0; i < rootCount; ++i)
5455
{
55-
var asset = new Types.MyAssetHierarchy();
56-
var guid = 0;
57-
for (var i = 0; i < rootCount; ++i)
58-
{
59-
var rootPart = BuildPart(asset, $"Part{i + 1}", depth - 1, childPerPart, ref guid);
60-
asset.Hierarchy.RootParts.Add(rootPart.Part);
61-
}
62-
return asset;
56+
var rootPart = BuildPart(asset, $"Part{i + 1}", depth - 1, childPerPart, ref guid);
57+
asset.Hierarchy.RootParts.Add(rootPart.Part);
6358
}
59+
return asset;
60+
}
6461

65-
private static Types.MyPartDesign BuildPart(Types.MyAssetHierarchy asset, string name, int depth, int childPerPart, ref int guidCount)
66-
{
67-
var part = new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(++guidCount), Name = name } };
68-
asset.Hierarchy.Parts.Add(part);
69-
if (depth <= 0)
70-
return part;
71-
72-
for (var i = 0; i < childPerPart; ++i)
73-
{
74-
var child = BuildPart(asset, name + $"-{i + 1}", depth - 1, childPerPart, ref guidCount);
75-
part.Part.AddChild(child.Part);
76-
}
62+
private static Types.MyPartDesign BuildPart(Types.MyAssetHierarchy asset, string name, int depth, int childPerPart, ref int guidCount)
63+
{
64+
var part = new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(++guidCount), Name = name } };
65+
asset.Hierarchy.Parts.Add(part);
66+
if (depth <= 0)
7767
return part;
68+
69+
for (var i = 0; i < childPerPart; ++i)
70+
{
71+
var child = BuildPart(asset, name + $"-{i + 1}", depth - 1, childPerPart, ref guidCount);
72+
part.Part.AddChild(child.Part);
7873
}
74+
return part;
7975
}
8076
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
34
using Stride.Core.Assets.Quantum.Internal;
45
using Stride.Core.Reflection;
56
using Stride.Core.Quantum;
67

7-
namespace Stride.Core.Assets.Quantum.Tests.Helpers
8+
namespace Stride.Core.Assets.Quantum.Tests.Helpers;
9+
10+
public static class AssetNodeInternalExtensions
811
{
9-
public static class AssetNodeInternalExtensions
12+
public static OverrideType GetItemOverride(this IAssetNode node, NodeIndex index)
1013
{
11-
public static OverrideType GetItemOverride(this IAssetNode node, NodeIndex index)
12-
{
13-
return ((IAssetObjectNodeInternal)node).GetItemOverride(index);
14-
}
14+
return ((IAssetObjectNodeInternal)node).GetItemOverride(index);
15+
}
1516

16-
public static OverrideType GetKeyOverride(this IAssetNode node, NodeIndex index)
17-
{
18-
return ((IAssetObjectNodeInternal)node).GetKeyOverride(index);
19-
}
17+
public static OverrideType GetKeyOverride(this IAssetNode node, NodeIndex index)
18+
{
19+
return ((IAssetObjectNodeInternal)node).GetKeyOverride(index);
2020
}
2121
}
Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,77 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3-
using System.IO;
3+
44
using Xunit;
5-
using Stride.Core.Annotations;
65
using Stride.Core.Diagnostics;
76

8-
namespace Stride.Core.Assets.Quantum.Tests.Helpers
7+
namespace Stride.Core.Assets.Quantum.Tests.Helpers;
8+
9+
public class AssetTestContainer
910
{
10-
public class AssetTestContainer
11+
public AssetTestContainer(AssetPropertyGraphContainer container, Asset asset)
1112
{
12-
public AssetTestContainer(AssetPropertyGraphContainer container, Asset asset)
13-
{
14-
Container = container;
15-
AssetItem = new AssetItem("MyAsset", asset);
16-
}
17-
18-
public AssetPropertyGraphContainer Container { get; }
13+
Container = container;
14+
AssetItem = new AssetItem("MyAsset", asset);
15+
}
1916

20-
public AssetItem AssetItem { get; }
17+
public AssetPropertyGraphContainer Container { get; }
2118

19+
public AssetItem AssetItem { get; }
2220

23-
[NotNull]
24-
public static Stream ToStream(string str)
25-
{
26-
var stream = new MemoryStream();
27-
var writer = new StreamWriter(stream);
28-
writer.Write(str);
29-
writer.Flush();
30-
stream.Position = 0;
31-
return stream;
32-
}
21+
public static Stream ToStream(string str)
22+
{
23+
var stream = new MemoryStream();
24+
var writer = new StreamWriter(stream);
25+
writer.Write(str);
26+
writer.Flush();
27+
stream.Position = 0;
28+
return stream;
3329
}
30+
}
3431

35-
public class AssetTestContainer<TAsset, TAssetPropertyGraph> : AssetTestContainer where TAsset : Asset where TAssetPropertyGraph : AssetPropertyGraph
36-
{
37-
private readonly LoggerResult logger = new LoggerResult();
32+
public class AssetTestContainer<TAsset, TAssetPropertyGraph> : AssetTestContainer
33+
where TAsset : Asset
34+
where TAssetPropertyGraph : AssetPropertyGraph
35+
{
36+
private readonly LoggerResult logger = new();
3837

39-
public AssetTestContainer(AssetPropertyGraphContainer container, TAsset asset)
40-
: base(container, asset)
41-
{
42-
}
38+
public AssetTestContainer(AssetPropertyGraphContainer container, TAsset asset)
39+
: base(container, asset)
40+
{
41+
}
4342

44-
public AssetTestContainer(TAsset asset)
45-
: base(new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } }), asset)
46-
{
47-
}
43+
public AssetTestContainer(TAsset asset)
44+
: base(new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } }), asset)
45+
{
46+
}
4847

49-
public TAsset Asset => (TAsset)AssetItem.Asset;
48+
public TAsset Asset => (TAsset)AssetItem.Asset;
5049

51-
public TAssetPropertyGraph Graph { get; private set; }
50+
public TAssetPropertyGraph Graph { get; private set; }
5251

53-
public void BuildGraph()
54-
{
55-
var baseGraph = AssetQuantumRegistry.ConstructPropertyGraph(Container, AssetItem, logger);
56-
Container.RegisterGraph(baseGraph);
57-
Assert.True(baseGraph is TAssetPropertyGraph);
58-
Graph = (TAssetPropertyGraph)baseGraph;
59-
}
52+
public void BuildGraph()
53+
{
54+
var baseGraph = AssetQuantumRegistry.ConstructPropertyGraph(Container, AssetItem, logger);
55+
Container.RegisterGraph(baseGraph);
56+
Assert.True(baseGraph is TAssetPropertyGraph);
57+
Graph = (TAssetPropertyGraph)baseGraph;
58+
}
6059

61-
public AssetTestContainer<TAsset, TAssetPropertyGraph> DeriveAsset()
62-
{
63-
var derivedAsset = (TAsset)Asset.CreateDerivedAsset("MyAsset");
64-
var result = new AssetTestContainer<TAsset, TAssetPropertyGraph>(Container, derivedAsset);
65-
result.BuildGraph();
66-
return result;
67-
}
60+
public AssetTestContainer<TAsset, TAssetPropertyGraph> DeriveAsset()
61+
{
62+
var derivedAsset = (TAsset)Asset.CreateDerivedAsset("MyAsset");
63+
var result = new AssetTestContainer<TAsset, TAssetPropertyGraph>(Container, derivedAsset);
64+
result.BuildGraph();
65+
return result;
66+
}
6867

69-
public static AssetTestContainer<TAsset, TAssetPropertyGraph> LoadFromYaml(string yaml)
70-
{
71-
var asset = AssetFileSerializer.Load<TAsset>(ToStream(yaml), $"MyAsset{Types.FileExtension}");
72-
var graphContainer = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
73-
var assetContainer = new AssetTestContainer<TAsset, TAssetPropertyGraph>(graphContainer, asset.Asset);
74-
asset.YamlMetadata.CopyInto(assetContainer.AssetItem.YamlMetadata);
75-
assetContainer.BuildGraph();
76-
return assetContainer;
77-
}
68+
public static AssetTestContainer<TAsset, TAssetPropertyGraph> LoadFromYaml(string yaml)
69+
{
70+
var asset = AssetFileSerializer.Load<TAsset>(ToStream(yaml), $"MyAsset{Types.FileExtension}");
71+
var graphContainer = new AssetPropertyGraphContainer(new AssetNodeContainer { NodeBuilder = { NodeFactory = new AssetNodeFactory() } });
72+
var assetContainer = new AssetTestContainer<TAsset, TAssetPropertyGraph>(graphContainer, asset.Asset);
73+
asset.YamlMetadata.CopyInto(assetContainer.AssetItem.YamlMetadata);
74+
assetContainer.BuildGraph();
75+
return assetContainer;
7876
}
7977
}

0 commit comments

Comments
 (0)