Editor/Embedded/ValveResourceFormat/ResourceTypes/ModelAnimation/AnimationEvent.cs

The AnimationEvent struct models an event within an animation file, used for metadata stored in the Valve Resource Format (VRF). It parses required event data like name, frame number, cycle time, and associated options from a KVObject.

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using HumanoidRetargeter.EditorTools.Embedded.ValveResourceFormat.Utils;
using HumanoidRetargeter.EditorTools.Embedded.ValveResourceFormat.Serialization.KeyValues;

namespace HumanoidRetargeter.EditorTools.Embedded.ValveResourceFormat.ResourceTypes.ModelAnimation;

    /// <summary>
    /// Represents an event that occurs at a specific frame in an animation.
    /// </summary>
    public readonly struct AnimationEvent
    {
        /// <summary>
        /// Gets or sets the name of the event.
        /// </summary>
        public string Name { get; init; }

        /// <summary>
        /// Gets or sets the frame at which the event occurs.
        /// </summary>
        public int Frame { get; init; }

        /// <summary>
        /// Gets or sets the normalized cycle time of the event.
        /// </summary>
        public float Cycle { get; init; }

        /// <summary>
        /// Gets or sets the event data.
        /// </summary>
        public KVObject EventData { get; init; }

        /// <summary>
        /// Gets or sets the event options.
        /// </summary>
        public string Options { get; init; }

        /// <summary>
        /// Initializes a new instance of the <see cref="AnimationEvent"/> struct.
        /// </summary>
        public AnimationEvent(KVObject data)
        {
            Name = data.GetStringProperty("m_sEventName");
            Frame = data.GetInt32Property("m_nFrame");
            Cycle = data.GetFloatProperty("m_flCycle");
            EventData = data.GetSubCollection("m_EventData");
            Options = data.GetStringProperty("m_sOptions");
        }
    }