Files
sbox-public/engine/Sandbox.Engine/Scene/Components/Particles/Renderers/ParticleSpriteRenderer.Versioning.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

55 lines
1.2 KiB
C#

using System.Text.Json.Nodes;
namespace Sandbox;
public sealed partial class ParticleSpriteRenderer
{
public override int ComponentVersion => 2;
/// <summary>
/// v2
/// - Use embedded Sprite resource instead of a single Texture
/// </summary>
[Expose, JsonUpgrader( typeof( ParticleSpriteRenderer ), 2 )]
static void Upgrader_v2( JsonObject obj )
{
string pivotValue = null;
if ( obj.TryGetPropertyValue( "Pivot", out var pivotNode ) )
{
pivotValue = (string)pivotNode;
}
if ( obj.TryGetPropertyValue( "Texture", out var textureNode ) )
{
var arrAnimations = new JsonArray();
var arrFrames = new JsonArray();
var frame = Json.SerializeAsObject( new Sprite.Frame() );
frame["Texture"] = textureNode.DeepClone();
arrFrames.Add( frame );
var objAnimation = new JsonObject()
{
["Name"] = "Default",
["Frames"] = arrFrames
};
if ( pivotNode != null )
{
objAnimation["Pivot"] = pivotValue;
}
arrAnimations.Add( objAnimation );
var objSprite = new JsonObject()
{
["Animations"] = arrAnimations
};
obj["Sprite"] = new JsonObject()
{
["$compiler"] = "embed",
["$source"] = null,
["data"] = objSprite,
["compiled"] = null
};
}
}
}