Beispiel #1
0
        public static void ClearDialogSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new SetDialogNode("Alice", "Hello world!")
                      , new ClearNode(ClearType.Dialog)
                  } }
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Alice", "Hello world!" }
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
            },
                rumor.State.GetDialog()
                );
        }
        public static void ChoiceSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new AddChoiceNode("choice1", "Hello?")
                      , new AddChoiceNode("choice2", "Hello??")
                  } }
            }
                );

            rumor.Start();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "choice1", "Hello?" },
                { "choice2", "Hello??" }
            },
                rumor.State.GetChoices()
                );
        }
        public static void AutoAdvance0()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new SetDialogNode("Alice", "Hello world!")
                      , new SetDialogNode("Alice", "How are you?")
                  } }
            }
                );

            rumor.Start();
            rumor.SetAutoAdvance(0);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Alice", "How are you?" }
            },
                rumor.State.GetDialog()
                );

            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
        public static void JumpSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new JumpNode("foobar")
                      , new WaitNode()
                  } },
                { "foobar", new List <Node>()
                  {
                      new WaitNode()
                  } }
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);

            rumor.Advance();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
Beispiel #5
0
        public static void ChoiceTimeoutSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new AddChoiceNode("choice1", "Hello?")
                      , new AddChoiceNode("choice2", "World?")
                      , new ChooseNode(
                          new NumberLiteral(2),
                          MoveType.Jump,
                          "choice2"
                          )
                  } },
                { "choice1", new List <Node>()
                  {
                      new SetDialogNode("Alice", "Choice 1!")
                  } },
                { "choice2", new List <Node>()
                  {
                      new SetDialogNode("Eve", "Choice 2!")
                  } }
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "choice1", "Hello?" },
                { "choice2", "World?" },
            },
                rumor.State.GetChoices()
                );

            rumor.Update(2);
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
            },
                rumor.State.GetChoices()
                );
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Eve", "Choice 2!" }
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
Beispiel #6
0
        void Awake()
        {
            rumor = new Rumor(asset.text);
            rumor.Scope.DefaultSpeaker = "Narrator";

            rumor.Bindings.Bind("get_apples", () => { return(Random.Range(2, 6)); });
            rumor.Bindings.Bind("get_pears", () => { return(Random.Range(2, 6)); });

            StartCoroutine(rumor.Start());
        }
        void Awake()
        {
            rumor = new Rumor(@"
label start:
	say ""Hi!""
	say ""Is this working?""

	choice ""Yes!"":
		say ""Great!""
	choice ""No."":
		say ""Darn...""
		pause 0.5
		add ""Maybe next time.""
		jump end
	choose

$ apples = get_apples()
$ pears = get_pears()

if apples == pears:
	$ pears += 1

say ""I have "" + apples + "" apples.""
say ""You have {pears} pears.""
say ""Who has more fruits?""

choice ""I do."":
	if apples < pears:
		jump correct
	jump incorrect
choice ""You do."":
	if apples > pears:
		jump correct
	jump incorrect
choose

label correct:
	say ""That's right!""
	jump end

label incorrect:
	say ""That's wrong!""
	jump end

label end:
	say ""Well, thanks for stopping by!""
	say ""See you next time!""
");
            rumor.Scope.DefaultSpeaker = "Narrator";

            rumor.Bindings.Bind("get_apples", () => { return(Random.Range(2, 6)); });
            rumor.Bindings.Bind("get_pears", () => { return(Random.Range(2, 6)); });

            StartCoroutine(rumor.Start());
        }
        public static void ReturnSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new ReturnNode()
                      , new WaitNode()
                  } },
            }
                );

            rumor.Start();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
        public static void CallFailure()
        {
            var rumor = new Rumor(
                new Dictionary<string, List<Node>>
                {
                    { Rumor.MainIdentifier, new List<Node>()
                        { new CallNode("foobar")
                        }
                    }
                }
            );

            var exception = Assert.Throws<InvalidOperationException>(() =>
                rumor.Start()
            );
            Assert.AreEqual(
                "The label \"foobar\" does not exist!",
                exception.Message
            );
        }
        public static void PauseSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new PauseNode(1d)
                  } },
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);

            rumor.Update(0.5f);
            Assert.IsTrue(rumor.Executing);

            rumor.Update(0.5f);
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
 private void Start()
 {
     StartCoroutine(rumor.Start());
 }