mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-19 19:59:26 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
47 lines
1.2 KiB
C#
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 );
|
|
}
|
|
}
|