public void RunRoomSession()
        {
            MazeRoom currentroom = mazemap.GetRoomByIteration(player.X, player.Y);
            string   ScriptName  = currentroom.SessionName;

            //Only parse the script if the name isn't blank
            if (currentroom.SessionName != "")
            {
                ScriptRepresentation script = new ScriptRepresentation();
                //Initialize the script
                script.init(ScriptName);
                SpeechScriptInterpreter RoomRunner = new SpeechScriptInterpreter();
                if (FirstRun)
                {
                    RoomRunner.init();
                    FirstRun = false;
                }
                else
                {
                    RoomRunner.Init_Voice(Program.voicename);
                }
                RoomRunner.parse(ScriptName);
                //Console.WriteLine(ScriptName);
            }
            //Move the player again.
            Player_Move();
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            if (Program.userpreferences.EnabledScriptFeatures.Count > 0)
            {
                //Is maze mode meant to run?
                if (Program.userpreferences.EnabledScriptFeatures.Contains(Program.ScriptFeatures.IncludeInMazeModePool))
                {
                    //This should be all we need to kick off maze mode now (hopefully)
                    MapForm MazeModeMap = new MapForm();


                    SessionGeneratorBase genner = new SessionGeneratorBase();
                    genner.PopulateScriptPoolNoPrefs();

                    genner.Remove_NonPrefs();
                    //The other prefs format, I cannot remember why I set up prefs-mirroring.
                    //Something something -script chaining logic. yeah. Not really needed now. Maybe?
                    Program.userpreferences.ResetAndFillPrefs();

                    //Generate session with 5 to start.
                    genner.GenerateGenericSession(5);
                    MazeModeMap.Show(this.Owner);
                    //Hide this form so it doesn't get in the way.
                    this.Hide();


                    Random MazeRng = new Random(System.DateTime.Now.Second + System.DateTime.Now.Year + System.DateTime.Now.Minute);

                    //You cannot update dictionary's values directly UGH, they are readonly. UGHHH!!
                    ICollection <Vector2 <int, int> > keys = new List <Vector2 <int, int> >(MazeModeMap.mazemap.rooms.Keys);
                    //Randomize the finish room too.
                    int roomindex  = MazeRng.Next(0, MazeModeMap.mazemap.rooms.Keys.Count);
                    int countindex = 0;
                    foreach (Vector2 <int, int> key in keys)
                    {
                        //If the finish is shown display it alongside the actual room.
                        if (countindex == roomindex)
                        {
                            MazeModeMap.mazemap.SetFinishRoom(key.X, key.Y);
                            MazeModeMap.RevealRoomTile(key.X, key.Y, MazeModeMap.PalletizedTiles);
                        }

                        //One final touch up to visually correct a backwards tile on start or something.
                        //--Dont ask questions this fixes stuff.
                        if (key.X == MazeModeMap.mazemap.StartRoom.X && key.Y == MazeModeMap.mazemap.StartRoom.Y)
                        {
                            MazeModeMap.RevealRoomTile(key.X, key.Y, MazeModeMap.PalletizedTiles);
                        }

                        //Just some RNG for defining if a tile has a session on it.
                        int value = MazeRng.Next(13);
                        if (value > 5)
                        {
                            MazeRoom troom_ = MazeModeMap.mazemap.rooms[key];
                            int      index  = MazeRng.Next(0, genner.Session_List.Count());
                            troom_.SessionName             = genner.Session_List.ToArray()[index].FileName;
                            MazeModeMap.mazemap.rooms[key] = troom_;
                        }
                        countindex++;
                    }

                    //And the game loop begins here. Maze Mode Only.

                    MazeModeMap.Player_Move();
                }


                if (!Program.userpreferences.EnabledScriptFeatures.Contains(Program.ScriptFeatures.IncludeInMazeModePool))
                {
                    SessionGeneratorBase genner = new SessionGeneratorBase();
                    genner.PopulateScriptPoolNoPrefs();
                    genner.Remove_NonPrefs();
                    //The other prefs format, I cannot remember why I set up prefs-mirroring.
                    //Something something -script chaining logic. yeah. Not really needed now. Maybe?
                    Program.userpreferences.ResetAndFillPrefs();
                    genner.GenerateGenericSession(5);


                    //f.UpdateTileAt(5, 5, 26);

                    //f.make_map(new Vector2<int, int>(5, 5), new Vector2<int, int>(10, 10), 25);
                    this.Hide();
                    bool first_time = true;
                    foreach (ScriptRepresentation rep in genner.Session_List)
                    {
                        SpeechScriptInterpreter interpreter = new SpeechScriptInterpreter();

                        if (first_time)
                        {
                            interpreter.init();
                            first_time = false;
                            Console.WriteLine("Hypnosis Randomizer Online. Programming you now.");
                        }
                        else
                        {
                            interpreter.Init_Voice(Program.voicename);
                        }
                        //interpreter.say_default("This is a test");
                        interpreter.parse(rep.FileName);
                    }
                }
                Console.WriteLine("Session finished. You may close this window.");
            }
            else
            {
                NoPreferencesSelectedError DialogePopup = new NoPreferencesSelectedError();
                DialogePopup.ShowDialog();
            }
        }
        //parse the entire thing out and say the stuff.
        public void parse(string filename)
        {
            //Load the file
            lines = System.IO.File.ReadAllLines(filename);

            //Parse the anchors
            Parse_Anchors();


            while (index < lines.Length)
            {
                string input = lines[index];
                index++;

                //Parse the context
                if (input.StartsWith("SetRate:"))
                {
                    string rate = input.Substring(8);
                    if (Ratevalues.ContainsKey(rate))
                    {
                        PromptRate pmt_rate = Ratevalues[rate];
                        style_.Rate = pmt_rate;
                    }
                }

                if (input.StartsWith("SetEmp:"))
                {
                    string Empsetting = input.Substring(7);
                    if (Emphasisvalues.ContainsKey(Empsetting))
                    {
                        PromptEmphasis emp_val = Emphasisvalues[Empsetting];
                        style_.Emphasis = emp_val;
                    }
                }
                if (input.StartsWith("<Deepener>"))
                {
                    //Make note of the deepender here.
                    if (!random_lines.ContainsKey(index))
                    {
                        random_lines.Add(index, "<Deepener>");
                    }
                    //now we will run a Deepener script here.

                    int    Deepener_Count = Deepener_names.Count();
                    Random r             = new Random();
                    int    next_Deepener = r.Next(Deepener_Count);
                    string Deepener_name = Deepener_names[next_Deepener];
                    //Some recursive magic now
                    SpeechScriptInterpreter Deepener_interpreter = new SpeechScriptInterpreter();
                    Deepener_interpreter.Init_Voice(Program.voicename); //Initialize the new interpreter instance
                    Deepener_interpreter.parse(Deepener_name);
                }

                if (input.StartsWith("<Goto:"))
                {
                    string command = "Goto";
                    //Get the anchor object.
                    Anchor A = FetchAnchor(input, command);

                    //The '!' character is reserved and anchors cannot use it
                    //It is used to denote a failed fetch. To prevent NullErrors.

                    if (A.name != "!")
                    {
                        int line_index = A.line_number;
                        //Assign indirectly the index of this trance to the Anchor index.
                        index = line_index;
                    }
                }

                //Change inputs by setting functions for them for more efficient parsing and
                //Templating of code blocks.
                if (input.StartsWith("<QueryMulti:"))
                {
                    QueryMulti(input);
                }

                if (input.StartsWith("<QueryDeepEnough>"))
                {
                    Dialouge get_state = new Dialouge();
                    say_default("Are you deep enough yet?");
                    get_state.ShowDialog();
                    //Find out yes or no
                    string result = get_state.ReturnValue;
                    if (result == "Yes")
                    {
                        continue;
                    }
                    if (result == "No")
                    {
                        for (int i = index; i > 0; i--)
                        {
                            //search backwards for the previous Deepener
                            //Did we find a '<Deepener> tag?
                            if (random_lines.ContainsKey(i))
                            {
                                if (random_lines[i] == "<Deepener>")
                                {
                                    //does it match?
                                    //if it does, we go backwards in the script
                                    //All the way to this point
                                    index = i - 1;
                                    break; //We want to quit the search
                                }
                            }
                        }
                    }
                }

                //Generic Query
                if (input.StartsWith("<QueryGeneric:"))
                {
                    HandleQuery(input);
                }


                //Say the stuff, treating our rate and emphasis as part of a state machine
                //Which we re-apply each time something is to be spoken.
                if (input.StartsWith("Say:"))
                {
                    string voice_string = input.Substring(4);
                    builder.ClearContent();
                    builder.StartVoice(Program.voicename);
                    builder.StartSentence();
                    builder.StartStyle(style_);
                    builder.AppendText(voice_string);
                    builder.EndStyle();
                    builder.EndSentence();
                    builder.EndVoice();
                    //lastly let the ball roll and see if we can hear some chatter.
                    reader.Speak(builder);
                }
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            SpeechScriptInterpreter interpreter = new SpeechScriptInterpreter();

            //Call Initialize on the interpreter
            interpreter.init();
            //Call parse so we can hear it talk! Hopefully it can parse the test file. :D.
            interpreter.parse("BiggusScript.txt");


            //Old stuff keeping as example below

            /*
             * SpeechSynthesizer reader = new SpeechSynthesizer();
             * reader.SelectVoice("IVONA 2 Salli");
             * PromptBuilder b = new PromptBuilder();
             *
             *
             * PromptStyle s = new PromptStyle(PromptRate.ExtraFast);
             * s.Rate = PromptRate.Medium;
             * s.Volume = PromptVolume.Loud;
             * s.Emphasis = PromptEmphasis.Strong;
             * PromptRate.
             *
             *
             *
             * b.StartSentence();
             * b.StartStyle(s);
             * b.AppendText("Hello Iridescent");
             * b.EndStyle();
             * b.AppendBreak(new TimeSpan(0, 0, 2));
             * s.Emphasis = PromptEmphasis.Reduced;
             * s.Rate = PromptRate.Fast;
             * b.StartStyle(s);
             * b.AppendText("This is less emphasized");
             * b.EndStyle();
             * b.EndSentence();
             *
             *
             *
             * b.AppendBreak(new TimeSpan(0, 0, (int) 1.5));
             * b.StartSentence();
             * b.AppendText("How", PromptEmphasis.Moderate);
             * b.AppendText("Are", PromptVolume.Loud);
             * b.AppendText("You?", PromptEmphasis.Strong);
             *
             * b.AppendText("WEEEEEEEEEEEEEEEEEEE");
             * b.EndSentence();
             *
             *
             * reader.Speak(b);
             *
             *
             * // b.StartStyle(c );
             * // b.EndStyle();
             * b.StartSentence();
             * b.AppendText("Hey");
             * b.EndSentence();
             * b.AppendBreak(new TimeSpan(0, 0, (int)3));
             *
             *
             * reader.Speak(b);
             * reader.SpeakCompleted += compl;
             * reader.Speak(b);
             *
             *
             *
             *
             *
             *
             *
             * List<string> vnames = new List<string>();
             * foreach (InstalledVoice voice in reader.GetInstalledVoices())
             * {
             *  VoiceInfo info = voice.VoiceInfo;
             *  //Console.WriteLine(" Voice Name: " + info.Name);
             *  vnames.Add(info.Name);
             * }
             * Console.WriteLine("hello");
             *
             * reader.Speak(b);
             *
             *
             *
             * for (int i=-10; i<10; i++)
             * {
             *  reader.Rate = i;
             *  reader.Speak("You will obey");
             *  reader.Rate = 5;
             *
             * }
             *
             *
             */
        }