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)
#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
}
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