Rename fix (#31654)

* Localize RenameCommand and delegate most of the process to MetaDataSystem.SetEntityName()

* Make renaming rely on the EntityRenamedEvent. Fix issue where renaming would keep old Examine text

Requires engine change

* Fix localisation strings

* Make PDA search be based on a renamed entity's Uid instead of its old name

To do this the pda component now has an PdaOwner field which gets
assigned when it is given as a loadout to a player

* Fix bad merge???

huh

* Use AllEntityQuery
This commit is contained in:
nikthechampiongr
2024-09-15 01:55:03 +00:00
committed by GitHub
parent f81d18914d
commit ee434e397d
11 changed files with 95 additions and 79 deletions

View File

@@ -1,6 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Content.Server.Access.Systems;
using Content.Server.Forensics;
using Content.Server.GameTicking;
using Content.Shared.Access.Components;
using Content.Shared.Inventory;
using Content.Shared.PDA;
using Content.Shared.Preferences;
@@ -35,12 +38,14 @@ public sealed class StationRecordsSystem : SharedStationRecordsSystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly StationRecordKeyStorageSystem _keyStorage = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IdCardSystem _idCard = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawn);
SubscribeLocalEvent<EntityRenamedEvent>(OnRename);
}
private void OnPlayerSpawn(PlayerSpawnCompleteEvent args)
@@ -51,6 +56,30 @@ public sealed class StationRecordsSystem : SharedStationRecordsSystem
CreateGeneralRecord(args.Station, args.Mob, args.Profile, args.JobId, stationRecords);
}
private void OnRename(ref EntityRenamedEvent ev)
{
// When a player gets renamed their card gets changed to match.
// Unfortunately this means that an event is called for it as well, and since TryFindIdCard will succeed if the
// given entity is a card and the card itself is the key the record will be mistakenly renamed to the card's name
// if we don't return early.
if (HasComp<IdCardComponent>(ev.Uid))
return;
if (_idCard.TryFindIdCard(ev.Uid, out var idCard))
{
if (TryComp(idCard, out StationRecordKeyStorageComponent? keyStorage)
&& keyStorage.Key is {} key)
{
if (TryGetRecord<GeneralStationRecord>(key, out var generalRecord))
{
generalRecord.Name = ev.NewName;
}
Synchronize(key);
}
}
}
private void CreateGeneralRecord(EntityUid station, EntityUid player, HumanoidCharacterProfile profile,
string? jobId, StationRecordsComponent records)
{