diff --git a/Content.Server/StationRecords/Components/StationRecordsComponent.cs b/Content.Server/StationRecords/Components/StationRecordsComponent.cs index f3b7c43d9b..4cd295dc12 100644 --- a/Content.Server/StationRecords/Components/StationRecordsComponent.cs +++ b/Content.Server/StationRecords/Components/StationRecordsComponent.cs @@ -1,11 +1,11 @@ namespace Content.Server.StationRecords; +[Access(typeof(StationRecordsSystem))] [RegisterComponent] public sealed class StationRecordsComponent : Component { // Every single record in this station, by key. // Essentially a columnar database, but I really suck // at implementing that so - [ViewVariables] - public StationRecordSet Records = new(); + [ViewVariables] public readonly StationRecordSet Records = new(); } diff --git a/Content.Server/StationRecords/Systems/StationRecordsSystem.cs b/Content.Server/StationRecords/Systems/StationRecordsSystem.cs index d0958a1804..1e7d754705 100644 --- a/Content.Server/StationRecords/Systems/StationRecordsSystem.cs +++ b/Content.Server/StationRecords/Systems/StationRecordsSystem.cs @@ -124,9 +124,8 @@ public sealed class StationRecordsSystem : EntitySystem DisplayPriority = jobPrototype.Weight }; - var key = records.Records.AddRecord(station); - records.Records.AddRecordEntry(key, record); - // entry.Entries.Add(typeof(GeneralStationRecord), record); + var key = AddRecord(station, records); + AddRecordEntry(key, record, records); if (idUid != null) { @@ -204,6 +203,45 @@ public sealed class StationRecordsSystem : EntitySystem return records.Records.GetRecordsOfType(); } + /// + /// Adds a record to a station's record set. + /// + /// The station to add a record to. + /// Station records component. + /// + /// A station record key, which can be used to add and get records. + /// + /// + /// Occurs when the entity given does not have a station records component. + /// + public StationRecordKey AddRecord(EntityUid station, StationRecordsComponent? records) + { + if (!Resolve(station, ref records)) + { + throw new ArgumentException($"Could not retrieve a {nameof(StationRecordsComponent)} from entity {station}"); + } + + return records.Records.AddRecord(station); + } + + /// + /// Adds a record entry to a station's record set. + /// + /// The key to add the record to. + /// The record to add. + /// Station records component. + /// The type of record to add. + public void AddRecordEntry(StationRecordKey key, T record, + StationRecordsComponent? records = null) + { + if (!Resolve(key.OriginStation, ref records)) + { + return; + } + + records.Records.AddRecordEntry(key, record); + } + /// /// Synchronizes a station's records with any systems that need it. ///