diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactComparer.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactComparer.cs index 3f4fadd7688071f1463b3d0bb8fae1569088a703..344df17b5ea2c7e848ada3bfd8a304dbb50d1bce 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactComparer.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactComparer.cs @@ -150,7 +150,7 @@ protected override bool Compare(Fact solution, Fact fact) // get positions of anker points var point_pos = - factLine.getDependentFactIds() + factLine.DependentFactIds .Select(id => FactOrganizer.AllFacts[id].Representation.transform.position) .ToArray(); diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs index 8ddfcbc67c92c30bb7fbd42302dd9c2d358c56d3..ef49d35a5fea72d8c8292221002fac572eadc56e 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs @@ -28,6 +28,7 @@ public class FactOrganizer : IJSONsavable<FactOrganizer>, IDisposable /// e.g: From a <see cref="SolutionOrganizer"/> which are being exposed to the Player. /// <remarks> Will NOT be recorded in <see cref="Workflow"/>!</remarks> /// </summary> + [JsonProperty] protected List<string> ImmutableFacts = new(); /// <summary> @@ -215,6 +216,7 @@ public stepnote(FactOrganizer that, string Id, bool samestep, bool creation, Gad if (new_gadget = !that.GadgetWorkflowDict.ContainsKey(gadget)) { that.GadgetWorkflowDict.Add(gadget, (that.marker, that.marker)); + that.WorkflowGadgetDict.Remove(that.marker); that.WorkflowGadgetDict.Add(that.marker, gadget); } @@ -322,9 +324,9 @@ public static T ReInitializeFactOrganizer<T>(T source, bool invoke, out Dictiona where T : FactOrganizer, new() { // TODO: other strategy needed when MMT save/load supported - bool not_from_JSON = source.JsonFactSpace == null; + bool source_initialized = source.MyFactSpace.Count > 0; - Dictionary<string, string> _old_to_new = not_from_JSON + Dictionary<string, string> _old_to_new = source_initialized ? source.MyFactSpace.Keys.ToDictionary(id => id) : new(); @@ -340,6 +342,9 @@ public static T ReInitializeFactOrganizer<T>(T source, bool invoke, out Dictiona foreach (var element in source.ImmutableFacts) { Fact ExposedFact = ReInitializeFact(element); + if (ExposedFact == null) + continue; + target.Add(ExposedFact, out _, false, null, null, isImmutable: true); } @@ -381,15 +386,15 @@ public static T ReInitializeFactOrganizer<T>(T source, bool invoke, out Dictiona target.soft_resetted = source.soft_resetted; - //if(not_from_JSON) - // source.Dispose(); + if (!source_initialized) + source.Dispose(); old_to_new = _old_to_new; return target; Fact ReInitializeFact(string old_id) { - if (not_from_JSON) + if (source_initialized) return source.MyFactSpace[old_id]; // is in GlobalFactDictionary.Facts if (_old_to_new.TryGetValue(old_id, out string newId)) @@ -397,9 +402,10 @@ Fact ReInitializeFact(string old_id) Fact old_Fact = source.JsonFactSpace[old_id]; - if (!old_Fact.getDependentFactIds().All(id => _old_to_new.ContainsKey(id))) + if (!old_Fact.DependentFactIds.All(id => _old_to_new.ContainsKey(id))) { - Debug.LogWarningFormat("Could not Instantiate Immutable Fact: {0}", old_Fact); + Debug.LogWarningFormat("Could not Instantiate Immutable Fact: {0}\n\tTrying to compensate...", old_Fact); + _old_to_new.Add(old_Fact.Id, old_Fact.Id); return null; } @@ -681,7 +687,7 @@ public bool safe_dependencies(string key, out List<string> dependencies) if (dependencies.Remove(Workflow[i].Id) && !Workflow[i].samestep) c_unsafe--; } - else if (this[Workflow[i].Id].getDependentFactIds().Intersect(dependencies).Any() && Workflow[i].Id != key) + else if (this[Workflow[i].Id].DependentFactIds.Intersect(dependencies).Any() && Workflow[i].Id != key) { dependencies.Add(Workflow[i].Id); if (!Workflow[i].samestep) diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs index 7842c2fb351e194b5cb16fa5bb31fc518bcf37db..e5d6616a396103318965bf3206ea15229e0de347 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs @@ -57,8 +57,8 @@ public void SpawnAttachedPositionFunction(AttachedPositionFunction fact) public void SpawnPoint(PointFact fact) { GameObject point = GameObject.Instantiate(Sphere); - point.transform.position = fact.Point; - point.transform.up = fact.Normal; + point.transform.position = fact.Position; + point.transform.rotation = fact.Rotation; point.GetComponentInChildren<TextMeshPro>().text = fact.Label; point.GetComponent<FactObject>().URI = fact.Id; fact.Representation = point; diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs index 6ca83aba2fe6b569d9d9b854f8d690a59734b6db..1bbd20d5a691dab3537270e65ededdc4ea99ad11 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs @@ -48,8 +48,6 @@ protected AbstractAngleFact(string pid1, string pid2, string pid3, FactOrganizer this.Pid1 = pid1; this.Pid2 = pid2; this.Pid3 = pid3; - - RecalculateTransform(); } /// <summary>\copydoc AbstractAngleFact.AbstractAngleFact(string, string, string, FactOrganizer)</summary> @@ -61,12 +59,13 @@ protected AbstractAngleFact(string pid1, string pid2, string pid3, float angle, } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Pid1, Pid2, Pid3 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Pid1, Pid2, Pid3 }; + } protected override void RecalculateTransform() { diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs index c3d20f97460abd86444a2b346738f8679ec3ef75..1f0242fbb6f310d5156d7f4d7ccff1261169b9af 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs @@ -75,8 +75,6 @@ private void set_public_members(string pid1, string pid2) Vector3 diff = (Point1.Point - Point2.Point); this.Dir = diff.normalized; this.Distance = diff.magnitude; - - RecalculateTransform(); } protected override void RecalculateTransform() @@ -87,12 +85,13 @@ protected override void RecalculateTransform() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Pid1, Pid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Pid1, Pid2 }; + } } /// <summary> diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs index f4ab7d9392561972a6e88ccc78e74e3ca34c7cf8..d1a9576e7c9ac8d3ee1141f46932c9fba61250ed 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs @@ -128,7 +128,7 @@ public static bool sendAdd(string path, string body, out string uri) [JsonSubtypes.KnownSubType(typeof(EqualCirclesFact), nameof(EqualCirclesFact))] [JsonSubtypes.KnownSubType(typeof(UnEqualCirclesFact), nameof(UnEqualCirclesFact))] [JsonSubtypes.KnownSubType(typeof(AttachedPositionFunction), nameof(AttachedPositionFunction))] -//[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof doesnot work (generic agnostic) +//[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof does not work (generic agnostic) [JsonSubtypes.KnownSubType(typeof(FunctionFact<float, float>), "FunctionFact<System.Single, System.Single>")] [JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")] public abstract class Fact @@ -154,6 +154,19 @@ public abstract class Fact [JsonProperty] protected string s_type; + /// <returns><see langword="true"/> if Fact depends on other \ref Fact "Facts"; equivalent to <see cref="getDependentFactIds"/> returns non empty array</returns> + [JsonIgnore] + public abstract bool HasDependentFacts { get; } + + /// <returns> array of Fact <see cref="Id"> Ids </see> on which this Fact depends.</returns> + /// <example><see cref="AngleFact"/> needs 3 <see cref="PointFact"/>s to be defined.</example> + public string[] DependentFactIds => _DependentFactIds ??= GetGetDependentFactIds(); + private string[] _DependentFactIds; + + /// <returns> array of Fact <see cref="Id"> Ids </see> on which this Fact depends.</returns> + /// <example><see cref="AngleFact"/> needs 3 <see cref="PointFact"/>s to be defined.</example> + protected abstract string[] GetGetDependentFactIds(); + /// <value> /// Unique Id. e.g.: MMT URI /// </value> @@ -342,13 +355,6 @@ public bool rename(string newLabel) } } - /// <returns><see langword="true"/> if Fact depends on other \ref Fact "Facts"; equivalent to <see cref="getDependentFactIds"/> returns non empty array</returns> - public abstract bool hasDependentFacts(); - - /// <returns> array of Fact <see cref="Id"> Ids </see> on which this Fact depends.</returns> - /// <example><see cref="AngleFact"/> needs 3 <see cref="PointFact"/>s to be defined.</example> - public abstract string[] getDependentFactIds(); - /// <summary> /// Initiates a <paramref name="prefab"/> at <paramref name="transform"/> e.g. by setting <see cref="Label"/>. /// </summary> @@ -397,7 +403,7 @@ public bool rename(string newLabel) /// </summary> /// <returns>unique-ish Hash</returns> public new virtual int GetHashCode() - => getDependentFactIds() + => GetGetDependentFactIds() .Select(id => id.GetHashCode()) .Aggregate((hash1, hash2) => hash1 ^ hash2); @@ -481,8 +487,8 @@ public override bool Equivalent(Fact f1, Fact f2) protected abstract bool EquivalentWrapped(T f1, T f2); protected bool DependentFactsEquivalent(T f1, T f2) - => f1.getDependentFactIds() - .Zip(f2.getDependentFactIds(), + => f1.GetGetDependentFactIds() + .Zip(f2.GetGetDependentFactIds(), (id1, id2) => id1.Equals(id2) || FactOrganizer.AllFacts[id1].Equivalent(FactOrganizer.AllFacts[id2]) @@ -498,13 +504,14 @@ public class PointFact : FactWrappedCRTP<PointFact> /// <summary> Position </summary> public Vector3 Point; /// <summary> Orientation for <see cref="Fact.Representation"/> </summary> - public Vector3 Normal; + [JsonProperty] + private Vector3 Normal; /// <summary> \copydoc Fact.Fact </summary> public PointFact() : base() { this.Point = Vector3.zero; - this.Normal = Vector3.zero; + this.Normal = Vector3.up; } /// <summary> @@ -519,14 +526,19 @@ public PointFact(Vector3 P, Vector3 N, FactOrganizer organizer) : base(organizer this.Point = P; this.Normal = N; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } protected override void RecalculateTransform() { Position = Point; - Rotation = Quaternion.LookRotation(Normal); + { // Rotation + Vector3 notNormal = Vector3.forward != Normal ? Vector3.forward : Vector3.up; + Rotation = Quaternion.LookRotation( + Vector3.Cross(Normal, notNormal), + Normal + ); + } } /// <summary> @@ -544,36 +556,32 @@ public PointFact(float a, float b, float c, string uri, FactOrganizer organizer) this.Normal = Vector3.up; this._URI = uri; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) public new static PointFact parseFact(Scroll.ScrollFact fact) { - string uri = fact.@ref.uri; - - OMA df = (OMA)((Scroll.ScrollSymbolFact)fact).df; - if (df == null) + if (((Scroll.ScrollSymbolFact)fact).df is not OMA df) return null; string parse_id = df.ToString(); if (!ParsingDictionary.parseTermsToId.ContainsKey(parse_id)) - ParsingDictionary.parseTermsToId[parse_id] = uri; + ParsingDictionary.parseTermsToId[parse_id] = fact.@ref.uri; float a = ((OMF)df.arguments[0]).f; float b = ((OMF)df.arguments[1]).f; float c = ((OMF)df.arguments[2]).f; - return new PointFact(a, b, c, uri, StageStatic.stage.factState); + return new PointFact(a, b, c, fact.@ref.uri, StageStatic.stage.factState); } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => false; + public override bool HasDependentFacts => false; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -586,7 +594,7 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans /// \copydoc Fact.GetHashCode public override int GetHashCode() - => this.Point.GetHashCode() ^ this.Normal.GetHashCode(); + => this.Point.GetHashCode(); /// \copydoc Fact.Equivalent(Fact, Fact) protected override bool EquivalentWrapped(PointFact f1, PointFact f2) @@ -646,7 +654,6 @@ public OnLineFact(string pid, string rid, FactOrganizer organizer) : base(organi this.Pid = pid; this.Rid = rid; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -654,7 +661,7 @@ protected override void RecalculateTransform() { Position = Point.Position; { //Rotation - Vector3 up = Point.Normal; + Vector3 up = Point.Rotation * Vector3.up; Vector3 forward = Ray.Dir; if (Math3d.IsApproximatelyEqual(up, forward)) @@ -683,8 +690,6 @@ public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) : this.Rid = rid; this._URI = uri; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -712,12 +717,13 @@ protected override string generateLabel() => Point.Label + "∈" + Ray.Label; /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Pid, Rid }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Pid, Rid }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -806,8 +812,6 @@ public ParallelLineFact(string Lid1, string Lid2, string backendURI, FactOrganiz this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -875,12 +879,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Lid1, Lid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Lid1, Lid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -946,7 +951,6 @@ public CircleFact(string pid1, string pid2, float radius, Vector3 normal, FactOr this.radius = radius; this.normal = normal; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -976,8 +980,6 @@ public CircleFact(string Pid1, string Pid2, float radius, Vector3 normal, string this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// <summary> @@ -1090,12 +1092,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Pid1, Pid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Pid1, Pid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1153,7 +1156,6 @@ public OnCircleFact(string pid, string cid, FactOrganizer organizer) : base(orga this.Pid = pid; this.Cid = cid; ; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1176,8 +1178,6 @@ public OnCircleFact(string pid, string cid, string uri, FactOrganizer organizer) this.Cid = cid; this._URI = uri; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1206,12 +1206,13 @@ protected override string generateLabel() => Point.Label + "∈" + Circle.Label; /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Pid, Cid }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Pid, Cid }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1295,7 +1296,6 @@ public AngleCircleLineFact(string cid1, string rid2, FactOrganizer organizer) : this.angle = Math3d.AngleVectorPlane(Ray.Dir, Circle.normal).ToDegrees(); Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position); - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1340,8 +1340,6 @@ public AngleCircleLineFact(string Cid1, string Rid2, float angle, string backend this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1396,12 +1394,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Rid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Rid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1453,7 +1452,6 @@ public RadiusFact(string cid1, FactOrganizer organizer) : base(organizer) this.Cid1 = cid1; this.rad = Circle.radius; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1475,8 +1473,6 @@ public RadiusFact(string Cid1, string backendURI, FactOrganizer organizer) : bas this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1520,12 +1516,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1578,7 +1575,6 @@ public AreaCircleFact(string cid1, FactOrganizer organizer) : base(organizer) this.A = Circle.radius * Circle.radius * ((float)System.Math.PI); - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1600,8 +1596,6 @@ public AreaCircleFact(string Cid1, string backendURI, FactOrganizer organizer) : this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1637,12 +1631,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1706,7 +1701,6 @@ public ConeVolumeFact(string cid1, string pid1, float vol, FactOrganizer organiz this.Pid1 = pid1; this.vol = vol; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1732,8 +1726,6 @@ public ConeVolumeFact(string Cid1, string Pid1, float volume, string backendURI, this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1785,12 +1777,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Pid1 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Pid1 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -1853,7 +1846,6 @@ public OrthogonalCircleLineFact(string cid1, string lid1, FactOrganizer organize this.Lid1 = lid1; Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position); - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -1888,8 +1880,6 @@ public OrthogonalCircleLineFact(string Cid1, string Lid1, string backendURI, Fac this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -1938,12 +1928,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Lid1 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Lid1 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -2019,7 +2010,6 @@ public TruncatedConeVolumeFact(string cid1, string cid2, float vol, string unequ this.unequalCirclesProof = unequalproof; this.vol = vol; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -2048,8 +2038,6 @@ public TruncatedConeVolumeFact(string Cid1, string Cid2, float volume, string un this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -2098,12 +2086,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Cid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Cid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -2172,7 +2161,6 @@ public CylinderVolumeFact(string cid1, string cid2, float vol, string eqProof, O this.equalCirclesProof = eqProof; this.vol = vol; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -2201,8 +2189,6 @@ public CylinderVolumeFact(string Cid1, string Cid2, float volume, string eqProof this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -2250,12 +2236,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Cid2, equalCirclesProof }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Cid2, equalCirclesProof }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -2310,7 +2297,6 @@ public EqualCirclesFact(string cid1, string cid2, FactOrganizer organizer) : bas this.Cid1 = cid1; this.Cid2 = cid2; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -2334,8 +2320,6 @@ public EqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrganiz this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) @@ -2394,12 +2378,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Cid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Cid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -2454,7 +2439,6 @@ public UnEqualCirclesFact(string cid1, string cid2, FactOrganizer organizer) : b this.Cid1 = cid1; this.Cid2 = cid2; - RecalculateTransform(); AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI); } @@ -2478,39 +2462,27 @@ public UnEqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrgan this._URI = backendURI; _ = this.Label; - - RecalculateTransform(); } /// \copydoc Fact.parseFact(Scroll.ScrollFact) public new static UnEqualCirclesFact parseFact(Scroll.ScrollFact fact) { - OMA tp = (OMA)((Scroll.ScrollSymbolFact)fact).tp; - if (tp == null) + if (((Scroll.ScrollSymbolFact)fact).tp is not OMA proof_OMA) // proof DED return null; - string circleAUri = ""; - string circleBUri = ""; - - string uri = fact.@ref.uri; - OMA proof_OMA = (OMA)((Scroll.ScrollSymbolFact)fact).tp; // proof DED - OMA unequal_circles_OMA = (OMA)proof_OMA.arguments[0]; // unequal - if (unequal_circles_OMA.arguments[0] is OMS) - { - // Normaler Fall - circleAUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[0]).uri; - circleBUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).uri; - } + if (unequal_circles_OMA.arguments[0] is not OMS) + return null; - if (StageStatic.stage.factState.ContainsKey(circleAUri) - && StageStatic.stage.factState.ContainsKey(circleBUri)) + string circleAUri = ((OMS)unequal_circles_OMA.arguments[0]).uri; + string circleBUri = ((OMS)unequal_circles_OMA.arguments[1]).uri; - return new UnEqualCirclesFact(circleAUri, circleBUri, uri, StageStatic.stage.factState); + if (!StageStatic.stage.factState.ContainsKey(circleAUri) + || !StageStatic.stage.factState.ContainsKey(circleBUri)) + return null; //If dependent facts do not exist return null - else //If dependent facts do not exist return null - return null; + return new UnEqualCirclesFact(circleAUri, circleBUri, fact.@ref.uri, StageStatic.stage.factState); } /// \copydoc Fact.generateLabel @@ -2534,12 +2506,13 @@ protected override MMTDeclaration MakeMMTDeclaration() } /// \copydoc Fact.hasDependentFacts - public override Boolean hasDependentFacts() - => true; + public override bool HasDependentFacts => true; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { Cid1, Cid2 }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { Cid1, Cid2 }; + } /// \copydoc Fact.instantiateDisplay(GameObject, Transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform) @@ -2632,13 +2605,10 @@ protected override string generateLabel() } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - { - return false; - } + public override bool HasDependentFacts => false; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() + protected override string[] GetGetDependentFactIds() { return new string[] { }; } diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs index 7c39a77a897f1ef67a7a33ad003a45b993844e66..e8cf7a0d32ea688a2ef0f8d3f8ee179ba3847a70 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs @@ -61,7 +61,6 @@ public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, FactOrganizer organ //ParsingDictionary.parseTermsToId[df.ToString()] = _URI; - RecalculateTransform(); return; } @@ -84,8 +83,6 @@ public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, string uri, FactOrg this._URI = uri; _ = this.Label; - - RecalculateTransform(); } protected override void RecalculateTransform() { } @@ -107,12 +104,13 @@ protected override void RecalculateTransform() { } } /// \copydoc Fact.hasDependentFacts - public override bool hasDependentFacts() - => false; + public override bool HasDependentFacts => false; /// \copydoc Fact.getDependentFactIds - public override string[] getDependentFactIds() - => new string[] { }; + protected override string[] GetGetDependentFactIds() + { + return new string[] { }; + } /// \copydoc Fact.GetHashCode public override int GetHashCode() @@ -219,8 +217,6 @@ private void init(string fid, string[] funcids) //TODO: call MMT, set URI _URI = Fact.Id + "{" + string.Join(", ", FunctionFacts.Select(f => f.Id)) + "}"; - - RecalculateTransform(); } protected AttachedPositionFunction(string fid, string[] funcids, string uri, FactOrganizer organizer) : base(organizer) @@ -231,8 +227,6 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac funcids.CopyTo(this.funcids, 0); _URI = uri; - - RecalculateTransform(); } public new static AttachedPositionFunction parseFact(Scroll.ScrollFact fact) @@ -250,7 +244,7 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac return new AttachedPositionFunction(default, default, uri, StageStatic.stage.factState); } - public override string[] getDependentFactIds() + protected override string[] GetGetDependentFactIds() { string[] ret = new string[1 + funcids.Length]; funcids.CopyTo(ret, 1); @@ -262,8 +256,7 @@ public override string[] getDependentFactIds() public override int GetHashCode() => Fact.GetHashCode() ^ FunctionFacts.GetHashCode(); - public override bool hasDependentFacts() - => true; + public override bool HasDependentFacts => true; public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs index ae659dfbddce8be17c19585dc0acb986abe16f5f..d402ccf3858b12bc2728f346a9b3d4f955148ba4 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs @@ -60,7 +60,7 @@ public enum GadgetIDs {typeof(PoleTool) , GadgetIDs.PoleTool }, {typeof(Remover) , GadgetIDs.Remover }, {typeof(EqualCircleGadget) , GadgetIDs.EqualCircles }, - {typeof(TestMiddlePoint), GadgetIDs.MiddlePoint }, + {typeof(TestMiddlePoint) , GadgetIDs.MiddlePoint }, }; /// <summary> Position in tool belt. </summary> @@ -127,7 +127,8 @@ public void Init(bool overrite) if (!GadgetBehaviour.DataContainerGadgetDict.ContainsKey(GadgetID)) { - Debug.LogError("No " + GadgetID.ToString() + " in assigned " + typeof(DataContainerGadgetCollection).Name + "!"); + if(null != GameObject.FindObjectsOfType<GadgetBehaviour>()) + Debug.LogError("No " + GadgetID.ToString() + " in assigned " + typeof(DataContainerGadgetCollection).Name + "!"); return; } var data_cache = GadgetBehaviour.DataContainerGadgetDict[GadgetID]; diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index dd9d1fa6c694d6ab65de4f4a54f4340d261811cb..563ea19856e354abdb89df6ec3147488c3def8ab 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -258,7 +258,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris //If the fact could not be parsed -> Therefore not all dependent Facts exist -> No Hint //AND if fact has no dependent facts -> No Hint - if (currentFact != null && currentFact.hasDependentFacts()) + if (currentFact != null && currentFact.HasDependentFacts) { //Hint available for abstract-problem uri hintUris.Add(currentFact.Id); diff --git a/Assets/Scripts/Loading/Stage.cs b/Assets/Scripts/Loading/Stage.cs index ec8a0dee30a5d54569d522753a5649ef472a1e55..94ca59beadace0833c0fb39e94be84074959386f 100644 --- a/Assets/Scripts/Loading/Stage.cs +++ b/Assets/Scripts/Loading/Stage.cs @@ -560,11 +560,18 @@ public void CopyExposedSolutionFacts(Stage mother) bool invoke_old = factState.invoke; factState.invoke = false; - foreach (string efURI in mother.solution.ExposedSolutionFacts) + Queue<string> IDs = new(mother.solution.ExposedSolutionFacts); + while (IDs.Count > 0) + { + string ID = IDs.Dequeue(); + foreach (string childID in mother.solution[ID].DependentFactIds) + IDs.Enqueue(childID); + factState.Add( - mother.solution[efURI], out _, - mother.solution.GetWorkflow(mother.solution.GetFactMeta(efURI).workflow_id).samestep, + mother.solution[ID], out _, + mother.solution.GetWorkflow(mother.solution.GetFactMeta(ID).workflow_id).samestep, null, null, isImmutable: true); + } factState.invoke = invoke_old; } diff --git a/Assets/Scripts/UI/FactExplorer/FactExplorer.cs b/Assets/Scripts/UI/FactExplorer/FactExplorer.cs index 78ea5ab520df9ab601cd5e8177631909a267fa76..52776d5a51c7ca00c4d696c076753f162a9a55cd 100644 --- a/Assets/Scripts/UI/FactExplorer/FactExplorer.cs +++ b/Assets/Scripts/UI/FactExplorer/FactExplorer.cs @@ -57,7 +57,7 @@ private List<Fact> GetParentFacts() private List<Fact> GetChildFacts() { - return mainFact.getDependentFactIds().Distinct().Select(factId => FactOrganizer.AllFacts[factId]).ToList(); + return mainFact.DependentFactIds.Distinct().Select(factId => FactOrganizer.AllFacts[factId]).ToList(); } private void UpdateFactExplorerUI()