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

Moved ListFact and TupleFact; BugFix;

BugFix:
+no level reload after GenerateDemoFile
parent b9d6ad0f
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,9 @@
public class GenerateDemoFiles
{
public static void GenerateAll()
{
if (GameObject.FindObjectOfType<GadgetBehaviour>(true) == null)
if (UnityEngine.Object.FindObjectOfType<GadgetBehaviour>(true) == null)
{
Debug.LogError("Cannot GenerateDemoFiles without populated GadgetManager");
return;
......
......@@ -2297,219 +2297,6 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F
=> new UnEqualCirclesFact(old_to_new[this.Cid1], old_to_new[this.Cid2], organizer);
}
/// <summary>
///
/// </summary>
/// <seealso cref="SOMDoc.MakeList(string[], string)"/>
/// <remarks>Needed to refere to lists serverside</remarks>
public class ListFact : FactWrappedCRTP<ListFact>
{
public string[] lids;
public string typeURI;
[JsonIgnore]
public Type ListType
{
get => MMT_OMS_URI.OMS_TO_TYPE[typeURI];
private set => typeURI = MMT_OMS_URI.TYPE_TO_OMS[value];
}
public ListFact() : base()
{
lids = new string[0];
}
public ListFact(string[] lids, Type ListType, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
this.ListType = ListType;
SendToMMT();
}
public ListFact(string[] lids, string typeURI, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
this.typeURI = typeURI;
_URI = backendURI;
}
protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI
&& DependentFactsEquivalent(f1, f2);
public override bool HasDependentFacts
=> true;
protected override string[] GetGetDependentFactIds()
=> lids;
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeList(lids, typeURI);
return new MMTSymbolDeclaration(Label, List.applicant, List.arguments[0]);
}
public static new ListFact parseFact(MMTDeclaration fact)
=> new(parseFactList(fact, out string typeURI).ToArray(), typeURI, fact.@ref.uri, StageStatic.stage.factState);
public static List<string> parseFactList(MMTDeclaration decl, out string typeURI)
{
if (decl is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.type is not OMA listOMA
|| listOMA.arguments[0] is not OMS typeOMS)
{
typeURI = null;
return null;
}
typeURI = typeOMS.uri;
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.Length)
{
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)
{
if (decl is not MMTSymbolDeclaration mMTSymbol)
return null;
List<T> ret = new();
SOMDoc next_element = mMTSymbol.defines;
while (true)
{
if (next_element is not OMA current_element)
return ret;
switch (current_element.arguments.Length)
{
case 2:
ret.Add((current_element.arguments[1].GetLambdaExpression().Compile() as Func<T>)());
next_element = current_element.arguments[0];
break;
case 0:
case 1:
default:
return ret;
}
}
}
protected override void RecalculateTransform() { }
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new ListFact(lids.Select(id => old_to_new[id]).ToArray(), ListType, organizer);
}
/// <summary>
///
/// </summary>
/// <seealso cref="SOMDoc.MakeTupel(SOMDoc[])"/>
/// <remarks>Needed to refere to tupels serverside</remarks>
public class TupelFact : FactWrappedCRTP<TupelFact>
{
public string[] lids = new string[0];
public SOMDoc[] payload = new SOMDoc[0];
public TupelFact() : base() { }
public TupelFact(string[] lids, SOMDoc[] payload, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
SendToMMT();
}
public TupelFact(string[] lids, SOMDoc[] payload, string backendURI, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
_URI = backendURI;
}
private void Init(string[] lids, SOMDoc[] payload)
{
this.lids = lids ?? new string[0];
if (!HasDependentFacts)
{
if (payload.Any(p => p == null))
throw new ArgumentException(nameof(payload) + "must not include null elements iff " + nameof(lids) + " is all nulls or empty!");
this.payload = payload;
}
else
{
this.payload = new SOMDoc[math.max(lids.Length, payload.Length)];
for (int i = 0; i < this.payload.Length; i++)
if (lids[i] != null)
payload[i] = new OMS(lids[i]);
else
if (lids[i] == null && payload[i] == null)
throw new ArgumentException(nameof(lids) + " and " + nameof(payload) + " have to be complementary not null!");
}
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new TupelFact(lids.Select(id => old_to_new[id]).ToArray(), payload, organizer);
public static new TupelFact parseFact(MMTDeclaration fact)
{
if (fact is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.defines is not OMA defineOMA)
{
return null;
}
string[] lids = defineOMA.arguments
.Select(oms => (oms as OMS)?.uri)
.ToArray();
return new(lids, defineOMA.arguments, fact.@ref.uri, StageStatic.stage.factState);
}
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeTupel(payload);
return new MMTSymbolDeclaration(Label, List.applicant, List);
}
protected override string[] GetGetDependentFactIds()
=> lids.Where(lid => lid != null).ToArray();
protected override void RecalculateTransform() { }
protected override bool EquivalentWrapped(TupelFact f1, TupelFact f2)
//=> DependentFactsEquivalent(f1, f2)
=> f1.payload.Length == f2.payload.Length
&& f1.payload
.Zip(f2.payload, (p1, p2) => SOMDoc.Equivalent(p1, p2))
.All(b => b);
}
#pragma warning disable // Testing...
/// TEST FACT
......
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System;
using static SOMDocManager;
/// <summary>
///
/// </summary>
/// <seealso cref="SOMDoc.MakeList(string[], string)"/>
/// <remarks>Needed to refere to lists serverside</remarks>
public class ListFact : FactWrappedCRTP<ListFact>
{
public string[] lids;
public string typeURI;
[JsonIgnore]
public Type ListType
{
get => MMT_OMS_URI.OMS_TO_TYPE[typeURI];
private set => typeURI = MMT_OMS_URI.TYPE_TO_OMS[value];
}
public ListFact() : base()
{
lids = new string[0];
}
public ListFact(string[] lids, Type ListType, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
this.ListType = ListType;
SendToMMT();
}
public ListFact(string[] lids, string typeURI, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.lids = lids;
this.typeURI = typeURI;
_URI = backendURI;
}
protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI
&& DependentFactsEquivalent(f1, f2);
public override bool HasDependentFacts
=> true;
protected override string[] GetGetDependentFactIds()
=> lids;
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeList(lids, typeURI);
return new MMTSymbolDeclaration(Label, List.applicant, List.arguments[0]);
}
public static new ListFact parseFact(MMTDeclaration fact)
=> new(parseFactList(fact, out string typeURI).ToArray(), typeURI, fact.@ref.uri, StageStatic.stage.factState);
public static List<string> parseFactList(MMTDeclaration decl, out string typeURI)
{
if (decl is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.type is not OMA listOMA
|| listOMA.arguments[0] is not OMS typeOMS)
{
typeURI = null;
return null;
}
typeURI = typeOMS.uri;
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.Length)
{
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)
{
if (decl is not MMTSymbolDeclaration mMTSymbol)
return null;
List<T> ret = new();
SOMDoc next_element = mMTSymbol.defines;
while (true)
{
if (next_element is not OMA current_element)
return ret;
switch (current_element.arguments.Length)
{
case 2:
ret.Add((current_element.arguments[1].GetLambdaExpression().Compile() as Func<T>)());
next_element = current_element.arguments[0];
break;
case 0:
case 1:
default:
return ret;
}
}
}
protected override void RecalculateTransform() { }
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new ListFact(lids.Select(id => old_to_new[id]).ToArray(), ListType, organizer);
}
/// <summary>
///
/// </summary>
/// <seealso cref="SOMDoc.MakeTupel(SOMDoc[])"/>
/// <remarks>Needed to refere to tupels serverside</remarks>
public class TupelFact : FactWrappedCRTP<TupelFact>
{
public string[] lids = new string[0];
public SOMDoc[] payload = new SOMDoc[0];
public TupelFact() : base() { }
public TupelFact(string[] lids, SOMDoc[] payload, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
SendToMMT();
}
public TupelFact(string[] lids, SOMDoc[] payload, string backendURI, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
_URI = backendURI;
}
private void Init(string[] lids, SOMDoc[] payload)
{
this.lids = lids ?? new string[0];
if (!HasDependentFacts)
{
if (payload.Any(p => p == null))
throw new ArgumentException(nameof(payload) + "must not include null elements iff " + nameof(lids) + " is all nulls or empty!");
this.payload = payload;
}
else
{
this.payload = new SOMDoc[Unity.Mathematics.math.max(lids.Length, payload.Length)];
for (int i = 0; i < this.payload.Length; i++)
if (lids[i] != null)
payload[i] = new OMS(lids[i]);
else
if (lids[i] == null && payload[i] == null)
throw new ArgumentException(nameof(lids) + " and " + nameof(payload) + " have to be complementary not null!");
}
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new TupelFact(lids.Select(id => old_to_new[id]).ToArray(), payload, organizer);
public static new TupelFact parseFact(MMTDeclaration fact)
{
if (fact is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.defines is not OMA defineOMA)
{
return null;
}
string[] lids = defineOMA.arguments
.Select(oms => (oms as OMS)?.uri)
.ToArray();
return new(lids, defineOMA.arguments, fact.@ref.uri, StageStatic.stage.factState);
}
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeTupel(payload);
return new MMTSymbolDeclaration(Label, List.applicant, List);
}
protected override string[] GetGetDependentFactIds()
=> lids.Where(lid => lid != null).ToArray();
protected override void RecalculateTransform() { }
protected override bool EquivalentWrapped(TupelFact f1, TupelFact f2)
//=> DependentFactsEquivalent(f1, f2)
=> f1.payload.Length == f2.payload.Length
&& f1.payload
.Zip(f2.payload, (p1, p2) => SOMDoc.Equivalent(p1, p2))
.All(b => b);
}
\ No newline at end of file
fileFormatVersion: 2
guid: 1310c9354caf7604dbd787fc4e90899f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -23,7 +23,7 @@ private void OnDestroy()
{
StageStatic.SetMode(Mode.Play); // no Mode.Create
// StageStatic.stage.solution.hardreset(invoke_event: false); NO! keep in memory!
StageStatic.stage.factState.hardreset(invoke_event: false);
StageStatic.stage?.factState.hardreset(invoke_event: false);
}
/// <summary>
......
......@@ -56,7 +56,7 @@ public static class StageStatic
/// </summary>
public static Stage stage {
get {
return (local_stage ? StageLocal : StageOfficial)[current_name];
return (local_stage ? StageLocal : StageOfficial)?[current_name];
}
set {
current_name = value.name;
......
......@@ -15,16 +15,16 @@ public abstract class ListLoader<T> : MenueLoader
protected void OnEnable()
{
// To measure correct timings, uncomment
//StartCoroutine(_Init());
StartCoroutine(_Init());
System.Collections.IEnumerator _Init()
{
yield return new WaitForFixedUpdate();
//System.Collections.IEnumerator _Init()
//{
// yield return new WaitForFixedUpdate();
Clear();
Init();
}
//}
}
protected void OnDisable()
......
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