using System; using Robust.Shared.GameStates; using Robust.Shared.Serialization; namespace Robust.Shared.GameObjects; /// /// An abstract base class for a component's network state. For simple cases, you can automatically generate this using /// and . /// /// /// /// If your component's state is particularly complex, or you otherwise want manual control, you can implement this /// directly and register necessary event handlers for and /// . /// /// /// How state is actually applied for a component, and what it looks like, is user defined. For an example, look at /// . /// /// [RequiresSerializable] [Serializable, NetSerializable] public abstract class ComponentState : IComponentState; /// /// Represents the state of a component for networking purposes. /// public interface IComponentState; /// /// Internal for RT, you probably want . /// public interface IComponentDeltaState : IComponentState { public void ApplyToFullState(IComponentState fullState); public IComponentState CreateNewFullState(IComponentState fullState); } /// /// Interface for component states that only contain partial state data. The actual delta state class should be a /// separate class from the full component states. /// /// The full-state class associated with this partial state public interface IComponentDeltaState : IComponentDeltaState where TState: IComponentState { /// /// This function will apply the current delta state to the provided full state, modifying it in the process. /// public void ApplyToFullState(TState fullState); /// /// This function should take in a full state and return a new full state with the current delta applied, /// WITHOUT modifying the original input state. /// public TState CreateNewFullState(TState fullState); void IComponentDeltaState.ApplyToFullState(IComponentState fullState) { if (fullState is not TState state) throw new Exception($"Unexpected type. Expected {typeof(TState).Name} but got {fullState.GetType().Name}"); ApplyToFullState(state); } IComponentState IComponentDeltaState.CreateNewFullState(IComponentState fullState) { if (fullState is not TState state) throw new Exception($"Unexpected type. Expected {typeof(TState).Name} but got {fullState.GetType().Name}"); return CreateNewFullState(state); } }