Skip to content
Snippets Groups Projects
Commit b1d7e508 authored by Marco Zimmer's avatar Marco Zimmer
Browse files

+FactOrganizer: hid FactDict +Facts: re-renamed URI to Id, enabled persistend,...

+FactOrganizer: hid FactDict +Facts: re-renamed URI to Id, enabled persistend, generated and compact LabelNamingSpace
parent f50302c5
No related branches found
No related tags found
No related merge requests found
Showing
with 154 additions and 147 deletions
...@@ -31,6 +31,8 @@ public class TaskCharakterAnimation : MonoBehaviour ...@@ -31,6 +31,8 @@ public class TaskCharakterAnimation : MonoBehaviour
private float happyTime = 7.5f; private float happyTime = 7.5f;
private static bool playerInTalkingZone = false; private static bool playerInTalkingZone = false;
// TODO: Level Reset doesn't reset this?
private static bool taskCharacterAddressed = false; private static bool taskCharacterAddressed = false;
......
...@@ -82,36 +82,55 @@ public abstract class Fact ...@@ -82,36 +82,55 @@ public abstract class Fact
{ {
public GameObject Representation; public GameObject Representation;
public string URI { get { return _URI; } } public string Id { get { return _URI; } }
protected string _URI; protected string _URI;
public string Label;
public string Label {
get { // in case of renamed dependables
return string.IsNullOrEmpty(_CustomLabel) ?
generateLabel() :
_CustomLabel;
}
}
protected string _CustomLabel = null;
private int LabelId = 0;
protected FactOrganizer _Facts; protected FactOrganizer _Facts;
private static int LabelId = 0; private static int MaxLabelId = 0;
private static SortedSet<int> UnusedLabelIds = new SortedSet<int>();
protected Fact(FactOrganizer organizer) protected Fact(FactOrganizer organizer)
{ {
this._Facts = organizer; this._Facts = organizer;
} }
//TODO: notify about updated dependable Labelnames
public void rename(string newLabel) public void rename(string newLabel)
{ {
this.Label = newLabel; if (_Facts.ContainsLabel(newLabel))
return;
freeLabel();
_CustomLabel = newLabel;
} }
//If FactType depends on other Facts, e.g. AngleFacts depend on 3 PointFacts //If FactType depends on other Facts, e.g. AngleFacts depend on 3 PointFacts
public abstract Boolean hasDependentFacts(); public abstract bool hasDependentFacts();
public abstract string[] getDependentFactIds(); public abstract string[] getDependentFactIds();
public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform); public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform);
public virtual void delete() public virtual void delete(bool keep_clean = true)
{ {
//TODO: MMT: delete over there //TODO: MMT: delete over there
if (keep_clean)
freeLabel();
if (VerboseURI) if (VerboseURI)
Debug.Log("Server removed Fact:\n" + this.URI); Debug.Log("Server removed Fact:\n" + this.Id);
} }
public abstract bool Equivalent(Fact f2); public abstract bool Equivalent(Fact f2);
...@@ -120,26 +139,39 @@ public virtual void delete() ...@@ -120,26 +139,39 @@ public virtual void delete()
public abstract override int GetHashCode(); public abstract override int GetHashCode();
protected abstract string generateLabel(); // TODO? only get _Fact to freeLabel/
public void freeLabel()
// TODO: "ID"/ Letter Management {
protected string generateLetter() if (LabelId > 0)
{ {
return ((char)(64 + LabelId++ + 1)).ToString(); UnusedLabelIds.Add(LabelId);
// store Label for name-persistance
LabelId = -LabelId;
}
if (!string.IsNullOrEmpty(_CustomLabel))
_CustomLabel = null;
}
/* Keeping track of free Ids protected virtual string generateLabel()
private static List<int> NextEmpties = new List<int>(); {
NextEmpties.Add(LabelId++); if (LabelId == 0)
if (UnusedLabelIds.Count == 0)
LabelId = ++MaxLabelId;
else
{
LabelId = UnusedLabelIds.Min;
UnusedLabelIds.Remove(LabelId);
}
public int GetFirstEmptyID() else if (LabelId < 0)
// reload Label if possible
{ {
NextEmpties.Sort(); LabelId = -LabelId;
UnusedLabelIds.Remove(LabelId);
}
int id = NextEmpties[0]; return ((char)(64 + LabelId)).ToString();
NextEmpties.RemoveAt(0);
if (NextEmpties.Count == 0)
NextEmpties.Add(LabelId++);
}*/
} }
} }
...@@ -186,7 +218,6 @@ private void set_public_members(string pid1, string pid2) ...@@ -186,7 +218,6 @@ private void set_public_members(string pid1, string pid2)
{ {
this.Pid1 = pid1; this.Pid1 = pid1;
this.Pid2 = pid2; this.Pid2 = pid2;
this.Label = generateLabel();
PointFact pf1 = _Facts[pid1] as PointFact; PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact; PointFact pf2 = _Facts[pid2] as PointFact;
this.Dir = (pf2.Point - pf1.Point).normalized; this.Dir = (pf2.Point - pf1.Point).normalized;
...@@ -237,7 +268,6 @@ public PointFact(Vector3 P, Vector3 N, FactOrganizer organizer) : base(organizer ...@@ -237,7 +268,6 @@ public PointFact(Vector3 P, Vector3 N, FactOrganizer organizer) : base(organizer
{ {
this.Point = P; this.Point = P;
this.Normal = N; this.Normal = N;
this.Label = generateLabel();
List<MMTTerm> arguments = new List<MMTTerm> List<MMTTerm> arguments = new List<MMTTerm>
{ {
...@@ -259,7 +289,6 @@ public PointFact(float a, float b, float c, string uri, FactOrganizer organizer) ...@@ -259,7 +289,6 @@ public PointFact(float a, float b, float c, string uri, FactOrganizer organizer)
{ {
this.Point = new Vector3(a, b, c); this.Point = new Vector3(a, b, c);
this.Normal = new Vector3(0, 1, 0); this.Normal = new Vector3(0, 1, 0);
this.Label = generateLabel();
this._URI = uri; this._URI = uri;
} }
...@@ -278,11 +307,6 @@ public static PointFact parseFact(Scroll.ScrollFact fact) { ...@@ -278,11 +307,6 @@ public static PointFact parseFact(Scroll.ScrollFact fact) {
} }
} }
protected override string generateLabel()
{
return generateLetter();
}
public override Boolean hasDependentFacts() { public override Boolean hasDependentFacts() {
return false; return false;
} }
...@@ -326,8 +350,8 @@ public LineFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, ...@@ -326,8 +350,8 @@ public LineFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1,
PointFact pf1 = _Facts[pid1] as PointFact; PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact; PointFact pf2 = _Facts[pid2] as PointFact;
string p1URI = pf1.URI; string p1URI = pf1.Id;
string p2URI = pf2.URI; string p2URI = pf2.Id;
float v = (pf1.Point - pf2.Point).magnitude; float v = (pf1.Point - pf2.Point).magnitude;
MMTTerm lhs = MMTTerm lhs =
...@@ -406,8 +430,8 @@ public RayFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, p ...@@ -406,8 +430,8 @@ public RayFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, p
PointFact pf1 = _Facts[pid1] as PointFact; PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact; PointFact pf2 = _Facts[pid2] as PointFact;
string p1URI = pf1.URI; string p1URI = pf1.Id;
string p2URI = pf2.URI; string p2URI = pf2.Id;
List<MMTTerm> arguments = new List<MMTTerm> List<MMTTerm> arguments = new List<MMTTerm>
{ {
...@@ -449,7 +473,6 @@ protected override string generateLabel() ...@@ -449,7 +473,6 @@ protected override string generateLabel()
public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { public override GameObject instantiateDisplay(GameObject prefab, Transform transform) {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.Label; obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.Label;
//obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts2[f.Pid2].Id);
obj.GetComponent<FactWrapper>().fact = this; obj.GetComponent<FactWrapper>().fact = this;
return obj; return obj;
} }
...@@ -477,12 +500,11 @@ public OnLineFact(string pid, string rid, FactOrganizer organizer) : base(organi ...@@ -477,12 +500,11 @@ public OnLineFact(string pid, string rid, FactOrganizer organizer) : base(organi
{ {
this.Pid = pid; this.Pid = pid;
this.Rid = rid; this.Rid = rid;
this.Label = generateLabel();
PointFact pf = _Facts[pid] as PointFact; PointFact pf = _Facts[pid] as PointFact;
RayFact rf = _Facts[rid] as RayFact; RayFact rf = _Facts[rid] as RayFact;
string pURI = pf.URI; string pURI = pf.Id;
string rURI = rf.URI; string rURI = rf.Id;
List<MMTTerm> innerArguments = new List<MMTTerm> List<MMTTerm> innerArguments = new List<MMTTerm>
{ {
...@@ -508,7 +530,6 @@ public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) : ...@@ -508,7 +530,6 @@ public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) :
{ {
this.Pid = pid; this.Pid = pid;
this.Rid = rid; this.Rid = rid;
this.Label = generateLabel();
this._URI = uri; this._URI = uri;
} }
...@@ -586,12 +607,11 @@ public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer) ...@@ -586,12 +607,11 @@ public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer)
PointFact pf3 = _Facts[pid3] as PointFact; PointFact pf3 = _Facts[pid3] as PointFact;
float v = GetAngle(); // sets is_right_angle float v = GetAngle(); // sets is_right_angle
this.Label = generateLabel(); //needs is_right_angle
MMTDeclaration mmtDecl; MMTDeclaration mmtDecl;
string p1URI = pf1.URI; string p1URI = pf1.Id;
string p2URI = pf2.URI; string p2URI = pf2.Id;
string p3URI = pf3.URI; string p3URI = pf3.Id;
if (is_right_angle) if (is_right_angle)
mmtDecl = generate90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI); mmtDecl = generate90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI);
else else
...@@ -607,7 +627,6 @@ public AngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactO ...@@ -607,7 +627,6 @@ public AngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactO
this.Pid3 = Pid3; this.Pid3 = Pid3;
GetAngle(); GetAngle();
this.Label = generateLabel();
this._URI = backendURI; this._URI = backendURI;
} }
......
...@@ -6,7 +6,7 @@ public abstract class FactComparer : EqualityComparer<Fact> ...@@ -6,7 +6,7 @@ public abstract class FactComparer : EqualityComparer<Fact>
{ {
protected bool search_righthanded; protected bool search_righthanded;
protected abstract bool Compare (Fact search, Fact fact); protected abstract bool Compare (Fact solution, Fact fact);
public FactComparer SetSearchRight() public FactComparer SetSearchRight()
{ {
...@@ -26,25 +26,25 @@ public override bool Equals(Fact left, Fact right) ...@@ -26,25 +26,25 @@ public override bool Equals(Fact left, Fact right)
public override int GetHashCode(Fact obj) public override int GetHashCode(Fact obj)
{ {
return 0; //obj.GetHashCode(); return obj.GetType().GetHashCode();
} }
} }
public class FactEquivalentsComparer : FactComparer public class FactEquivalentsComparer : FactComparer
{ {
protected override bool Compare (Fact search, Fact fact) protected override bool Compare (Fact solution, Fact fact)
{ {
return search.Equivalent(fact); return solution.Equivalent(fact);
} }
} }
class LineFactHightDirectionComparer : FactComparer class LineFactHightDirectionComparer : FactComparer
{ {
protected override bool Compare (Fact search, Fact fact) protected override bool Compare (Fact solution, Fact fact)
{ {
return fact is LineFact && search is LineFact return fact is LineFact && solution is LineFact
&& Math3d.IsApproximatelyParallel(((LineFact) fact).Dir, ((LineFact) search).Dir) && Math3d.IsApproximatelyParallel(((LineFact) fact).Dir, ((LineFact) solution).Dir)
&& ((LineFact) fact).Distance + Math3d.vectorPrecission >= ((LineFact) search).Distance; && ((LineFact) fact).Distance + Math3d.vectorPrecission >= ((LineFact) solution).Distance;
// && Mathf.Approximately(((LineFact) x).Distance, ((LineFact) y).Distance); // && Mathf.Approximately(((LineFact) x).Distance, ((LineFact) y).Distance);
} }
} }
...@@ -50,7 +50,7 @@ void AddHitIfOnLine(RaycastHit hit) ...@@ -50,7 +50,7 @@ void AddHitIfOnLine(RaycastHit hit)
{ {
if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position)) if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position))
{ {
AddOnLineFact(hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.URI, true); AddOnLineFact(hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.Id, true);
} }
} }
...@@ -61,8 +61,8 @@ void AddHitIfOnLine(RaycastHit hit) ...@@ -61,8 +61,8 @@ void AddHitIfOnLine(RaycastHit hit)
AddHitIfOnLine(hit); AddHitIfOnLine(hit);
// for good measure // for good measure
AddOnLineFact(rayFact.Pid1, rayFact.URI, true); AddOnLineFact(rayFact.Pid1, rayFact.Id, true);
AddOnLineFact(rayFact.Pid2, rayFact.URI, true); AddOnLineFact(rayFact.Pid2, rayFact.Id, true);
return rayFact; return rayFact;
} }
......
...@@ -4,18 +4,15 @@ ...@@ -4,18 +4,15 @@
using System.Linq; using System.Linq;
//TODO? PERF? (often inserts) SortedDict <-> Dict (often reads) //TODO? PERF? (often inserts) SortedDict <-> Dict (often reads)
//TODO? hide base dict
//TODO: MMT: move some functionality there //TODO: MMT: move some functionality there
//TODO: consequent!= samestep != dependent //TODO: consequent!= samestep != dependent
//PERF: avoid string as key (general: allocations & dict: hash -> colission? -> strcmp[!]) //PERF: avoid string as key (general: allocations & dict: hash -> colission? -> strcmp[!])
[System.Serializable] [System.Serializable]
public class FactOrganizer: Dictionary<string, Fact> public class FactOrganizer
{ {
// InvokeEvents? private Dictionary<string, Fact> FactDict;
private bool invoke;
private Dictionary<string, meta> MetaInf = new Dictionary<string, meta>(); private Dictionary<string, meta> MetaInf = new Dictionary<string, meta>();
private List<stepnote> Workflow = new List<stepnote>(); private List<stepnote> Workflow = new List<stepnote>();
// notes position in Workflow for un-/redo; the pointed to element is non-acitve // notes position in Workflow for un-/redo; the pointed to element is non-acitve
...@@ -25,6 +22,8 @@ public class FactOrganizer: Dictionary<string, Fact> ...@@ -25,6 +22,8 @@ public class FactOrganizer: Dictionary<string, Fact>
private int backlog = 0; private int backlog = 0;
// set if recently been resetted // set if recently been resetted
private bool soft_resetted = false; private bool soft_resetted = false;
// InvokeEvents?
private bool invoke;
private struct stepnote private struct stepnote
{ {
...@@ -74,29 +73,49 @@ public meta(int workflow_id, bool active = true) ...@@ -74,29 +73,49 @@ public meta(int workflow_id, bool active = true)
} }
} }
public FactOrganizer(bool invoke = false) : base() public FactOrganizer(bool invoke = false)
{ {
FactDict = new Dictionary<string, Fact>();
this.invoke = invoke; this.invoke = invoke;
} }
public FactOrganizer(IDictionary<string, Fact> dictionary, bool invoke = false) : base(dictionary) public FactOrganizer(IDictionary<string, Fact> dictionary, bool invoke = false)
{ {
FactDict = new Dictionary<string, Fact>(dictionary);
this.invoke = invoke; this.invoke = invoke;
} }
public Fact this[string id]
{
get{ return FactDict[id]; }
}
public bool ContainsKey(string id)
{
return FactDict.ContainsKey(id);
}
public bool ContainsLabel(string label)
{
if (string.IsNullOrEmpty(label))
return false;
var hit = FactDict.FirstOrDefault(e => e.Value.Label == label);
return !hit.Equals(System.Activator.CreateInstance(hit.GetType()));
}
//TODO? MMT? PERF: O(n), every Fact-insertion //TODO? MMT? PERF: O(n), every Fact-insertion
private bool FindEquivalent(Fact search, out string found, out bool exact) private bool FindEquivalent(Fact search, out string found, out bool exact)
// Looks for existent facts (found) which are very similar to prposed fact (search) // Looks for existent facts (found) which are very similar to prposed fact (search)
// does not check active state // does not check active state
{ {
if (exact = this.ContainsKey(search.URI)) if (exact = FactDict.ContainsKey(search.Id))
{ {
found = search.URI; found = search.Id;
return true; return true;
} }
foreach (var entry in this) foreach (var entry in FactDict)
{ {
if (entry.Value.Equivalent(search)) if (entry.Value.Equivalent(search))
{ {
...@@ -150,7 +169,7 @@ private void PruneWorkflow() ...@@ -150,7 +169,7 @@ private void PruneWorkflow()
// remove for good, if original creation gets pruned // remove for good, if original creation gets pruned
{ {
this[last.Id].delete(); this[last.Id].delete();
base.Remove(last.Id); FactDict.Remove(last.Id);
MetaInf.Remove(last.Id); MetaInf.Remove(last.Id);
} }
} }
...@@ -160,12 +179,6 @@ private void PruneWorkflow() ...@@ -160,12 +179,6 @@ private void PruneWorkflow()
} }
} }
public new void Add(string key, Fact value)
// hide
{
this.Add(value, out _);
}
public string Add(Fact value, out bool exists, bool samestep = false) public string Add(Fact value, out bool exists, bool samestep = false)
// also checks for duplicates and active state // also checks for duplicates and active state
// returns key of actual Fact // returns key of actual Fact
...@@ -192,8 +205,8 @@ public string Add(Fact value, out bool exists, bool samestep = false) ...@@ -192,8 +205,8 @@ public string Add(Fact value, out bool exists, bool samestep = false)
else else
// brand new Fact // brand new Fact
{ {
key = value.URI; key = value.Id;
base.Add(key, value); FactDict.Add(key, value);
MetaInf.Add(key, new meta(marker, true)); MetaInf.Add(key, new meta(marker, true));
} }
...@@ -201,21 +214,15 @@ public string Add(Fact value, out bool exists, bool samestep = false) ...@@ -201,21 +214,15 @@ public string Add(Fact value, out bool exists, bool samestep = false)
return key; return key;
} }
public new bool Remove(string key)
// hide
{
return this.Remove(key, false);
}
public bool Remove(Fact value, bool samestep = false) public bool Remove(Fact value, bool samestep = false)
{ {
return this.Remove(value.URI, samestep); return this.Remove(value.Id, samestep);
} }
public bool Remove(string key, bool samestep = false) public bool Remove(string key, bool samestep = false)
//no reset check needed (impossible state) //no reset check needed (impossible state)
{ {
if (!base.ContainsKey(key)) if (!FactDict.ContainsKey(key))
return false; return false;
//TODO: see issue #58 //TODO: see issue #58
...@@ -332,10 +339,10 @@ public void redo() ...@@ -332,10 +339,10 @@ public void redo()
} }
} }
public new void Clear() public void Clear()
// Does not Invoke RemoveFactEvent(s)! // Does not Invoke RemoveFactEvent(s)!
{ {
base.Clear(); FactDict.Clear();
MetaInf.Clear(); MetaInf.Clear();
Workflow.Clear(); Workflow.Clear();
marker = 0; marker = 0;
...@@ -346,7 +353,7 @@ public void redo() ...@@ -346,7 +353,7 @@ public void redo()
public void hardreset(bool invoke_event = true) public void hardreset(bool invoke_event = true)
{ {
foreach(var entry in this) foreach(var entry in FactDict)
{ {
if (invoke_event && invoke && MetaInf[entry.Key].active) if (invoke_event && invoke && MetaInf[entry.Key].active)
CommunicationEvents.RemoveFactEvent.Invoke(entry.Value); CommunicationEvents.RemoveFactEvent.Invoke(entry.Value);
...@@ -389,6 +396,7 @@ public void load(bool draw_all = true) ...@@ -389,6 +396,7 @@ public void load(bool draw_all = true)
// call this after assigning a stored instance in an empty world // call this after assigning a stored instance in an empty world
{ {
// TODO: see issue #58 // TODO: see issue #58
// TODO: communication with MMT
foreach (var mett in MetaInf) foreach (var mett in MetaInf)
{ {
...@@ -422,6 +430,9 @@ private void InvokeFactEvent(bool creation, string Id) ...@@ -422,6 +430,9 @@ private void InvokeFactEvent(bool creation, string Id)
CommunicationEvents.AddFactEvent.Invoke(this[Id]); CommunicationEvents.AddFactEvent.Invoke(this[Id]);
else else
CommunicationEvents.RemoveFactEvent.Invoke(this[Id]); CommunicationEvents.RemoveFactEvent.Invoke(this[Id]);
if (!creation)
FactDict[Id].freeLabel();
} }
public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElements, out List<Fact> Solutions) public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElements, out List<Fact> Solutions)
...@@ -433,7 +444,7 @@ public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElem ...@@ -433,7 +444,7 @@ public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElem
//TODO: PERF: see CommunicationEvents.Solution //TODO: PERF: see CommunicationEvents.Solution
public bool DynamiclySolved(List<Fact> MinimalSolution, out List<Fact> MissingElements, out List<Fact> Solutions, FactComparer FactComparer) public bool DynamiclySolved(List<Fact> MinimalSolution, out List<Fact> MissingElements, out List<Fact> Solutions, FactComparer FactComparer)
{ {
Solutions = this.Values.Where(f => MetaInf[f.URI].active) Solutions = FactDict.Values.Where(f => MetaInf[f.Id].active)
.Where(active => MinimalSolution.Contains(active, FactComparer.SetSearchRight())) .Where(active => MinimalSolution.Contains(active, FactComparer.SetSearchRight()))
.ToList(); .ToList();
......
...@@ -56,7 +56,7 @@ public Fact SpawnPoint(Fact pointFact) ...@@ -56,7 +56,7 @@ public Fact SpawnPoint(Fact pointFact)
point.transform.position = fact.Point; point.transform.position = fact.Point;
point.transform.up = fact.Normal; point.transform.up = fact.Normal;
point.GetComponentInChildren<TextMeshPro>().text = fact.Label; point.GetComponentInChildren<TextMeshPro>().text = fact.Label;
point.GetComponent<FactObject>().URI = fact.URI; point.GetComponent<FactObject>().URI = fact.Id;
fact.Representation = point; fact.Representation = point;
return fact; return fact;
} }
...@@ -92,7 +92,7 @@ public Fact SpawnLine(Fact fact) ...@@ -92,7 +92,7 @@ public Fact SpawnLine(Fact fact)
//line.GetComponentInChildren<TextMeshPro>().text = letter; //line.GetComponentInChildren<TextMeshPro>().text = letter;
line.GetComponentInChildren<TextMeshPro>().text = pointFact1.Label + pointFact2.Label; line.GetComponentInChildren<TextMeshPro>().text = pointFact1.Label + pointFact2.Label;
line.GetComponentInChildren<TextMeshPro>().text += " = " + Math.Round((point1-point2).magnitude, 2) + " m"; line.GetComponentInChildren<TextMeshPro>().text += " = " + Math.Round((point1-point2).magnitude, 2) + " m";
line.GetComponentInChildren<FactObject>().URI = lineFact.URI; line.GetComponentInChildren<FactObject>().URI = lineFact.Id;
lineFact.Representation = line; lineFact.Representation = line;
return lineFact; return lineFact;
...@@ -134,7 +134,7 @@ public Fact SpawnRay(Fact fact) ...@@ -134,7 +134,7 @@ public Fact SpawnRay(Fact fact)
line.transform.GetChild(0).rotation = Quaternion.FromToRotation(Vector3.right, point2 - point1); line.transform.GetChild(0).rotation = Quaternion.FromToRotation(Vector3.right, point2 - point1);
line.GetComponentInChildren<TextMeshPro>().text = rayFact.Label; line.GetComponentInChildren<TextMeshPro>().text = rayFact.Label;
line.GetComponentInChildren<FactObject>().URI = rayFact.URI; line.GetComponentInChildren<FactObject>().URI = rayFact.Id;
rayFact.Representation = line; rayFact.Representation = line;
return rayFact; return rayFact;
...@@ -190,7 +190,7 @@ public Fact SpawnAngle(Fact fact) ...@@ -190,7 +190,7 @@ public Fact SpawnAngle(Fact fact)
foreach (CircleSegmentGenerator c in segments) foreach (CircleSegmentGenerator c in segments)
c.setAngle(angleValue); c.setAngle(angleValue);
angle.GetComponentInChildren<FactObject>().URI = angleFact.URI; angle.GetComponentInChildren<FactObject>().URI = angleFact.Id;
angleFact.Representation = angle; angleFact.Representation = angle;
return angleFact; return angleFact;
} }
......
...@@ -56,9 +56,9 @@ public override void OnHit(RaycastHit hit) ...@@ -56,9 +56,9 @@ public override void OnHit(RaycastHit hit)
{ {
//Create AngleFact //Create AngleFact
//Check if new Point is equal to one of the previous points -> if true -> cancel //Check if new Point is equal to one of the previous points -> if true -> cancel
if (!(this.angleModeFirstPointSelected.URI == tempFact.URI || this.angleModeSecondPointSelected.URI == tempFact.URI)) if (!(this.angleModeFirstPointSelected.Id == tempFact.Id || this.angleModeSecondPointSelected.Id == tempFact.Id))
{ {
FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).URI, ((PointFact)this.angleModeSecondPointSelected).URI, ((PointFact)tempFact).URI); FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id);
} }
ResetGadget(); ResetGadget();
...@@ -67,7 +67,7 @@ public override void OnHit(RaycastHit hit) ...@@ -67,7 +67,7 @@ public override void OnHit(RaycastHit hit)
else if (this.angleModeIsFirstPointSelected && !this.angleModeIsSecondPointSelected) else if (this.angleModeIsFirstPointSelected && !this.angleModeIsSecondPointSelected)
{ {
//Check if the 2 selected points are the same: If not //Check if the 2 selected points are the same: If not
if (this.angleModeFirstPointSelected.URI != tempFact.URI) if (this.angleModeFirstPointSelected.Id != tempFact.Id)
{ {
this.angleModeIsSecondPointSelected = true; this.angleModeIsSecondPointSelected = true;
this.angleModeSecondPointSelected = tempFact; this.angleModeSecondPointSelected = tempFact;
...@@ -134,33 +134,9 @@ public void ActivateCurveDrawing() ...@@ -134,33 +134,9 @@ public void ActivateCurveDrawing()
} }
public void UpdateCurveDrawing(Vector3 currentPosition) public void UpdateCurveDrawing(Vector3 currentPosition)
{
//TODO! PERF O(n)
//Find the nearest of all potential third points
PointFact nearestPoint = null;
foreach (var entry in LevelFacts)
{
Fact fact = entry.Value;
if (fact is PointFact && fact.URI != angleModeFirstPointSelected.URI && fact.URI != angleModeSecondPointSelected.URI && nearestPoint == null)
nearestPoint = (PointFact)fact;
else if (fact is PointFact && fact.URI != angleModeFirstPointSelected.URI && fact.URI != angleModeSecondPointSelected.URI && (nearestPoint.Point - currentPosition).magnitude > (((PointFact)fact).Point - currentPosition).magnitude)
nearestPoint = (PointFact)fact;
}
Vector3 startPoint = new Vector3(0, 0, 0);
if (nearestPoint != null)
{
Vector3 planePoint = Vector3.ProjectOnPlane(currentPosition, Vector3.Cross((nearestPoint.Point - angleMiddlePoint), (curveEndPoint - angleMiddlePoint)));
//Determine the Start-Point for the nearest third-point
startPoint = angleMiddlePoint + curveRadius * (planePoint - angleMiddlePoint).normalized;
}
else
{ {
//Determine the Start-Point //Determine the Start-Point
startPoint = angleMiddlePoint + curveRadius * (currentPosition - angleMiddlePoint).normalized; Vector3 startPoint = angleMiddlePoint + curveRadius * (currentPosition - angleMiddlePoint).normalized;
}
//Determine the Center of Start-Point and End-Point //Determine the Center of Start-Point and End-Point
Vector3 tempCenterPoint = Vector3.Lerp(startPoint, curveEndPoint, 0.5f); Vector3 tempCenterPoint = Vector3.Lerp(startPoint, curveEndPoint, 0.5f);
......
...@@ -43,10 +43,10 @@ public override void OnHit(RaycastHit hit) ...@@ -43,10 +43,10 @@ public override void OnHit(RaycastHit hit)
Fact tempFact = LevelFacts[hit.transform.GetComponent<FactObject>().URI]; Fact tempFact = LevelFacts[hit.transform.GetComponent<FactObject>().URI];
//If first point was already selected AND second point != first point //If first point was already selected AND second point != first point
if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.URI != tempFact.URI) if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.Id != tempFact.Id)
{ {
//Create LineFact //Create LineFact
FactManager.AddRayFact(this.LineModeFirstPointSelected.URI, tempFact.URI); FactManager.AddRayFact(this.LineModeFirstPointSelected.Id, tempFact.Id);
this.ResetGadget(); this.ResetGadget();
} }
...@@ -72,8 +72,8 @@ public override void OnHit(RaycastHit hit) ...@@ -72,8 +72,8 @@ public override void OnHit(RaycastHit hit)
{ {
//Create LineFact //Create LineFact
var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI; var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI;
var idB = this.LineModeFirstPointSelected.URI; var idB = this.LineModeFirstPointSelected.Id;
FactManager.AddAngleFact(idA, idB, FactManager.AddPointFact(hit).URI); FactManager.AddAngleFact(idA, idB, FactManager.AddPointFact(hit).Id);
this.ResetGadget(); this.ResetGadget();
} }
......
...@@ -65,7 +65,7 @@ void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool sa ...@@ -65,7 +65,7 @@ void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool sa
Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point); Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point);
//TODO: which normal? //TODO: which normal?
CreateRayAndAngles(this.LotModeIntersectionPoint.URI, FactManager.AddPointFact(LotPoint, hit.normal).URI, true); CreateRayAndAngles(this.LotModeIntersectionPoint.Id, FactManager.AddPointFact(LotPoint, hit.normal).Id, true);
this.ResetGadget(); this.ResetGadget();
} }
...@@ -85,12 +85,12 @@ void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool sa ...@@ -85,12 +85,12 @@ void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool sa
//TODO: test Facts existance //TODO: test Facts existance
//add Facts //add Facts
var intersectionId = FactManager.AddPointFact(intersectionPoint, this.LotModeLineHit.normal).URI; var intersectionId = FactManager.AddPointFact(intersectionPoint, this.LotModeLineHit.normal).Id;
if(this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line if(this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line
FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.URI, true); FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.Id, true);
CreateRayAndAngles(intersectionId, tempFact.URI, true); CreateRayAndAngles(intersectionId, tempFact.Id, true);
this.ResetGadget(); this.ResetGadget();
} }
......
...@@ -28,7 +28,7 @@ public override void OnHit(RaycastHit hit) ...@@ -28,7 +28,7 @@ public override void OnHit(RaycastHit hit)
{ {
if (!this.isActiveAndEnabled) return; if (!this.isActiveAndEnabled) return;
var pid = FactManager.AddPointFact(hit).URI; var pid = FactManager.AddPointFact(hit).Id;
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray")) if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray"))
{ {
......
...@@ -49,10 +49,10 @@ public override void OnHit(RaycastHit hit) ...@@ -49,10 +49,10 @@ public override void OnHit(RaycastHit hit)
return; return;
//If first point was already selected AND second point != first point //If first point was already selected AND second point != first point
if (this.TapeModeIsFirstPointSelected && this.TapeModeFirstPointSelected.URI != tempFact.URI) if (this.TapeModeIsFirstPointSelected && this.TapeModeFirstPointSelected.Id != tempFact.Id)
{ {
//Create LineFact //Create LineFact
FactManager.AddLineFact(this.TapeModeFirstPointSelected.URI, tempFact.URI); FactManager.AddLineFact(this.TapeModeFirstPointSelected.Id, tempFact.Id);
this.ResetGadget(); this.ResetGadget();
} }
...@@ -77,8 +77,8 @@ public override void OnHit(RaycastHit hit) ...@@ -77,8 +77,8 @@ public override void OnHit(RaycastHit hit)
if (Physics.Raycast(hit.transform.gameObject.transform.position - Vector3.down * 2, Vector3.down, out downHit)) if (Physics.Raycast(hit.transform.gameObject.transform.position - Vector3.down * 2, Vector3.down, out downHit))
{ {
var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI; var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI;
var idB = this.TapeModeFirstPointSelected.URI; var idB = this.TapeModeFirstPointSelected.Id;
var idC = FactManager.AddPointFact(hit).URI; var idC = FactManager.AddPointFact(hit).Id;
//Create LineFact //Create LineFact
FactManager.AddAngleFact(idA, idB, idC, true); FactManager.AddAngleFact(idA, idB, idC, true);
......
...@@ -45,16 +45,16 @@ void Start() ...@@ -45,16 +45,16 @@ void Start()
} }
public void AddFact(Fact fact) { public void AddFact(Fact fact) {
var fid = fact.URI; var fid = fact.Id;
var obj = CreateDisplay(transform, fact); var obj = CreateDisplay(transform, fact);
obj.GetComponent<RectTransform>().localPosition = GetPosition(displayedFacts.Count); obj.GetComponent<RectTransform>().localPosition = GetPosition(displayedFacts.Count);
displayedFacts.Add(fact.URI, obj); displayedFacts.Add(fact.Id, obj);
} }
public void RemoveFact(Fact fact) public void RemoveFact(Fact fact)
{ {
GameObject.Destroy(displayedFacts[fact.URI]); GameObject.Destroy(displayedFacts[fact.Id]);
displayedFacts.Remove(fact.URI); displayedFacts.Remove(fact.Id);
UpdatePositions(); UpdatePositions();
} }
...@@ -66,7 +66,7 @@ public void UpdatePositions() ...@@ -66,7 +66,7 @@ public void UpdatePositions()
} }
public void AnimateFact(Fact fact) { public void AnimateFact(Fact fact) {
var factIcon = displayedFacts[fact.URI]; var factIcon = displayedFacts[fact.Id];
factIcon.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); factIcon.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger();
} }
......
...@@ -25,7 +25,7 @@ public void OnDrop(PointerEventData eventData) ...@@ -25,7 +25,7 @@ public void OnDrop(PointerEventData eventData)
current.transform.SetParent(gameObject.transform, false); current.transform.SetParent(gameObject.transform, false);
currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact; currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact;
Debug.Log("recieved Fact: " + currentFact.URI); Debug.Log("recieved Fact: " + currentFact.Id);
CommunicationEvents.NewAssignmentEvent.Invoke(); CommunicationEvents.NewAssignmentEvent.Invoke();
} }
......
...@@ -145,7 +145,7 @@ private string prepareScrollAssignments() ...@@ -145,7 +145,7 @@ private string prepareScrollAssignments()
if (tempFact != null) if (tempFact != null)
{ {
listEntry.fact = new Scroll.UriReference(this.scroll.requiredFacts[i].@ref.uri); listEntry.fact = new Scroll.UriReference(this.scroll.requiredFacts[i].@ref.uri);
listEntry.assignment = new JSONManager.OMS(tempFact.URI); listEntry.assignment = new JSONManager.OMS(tempFact.Id);
assignmentList.Add(listEntry); assignmentList.Add(listEntry);
} }
} }
...@@ -218,7 +218,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris ...@@ -218,7 +218,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris
if (currentFact != null && currentFact.hasDependentFacts()) if (currentFact != null && currentFact.hasDependentFacts())
{ {
//Hint available for abstract-problem uri //Hint available for abstract-problem uri
hintUris.Add(currentFact.URI); hintUris.Add(currentFact.Id);
LatestRenderedHints.Add(currentFact); LatestRenderedHints.Add(currentFact);
} }
} }
...@@ -244,10 +244,10 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) { ...@@ -244,10 +244,10 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) {
fact.Representation.GetComponentInChildren<MeshRendererHintAnimation>().AnimationTrigger(); fact.Representation.GetComponentInChildren<MeshRendererHintAnimation>().AnimationTrigger();
} }
} }
else if (LatestRenderedHints.Exists(x => x.URI.Equals(scrollParameterUri))) else if (LatestRenderedHints.Exists(x => x.Id.Equals(scrollParameterUri)))
{ {
fact = LatestRenderedHints.Find(x => x.URI.Equals(scrollParameterUri)); fact = LatestRenderedHints.Find(x => x.Id.Equals(scrollParameterUri));
var factId = fact.URI; var factId = fact.Id;
//If there is an equal existing fact -> Animate that fact AND ScrollParameter //If there is an equal existing fact -> Animate that fact AND ScrollParameter
if (LevelFacts.ContainsKey(factId)) if (LevelFacts.ContainsKey(factId))
......
...@@ -23,14 +23,14 @@ void Start() ...@@ -23,14 +23,14 @@ void Start()
SolutionManager.Add(buttom, out _); SolutionManager.Add(buttom, out _);
SolutionManager.Add(top, out _, true); SolutionManager.Add(top, out _, true);
LineFact target = new LineFact(buttom.URI, top.URI, SolutionManager); LineFact target = new LineFact(buttom.Id, top.Id, SolutionManager);
Solution.Add(SolutionManager[SolutionManager.Add(target, out _, true)]); Solution.Add(SolutionManager[SolutionManager.Add(target, out _, true)]);
} }
public static bool gameSolved() public static bool gameSolved()
{ {
solved = solved =
LevelFacts.DynamiclySolved(Solution, out _, out List<Fact> hits, new LineFactHightDirectionComparer()); LevelFacts.DynamiclySolved(Solution, out _, out List<Fact> hits, FactComparer: new LineFactHightDirectionComparer());
if (solved) if (solved)
foreach (var hit in hits) foreach (var hit in hits)
......
...@@ -6,7 +6,6 @@ public class Restart : MonoBehaviour ...@@ -6,7 +6,6 @@ public class Restart : MonoBehaviour
public void LevelReset() public void LevelReset()
{ {
CommunicationEvents.LevelReset.Invoke(); // currently unused CommunicationEvents.LevelReset.Invoke(); // currently unused
Level.solved = false; // needed since static
// delete Facts at Server // delete Facts at Server
CommunicationEvents.LevelFacts.hardreset(false); CommunicationEvents.LevelFacts.hardreset(false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment