Content PR for auto-componentstate sourcegen (#14845)
* Content PR for auto-componentstate sourcegen # Conflicts: # Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs # Content.Shared/Content.Shared.csproj # SpaceStation14.sln * shared file too * afterautohandlestate example * oops * anudda * access fixed * smart
This commit is contained in:
@@ -6,28 +6,18 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.Access.Components
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[AutoGenerateComponentState]
|
||||
[Access(typeof(SharedIdCardSystem), typeof(SharedPDASystem), typeof(SharedAgentIdCardSystem))]
|
||||
public sealed class IdCardComponent : Component
|
||||
public sealed partial class IdCardComponent : Component
|
||||
{
|
||||
[DataField("fullName")]
|
||||
[AutoNetworkedField]
|
||||
[Access(typeof(SharedIdCardSystem), typeof(SharedPDASystem), typeof(SharedAgentIdCardSystem),
|
||||
Other = AccessPermissions.ReadWrite)] // FIXME Friends
|
||||
public string? FullName;
|
||||
|
||||
[DataField("jobTitle")]
|
||||
[AutoNetworkedField]
|
||||
public string? JobTitle;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class IdCardComponentState : ComponentState
|
||||
{
|
||||
public string? FullName;
|
||||
public string? JobTitle;
|
||||
|
||||
public IdCardComponentState(string? fullName, string? jobTitle)
|
||||
{
|
||||
FullName = fullName;
|
||||
JobTitle = jobTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,28 +11,6 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<IdCardComponent, ComponentGetState>(OnComponentGetState);
|
||||
SubscribeLocalEvent<IdCardComponent, ComponentHandleState>(OnComponentHandleState);
|
||||
}
|
||||
|
||||
private void OnComponentGetState(EntityUid uid, IdCardComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new IdCardComponentState(component.FullName, component.JobTitle);
|
||||
}
|
||||
|
||||
private void OnComponentHandleState(EntityUid uid, IdCardComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is IdCardComponentState state)
|
||||
{
|
||||
component.FullName = state.FullName;
|
||||
component.JobTitle = state.JobTitle;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to find an ID card on an entity. This will look in the entity itself, in the entity's hands, and
|
||||
/// in the entity's inventory.
|
||||
|
||||
Reference in New Issue
Block a user