diff --git a/Assets/Scripts/UI/FactExplorer/FactExplorer.cs b/Assets/Scripts/UI/FactExplorer/FactExplorer.cs index 439eaf681dcdfb4a8d1d55aad4b676614633deed..f47cbf1e2527a64d723f485497febf68b812066b 100644 --- a/Assets/Scripts/UI/FactExplorer/FactExplorer.cs +++ b/Assets/Scripts/UI/FactExplorer/FactExplorer.cs @@ -51,27 +51,13 @@ public void Initialize(Fact fact, Vector3 factPosition) #region Implementation private List<Fact> GetParentFacts() { - //TODO: TSC how to get all current facts without this dumb workaround - var allFacts = DisplayFacts.displayedFacts.Values.Select(x => x.GetComponent<FactWrapper>().fact); - 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; + _ = StageStatic.stage.factState.safe_dependencies(mainFact.Id, out var parentFactIds); + return parentFactIds.Distinct().Select(factId => StageStatic.stage.factState[factId]).Where(f => f != mainFact).ToList(); } private List<Fact> GetChildFacts() { - List<Fact> childFacts = new(); - - // 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; + return mainFact.getDependentFactIds().Distinct().Select(factId => StageStatic.stage.factState[factId]).ToList(); } private void UpdateFactExplorerUI() @@ -175,18 +161,4 @@ private void SpawnChildLines(GameObject parent, Transform mainFactUI) }); } #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 }