mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Auto-componentstate source generator (#3684)
* dog what am i doing * finish gen source part from class symbol * we are dangerously close to things happening * generation fixes * oh? on god? * stop autogenerating the attribute for no reason + diagnostics * testing diagnostics * proper type name handling + clonedata bool * thank you material storage for making me realize this * forgot to commit * p * fixes for afterautohandlestate * make it work with access
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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(Component))]
|
||||
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;
|
||||
|
||||
public AutoGenerateComponentStateAttribute(bool raiseAfterAutoHandleState = false)
|
||||
{
|
||||
RaiseAfterAutoHandleState = raiseAfterAutoHandleState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Determines whether the data should be wrapped in a new() when setting in get/handlestate
|
||||
/// e.g. for cloning collections like dictionaries or hashsets which is sometimes necessary.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This should only be true if the type actually has a constructor that takes in itself.
|
||||
/// </remarks>
|
||||
[UsedImplicitly]
|
||||
public bool CloneData;
|
||||
|
||||
public AutoNetworkedFieldAttribute(bool cloneData=false)
|
||||
{
|
||||
CloneData = cloneData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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]
|
||||
public record struct AfterAutoHandleStateEvent(ComponentState State);
|
||||
12
Robust.Shared/Analyzers/RobustAutoGeneratedAttribute.cs
Normal file
12
Robust.Shared/Analyzers/RobustAutoGeneratedAttribute.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Shared.Analyzers;
|
||||
|
||||
/// <summary>
|
||||
/// Placed on auto-generated classes to mark to certain robust analyzers that they are auto-generated
|
||||
/// and may need to be ignored (e.g. the access analyzer)
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class RobustAutoGeneratedAttribute : Attribute
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user