Commit f90ef152 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Rework node logic, add console display of working example

parent 9f184048
......@@ -10,6 +10,8 @@ import android.os.Bundle;
import com.example.qrquest.actions.Action;
import com.example.qrquest.actions.AddAtom;
import com.example.qrquest.actions.AddNode;
import com.example.qrquest.actions.ClearNodes;
import com.example.qrquest.actions.RemoveAtom;
import com.example.qrquest.actions.TTSReading;
import com.example.qrquest.atom.Atom;
......@@ -74,32 +76,48 @@ public class MainActivity extends AppCompatActivity {
ArrayList<Action> A1 = new ArrayList<Action>();
A1.add(new AddAtom(this, new ItemAtom(2)));
A1.add(new TTSReading(this, "Test 1"));
//A1.add(new TTSReading(this, "Test 1"));
A1.add(new RemoveAtom(this, new ItemAtom(0)));
A1.add(new AddAtom(this, new ItemAtom(1)));
A1.add(new ClearNodes(this));
A1.add(new AddNode(this, 2));
ArrayList<Atom> C1 = new ArrayList<Atom>();
C1.add(new ItemAtom(0));
ArrayList<Action> A2 = new ArrayList<Action>();
A1.add(new TTSReading(this, "Test 2"));
A2.add(new ClearNodes(this));
// A2.add(new TTSReading(this, "Test 2"));
ArrayList<Atom> C2 = new ArrayList<Atom>();
C1.add(new ItemAtom(1));
C2.add(new ItemAtom(1));
Node n1 = new Node(A1, C1);
Node n2 = new Node(A2, C2);
Node n1 = new Node(1, A1, C1);
Node n2 = new Node(2, A2, C2);
EveryNode.add(n1);
EveryNode.add(n2);
OpenNodes.add(n1);
Log.d("Debug2", "Nodes initialized");
CheckOpenNodes();
}
protected void CheckOpenNodes()
{
Log.d("Debug2", "CheckOpenNodes called");
Log.d("Debug2", "Open Nodes:");
for (Node n :
OpenNodes) {Log.d("Debug2", Integer.toString(n.ID));
}
Log.d("Debug2", "Current Atoms : ");
for (Atom a :
Atoms) {Log.d("Debug2", a.GetStringValue());
}
for (Node n :
OpenNodes) {
if (n.CheckConditions(Atoms))
{
Log.d("Debug2", "Triggering node " + Integer.toString(n.ID));
n.Trigger();
CheckOpenNodes();
}
......
......@@ -16,7 +16,8 @@ public class AddAtom extends Action {
public void Do()
{
Log.d("Debug2", "Added Atom");
Log.d("Debug2", "Added Atom " + atom.GetStringValue());
mainActivity.Atoms.add((atom));
isOver = true;
}
}
......@@ -7,16 +7,18 @@ import com.example.qrquest.node.Node;
public class AddNode extends Action {
private Node node;
private int NodeToAddID;
public AddNode(MainActivity mainActivity, Node node) {
public AddNode(MainActivity mainActivity, int NodeToAddID) {
super(mainActivity);
this.node = node;
this.NodeToAddID = NodeToAddID;
}
public void Do()
{
Log.d("Debug2", "Added Node " + node.ID);
mainActivity.OpenNodes.add(node);
Node toAdd = mainActivity.GetNode(NodeToAddID);
Log.d("Debug2", "Added Node " + toAdd.ID);
mainActivity.OpenNodes.add(toAdd);
isOver = true;
}
}
......@@ -14,5 +14,6 @@ public class CaptureQR extends Action {
public void Do()
{
// open QRCaptureActivity here and wait for its result
isOver = true;
}
}
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
public class ClearNodes extends Action {
public ClearNodes(MainActivity mainActivity) {
super(mainActivity);
}
public void Do()
{
this.mainActivity.OpenNodes.clear();
isOver = true;
}
}
......@@ -23,9 +23,10 @@ public class RemoveAtom extends Action {
if(atomToRemove != null)
{
Log.d("Debug2", "Removed atom");
Log.d("Debug2", "Removed atom " + atomToRemove.GetStringValue());
mainActivity.Atoms.remove(atomToRemove);
}
else Log.d("Debug2", "Tried to remove an atom that doesn't exist");
isOver = true;
}
}
......@@ -18,5 +18,6 @@ public class RemoveNode extends Action {
if(!mainActivity.OpenNodes.contains(mainActivity.GetNode(_nodeID))) throw new Error("Tried to remove a node that wasn't open");
Log.d("Debug2", "Removed node " + _nodeID);
mainActivity.OpenNodes.remove(mainActivity.GetNode(_nodeID));
isOver = true;
}
}
......@@ -5,7 +5,7 @@ import com.example.qrquest.MainActivity;
import com.example.qrquest.TTSReader;
public class TTSReading extends Action {
TextToSpeech tts;
// TextToSpeech tts;
private String TextToRead;
......
......@@ -20,6 +20,11 @@ public abstract class Atom {
public boolean hasSameValue(Atom atom)
{
throw new Error(("has same value should be overriden for every final atom class"));
throw new Error(("hasSameValue should be overriden for every final atom class"));
}
public String GetStringValue()
{
throw new Error(("GetValue should be overriden for every final atom class"));
}
}
......@@ -8,8 +8,12 @@ public final class ItemAtom extends Atom {
this.ID = ID;
}
public boolean hasSameValue(ItemAtom atom)
public boolean hasSameValue(Atom atom)
{
return (atom.ID == ID);
if(atom.getClass() != ItemAtom.class) return false;
ItemAtom iAtom = (ItemAtom) atom;
return (iAtom.ID == ID);
}
public String GetStringValue() { return (Integer.toString(ID)); }
}
......@@ -8,8 +8,12 @@ public final class QRAtom extends Atom {
this.AtomContent = AtomContent;
}
public boolean hasSameValue(QRAtom atom)
public boolean hasSameValue(Atom atom)
{
return (atom.AtomContent == AtomContent);
if(atom.getClass() != QRAtom.class) return false;
QRAtom qrAtom = (QRAtom) atom;
return (qrAtom.AtomContent == AtomContent);
}
public String GetStringValue() { return (AtomContent); }
}
......@@ -8,8 +8,12 @@ public final class SpeechAtom extends Atom {
this.AtomContent = AtomContent;
}
public boolean hasSameValue(QRAtom atom)
public boolean hasSameValue(Atom atom)
{
return (atom.AtomContent == AtomContent);
if(atom.getClass() != SpeechAtom.class) return false;
SpeechAtom sAtom = (SpeechAtom) atom;
return (sAtom.AtomContent == AtomContent);
}
public String GetStringValue() { return (AtomContent); }
}
......@@ -14,8 +14,9 @@ public class Node {
public List<Atom> Conditions;
public int ID;
public Node(List<Action> Actions, List<Atom> Conditions)
public Node(int ID, List<Action> Actions, List<Atom> Conditions)
{
this.ID = ID;
this.Actions = Actions;
this.Conditions = Conditions;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment