Adds AddRecord/AddRecordEntry to StationRecordsSystem (#11732)
* adds an API to add station records from StationRecordsSystem * removes a lingering comment * adds a comment to AddRecord * Update Content.Server/StationRecords/Systems/StationRecordsSystem.cs Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com> Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a record to a station's record set.
|
||||
/// </summary>
|
||||
/// <param name="station">The station to add a record to.</param>
|
||||
/// <param name="records">Station records component.</param>
|
||||
/// <returns>
|
||||
/// A station record key, which can be used to add and get records.
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Occurs when the entity given does not have a station records component.
|
||||
/// </exception>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a record entry to a station's record set.
|
||||
/// </summary>
|
||||
/// <param name="key">The key to add the record to.</param>
|
||||
/// <param name="record">The record to add.</param>
|
||||
/// <param name="records">Station records component.</param>
|
||||
/// <typeparam name="T">The type of record to add.</typeparam>
|
||||
public void AddRecordEntry<T>(StationRecordKey key, T record,
|
||||
StationRecordsComponent? records = null)
|
||||
{
|
||||
if (!Resolve(key.OriginStation, ref records))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
records.Records.AddRecordEntry(key, record);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Synchronizes a station's records with any systems that need it.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user