Files
sbox-public/engine/Sandbox.Engine/Resources/Scene/SceneFile.Version02.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

47 lines
1.2 KiB
C#

using System.Text.Json.Nodes;
namespace Sandbox;
public partial class SceneFile
{
/// <summary>
/// Version 1 to 2
/// - Title and Description moved to SceneInformation metadata component
/// </summary>
[Expose, JsonUpgrader( typeof( SceneFile ), 2 )]
internal static void Upgrader_v2( JsonObject obj )
{
var title = obj.GetPropertyValue<string>( "Title", null );
var description = obj.GetPropertyValue<string>( "Description", null );
if ( string.IsNullOrEmpty( title ) && string.IsNullOrEmpty( description ) )
return;
//
// Add them to the metadata
//
if ( obj["SceneProperties"] is JsonObject properties )
{
var metadata = new JsonObject();
metadata["Title"] = title;
metadata["Description"] = description;
properties["Metadata"] = metadata;
}
if ( obj["GameObjects"] is not JsonArray gameObjects )
return;
var component = new JsonObject();
component["__type"] = "SceneInformation";
component["Title"] = title;
component["Description"] = description;
var go = new JsonObject();
go["Id"] = Guid.NewGuid();
go["Name"] = "Scene Information";
go["Enabled"] = true;
go["Components"] = new JsonArray( component );
gameObjects.Insert( 0, go );
}
}