Skip to content
Snippets Groups Projects
Commit 419ec29c authored by Tobias Schöner's avatar Tobias Schöner
Browse files

fix: FactExplorer use factState methods for getting child and parent facts

parent ec7f833d
No related branches found
No related tags found
No related merge requests found
...@@ -51,27 +51,13 @@ public void Initialize(Fact fact, Vector3 factPosition) ...@@ -51,27 +51,13 @@ public void Initialize(Fact fact, Vector3 factPosition)
#region Implementation #region Implementation
private List<Fact> GetParentFacts() private List<Fact> GetParentFacts()
{ {
//TODO: TSC how to get all current facts without this dumb workaround _ = StageStatic.stage.factState.safe_dependencies(mainFact.Id, out var parentFactIds);
var allFacts = DisplayFacts.displayedFacts.Values.Select(x => x.GetComponent<FactWrapper>().fact); return parentFactIds.Distinct().Select(factId => StageStatic.stage.factState[factId]).Where(f => f != mainFact).ToList();
List<Fact> _parentFacts = new();
// get all facts that reference the mainFact
foreach (Fact f in allFacts)
if (GetReferencedPids(f).Contains(mainFact.Id)) // if f contains reference to mainFact
_parentFacts.Add(f);
return _parentFacts;
} }
private List<Fact> GetChildFacts() private List<Fact> GetChildFacts()
{ {
List<Fact> childFacts = new(); return mainFact.getDependentFactIds().Distinct().Select(factId => StageStatic.stage.factState[factId]).ToList();
// get all properties of Type mainFactType that are strings and start with "pid"
foreach (string factId in GetReferencedPids(mainFact))
childFacts.Add(StageStatic.stage.factState[factId]);
return childFacts;
} }
private void UpdateFactExplorerUI() private void UpdateFactExplorerUI()
...@@ -175,18 +161,4 @@ private void SpawnChildLines(GameObject parent, Transform mainFactUI) ...@@ -175,18 +161,4 @@ private void SpawnChildLines(GameObject parent, Transform mainFactUI)
}); });
} }
#endregion Spawner #endregion Spawner
#region Helper
/// <summary>
/// Check all fields of a Fact for references to other facts and return their ids
/// </summary>
/// <param name="f"></param>
/// <returns>An Enumerable containing the ids of facts referenced by the input fact</returns>
private static IEnumerable<string> GetReferencedPids(Fact f)
{
return (f.GetType().GetFields()
.Where(field => field.FieldType == typeof(string) && field.Name.ToLower().StartsWith("pid"))
).Select(fi => (string)fi.GetValue(f));
}
#endregion Helper
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment