Skip to content
Snippets Groups Projects
Commit 73ecf7ea authored by Falampe's avatar Falampe
Browse files

[WIP]stuff may break

Added StudentNodechains for  Studentnodes
however:
	Time between nodes is not based on soundfile length
	Interaktion between animnodes and soundnodes are not testet and seem to be off
parent b1268369
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ namespace TeachR.StructureTree
[Loggable]
public class ImpulseController : MonoBehaviour_Loggable
{
private enum SECOND_AUDIOFILE { NONE, PREPARE, TALK }
private int _levelOfDistortion = 0;
private List<GameObject> _impulsedStudents = new();
[SerializeField] private UnityWaiter waiter;
......@@ -43,6 +44,7 @@ namespace TeachR.StructureTree
public Dictionary<string, Dictionary<ImpulseType, string>> impulseDescriptionTexts;
public List<GraphToTreeConverter.StringImpulseTypeDictionary> impulseDescriptionDebug;
private ConfigLoader config;
// in case something specific needs to be loaded for each theme, there is an EventHook.
public static event Action<string> ThemeChangedHook;
......@@ -141,7 +143,7 @@ namespace TeachR.StructureTree
ambient.PlayIntro(waiter);
}
HandleImpulse(new List<GameObject>(AllStudentAttributes.StudentSlots), "none", chanceToMisbehave, 141, true);
HandleImpulse(new List<GameObject>(AllStudentAttributes.StudentSlots), "none", chanceToMisbehave, true);
LogData($"{DateTime.Now.ToString(DateTimeFormat)};themeChange:{themeChange.theme};chanceToMisbehave:{chanceToMisbehave}");
yield return true;
}
......@@ -164,15 +166,15 @@ namespace TeachR.StructureTree
{
if (impulseGiven.impulse == "evoke")
{
Assert.IsTrue(_impulsedStudents.Count > 0); // evoke with empty list bricks the whole process without a usefull message - should be catched
List<BehaviourController> bc = new List<BehaviourController>
Assert.IsTrue(_impulsedStudents.Count > 0); // evoke with empty list bricks the whole process without a usefull message - TODO: should be catched with a usefull message [FL]
List<BehaviourController> bcList = new List<BehaviourController>
{
_impulsedStudents[0].GetComponent<BehaviourController>()
_impulsedStudents[0].GetComponent<BehaviourController>() // TODO: if global Knowledge set all BehaviourControllers in this list [FL]
};
GoToNextNode(bc);
GoToNextNode(bcList);
// if there are several students selected, just let the first one answer
if (showDebug) Debug.Log($"StartTalkPerformedBy first student: {_impulsedStudents[0].name}");
StartTalkPerformedBy(_impulsedStudents[0]);
StartTalkPerformedBy(_impulsedStudents[0]);
SetBehavioursToIdle("RaiseArm");
}
......@@ -195,17 +197,17 @@ namespace TeachR.StructureTree
}
else
{
List<BehaviourController> bc = new List<BehaviourController>();
List<BehaviourController> bcList = new List<BehaviourController>();
foreach(string requestedStudent in requestedStudents)
{
var matchingSlot = AllStudentAttributes.StudentSlots.FirstOrDefault(slot => slot.GetComponent<StudentController>().Id == requestedStudent);
GameObject matchingSlot = AllStudentAttributes.StudentSlots.FirstOrDefault(slot => slot.GetComponent<StudentController>().Id == requestedStudent);
if (matchingSlot != null)
{
bc.Add(matchingSlot.GetComponent<BehaviourController>());
bcList.Add(matchingSlot.GetComponent<BehaviourController>());
}
}
GoToNextNode(bc);
GoToNextNode(bcList);
if (showDebug)
Debug.Log($"StartTalkPerformedBy requested student: {studentSlot.name}");
StartTalkPerformedBy(studentSlot);
......@@ -215,7 +217,7 @@ namespace TeachR.StructureTree
}
}
}
HandleImpulse(studentSlots, impulseGiven.impulse, chanceToMisbehave, 212);
HandleImpulse(studentSlots, impulseGiven.impulse, chanceToMisbehave);
}
}
......@@ -239,25 +241,26 @@ namespace TeachR.StructureTree
{
randomStudents.Add(ClassController.GetRandomStudent());
}
HandleImpulse(randomStudents, impulse, chanceToMisbehave, 236);
HandleImpulse(randomStudents, impulse, chanceToMisbehave);
}
public void HandleImpulse(GameObject studentSlot, string impulse, float chanceToMisbehave)
{
List<GameObject> studentSlots = new List<GameObject>();
studentSlots.Add(studentSlot);
HandleImpulse(studentSlots, impulse, chanceToMisbehave, 243);
HandleImpulse(studentSlots, impulse, chanceToMisbehave);
LogData($"{DateTime.Now.ToString(DateTimeFormat)};-;{impulse};{chanceToMisbehave};{studentSlot.name}");
}
public void HandleImpulse(List<GameObject> studentSlots, string impulse, float chanceToMisbehave, int line, bool isInitiationInTree = false)
public void HandleImpulse(List<GameObject> studentSlots, string impulse, float chanceToMisbehave, bool isInitiationInTree = false)
{
bool followedbyStudentNode = false; // rekursion bool for Studentnodechains
bool initialStudentnode = false;
foreach (GameObject studentSlot in studentSlots)
{
BehaviourController bc = studentSlot.GetComponent<BehaviourController>();
string currentNode = bc.currentNodeInDiscussion;
if (showDebug)
Debug.Log($"{line}) student: {studentSlot.name}, currentNode: {currentNode}");
GraphToTreeConverter.StructureTreeNode nextNode = default;
StudentController studenController = studentSlot.GetComponent<StudentController>();
......@@ -275,7 +278,7 @@ namespace TeachR.StructureTree
Debug.LogWarning(e.Message);
}
}
// No node based on a tag was found, set the next node by impulse:
if (nextNode.Equals(default(GraphToTreeConverter.StructureTreeNode)))
{
......@@ -284,21 +287,43 @@ namespace TeachR.StructureTree
{
case "none":
nextNode = StructureTreeHandler.GetNextNode(ImpulseType.None, currentNode, chanceToMisbehave);
if (nextNode.Equals(new GraphToTreeConverter.StructureTreeNode())) // [Fabian L.] checks if next node is none as well
if (nextNode.nodeType == NodeType.studentNode)
{
followedbyStudentNode = true;
}
if (nextNode.Equals(new GraphToTreeConverter.StructureTreeNode()) && followedbyStudentNode == false) // [FL] checks if next node is none as well
{
return; //in case no next node was found with give "none"-Impulse, nothing shall change. // [Fabian L.] this prevents the logging as well as the node change
return; //in case no next node was found with give "none"-Impulse, nothing shall change.
}
break;
case "positive":
nextNode = StructureTreeHandler.GetNextNode(ImpulseType.Positive, currentNode, chanceToMisbehave);
if (nextNode.nodeType == NodeType.studentNode && StructureTreeHandler.GetNextNode(ImpulseType.None, nextNode.nodeId, chanceToMisbehave).nodeType == NodeType.studentNode)
{
followedbyStudentNode = true;
initialStudentnode = true;
}
_levelOfDistortion = Math.Max(0, _levelOfDistortion - 2);
break;
case "neutral":
nextNode = StructureTreeHandler.GetNextNode(ImpulseType.Neutral, currentNode, chanceToMisbehave);
if (nextNode.nodeType == NodeType.studentNode && StructureTreeHandler.GetNextNode(ImpulseType.None, nextNode.nodeId, chanceToMisbehave).nodeType == NodeType.studentNode)
{
followedbyStudentNode = true;
initialStudentnode = true;
}
_levelOfDistortion = Math.Max(0, _levelOfDistortion - 1);
break;
case "negative":
nextNode = StructureTreeHandler.GetNextNode(ImpulseType.Negative, currentNode, chanceToMisbehave);
if (nextNode.nodeType == NodeType.studentNode && StructureTreeHandler.GetNextNode(ImpulseType.None, nextNode.nodeId, chanceToMisbehave).nodeType == NodeType.studentNode)
{
followedbyStudentNode = true;
initialStudentnode = true;
}
break;
default:
Debug.LogWarning("unknown Impulse: " + impulse);
......@@ -313,13 +338,40 @@ namespace TeachR.StructureTree
if (bc.nextNode != null)
{
if (followedbyStudentNode)
{
if (initialStudentnode)
{//Start Student Node Chain
BranchPredictionInStructureTree(bc, nextNode, impulse, isInitiationInTree);
}
else
{//In Studentnode Chain
float audioFileDuration = 2f;// TODO: get soundfile length
nextNode = StructureTreeHandler.GetNextNode(ImpulseType.None, currentNode, chanceToMisbehave);
StartCoroutine(WaitForTalk(audioFileDuration, bc, studentSlot, nextNode, impulse, isInitiationInTree));
}
}
else
{// Single Node
BranchPredictionInStructureTree(bc, nextNode, impulse, isInitiationInTree);
}
}
}
}
}
IEnumerator WaitForTalk(float delay, BehaviourController bc, GameObject studentSlot, GraphToTreeConverter.StructureTreeNode nextNode, string impulse, bool isInitiationInTree)
{
// Wartet für die angegebene Zeit
yield return new WaitForSeconds(delay);
GoToNextNode(new List<BehaviourController>() { bc });
StartTalkPerformedBy(studentSlot);
HandleImpulse(bc.gameObject, "none", chanceToMisbehave);
//BranchPredictionInStructureTree(bc, nextNode, impulse, isInitiationInTree);
}
private void BranchPredictionInStructureTree(BehaviourController bc, GraphToTreeConverter.StructureTreeNode nextNode, string impulse, bool isInitiationInTree)
{
// Was it the last node and negative? Start desaster!
......@@ -468,6 +520,7 @@ namespace TeachR.StructureTree
StudentController sc = studentSlot.GetComponent<StudentController>();
if (showDebug)
Debug.Log($"StartTalkPerformedBy: {studentSlot.name}");
string soundFileFolder = StructureTreeHandler.stc[currentNode].soundFileName;
string previousVoice = sc.StudentObj.PreviousVoice;
string pathOfAudioFile = StructureTreeHandler.GetPathOfAudioFile(soundFileFolder, sc.IsMale, previousVoice);
......
......@@ -16,7 +16,7 @@ namespace TeachR.StructureTree
public static bool classHasGlobalKnowledge = true; // globalKnwoledge means, that teachers speak to the whole class at once and every student follows the discussion.
public static Dictionary<string, GraphToTreeConverter.StructureTreeNode> stc { get; set; }
private static string themeFolder;
public static bool showDebug = true;
public static bool showDebug = false;
public static void LoadStructureTree(string fromFolder)
{
......
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