Fix IDs without station records not being able to have nonstandard contents (#34921)

* fix ID console resetting to passenger

* review

* whoopsie! whitespace

---------

Co-authored-by: Milon <milonpl.git@proton.me>
This commit is contained in:
Alfred Baumann
2025-04-14 17:02:27 +02:00
committed by GitHub
parent 3cc917f1a8
commit 5e74afc72c
3 changed files with 18 additions and 3 deletions

View File

@@ -174,7 +174,8 @@ namespace Content.Client.Access.UI
new List<ProtoId<AccessLevelPrototype>>()); new List<ProtoId<AccessLevelPrototype>>());
var jobIndex = _jobPrototypeIds.IndexOf(state.TargetIdJobPrototype); var jobIndex = _jobPrototypeIds.IndexOf(state.TargetIdJobPrototype);
// If the job index is < 0 that means they don't have a job registered in the station records. // If the job index is < 0 that means they don't have a job registered in the station records
// or the IdCardComponent's JobPrototype field.
// For example, a new ID from a box would have no job index. // For example, a new ID from a box would have no job index.
if (jobIndex < 0) if (jobIndex < 0)
{ {

View File

@@ -98,7 +98,7 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
var targetIdComponent = EntityManager.GetComponent<IdCardComponent>(targetId); var targetIdComponent = EntityManager.GetComponent<IdCardComponent>(targetId);
var targetAccessComponent = EntityManager.GetComponent<AccessComponent>(targetId); var targetAccessComponent = EntityManager.GetComponent<AccessComponent>(targetId);
var jobProto = new ProtoId<AccessLevelPrototype>(string.Empty); var jobProto = targetIdComponent.JobPrototype ?? new ProtoId<AccessLevelPrototype>(string.Empty);
if (TryComp<StationRecordKeyStorageComponent>(targetId, out var keyStorage) if (TryComp<StationRecordKeyStorageComponent>(targetId, out var keyStorage)
&& keyStorage.Key is { } key && keyStorage.Key is { } key
&& _record.TryGetRecord<GeneralStationRecord>(key, out var record)) && _record.TryGetRecord<GeneralStationRecord>(key, out var record))
@@ -151,6 +151,13 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
} }
UpdateStationRecord(uid, targetId, newFullName, newJobTitle, job); UpdateStationRecord(uid, targetId, newFullName, newJobTitle, job);
if ((!TryComp<StationRecordKeyStorageComponent>(targetId, out var keyStorage)
|| keyStorage.Key is not { } key
|| !_record.TryGetRecord<GeneralStationRecord>(key, out _))
&& newJobProto != string.Empty)
{
Comp<IdCardComponent>(targetId).JobPrototype = newJobProto;
}
if (!newAccessList.TrueForAll(x => component.AccessLevels.Contains(x))) if (!newAccessList.TrueForAll(x => component.AccessLevels.Contains(x)))
{ {

View File

@@ -36,6 +36,13 @@ public sealed partial class IdCardComponent : Component
[AutoNetworkedField] [AutoNetworkedField]
public ProtoId<JobIconPrototype> JobIcon = "JobIconUnknown"; public ProtoId<JobIconPrototype> JobIcon = "JobIconUnknown";
/// <summary>
/// Holds the job prototype when the ID card has no associated station record
/// </summary>
[DataField]
[AutoNetworkedField]
public ProtoId<AccessLevelPrototype>? JobPrototype;
/// <summary> /// <summary>
/// The proto IDs of the departments associated with the job /// The proto IDs of the departments associated with the job
/// </summary> /// </summary>