Commit 76c75dd6 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Fix TTS Action and thread main logic

parent f90ef152
......@@ -46,6 +46,7 @@ public class MainActivity extends AppCompatActivity {
SpeechRecognizer sr;
GoogleApiAvailability m_gga;
public TTSReader ttsreader;
private MainThread mainThread;
//game logic
public ArrayList<Atom> Atoms;
......@@ -68,6 +69,8 @@ public class MainActivity extends AppCompatActivity {
errorDia.show();
}
mainThread = new MainThread(this);
Atoms = new ArrayList<Atom>();
Atoms.add(new ItemAtom(0));
......@@ -76,7 +79,7 @@ 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 aaa test 1"));
A1.add(new RemoveAtom(this, new ItemAtom(0)));
A1.add(new AddAtom(this, new ItemAtom(1)));
A1.add(new ClearNodes(this));
......@@ -86,7 +89,7 @@ public class MainActivity extends AppCompatActivity {
ArrayList<Action> A2 = new ArrayList<Action>();
A2.add(new ClearNodes(this));
// A2.add(new TTSReading(this, "Test 2"));
A2.add(new TTSReading(this, "Test 2 aaa test 2"));
ArrayList<Atom> C2 = new ArrayList<Atom>();
C2.add(new ItemAtom(1));
......@@ -98,30 +101,10 @@ public class MainActivity extends AppCompatActivity {
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();
}
}
protected void CheckOpenNodes() throws InterruptedException {
mainThread.CheckOpenNodes();
}
public Node GetNode(int ID)
......@@ -185,8 +168,10 @@ public class MainActivity extends AppCompatActivity {
});
}
public void LaunchGame(View v) // called when the "play" button is pressed on title screen
public void LaunchGame(View v) throws InterruptedException // called when the "play" button is pressed on title screen
{
CheckOpenNodes();
setContentView(R.layout.activity_main);
initializeListeners();
}
......
package com.example.qrquest;
import android.util.Log;
import com.example.qrquest.atom.Atom;
import com.example.qrquest.node.Node;
public class MainThread extends Thread {
private MainActivity mainActivity;
public MainThread(MainActivity mainActivity)
{
super();
this.mainActivity = mainActivity;
}
public void CheckOpenNodes() throws InterruptedException {
Log.d("Debug2", "CheckOpenNodes called");
Log.d("Debug2", "Open Nodes:");
for (Node n :
mainActivity.OpenNodes) {Log.d("Debug2", Integer.toString(n.ID));
}
Log.d("Debug2", "Current Atoms : ");
for (Atom a :
mainActivity.Atoms) {Log.d("Debug2", a.GetStringValue());
}
for (Node n :
mainActivity.OpenNodes) {
if (n.CheckConditions(mainActivity.Atoms))
{
Log.d("Debug2", "Triggering node " + Integer.toString(n.ID));
Thread NodeThread = new Thread(n);
// n.Trigger();
NodeThread.run();
NodeThread.join();
//while(NodeThread.isAlive()) {};
this.CheckOpenNodes();
}
}
}
}
......@@ -4,7 +4,7 @@ import com.example.qrquest.atom.Atom;
import java.util.List;
public class Node {
public class Node implements Runnable {
/*
* A node is a potential series of actions for the player to do.
* It triggers when the player has gathered every required atoms
......@@ -43,4 +43,9 @@ public class Node {
while(!a.isOver){ };
}
}
@Override
public void run() {
this.Trigger();
}
}
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