IEnumerator DynamicStoryExample()
    {
        NovelController.instance.LoadChapterFile("story_1"); yield return(new WaitForEndOfFrame());

        while (NovelController.instance.isHandlingChapterFile)
        {
            yield return(new WaitForEndOfFrame());
        }

        ChoiceScreen.Show("What will you do?", "Go with Terrance", "Stay where you are");
        while (ChoiceScreen.isWaitingForChoiceToBeMade)
        {
            yield return(new WaitForEndOfFrame());
        }

        //you chose to go with Terrance
        if (ChoiceScreen.lastChoiceMade.index == 0)
        {
            NovelController.instance.LoadChapterFile("story_a1");
        }
        //you chose to stay where you are
        else
        {
            NovelController.instance.LoadChapterFile("story_b1");
        }

        yield return(new WaitForEndOfFrame());

        NovelController.instance.Next();

        while (NovelController.instance.isHandlingChapterFile)
        {
            yield return(new WaitForEndOfFrame());
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         ChoiceScreen.Show(title, "Dogs", "Cats");
     }
 }
Exemple #3
0
    IEnumerator HandlingChoiceLine(string line)
    {
        string        title   = line.Split('"')[1];
        List <string> choices = new List <string>();
        List <string> actions = new List <string>();

        bool gatheringChoices = true;

        while (gatheringChoices)
        {
            chapterProgress++;
            line = data[chapterProgress];

            if (line == "{")
            {
                continue;
            }

            line = line.Replace("\t", "");//remove the tabs that have become quad spaces.

            if (line != "}")
            {
                choices.Add(line.Split('"')[1]);
                actions.Add(data[chapterProgress + 1].Replace("\t", ""));
                chapterProgress++;
            }
            else
            {
                gatheringChoices = false;
            }
        }

        //display choices if
        if (choices.Count > 0)
        {
            ChoiceScreen.Show(title, choices.ToArray()); yield return(new WaitForEndOfFrame());

            while (ChoiceScreen.isWaitingForChoiceToBeMade)
            {
                yield return(new WaitForEndOfFrame());
            }

            //choice is made
            string action = actions[ChoiceScreen.lastChoiceMade.index];
            HandleLine(action);

            while (isHandlingLine)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
        else
        {
            Debug.LogError("Invalid choice operation. No choices were found.");
        }
    }
Exemple #4
0
    /// <summary>
    /// Handling choice command
    /// </summary>
    /// <param name="choice"></param>
    /// <returns></returns>
    IEnumerator HandlingChoiceLine(string line)
    {
        string        title   = line.Split('"')[1];
        List <string> choices = new List <string>();
        List <string> actions = new List <string>();

        while (true)
        {
            chapterProgress++;
            line = data[chapterProgress];

            if (line == "{")
            {
                continue;
            }

            line = line.Replace("\t", "");
            if (line != "}")
            {
                choices.Add(line.Split('"')[1]);
                string act = data[chapterProgress + 1].Replace("\t", "");
                print(act);
                actions.Add(act);
                chapterProgress++;
            }
            else
            {
                break;
            }
        }
        if (choices.Count > 0)
        {
            ChoiceScreen.Show(title, choices.ToArray());
            yield return(new WaitForEndOfFrame());

            while (ChoiceScreen.isWaitingChoiceToBeMade)
            {
                yield return(new WaitForEndOfFrame());
            }

            // choice is made. execute the paired actions
            string action = actions[ChoiceScreen.lastChoiceMade.index];
            handleLine(action);

            while (isHandlingLine)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
        else
        {
            Debug.LogError("invalid Choice operation");
        }
    }
    public IEnumerator HandleLine(string line)
    {
        string title = line.Split('"')[1];

        List <string> choices = new List <string>();
        Dictionary <string /*choice*/, List <string> > /*line / action list*/ actions = new Dictionary <string, List <string> >();
        bool gatheringChoices = true;
        bool gatheringActions = false;

        int cProgress = dialogueController.chapterProgress;

        while (gatheringChoices || gatheringActions)
        {
            cProgress++;
            line = dialogueController.data[cProgress];

            if (line == "{")
            {
                continue;
            }
            if (line == "}")
            {
                gatheringChoices = false;
                gatheringActions = false;
                continue;
            }

            line = line.Trim();

            if (gatheringChoices)
            {
                if (line.ToLower().StartsWith("["))
                {
                    gatheringChoices = false;
                    gatheringActions = true;
                    continue;
                }

                choices.Add(line.Split('"')[1]);
                actions.Add(line.Split('"')[1], new List <string>());
            }
            else
            {
                if (line.ToLower().StartsWith("]"))
                {
                    gatheringChoices = true;
                    gatheringActions = false;
                    continue;
                }

                actions[choices.Last()].Add(line);
            }
        }

        if (choices.Count > 0)
        {
            ChoiceScreen.Show(title, choices.ToArray());


            ///TODO:
            ///BLOCK OFF CHOICES THAT ARE NOT SELECTED if this is the past.

            yield return(new WaitForEndOfFrame());

            Debug.Log("BEGIN WAITING FOR CHOICE");

            while (ChoiceScreen.isWaitingForChoiceToBeMade)
            {
                yield return(new WaitForEndOfFrame());
            }

            Debug.Log("DONE WAITING FOR CHOICE");

            List <string> actionList = actions[choices[ChoiceScreen.lastChoiceMade.index]];

            foreach (Tuple <int, string> addedData in actionList.Select(s => new Tuple <int, string>(actionList.IndexOf(s) + 1 + cProgress, s)))
            {
                if (dialogueController.data[addedData.Item1] != addedData.Item2)
                {
                    dialogueController.data.Insert(addedData.Item1, addedData.Item2);
                }
            }
        }
        else
        {
            Debug.LogError("Invalid choice operation, no choices are found");
        }

        dialogueController.chapterProgress = cProgress;
        dialogueController.chapterProgress++;
        //Debug.Log("cProgress at: " + cProgress + " chaoterProgessAt: " + dialogueController.chapterProgress);

        dialogueController._next = true;
        dialogueController.StopHandlingLine();
    }