diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs index 94d864e7210a2748ff89aca748a2128794dc948a..0654b7823d7462d96feeb8ec584f0bca28f1d36b 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs @@ -42,7 +42,7 @@ public class FactOrganizer : IJSONsavable<FactOrganizer>, IDisposable /// - <c>Value</c>: <see cref="Fact"/> /// </summary> [JsonIgnore] - protected IReadOnlyDictionary<string, Fact> MyFactSpace + public IReadOnlyDictionary<string, Fact> MyFactSpace { get => GlobalFactDictionary.MyFactSpace(this); } @@ -403,10 +403,11 @@ Fact ReInitializeFact(string old_id) return null; } - Fact new_Fact = old_Fact.ReInitializeMe(_old_to_new, target); // check for dupes? - - _old_to_new.Add(old_Fact.Id, new_Fact.Id); //move up + //// old_Fact => map dependent Facts!! + //if (!GlobalFactDictionary.FindEquivalent(AllFacts, old_Fact, out string uri, out Fact new_Fact, out _)) + Fact new_Fact = old_Fact.ReInitializeMe(_old_to_new, target); + _old_to_new.Add(old_Fact.Id, new_Fact.Id); return new_Fact; } } @@ -548,7 +549,7 @@ public string Add(Fact value, out bool exists, bool samestep, Gadget gadget, str string key; #pragma warning restore IDE0018 // Inlinevariablendeklaration - if (exists = GlobalFactDictionary.FindEquivalent(MyFactSpace, value, out key, out bool _)) + if (exists = GlobalFactDictionary.FindEquivalent(MyFactSpace, value, out key, out Fact _, out bool _)) { if (exists = MetaInf[key].active) //Fact in Scene? // desired outcome already achieved @@ -565,7 +566,7 @@ public string Add(Fact value, out bool exists, bool samestep, Gadget gadget, str //if (GlobalFactDictionary.FindEquivalent(AllFacts, value, out key, out bool _)) // value = AllFacts[key]; //else - key = value.Id; + key = value.Id; GlobalFactDictionary.FactSpaceAdd(this, value); MetaInf.Add(key, new meta(marker, true, isImmutable)); @@ -966,6 +967,8 @@ public IEnumerable<string> GetUsedScrolls() public int GetNumberOfFacts() => MyFactSpace.Count; + public static bool FindEquivalent(IReadOnlyDictionary<string, Fact> FactSpace, Fact search, out string found_key, out Fact found_value, out bool exact, bool allow_exact = true) + => GlobalFactDictionary.FindEquivalent(FactSpace, search, out found_key, out found_value, out exact, allow_exact); protected static class GlobalFactDictionary { @@ -1035,19 +1038,23 @@ public static void FactSpaceRemove(FactOrganizer me, string key) //TODO? MMT? PERF: O(n), every Fact-insertion /// <summary> - /// Looks for existent <see cref="Fact"/> (<paramref name="found"/>) which is very similar or identical (<paramref name="exact"/>) to prposed <see cref="Fact"/> (<paramref name="search"/>) + /// Looks for existent <see cref="Fact"/> (<paramref name="found_key"/>) which is very similar or identical (<paramref name="exact"/>) to prposed <see cref="Fact"/> (<paramref name="search"/>) /// <remarks>does not check active state</remarks> /// </summary> /// <param name="FactSpace">to search in</param> /// <param name="search">to be searched for</param> - /// <param name="found"><see cref="Fact.Id"/> if return value is <c>true</c></param> - /// <param name="exact"><c>true</c> iff <paramref name="found"/> == <paramref name="search"/><see cref="Fact.Id">.Id</see></param> + /// <param name="found_key"><see cref="Fact.Id"/> if return value is <c>true</c></param> + /// <param name="found_value"><see cref="Fact"/> if return value is <c>true</c></param> + /// <param name="exact"><c>true</c> iff <paramref name="found_key"/> == <paramref name="search"/><see cref="Fact.Id">.Id</see></param> + /// <param name="allow_exact">if set to <c>true</c>: ignores cases where <paramref name="exact"/> returns <c>true</c></param> /// <returns><c>true</c> iff the exact same or an equivalent <see cref="Fact"/> to <paramref name="search"/> was found in <see cref="MyFactSpace"/></returns> - public static bool FindEquivalent(IReadOnlyDictionary<string, Fact> FactSpace, Fact search, out string found, out bool exact) + public static bool FindEquivalent(IReadOnlyDictionary<string, Fact> FactSpace, Fact search, out string found_key, out Fact found_value, out bool exact, bool allow_exact = true) { - if (exact = FactSpace.ContainsKey(search.Id)) + if (exact = FactSpace.ContainsKey(search.Id) + && allow_exact) { - found = search.Id; + found_key = search.Id; + found_value = FactSpace[found_key]; return true; } @@ -1055,12 +1062,14 @@ public static bool FindEquivalent(IReadOnlyDictionary<string, Fact> FactSpace, F { if (entry.Value.Equivalent(search)) { - found = entry.Key; + found_key = entry.Key; + found_value = entry.Value; return true; } } - found = null; + found_key = null; + found_value = null; return false; } } diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs index 2ede0e554c0970b6cbdd947ae01e79c7f89fd935..681d0712a89a4f93395dbb69f04365a9d4510344 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs @@ -147,14 +147,12 @@ public void SpawnCircle(CircleFact circleFact, Transform parent = null) public void AnimateNonExistingFactTrigger(Fact fact) { - StartCoroutine(animateNonExistingFact(fact)); + StartCoroutine(_BlossomAndDie(fact)); - IEnumerator animateNonExistingFact(Fact fact) + IEnumerator _BlossomAndDie(Fact fact) { SpawnFactRepresentation(fact); - AnimateExistingFactEvent.Invoke(fact.Id, FactWrapper.FactMaterials.Hint); - yield return new WaitForSeconds(GlobalBehaviour.HintAnimationDuration); RemoveFactEvent.Invoke(fact); diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs index 03139734d99c51f67af9a0cfe2590cd51d1f3db9..e6cfd7aa086ce326ba68bbb3bb96c5c1b9fec099 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs @@ -516,7 +516,7 @@ protected bool DependentFactsEquivalent(T f1, T f2) => f1.GetGetDependentFactIds() .Zip(f2.GetGetDependentFactIds(), (id1, id2) => - id1.Equals(id2) + id1 == id2 || FactOrganizer.AllFacts[id1].Equivalent(FactOrganizer.AllFacts[id2]) ) .All(b => b); diff --git a/Assets/Scripts/InteractionEngine/WorldCursor.cs b/Assets/Scripts/InteractionEngine/WorldCursor.cs index aaa376b67378de2b20b05a071930a2c323281a0f..bbc26561dd7b1abf6b4da7ea236eb94d698e549b 100644 --- a/Assets/Scripts/InteractionEngine/WorldCursor.cs +++ b/Assets/Scripts/InteractionEngine/WorldCursor.cs @@ -8,6 +8,7 @@ public class WorldCursor : MonoBehaviour { public RaycastHit[] Hits; + public Fact[] HitFacts; public float IntersectionDistance = 0.1f; @@ -115,12 +116,10 @@ void Update() break; // we had at least 1 succesfull case } - Fact[] facts; - if (i == Hits.Length) { Hits = new[] { Hits[0] }; - facts = new Fact[0]; + HitFacts = new Fact[0]; } else { @@ -128,7 +127,7 @@ void Update() .TakeWhile(h => h.distance - Hits[i].distance < IntersectionDistance) .ToArray(); - facts = Hits + HitFacts = Hits .Select(h => h.transform.TryGetComponent(out FactObject factObj) ? FactOrganizer.AllFacts[factObj.URI] @@ -138,8 +137,8 @@ void Update() if (Hits.Length > 1) { // we have two or more objects intersecting - if (facts[0] is RayFact rayFact1 - && facts[1] is RayFact rayFact2) + if (HitFacts[0] is RayFact rayFact1 + && HitFacts[1] is RayFact rayFact2) { if (Math3d.LineLineIntersection(out Vector3 intersectionPoint , rayFact2.Point1.Point, rayFact2.Dir @@ -156,6 +155,10 @@ void Update() transform.up = Hits[0].normal; transform.position = Hits[0].point + .01f * Hits[0].normal; + //for (i = 0; i < HitFacts.Length; i++) //TODO: not constantly => see ShinyThings.Update + // if (HitFacts[i]?.Id != null) + // CommunicationEvents.AnimateExistingFactEvent.Invoke(HitFacts[i].Id, FactWrapper.FactMaterials.Selected); + if (Input.GetMouseButtonDown(0)) ClickHandler(); } diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index 22e20cc7c0d198ce90cef49245de8bf671e6ab10..eedf91dc552fb5df40e16d6abb8ee1482c291d4c 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -297,10 +297,10 @@ public void animateHint(string scrollParameterUri) else if (null != (fact = LatestRenderedHints.Find(x => x.Id == scrollParameterUri))) { - if (FactOrganizer.AllFacts.ContainsKey(fact.Id)) + if (FactOrganizer.FindEquivalent(StageStatic.stage.factState.MyFactSpace, fact, out string found_key, out Fact _, out bool _, false)) // existing fact -> Animate that AnimateExistingFactEvent.Invoke( - fact.Id, + found_key, FactWrapper.FactMaterials.Hint ); diff --git a/Assets/Scripts/UI/MainMenue/ListLoader.cs b/Assets/Scripts/UI/MainMenue/ListLoader.cs index a43a6161e7f96b687f8a7bf1c29c97e7a4a283b2..c78b473f18f7ab29893c5bd671f985a96bc2dae4 100644 --- a/Assets/Scripts/UI/MainMenue/ListLoader.cs +++ b/Assets/Scripts/UI/MainMenue/ListLoader.cs @@ -20,7 +20,8 @@ protected void OnEnable() System.Collections.IEnumerator _Init() { - yield return new WaitForEndOfFrame(); + yield return new WaitForFixedUpdate(); + Clear(); Init(); }