Skip to content
Snippets Groups Projects
Commit e7ac1ce0 authored by MaZiFAU's avatar MaZiFAU
Browse files

HotFix; Bug Fix; +ListFact;

ListFact:
+Intrduction, needed for lists on MMT server side
+Incomplete
+-> see SOMDocManager.MMT_OMS_URI.FactRef
Bug Fix:
+Fact Ordering was broken
+ScrollFactContainer marked as IsSet wrongly
+Angle Hint showed up with 0°
HotFix;
+Game Crash when Scrolls not loaded
+-> patched with guard clausel (pls find better way)
parent bed13c1c
No related branches found
No related tags found
No related merge requests found
...@@ -234,6 +234,11 @@ public static void GenerateCanonBallStage() ...@@ -234,6 +234,11 @@ public static void GenerateCanonBallStage()
} }
// Set Solution // Set Solution
StageStatic.stage.solution.Add( // for CannonBallScroll
new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), StageStatic.stage.solution),
out bool _, true, null, null
);
string BallURI = StageStatic.stage.solution.Add( string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up, StageStatic.stage.solution), new PointFact(StartPos, Vector3.up, StageStatic.stage.solution),
out _, false, null, null); out _, false, null, null);
......
...@@ -46,12 +46,11 @@ public string ScrollFactLabel ...@@ -46,12 +46,11 @@ public string ScrollFactLabel
protected override void FactUpdated() protected override void FactUpdated()
{ {
_URI ??= ScrollFactURI;
Destroy(_Payload); Destroy(_Payload);
NewAssignmentEvent.Invoke(); NewAssignmentEvent.Invoke();
_URI ??= ScrollFactURI;
if (VerboseURI) if (VerboseURI)
Debug.Log(nameof(RenderedScrollFact) + " recieved Fact: " + URI); Debug.Log(nameof(RenderedScrollFact) + " recieved Fact: " + URI);
} }
......
...@@ -54,7 +54,9 @@ protected AbstractAngleFact(string pid1, string pid2, string pid3, FactOrganizer ...@@ -54,7 +54,9 @@ protected AbstractAngleFact(string pid1, string pid2, string pid3, FactOrganizer
protected AbstractAngleFact(string pid1, string pid2, string pid3, float angle, string backendURI, FactOrganizer organizer) protected AbstractAngleFact(string pid1, string pid2, string pid3, float angle, string backendURI, FactOrganizer organizer)
: this(pid1, pid2, pid3, organizer) : this(pid1, pid2, pid3, organizer)
{ {
this.angle = angle; this.angle = angle == -0f
? Vector3.Angle((Point1.Point - Point2.Point), (Point3.Point - Point2.Point))
: angle;
this._URI = backendURI; this._URI = backendURI;
} }
...@@ -175,7 +177,7 @@ public override MMTDeclaration MakeMMTDeclaration() ...@@ -175,7 +177,7 @@ public override MMTDeclaration MakeMMTDeclaration()
return null; return null;
float angle = value_fact.value == null float angle = value_fact.value == null
? 0f ? -0f
: ((OMF)value_fact.value).@float; : ((OMF)value_fact.value).@float;
string pointAUri = ((OMS)lhs.arguments[0]).uri; string pointAUri = ((OMS)lhs.arguments[0]).uri;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
using JsonSubTypes; using JsonSubTypes;
using System.Linq; using System.Linq;
using static SOMDocManager; using static SOMDocManager;
using System.Collections;
using static Scroll; using static Scroll;
public static class ParsingDictionary public static class ParsingDictionary
...@@ -57,6 +56,8 @@ public static class ParsingDictionary ...@@ -57,6 +56,8 @@ public static class ParsingDictionary
EqualCirclesFact.parseFact }, EqualCirclesFact.parseFact },
{ MMT_OMS_URI.UnEqualityCircles, { MMT_OMS_URI.UnEqualityCircles,
UnEqualCirclesFact.parseFact }, UnEqualCirclesFact.parseFact },
{ MMT_OMS_URI.ListLiteral,
ListFact.parseFact },
}; };
// TODO: get rid of this // TODO: get rid of this
...@@ -90,6 +91,7 @@ public static class ParsingDictionary ...@@ -90,6 +91,7 @@ public static class ParsingDictionary
[JsonSubtypes.KnownSubType(typeof(AttachedPositionFunction), nameof(AttachedPositionFunction))] [JsonSubtypes.KnownSubType(typeof(AttachedPositionFunction), nameof(AttachedPositionFunction))]
[JsonSubtypes.KnownSubType(typeof(FunctionFact), nameof(FunctionFact))] [JsonSubtypes.KnownSubType(typeof(FunctionFact), nameof(FunctionFact))]
[JsonSubtypes.KnownSubType(typeof(FunctionCallFact), nameof(FunctionCallFact))] [JsonSubtypes.KnownSubType(typeof(FunctionCallFact), nameof(FunctionCallFact))]
[JsonSubtypes.KnownSubType(typeof(ListFact), nameof(ListFact))]
//[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof does not work (generic agnostic) //[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof does not work (generic agnostic)
//[JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")] //[JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")]
public abstract class Fact public abstract class Fact
...@@ -2296,20 +2298,38 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F ...@@ -2296,20 +2298,38 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <remarks>Hopefully not needed <see cref="SOMDoc.MakeList(string[], string)"/></remarks> /// <seealso cref="SOMDoc.MakeList(string[], string)"/>
/// <remarks>Needed to refere to lists serverside</remarks>
public class ListFact : FactWrappedCRTP<ListFact> public class ListFact : FactWrappedCRTP<ListFact>
{ {
public string[] lids = new string[0]; public string[] lids;
public string typeURI; //public string typeURI;
//[JsonIgnore]
//public Type type => MMT_OMS_URI.OMS_TO_TYPE[typeURI];
[JsonIgnore]
public Type type => MMT_OMS_URI.OMS_TO_TYPE[typeURI]; public ListFact() : base()
{
lids = new string[0];
}
public ListFact(string[] lids, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
SendToMMT();
}
public ListFact(string[] lids, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
_URI = backendURI;
}
protected override bool EquivalentWrapped(ListFact f1, ListFact f2) protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI => //f1.typeURI == f2.typeURI &&
&& DependentFactsEquivalent(f1, f2); DependentFactsEquivalent(f1, f2);
public override bool HasDependentFacts public override bool HasDependentFacts
=> true; => true;
...@@ -2319,10 +2339,43 @@ protected override string[] GetGetDependentFactIds() ...@@ -2319,10 +2339,43 @@ protected override string[] GetGetDependentFactIds()
public override MMTDeclaration MakeMMTDeclaration() public override MMTDeclaration MakeMMTDeclaration()
{ {
OMA List = SOMDoc.MakeList(lids, typeURI); OMA List = SOMDoc.MakeList(lids, typeof(OMS));
return new MMTSymbolDeclaration(Label, List.applicant, List.applicant); return new MMTSymbolDeclaration(Label, List.applicant, List.applicant);
} }
public static new ListFact parseFact(MMTDeclaration fact)
=> new(parseFactList(fact).ToArray(), fact.@ref.uri, StageStatic.stage.factState);
public static List<string> parseFactList(MMTDeclaration decl)
{
if (decl is not MMTSymbolDeclaration mMTSymbol)
return null;
List<string> ret = new();
SOMDoc next_element = mMTSymbol.defines;
while (true)
{
if (next_element is not OMA current_element)
return ret;
switch (current_element.arguments.Count)
{
case 2:
if (current_element.arguments[1] is not OMS oMS)
return ret;
ret.Add(oMS.uri);
next_element = current_element.arguments[0];
break;
case 0:
case 1:
default:
return ret;
}
}
}
public static List<T> parseFactList<T>(MMTDeclaration decl) public static List<T> parseFactList<T>(MMTDeclaration decl)
{ {
if (decl is not MMTSymbolDeclaration mMTSymbol) if (decl is not MMTSymbolDeclaration mMTSymbol)
......
...@@ -183,14 +183,20 @@ public class AttachedPositionFunction : FactWrappedCRTP<AttachedPositionFunction ...@@ -183,14 +183,20 @@ public class AttachedPositionFunction : FactWrappedCRTP<AttachedPositionFunction
{ {
public string fid; public string fid;
public string[] func_call_ids; public string func_calls_list_id;
[JsonIgnore]
public string[] FuncCallIds => FunctionCallFactsList.lids;
[JsonIgnore] [JsonIgnore]
public Fact Fact => FactOrganizer.AllFacts[fid]; public Fact Fact => FactOrganizer.AllFacts[fid];
[JsonIgnore]
public ListFact FunctionCallFactsList => (ListFact) FactOrganizer.AllFacts[func_calls_list_id];
[JsonIgnore] [JsonIgnore]
public FunctionCallFact[] FunctionCallFacts public FunctionCallFact[] FunctionCallFacts
=> func_call_ids.Select(f => FactOrganizer.AllFacts[f] as FunctionCallFact).ToArray(); => FuncCallIds.Select(f => FactOrganizer.AllFacts[f] as FunctionCallFact).ToArray();
/// <summary>\copydoc Fact.Fact()</summary> /// <summary>\copydoc Fact.Fact()</summary>
public AttachedPositionFunction() : base() { } public AttachedPositionFunction() : base() { }
...@@ -198,21 +204,40 @@ public AttachedPositionFunction() : base() { } ...@@ -198,21 +204,40 @@ public AttachedPositionFunction() : base() { }
/// <summary>\copydoc Fact.Fact(FactOrganizer)</summary> /// <summary>\copydoc Fact.Fact(FactOrganizer)</summary>
public AttachedPositionFunction(string fid, string[] funcids, FactOrganizer organizer) : base(organizer) public AttachedPositionFunction(string fid, string[] funcids, FactOrganizer organizer) : base(organizer)
{ {
init(fid, funcids); init(fid, funcids, organizer);
//TODO: call MMT, set URI
_URI = Fact.Id + "{" + string.Join(", ", FunctionCallFacts.Select(f => f.Id)) + "}";
}
/// <summary>\copydoc Fact.Fact(FactOrganizer)</summary>
public AttachedPositionFunction(string fid, string func_calls_list_id, FactOrganizer organizer) : base(organizer)
{
init(fid, func_calls_list_id);
//TODO: call MMT, set URI //TODO: call MMT, set URI
_URI = Fact.Id + "{" + string.Join(", ", FunctionCallFacts.Select(f => f.Id)) + "}"; _URI = Fact.Id + "{" + string.Join(", ", FunctionCallFacts.Select(f => f.Id)) + "}";
} }
private void init(string fid, string[] funcids) private void init(string fid, string[] funcids, FactOrganizer organizer)
{
this.fid = fid;
func_calls_list_id = organizer.Add(new ListFact(funcids, organizer), out bool _, false, null, null);
}
private void init(string fid, string func_calls_list_id)
{ {
this.fid = fid; this.fid = fid;
this.func_call_ids = funcids; this.func_calls_list_id = func_calls_list_id;
} }
protected AttachedPositionFunction(string fid, string[] funcids, string uri, FactOrganizer organizer) : base(organizer) protected AttachedPositionFunction(string fid, string[] funcids, string uri, FactOrganizer organizer) : base(organizer)
{ {
init(fid, funcids); init(fid, funcids, organizer);
_URI = uri;
}
protected AttachedPositionFunction(string fid, string func_calls_list_id, string uri, FactOrganizer organizer) : base(organizer)
{
init(fid, func_calls_list_id);
_URI = uri; _URI = uri;
} }
...@@ -223,14 +248,15 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac ...@@ -223,14 +248,15 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac
ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri); ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri);
return new AttachedPositionFunction(default, default, fact.@ref.uri, StageStatic.stage.factState); return new AttachedPositionFunction(default, default(string), fact.@ref.uri, StageStatic.stage.factState);
} }
public override bool HasDependentFacts public override bool HasDependentFacts
=> true; => true;
protected override string[] GetGetDependentFactIds() protected override string[] GetGetDependentFactIds()
=> new string[] { fid }.ShallowCloneAppend(func_call_ids); => new string[] { fid, func_calls_list_id };
public override int GetHashCode() public override int GetHashCode()
=> Fact.GetHashCode() ^ FunctionCallFacts.GetHashCode(); => Fact.GetHashCode() ^ FunctionCallFacts.GetHashCode();
...@@ -246,7 +272,8 @@ protected override void RecalculateTransform() ...@@ -246,7 +272,8 @@ protected override void RecalculateTransform()
} }
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new AttachedPositionFunction(old_to_new[this.fid], this.func_call_ids.Select(id => old_to_new[id]).ToArray(), organizer); => new AttachedPositionFunction(old_to_new[this.fid], old_to_new[func_calls_list_id], organizer);
// => new AttachedPositionFunction(old_to_new[this.fid], this.FuncCallIds.Select(id => old_to_new[id]).ToArray(), organizer);
public override MMTDeclaration MakeMMTDeclaration() public override MMTDeclaration MakeMMTDeclaration()
{ {
......
...@@ -154,7 +154,7 @@ public static GameObject InstantiateDisplay(Fact fact, Transform transform) ...@@ -154,7 +154,7 @@ public static GameObject InstantiateDisplay(Fact fact, Transform transform)
#region AscDesc #region AscDesc
public void AscDescChanged(Toggle t) public void AscDescChanged(Toggle t)
{ {
sortDescending = !sortDescending; sortDescending = !sortDescending; // t.isOn
factscreenContent.gameObject.ForAllChildren(child => child.transform.SetAsFirstSibling()); factscreenContent.gameObject.ForAllChildren(child => child.transform.SetAsFirstSibling());
} }
#endregion AscDesc #endregion AscDesc
...@@ -165,9 +165,14 @@ public void GroupingChanged(Toggle t) ...@@ -165,9 +165,14 @@ public void GroupingChanged(Toggle t)
showGrouped = t.isOn; showGrouped = t.isOn;
var vals = factscreenContent.gameObject.GetDirectChildren(); var vals = factscreenContent.gameObject.GetDirectChildren();
var ordered = showGrouped var ordered = showGrouped
? vals.OrderBy(tr => tr.GetComponent<FactObject>().Fact, new FactTypeComparer()).ToList() ? vals.OrderBy(tr => tr.GetComponent<FactWrapper>().Fact, new FactTypeComparer()).ToList()
: vals.OrderBy(tr => displayedFacts.Keys.ToList().IndexOf(tr.GetComponent<FactObject>().Fact.Id)).ToList(); : vals.OrderBy(tr =>
displayedFacts.Keys.ToList()
.IndexOf(
tr.GetComponent<FactWrapper>().URI
)).ToList();
if (sortDescending) if (sortDescending)
ordered.Reverse(); ordered.Reverse();
...@@ -183,7 +188,7 @@ private int GetIndexInSortedList(Fact f, List<Fact> toCheck) ...@@ -183,7 +188,7 @@ private int GetIndexInSortedList(Fact f, List<Fact> toCheck)
return index; return index;
} }
internal class FactTypeComparer : IComparer<Fact> private class FactTypeComparer : IComparer<Fact>
{ {
/// <summary> /// <summary>
/// Compare two facts by type and label /// Compare two facts by type and label
...@@ -193,11 +198,58 @@ internal class FactTypeComparer : IComparer<Fact> ...@@ -193,11 +198,58 @@ internal class FactTypeComparer : IComparer<Fact>
/// <returns></returns> /// <returns></returns>
public int Compare(Fact x, Fact y) public int Compare(Fact x, Fact y)
{ {
if (x.GetType() == y.GetType()) // same type: compare labels int ret, index_x;
return string.Compare(x.Label, y.Label);
else // different types: compare type #pragma warning disable CS0642 // Möglicherweise falsche leere Anweisung
return string.Compare(x.GetType().ToString(), y.GetType().ToString());
if (0 != (ret = (index_x = TypeRank.IndexOf(x.GetType())) - TypeRank.IndexOf(y.GetType()))) ;
else
if (index_x < 0) // Types not in List and same
if (0 != (ret = x.DependentFactIds.Length - y.DependentFactIds.Length)) ;
else
if (0 != (ret = string.Compare(x.GetType().ToString(), y.GetType().ToString()))) ;
else;
else if (true) // keep auto format // Types in List and same
if (0 != (ret = x.DependentFactIds.Zip(y.DependentFactIds, (x, y) => string.Compare(x, y)).Aggregate(0, (r1, r2) => r1 + r2))) ;
else
if (0 != (ret = string.Compare(x.Label, y.Label))) ;
#pragma warning restore CS0642 // Möglicherweise falsche leere Anweisung
return ret;
} }
private List<Type> TypeRank = new()
{
typeof(PointFact),
typeof(OnLineFact),
typeof(LineFact),
typeof(RayFact),
typeof(ParallelLineFact),
typeof(RightAngleFact),
typeof(AngleFact),
typeof(CircleFact),
typeof(RadiusFact),
typeof(AreaCircleFact),
typeof(EqualCirclesFact),
typeof(UnEqualCirclesFact),
typeof(OnCircleFact),
typeof(AngleCircleLineFact),
typeof(OrthogonalCircleLineFact),
typeof(CylinderVolumeFact),
typeof(ConeVolumeFact),
typeof(TruncatedConeVolumeFact),
typeof(FunctionFact),
typeof(FunctionCallFact),
typeof(AttachedPositionFunction),
typeof(TestFact),
};
} }
#endregion Grouping #endregion Grouping
#endregion Sorting #endregion Sorting
...@@ -222,9 +274,8 @@ private void OnFavoriteChange(Fact changedFact, bool isFavourite) ...@@ -222,9 +274,8 @@ private void OnFavoriteChange(Fact changedFact, bool isFavourite)
if (!showOnlyFavorites) if (!showOnlyFavorites)
return; return;
var id = changedFact.Id; if (displayedFacts.TryGetValue(changedFact.Id, out GameObject display))
if (displayedFacts.ContainsKey(id)) display.transform.parent.gameObject.SetActive(isFavourite);
displayedFacts[id].transform.parent.gameObject.SetActive(isFavourite);
} }
#endregion Favorites #endregion Favorites
......
...@@ -140,6 +140,11 @@ private int[] PrePopulateActiveScroll() ...@@ -140,6 +140,11 @@ private int[] PrePopulateActiveScroll()
switch (ActiveScroll.@ref) switch (ActiveScroll.@ref)
{ {
case MMT_OMS_URI.ScrollCannonBall: case MMT_OMS_URI.ScrollCannonBall:
string lid_override = StageStatic.stage.solution.MyFactSpace.Values.FirstOrDefault(sol => sol is ListFact)?.Id;
if (lid_override == null)
goto default;
ParameterDisplays[2].URI = lid_override;
return new int[] { 2 }; return new int[] { 2 };
default: default:
......
...@@ -41,6 +41,12 @@ public static bool LoadStage(string name, bool local, bool restore_session) ...@@ -41,6 +41,12 @@ public static bool LoadStage(string name, bool local, bool restore_session)
/// <param name="scene">sets <see cref="nextscene"/></param> /// <param name="scene">sets <see cref="nextscene"/></param>
public static void LoadScene(string scene) public static void LoadScene(string scene)
{ {
if(GlobalBehaviour.AvailableScrolls == null) // Game crashes otherwise
{
Debug.LogWarning("Wait for Server to finish Scroll/all!\nFind a better Way than this guard clause.,,");
return;
}
nextscene = scene; nextscene = scene;
SceneManager.LoadScene("LoadingScene"); SceneManager.LoadScene("LoadingScene");
// loads LoadingScreen, which will call LoaderCallback() in LoadingScreenPercentage // loads LoadingScreen, which will call LoaderCallback() in LoadingScreenPercentage
......
...@@ -59,6 +59,8 @@ public static class MMT_OMS_URI ...@@ -59,6 +59,8 @@ public static class MMT_OMS_URI
public static readonly string ListLiteral = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons"; public static readonly string ListLiteral = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons";
public static readonly string ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant"; public static readonly string ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant";
public static readonly string FactRef = "SET_IN_SOMDocManager!";
public static readonly string Sin = "Sin"; public static readonly string Sin = "Sin";
public static readonly string Cos = "Cos"; public static readonly string Cos = "Cos";
public static readonly string Add = "Add"; public static readonly string Add = "Add";
...@@ -130,6 +132,8 @@ public static class MMT_OMS_URI ...@@ -130,6 +132,8 @@ public static class MMT_OMS_URI
{ UnEqualityCircles, { UnEqualityCircles,
typeof(UnEqualCirclesFact) }, typeof(UnEqualCirclesFact) },
{ FactRef,
typeof(OMS) },
{ RealLit, { RealLit,
typeof(float) }, typeof(float) },
{ Tuple, { Tuple,
......
...@@ -24,15 +24,15 @@ public static void SetActiveAllChildren(this GameObject root, bool active) ...@@ -24,15 +24,15 @@ public static void SetActiveAllChildren(this GameObject root, bool active)
public static void ForAllChildren(this GameObject root, Action<GameObject> func_on_child) public static void ForAllChildren(this GameObject root, Action<GameObject> func_on_child)
{ {
for (int i = 0; i < root.transform.childCount; i++) foreach (Transform transform in root.transform)
func_on_child(root.transform.GetChild(i).gameObject); func_on_child(transform.gameObject);
} }
public static List<GameObject> GetDirectChildren(this GameObject root) public static List<GameObject> GetDirectChildren(this GameObject root)
{ {
List<GameObject> ret = new (capacity: root.transform.childCount); List<GameObject> ret = new (capacity: root.transform.childCount);
foreach (GameObject child in root.transform) foreach (Transform transform in root.transform)
ret.Add(child); ret.Add(transform.gameObject);
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment