Files
sbox-public/engine/Sandbox.Engine/Resources/Scene/PrefabFile.Version01.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

56 lines
940 B
C#

using System.Text.Json.Nodes;
namespace Sandbox;
public partial class PrefabFile
{
/// <summary>
/// Version 0 to 1
/// - "Id" changed to "__guid"
/// </summary>
[Expose, JsonUpgrader( typeof( PrefabFile ), 1 )]
internal static void Upgrader_v1( JsonObject obj )
{
if ( obj["RootObject"] is JsonObject root )
{
Upgrader_v1( root );
}
if ( obj.TryGetPropertyValue( "Id", out var id ) )
{
try
{
obj["__guid"] = (Guid)id;
obj.Remove( "Id" );
}
catch ( System.Exception e )
{
Log.Warning( e );
}
}
if ( obj["Children"] is JsonArray childArray )
{
foreach ( var child in childArray )
{
if ( child is not JsonObject jso )
continue;
Upgrader_v1( jso );
}
}
if ( obj["Components"] is JsonArray componentArray )
{
foreach ( var child in componentArray )
{
if ( child is not JsonObject jso )
continue;
Upgrader_v1( jso );
}
}
}
}