Move Access to ECS (#4826)

* Moved access to ecs

* Fixed tests

* Moved test to integration

* Better IoC

* Moved preset ID card

* Moved id card to ECS

* Moved access component to ECS

* Fixed pda access

* Final touches

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Alex Evgrashin
2021-10-22 05:31:07 +03:00
committed by GitHub
parent 430485de06
commit a3f16295ea
26 changed files with 409 additions and 466 deletions

View File

@@ -1,77 +1,24 @@
using Content.Server.Access.Systems;
using Content.Server.PDA;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Access.Components
{
[RegisterComponent]
[Friend(typeof(IdCardSystem), typeof(PDASystem))]
public class IdCardComponent : Component
{
public override string Name => "IdCard";
/// See <see cref="UpdateEntityName"/>.
[DataField("originalOwnerName")]
private string _originalOwnerName = default!;
public string OriginalOwnerName = default!;
[DataField("fullName")]
private string? _fullName;
[ViewVariables(VVAccess.ReadWrite)]
public string? FullName
{
get => _fullName;
set
{
_fullName = value;
UpdateEntityName();
}
}
public string? FullName;
[DataField("jobTitle")]
private string? _jobTitle;
[ViewVariables(VVAccess.ReadWrite)]
public string? JobTitle
{
get => _jobTitle;
set
{
_jobTitle = value;
UpdateEntityName();
}
}
/// <summary>
/// Changes the <see cref="Entity.Name"/> of <see cref="Component.Owner"/>.
/// </summary>
/// <remarks>
/// If either <see cref="FullName"/> or <see cref="JobTitle"/> is empty, it's replaced by placeholders.
/// If both are empty, the original entity's name is restored.
/// </remarks>
private void UpdateEntityName()
{
if (string.IsNullOrWhiteSpace(FullName) && string.IsNullOrWhiteSpace(JobTitle))
{
Owner.Name = _originalOwnerName;
return;
}
var jobSuffix = string.IsNullOrWhiteSpace(JobTitle) ? string.Empty : $" ({JobTitle})";
Owner.Name = string.IsNullOrWhiteSpace(FullName)
? Loc.GetString("access-id-card-component-owner-name-job-title-text",
("originalOwnerName", _originalOwnerName),
("jobSuffix", jobSuffix))
: Loc.GetString("access-id-card-component-owner-full-name-job-title-text",
("fullName", FullName),
("jobSuffix", jobSuffix));
}
protected override void Initialize()
{
base.Initialize();
// ReSharper disable once ConstantNullCoalescingCondition
_originalOwnerName ??= Owner.Name;
UpdateEntityName();
}
public string? JobTitle;
}
}