feat: смена значков в консоли ID карт

This commit is contained in:
Remuchi
2024-01-24 15:15:13 +07:00
parent cf8709f1ea
commit e09cc7b802
5 changed files with 213 additions and 28 deletions

View File

@@ -45,7 +45,8 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
if (args.Session.AttachedEntity is not { Valid: true } player)
return;
TryWriteToTargetId(uid, args.FullName, args.JobTitle, args.AccessList, args.JobPrototype, player, component);
TryWriteToTargetId(uid, args.FullName, args.JobTitle, args.AccessList, args.JobPrototype, args.SelectedIcon,
player, component);
UpdateUserInterface(uid, component, args);
}
@@ -77,7 +78,8 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
possibleAccess,
string.Empty,
privilegedIdName,
string.Empty);
string.Empty,
"JobIconNoId"); // WD EDIt
}
else
{
@@ -85,12 +87,16 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
var targetAccessComponent = EntityManager.GetComponent<AccessComponent>(targetId);
var jobProto = string.Empty;
var jobIcon = string.Empty; //WD-EDIT
if (_station.GetOwningStation(uid) is { } station
&& EntityManager.TryGetComponent<StationRecordKeyStorageComponent>(targetId, out var keyStorage)
&& keyStorage.Key != null
&& _record.TryGetRecord<GeneralStationRecord>(station, keyStorage.Key.Value, out var record))
{
jobProto = record.JobPrototype;
jobIcon = record.JobIcon;
Dirty(targetId, targetIdComponent);
}
newState = new IdCardConsoleBoundUserInterfaceState(
@@ -103,7 +109,9 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
possibleAccess,
jobProto,
privilegedIdName,
EntityManager.GetComponent<MetaDataComponent>(targetId).EntityName);
EntityManager.GetComponent<MetaDataComponent>(targetId).EntityName,
jobIcon
);
}
_userInterface.TrySetUiState(uid, IdCardConsoleUiKey.Key, newState);
@@ -113,11 +121,14 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
/// Called whenever an access button is pressed, adding or removing that access from the target ID card.
/// Writes data passed from the UI into the ID stored in <see cref="IdCardConsoleComponent.TargetIdSlot"/>, if present.
/// </summary>
private void TryWriteToTargetId(EntityUid uid,
/// WD-INFO: Also called when icon is changed, to update it on ID.
private void TryWriteToTargetId(
EntityUid uid,
string newFullName,
string newJobTitle,
List<string> newAccessList,
string newJobProto,
string? newJobIcon,
EntityUid player,
IdCardConsoleComponent? component = null)
{
@@ -127,6 +138,13 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
if (component.TargetIdSlot.Item is not { Valid: true } targetId || !PrivilegedIdIsAuthorized(uid, component))
return;
//WD-EDIT
if (TryComp<IdCardComponent>(targetId, out var idCardComponent) && newJobIcon != null)
{
idCardComponent.JobIcon = newJobIcon;
}
//WD-EDIT
_idCard.TryChangeFullName(targetId, newFullName, player: player);
_idCard.TryChangeJobTitle(targetId, newJobTitle, player: player);
@@ -148,7 +166,10 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
var privilegedId = component.PrivilegedIdSlot.Item;
if (oldTags.SequenceEqual(newAccessList))
{
UpdateStationRecord(uid, targetId, newFullName, newJobTitle, job, newJobIcon); //WD-EDIT
return;
}
// I hate that C# doesn't have an option for this and don't desire to write this out the hard way.
// var difference = newAccessList.Difference(oldTags);
@@ -170,7 +191,7 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(player):player} has modified {ToPrettyString(targetId):entity} with the following accesses: [{string.Join(", ", addedTags.Union(removedTags))}] [{string.Join(", ", newAccessList)}]");
UpdateStationRecord(uid, targetId, newFullName, newJobTitle, job);
UpdateStationRecord(uid, targetId, newFullName, newJobTitle, job, newJobIcon);
}
/// <summary>
@@ -191,7 +212,13 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
return privilegedId != null && _accessReader.IsAllowed(privilegedId.Value, uid, reader);
}
private void UpdateStationRecord(EntityUid uid, EntityUid targetId, string newFullName, string newJobTitle, JobPrototype? newJobProto)
private void UpdateStationRecord(
EntityUid uid,
EntityUid targetId,
string newFullName,
string newJobTitle,
JobPrototype? newJobProto,
string? newJobIcon) // WD EDIT
{
if (_station.GetOwningStation(uid) is not { } station
|| !EntityManager.TryGetComponent<StationRecordKeyStorageComponent>(targetId, out var keyStorage)
@@ -210,6 +237,9 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
record.JobIcon = newJobProto.Icon;
}
if (!string.IsNullOrWhiteSpace(newJobIcon))
record.JobIcon = newJobIcon;
_record.Synchronize(station);
}
}