Exemple #1
0
        public SpeechText DeserializeSpeechText(YamlMappingNode yamlNode)
        {
            SpeechText text = new SpeechText();

            // see TODO 1
            text.Text = GetScalarYamlNodeValue("text", yamlNode);

            if (yamlNode.Children.ContainsKey(new YamlScalarNode("attr")))
            {
                YamlMappingNode attributeMapNode = (YamlMappingNode)yamlNode.Children[new YamlScalarNode("attr")];
                text.Attributes = DeserializeAttributes(attributeMapNode);
            }

            return(text);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            String        token  = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNjNDExOWMwLWExYzEtMTFlYS1iOTdjLTFiOTdlMzMzNTc2NCIsImlhdCI6MTU5MDc2NjYzNn0.K36Axz4FnuORA9jGr_6cs0CjV2vVAI9DZLxe5sjNb7A";
            Configuration config = new Configuration(token, AudioEncoding.AMR, 10000, 16000, 51200);
            SpeechText    speech = new SpeechText(config);
            FileStream    file   = File.Create("./processing.wav");

            try
            {
                string result = speech.Call(file).Result;
                Console.WriteLine(result);
            } catch (AggregateException ex)
            {
                Console.WriteLine("Something went wrong" + ex.Message);
            }
        }
    IEnumerator PopulateText(SpeechText sText)
    {
        int count = 0;

        //TODO: Add text population word by word with overflow detect
        for (int i = 0; i < sText.ItemText.Length; i++)
        {
            if (CheckTextOverflowHeight(sText.UIText.GetComponent <RectTransform>()))
            {
                Debug.Log("Text overflowed height!");
                yield return(null);
            }
            else
            {
                sText.UIText.GetComponent <Text>().text += sText.ItemText.Substring(i, 1);
                yield return(new WaitForSeconds(_textDelayTime));
            }
        }
    }
Exemple #4
0
        private SpeechText ParseSpeechText(TomeStream stream, ref ParsingState state)
        {
            SpeechText st = new SpeechText();

            state = ParsingState.ExpectingMore;

            // parse text here
            string text = ParseAndCleanTextWithEscape(stream);

            // make sure the text ends in a star
            if (stream.PeekChar() == '*')
            {
                stream.NextChar();
            }
            else
            {
                String msg = String.Format("Expected * to end speech parsing but found {0} at {1}",
                                           stream.PeekChar(), stream.Position);
                throw new Exception(msg);
            }

            // parse the attribute
            if (stream.PeekChar() == '[')
            {
                // this closes the paren for us if there is any
                st.Attributes = ParseAttributes(stream);
            }

            EatWhitespace(stream);

            // check if it ended
            // at this point we know there is at least 1 star
            // if this is true then this will be the last speech text
            if (stream.PeekChar() == '}')
            {
                stream.NextChar();
                state = ParsingState.Complete;
            }

            st.Text = text;

            return(st);
        }
Exemple #5
0
        public void Parse_TomeTest4()
        {
            var yaml = new YamlStream();

            yaml.Load(GetReader("TomeTest_4.yml"));
            var mapping    = (YamlMappingNode)yaml.Documents[0].RootNode;
            var yamlParser = new BrigitYamlParser(mapping);
            var conv       = yamlParser.CreateGraphFromYaml();

            var constructed = new BrigitGraph();

            constructed.AddNode(new Node
            {
                Data = new Dialog("Diego", "Hey what's happening")
            });

            // first choice
            Choice ch1 = new Choice("This sets one to true", 0);

            ch1.Attributes.SetFlags.Add("one", Attributes.Flag.True);
            Choice ch2 = new Choice("This sets two to true", 0);

            ch2.Attributes.SetFlags.Add("two", Attributes.Flag.True);

            // the decsion block
            var choices = new Node()
            {
                Data = new Decision()
                {
                    Choices = new List <Choice>
                    {
                        ch1,
                        ch2
                    }
                }
            };

            constructed.AddNode(choices);

            // Dialog Node
            var dialog  = new Dialog("Person");
            var speech1 = new SpeechText("Hello");

            speech1.Attributes.Expression = new Variable("one");
            var speech2 = new SpeechText("Hey");

            speech2.Attributes.Expression = new Variable("two");
            dialog.Text = new List <SpeechText>()
            {
                speech1,
                speech2,
                new SpeechText("Blah")
            };

            constructed.AddNode(new Node()
            {
                Data = dialog
            });

            // second dialog node
            var dialog2 = new Dialog("Other", "Heyo", "What's going on");

            dialog2.Attributes.Expression = new Variable("one");

            constructed.AddNode(new Node()
            {
                Data = dialog2
            });

            //assertion
            bool checker = conv.Equals(constructed);

            Assert.AreEqual(true, checker);
        }
Exemple #6
0
 void Start()
 {
     dialogue         = DialogueSystem.instance;
     speechText       = GetComponent <SpeechText>();
     dialogue.waitfor = textSpeed;
 }
Exemple #7
0
 public void OnEnable()
 {
     script = (SpeechText)target;
 }
Exemple #8
0
//    public void PopulateText()
//    {
//        DialogueChain dialogue = currDialogueChain;
//        /*Create object to pass to text coroutine*/
//        SpeechText sText = new SpeechText(dialogue.SpeechText[CurrDialogueIndex].Text, currText);
//
//        int count = 0;
//        //TODO: Add text population word by word with overflow detect
//        foreach (string s in sText.Text)
//        {
//            count++;
//
//            for (int i = 0; i < s.Length; i++)
//            {
//                if (CheckTextOverflowHeight(sText.UIText.GetComponent<RectTransform>()))
//                {
//                    Debug.Log("Text overflowed height!");
//                    yield return null;
//                }
//                else
//                {
//                    sText.UIText.GetComponent<Text>().text += s.Substring(i, 1);
//                    yield return(new WaitForSeconds(_textDelayTime));
//                }
//
//            }
//
//
//
//            if (count < sText.Text.Length)
//            {
//                Debug.Log("Waiting for player input");
//
//                //Check for if this requires responses
//                if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ReqResponse && !rBox.activeInHierarchy)
//                {
//                    Debug.Log("Response required detected!!");
//                    Debug.Log("Dialogue text at 0 is: "+ currDialogueChain.SpeechText[0].Text[0]);
//                    rBox.SetActive(true);
//
//                    currResponseScript.CreateResponses(currDialogueChain.SpeechText[this.CurrDialogueIndex].Responses);
//                    //Initialize references for UI elements for dialogue responses
//                    currResponseScript.Init();
//                    //Set flag to wait for response
//                    this.DialogueChoice = true;
//                }
//                //flag to wait for player input
//                _waitForPlayer = true;
//
//                //Turn on continue arrow
//                sText.UIText.GetComponent<TextBoxScript>().SwitchArrow();
//                /*String finished populating, now we wait for player's input to continue*/
//                while (_waitForPlayer)
//                {
//                    yield return null;
//                }
//                //turn off continue arrow that is parented to the UI text object
//                sText.UIText.transform.GetComponent<TextBoxScript>().SwitchArrow();
//                //Clear previous string from text box
//                sText.UIText.GetComponent<Text>().text = "";
//            }
//            else
//            {
//                Debug.Log("End of dialog reached. Waiting for player to close.");
//                //do nothing
//                _waitForPlayer = true;
//
//                while (_waitForPlayer)
//                {
//                    yield return null;
//                }
//                //Check to see if there is a new dialog chain to display
//                if (newDialogueChain)
//                {
//                    newDialogueChain = false;
//                }
//                else
//                {
//                    //if no new dialogue chain then End of dialog reached so close text box
//                    CloseTextBox();
//                }
//            }
//        }
//
//
//    }

    IEnumerator PopulateText(DialogueChain dialogue)
    {
        while (DialogueActive)
        {
            Debug.Log("Top of while loop");
            /*Create object to pass to text coroutine*/
            SpeechText sText = new SpeechText(dialogue.SpeechText[CurrDialogueIndex].Text, currText);
            /*set reference variable for debug*/
            currDialogueChain = dialogue;


            //TODO: Add text population word by word with overflow detect
            for (int count = 0; count <= sText.Text.Length; count++)
            {
                if (count < sText.Text.Length)
                {
                    for (int i = 0; i < sText.Text[count].Length; i++)
                    {
                        if (CheckTextOverflowHeight(sText.UIText.GetComponent <RectTransform>()))
                        {
                            Debug.Log("Text overflowed height!");
                            yield return(null);
                        }
                        else
                        {
                            sText.UIText.GetComponent <Text>().text += sText.Text[count].Substring(i, 1);
                            yield return(new WaitForSeconds(_textDelayTime));
                        }
                    }

                    Debug.Log("Waiting for player input");
                    Debug.Log("--Count is:" + count + "---");
                    Debug.Log("SText.Text.Length is:" + sText.Text.Length);
                    //Check if the character gives the player an item
                    if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ItemIndex != -1)
                    {
                        int index = currDialogueChain.SpeechText[this.CurrDialogueIndex].ItemIndex;
                        //Call player state manager to add item
                        PlayerStateManager.Instance.AddToInventory(speaker.dialogueEventItems[index], true);
                        //Create notification
                        GameObject notif = (GameObject)GameObject.Instantiate(notifBox);
                        //Set parent to ui_container because the object is a ui elemetn
                        notif.transform.SetParent(_uiContainer.transform, false);
                        //position notification and set reference elements as part of initialization
                        notif.GetComponent <NotificationScript>().Init(speaker.dialogueEventItems[index].thisItem.PickupText, PlayerStateManager.Instance.LocalPosition);
                        //Trigger fade out
                        notif.GetComponent <NotificationScript>().StartFadeOut();
                    }
                    //Check for if this requires responses
                    if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ReqResponse && !rBox.activeInHierarchy)
                    {
//                        Debug.Log("Response required detected!!");
//                        Debug.Log("Dialogue text at 0 is: " + currDialogueChain.SpeechText[0].Text[0]);
                        rBox.SetActive(true);

                        currResponseScript.CreateResponses(currDialogueChain.SpeechText[this.CurrDialogueIndex].Responses);
                        //Initialize references for UI elements for dialogue responses
                        currResponseScript.Init();
                        //Set flag to wait for response
                        this.DialogueChoice = true;
                    }
                    //flag to wait for player input
                    _waitForPlayer = true;

                    //Turn on continue arrow
                    sText.UIText.GetComponent <TextBoxScript>().SwitchArrow();
                    /*String finished populating, now we wait for player's input to continue*/
                    while (_waitForPlayer)
                    {
                        yield return(null);
                    }
                    //turn off continue arrow that is parented to the UI text object
                    sText.UIText.transform.GetComponent <TextBoxScript>().SwitchArrow();
                    //Clear previous string from text box
                    sText.UIText.GetComponent <Text>().text = "";
                }
                else
                {
//                    Debug.Log("End of dialog reached. Waiting for player to close.");
//                    //do nothing
//                    _waitForPlayer = true;
//
//                    while (_waitForPlayer)
//                    {
//                        yield return null;
//                    }

                    if (newDialogueChain)
                    {
                        Debug.Log("New dialog chain created!");
                        this.CurrDialogueIndex = this.newDialogueIndex;
                    }
                    else
                    {
                        //Update the Dialogue Manager's state
                        this.DialogueActive = false;
                        //End of dialog reached so close text box
                        CloseTextBox();
                    }
                }
            }
        }
    }