Files
RobustToolbox/Robust.Shared/Analyzers/ComponentNetworkGeneratorAuxiliary.cs
metalgearsloth 9837c33de7 Add sourcegenned field deltas (#5155)
* Remove full "delta" states

* Update MapGridComponentState

* abstract ComponentState

* Release notes

* Fix tests

* Fix nullable errors

* A

* Sourcegen component deltas

* Audio deltas + methids

* Also eye

* Optimise out the dictionary

* Minor fixes

* Physics deltas

* Also this

* Fix field deltas

* remove old release notes

* Make IComponentDelta implement IComponent

* add sourcegen launch settings

* make silent error loud

* Review

* UI deltas

* Slimmer

* Sourcegen bandaid

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2024-12-21 15:48:33 +11:00

50 lines
2.0 KiB
C#

using System;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Analyzers;
/// <summary>
/// When a component is marked with this attribute, any members it has marked with <see cref="AutoNetworkedFieldAttribute"/>
/// will automatically be replicated using component states to clients. Systems which need to have more intelligent
/// component state replication beyond just directly setting variables should not use this attribute.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
[BaseTypeRequired(typeof(IComponent))]
public sealed class AutoGenerateComponentStateAttribute : Attribute
{
/// <summary>
/// If this is true, the autogenerated code will raise a <see cref="AfterAutoHandleStateEvent"/> component event
/// so that user-defined systems can have effects after handling state without redefining all replication.
/// </summary>
public bool RaiseAfterAutoHandleState;
/// <summary>
/// Should delta states be generated for every field.
/// </summary>
public bool FieldDeltas;
public AutoGenerateComponentStateAttribute(bool raiseAfterAutoHandleState = false, bool fieldDeltas = false)
{
RaiseAfterAutoHandleState = raiseAfterAutoHandleState;
FieldDeltas = fieldDeltas;
}
}
/// <summary>
/// Used to mark component members which should be automatically replicated, assuming the component is marked with
/// <see cref="AutoGenerateComponentStateAttribute"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class AutoNetworkedFieldAttribute : Attribute
{
}
/// <summary>
/// Raised as a component event after auto handling state is done, if
/// <see cref="AutoGenerateComponentStateAttribute.RaiseAfterAutoHandleState"/> is true, so that other systems
/// can have effects after handling state without having to redefine all replication.
/// </summary>
[ByRefEvent, ComponentEvent]
public record struct AfterAutoHandleStateEvent(IComponentState State);