mirror of
https://github.com/AssetRipper/AssetRipper.Mining.git
synced 2026-11-14 06:18:09 -10:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcd32bbdba | ||
|
|
98cf7b1eed | ||
|
|
58d5eaf0aa | ||
|
|
888b673dce | ||
|
|
9627dc2d8d | ||
|
|
54f41eda93 | ||
|
|
8df013ebed | ||
|
|
9047c383bb | ||
|
|
bd12d9eae3 | ||
|
|
87328aaac2 |
No files matched your search
+5
-5
@@ -1,18 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetsTools.NET" Version="3.0.0-preview3" />
|
||||
<PackageReference Include="AssetsTools.NET" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.Mining.PredefinedAssets\AssetRipper.Mining.PredefinedAssets.csproj" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.Mining.PredefinedAssets\AssetRipper.Mining.PredefinedAssets.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,6 @@
|
||||
using AssetsTools.NET;
|
||||
using AssetRipper.Mining.PredefinedAssets;
|
||||
using AssetsTools.NET;
|
||||
using System.Numerics;
|
||||
|
||||
namespace AssetRipper.Mining.EngineFileExtractor;
|
||||
|
||||
@@ -9,4 +11,14 @@ internal static class AssetTypeValueFieldExtensions
|
||||
AssetTypeValueField result = @this.Get(name);
|
||||
return result.IsDummy ? null : result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 AsVector3(this AssetTypeValueField @this)
|
||||
{
|
||||
return new Vector3(@this["x"].AsFloat, @this["y"].AsFloat, @this["z"].AsFloat);
|
||||
}
|
||||
|
||||
public static AxisAlignedBoundingBox AsAxisAlignedBoundingBox(this AssetTypeValueField @this)
|
||||
{
|
||||
return new AxisAlignedBoundingBox(@this["m_Center"].AsVector3(), @this["m_Extent"].AsVector3());
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,8 @@ internal static class Program
|
||||
{
|
||||
Name = asset.Name,
|
||||
VertexCount = asset.BaseField.Get("m_VertexData").Get("m_VertexCount").AsInt,
|
||||
SubMeshCount = asset.BaseField.Get("m_SubMeshes").Get("Array").Children.Count
|
||||
SubMeshCount = asset.BaseField.Get("m_SubMeshes").Get("Array").Children.Count,
|
||||
LocalAABB = asset.BaseField.Get("m_LocalAABB").AsAxisAlignedBoundingBox(),
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
+9
-6
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net5.0;net7.0;net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>net4.8;net9.0</TargetFrameworks>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -11,14 +11,17 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="NUnit" Version="4.3.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.7.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Numerics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets.Tests;
|
||||
|
||||
public class Tests
|
||||
@@ -40,4 +43,43 @@ public class Tests
|
||||
return package.ToJson();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Vector3Serialization()
|
||||
{
|
||||
string result = """
|
||||
{
|
||||
"X": 1,
|
||||
"Y": 2,
|
||||
"Z": 3
|
||||
}
|
||||
""".Replace("\r", null);
|
||||
Vector3 vector = new Vector3(1.0f, 2.0f, 3.0f);
|
||||
Assert.That(JsonSerializer.Serialize(vector, MiningSerializerContext.Default.Vector3).Replace("\r", null), Is.EqualTo(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Vector3Deserialization()
|
||||
{
|
||||
string json = """{ "X": 1.0, "Y": 2.0, "Z": 3.0 }""";
|
||||
Vector3 result = new Vector3(1.0f, 2.0f, 3.0f);
|
||||
Assert.That(JsonSerializer.Deserialize(json, MiningSerializerContext.Default.Vector3), Is.EqualTo(result));
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
[TestCase("{}")]
|
||||
public void EmptyEngineResourceDataDeserialization(string json)
|
||||
{
|
||||
EngineResourceData result = EngineResourceData.FromJson(json);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.DefaultResources, Is.Not.Null);
|
||||
Assert.That(result.ExtraResources, Is.Not.Null);
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.DefaultResources, Is.Empty);
|
||||
Assert.That(result.ExtraResources, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using AssetRipper.Primitives;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
|
||||
@@ -1,41 +1,47 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net7.0;net8.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>1.2.1</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Mining.PredefinedAssets</PackageId>
|
||||
<PackageTags>C# Unity</PackageTags>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/AssetRipper.Mining</RepositoryUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
|
||||
<Copyright>Copyright (c) 2023 - 2024 ds5678</Copyright>
|
||||
<Description>Library for storing datamined asset information.</Description>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Primitives" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PolySharp" Version="1.14.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>1.5.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Mining.PredefinedAssets</PackageId>
|
||||
<PackageTags>C# Unity</PackageTags>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/AssetRipper.Mining</RepositoryUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
|
||||
<Copyright>Copyright (c) 2023 - 2025 ds5678</Copyright>
|
||||
<Description>Library for storing datamined asset information.</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Primitives" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PolySharp" Version="1.15.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public record struct AxisAlignedBoundingBox(Vector3 Center, Vector3 Extent);
|
||||
@@ -1,20 +1,35 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public readonly record struct EngineResourceData(Dictionary<long, Object> DefaultResources, Dictionary<long, Object> ExtraResources)
|
||||
public readonly record struct EngineResourceData
|
||||
{
|
||||
public EngineResourceData() : this(new(), new())
|
||||
{
|
||||
public Dictionary<long, Object> DefaultResources { get; }
|
||||
public Dictionary<long, Object> ExtraResources { get; }
|
||||
|
||||
public EngineResourceData()
|
||||
{
|
||||
DefaultResources = new();
|
||||
ExtraResources = new();
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public EngineResourceData(Dictionary<long, Object>? defaultResources, Dictionary<long, Object>? extraResources)
|
||||
{
|
||||
DefaultResources = defaultResources ?? new();
|
||||
ExtraResources = extraResources ?? new();
|
||||
}
|
||||
|
||||
public readonly string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.EngineResourceData);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.EngineResourceData);
|
||||
}
|
||||
|
||||
public static EngineResourceData FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.EngineResourceData);
|
||||
return string.IsNullOrEmpty(text)
|
||||
? new()
|
||||
: JsonSerializer.Deserialize(text, MiningSerializerContext.Default.EngineResourceData);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public sealed record class GameObject : Object
|
||||
{
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(EngineResourceData))]
|
||||
[JsonSerializable(typeof(UnityPackageData))]
|
||||
internal sealed partial class InternalSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -4,15 +4,17 @@ public sealed record class Mesh : NamedObject
|
||||
{
|
||||
public required int VertexCount { get; init; }
|
||||
public required int SubMeshCount { get; init; }
|
||||
public required AxisAlignedBoundingBox LocalAABB { get; init; }
|
||||
|
||||
public Mesh()
|
||||
{
|
||||
}
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public Mesh(string name, int vertexCount, int subMeshCount) : base(name)
|
||||
public Mesh(string name, int vertexCount, int subMeshCount, AxisAlignedBoundingBox localAabb) : base(name)
|
||||
{
|
||||
VertexCount = vertexCount;
|
||||
SubMeshCount = subMeshCount;
|
||||
LocalAABB = localAabb;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, IncludeFields = true)]
|
||||
[JsonSerializable(typeof(EngineResourceData))]
|
||||
[JsonSerializable(typeof(UnityPackageData))]
|
||||
[JsonSerializable(typeof(ReferenceAssemblyData))]
|
||||
public sealed partial class MiningSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -20,6 +20,6 @@ public sealed record class MonoScript : Object
|
||||
|
||||
public static MonoScript FromType(Type type)
|
||||
{
|
||||
return new MonoScript(type.Assembly.GetName().Name, type.Namespace, type.Name);
|
||||
return new MonoScript(type.Assembly.GetName().Name ?? "", type.Namespace ?? "", type.Name);
|
||||
}
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public abstract record class Object
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.Object);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.Object);
|
||||
}
|
||||
|
||||
public static Object? FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.Object);
|
||||
return JsonSerializer.Deserialize(text, MiningSerializerContext.Default.Object);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using AssetRipper.Primitives;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
/// <summary>
|
||||
/// A data structure representing a reference to an asset.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# AssetRipper.Mining.PredefinedAssets
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public readonly record struct ReferenceAssemblyData(List<string> Unity, List<string>? Mono2, List<string>? Mono4, List<string>? CoreCLR)
|
||||
{
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.ReferenceAssemblyData);
|
||||
}
|
||||
|
||||
public static ReferenceAssemblyData FromJson(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize<ReferenceAssemblyData>(json, MiningSerializerContext.Default.ReferenceAssemblyData);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public sealed record class Shader : NamedObject
|
||||
{
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using AssetRipper.Primitives;
|
||||
using System.Collections;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
@@ -32,11 +30,11 @@ public readonly record struct UnityPackageData(
|
||||
|
||||
public readonly string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.UnityPackageData);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.UnityPackageData);
|
||||
}
|
||||
|
||||
public static UnityPackageData FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.UnityPackageData);
|
||||
return JsonSerializer.Deserialize(text, MiningSerializerContext.Default.UnityPackageData);
|
||||
}
|
||||
}
|
||||
@@ -1 +1,6 @@
|
||||
global using System.Diagnostics.CodeAnalysis;
|
||||
#if NET5_0_OR_GREATER
|
||||
global using UnityGuid = AssetRipper.Primitives.UnityGuid;
|
||||
#else
|
||||
global using UnityGuid = string;
|
||||
#endif
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.0-preview.6.23329.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +0,0 @@
|
||||
using AssetRipper.Mining.Unity.Documentation.Web;
|
||||
|
||||
TocNode root = TocNode.FromJsonFile(@"toc.json") ?? throw new NullReferenceException();
|
||||
Dictionary<string, string> dictionary = TocAnalyzer.Analyze(root);
|
||||
Dictionary<string, string> reverseDictionary = dictionary.OrderBy(pair => pair.Value).ToDictionary(pair => pair.Value, pair => pair.Key);
|
||||
_ = reverseDictionary;
|
||||
@@ -1,69 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AssetRipper.Mining.Unity.Documentation.Web;
|
||||
public static class TocAnalyzer
|
||||
{
|
||||
public static Dictionary<string, string> Analyze(TocNode root)
|
||||
{
|
||||
Debug.Assert(root.IsRoot);
|
||||
Debug.Assert(root.HasChildren);
|
||||
|
||||
//Link : Full name
|
||||
Dictionary<string, string> result = new();
|
||||
Stack<(TocNode, int)> stack = new();
|
||||
foreach (TocNode rootChild in root.Children)
|
||||
{
|
||||
if (rootChild.Title is "Other")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
stack.Push((rootChild, -1));
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
(TocNode node, int childIndex) = stack.Pop();
|
||||
if (childIndex == -1)
|
||||
{
|
||||
if (node.IsType)
|
||||
{
|
||||
string @namespace = GetNamespace(stack, result);
|
||||
string fullName = $"{@namespace}.{node.Title}";
|
||||
result.Add(node.Link, fullName);
|
||||
}
|
||||
if (node.HasChildren && !node.IsAssemblyCollection)
|
||||
{
|
||||
stack.Push((node, 0));
|
||||
}
|
||||
}
|
||||
else if (childIndex < node.Children!.Length)
|
||||
{
|
||||
stack.Push((node, childIndex + 1));
|
||||
stack.Push((node.Children[childIndex], -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetNamespace(Stack<(TocNode, int)> stack, Dictionary<string, string> dictionary)
|
||||
{
|
||||
foreach ((TocNode node, _) in stack)
|
||||
{
|
||||
if (node.IsNamespace)
|
||||
{
|
||||
return node.Title;
|
||||
}
|
||||
if (node.IsType)
|
||||
{
|
||||
return dictionary[node.Link];
|
||||
}
|
||||
}
|
||||
if (stack.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("The stack is empty.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Could not determine the namespace from the stack.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.Mining.Unity.Documentation.Web;
|
||||
|
||||
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
|
||||
public sealed class TocNode
|
||||
{
|
||||
private const string TOC = "toc";
|
||||
private const string Classes = "Classes";
|
||||
private const string Interfaces = "Interfaces";
|
||||
private const string Enumerations = "Enumerations";
|
||||
private const string Attributes = "Attributes";
|
||||
private const string Assemblies = "Assemblies";
|
||||
private string? link;
|
||||
|
||||
[JsonPropertyName("link")]
|
||||
public required string? Link
|
||||
{
|
||||
get => link;
|
||||
init
|
||||
{
|
||||
link = value is "null" ? null : value;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("title")]
|
||||
public required string Title { get; init; }
|
||||
|
||||
[JsonPropertyName("children")]
|
||||
public required TocNode[]? Children { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(true, nameof(Link))]
|
||||
public bool IsRoot => Link is TOC && Title is TOC;
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(true, nameof(Link))]
|
||||
public bool IsType => Link is not null and not TOC;
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(false, nameof(Link))]
|
||||
public bool IsTypeCollection => Link is null && Title is Classes or Interfaces or Enumerations or Attributes;
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(false, nameof(Link))]
|
||||
public bool IsAssemblyCollection => Link is null && Title is Assemblies;
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(false, nameof(Link))]
|
||||
public bool IsNamespace => Link is null && Title is not Classes and not Interfaces and not Enumerations and not Attributes and not Assemblies;
|
||||
|
||||
[JsonIgnore]
|
||||
[MemberNotNullWhen(true, nameof(Children))]
|
||||
public bool HasChildren => Children is not null && Children.Length > 0;
|
||||
|
||||
public static TocNode? FromJsonText(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize(json, TocSerializerContext.Default.TocNode);
|
||||
}
|
||||
|
||||
public static TocNode? FromJsonFile(string path)
|
||||
{
|
||||
return JsonSerializer.Deserialize(File.OpenRead(path), TocSerializerContext.Default.TocNode);
|
||||
}
|
||||
|
||||
private string GetDebuggerDisplay()
|
||||
{
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AssetRipper.Mining.Unity.Documentation.Web;
|
||||
|
||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||
[JsonSerializable(typeof(TocNode))]
|
||||
internal partial class TocSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
Reference in new issue
Block a user