Added the system from trail
This commit is contained in:
33
Runtime/EncounterLink.cs
Normal file
33
Runtime/EncounterLink.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace Jovian.EncounterSystem {
|
||||
/// <summary>
|
||||
/// Cross-table reference to an <see cref="IEncounter"/>. Stores the owning
|
||||
/// <see cref="EncounterTable"/> asset and the target encounter's <see cref="EncounterDefinition.internalId"/>.
|
||||
/// Rename-safe because the stored key is a GUID.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct EncounterLink {
|
||||
/// <summary>The table that owns the linked encounter.</summary>
|
||||
public EncounterTable table;
|
||||
|
||||
/// <summary>The target encounter's stable GUID (<see cref="EncounterDefinition.internalId"/>).</summary>
|
||||
public string internalId;
|
||||
|
||||
/// <summary>Look up the referenced encounter, or <c>null</c> if the table is missing or the id
|
||||
/// no longer exists in it.</summary>
|
||||
public IEncounter Resolve() {
|
||||
if(table == null || table.encounters == null || string.IsNullOrEmpty(internalId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach(var encounter in table.encounters) {
|
||||
if(encounter?.EncounterDefinition?.internalId == internalId) {
|
||||
return encounter;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user