Predict identity (#40185)
* crossing the pond * share some station records * share some criminal records * single system * comments * minor touchups * I always forget this part * requested changes * revert predicted spawn * requested changes --------- Co-authored-by: iaada <iaada@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Shared.StationRecords;
|
||||
|
||||
public abstract class SharedStationRecordsSystem : EntitySystem
|
||||
@@ -40,4 +42,60 @@ public abstract class SharedStationRecordsSystem : EntitySystem
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to get a record from this station's record entries,
|
||||
/// from the provided station record key. Will always return
|
||||
/// null if the key does not match the station.
|
||||
/// </summary>
|
||||
/// <param name="key">Station and key to try and index from the record set.</param>
|
||||
/// <param name="entry">The resulting entry.</param>
|
||||
/// <param name="records">Station record component.</param>
|
||||
/// <typeparam name="T">Type to get from the record set.</typeparam>
|
||||
/// <returns>True if the record was obtained, false otherwise. Always false on client.</returns>
|
||||
public bool TryGetRecord<T>(StationRecordKey key, [NotNullWhen(true)] out T? entry, StationRecordsComponent? records = null)
|
||||
{
|
||||
entry = default;
|
||||
|
||||
if (!Resolve(key.OriginStation, ref records))
|
||||
return false;
|
||||
|
||||
return records.Records.TryGetRecordEntry(key.Id, out entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all records of a specific type from a station.
|
||||
/// </summary>
|
||||
/// <param name="station">The station to get the records from.</param>
|
||||
/// <param name="records">Station records component.</param>
|
||||
/// <typeparam name="T">Type of record to fetch</typeparam>
|
||||
/// <returns>Enumerable of pairs with a station record key, and the entry in question of type T. Always empty on client.</returns>
|
||||
public IEnumerable<(uint, T)> GetRecordsOfType<T>(EntityUid station, StationRecordsComponent? records = null)
|
||||
{
|
||||
if (!Resolve(station, ref records))
|
||||
return Array.Empty<(uint, T)>();
|
||||
|
||||
return records.Records.GetRecordsOfType<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an id if a record with the same name exists.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Linear search so O(n) time complexity.
|
||||
/// </remarks>
|
||||
/// <returns>Returns a station record id. Always null on client.</returns>
|
||||
public uint? GetRecordByName(EntityUid station, string name, StationRecordsComponent? records = null)
|
||||
{
|
||||
if (!Resolve(station, ref records, false))
|
||||
return null;
|
||||
|
||||
foreach (var (id, record) in GetRecordsOfType<GeneralStationRecord>(station, records))
|
||||
{
|
||||
if (record.Name == name)
|
||||
return id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user