Exemplo n.º 1
0
        public void NewBranchNameDuplication()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            List <string> newNames = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                DialogTreeBranch newBranch = tree.CreateNewBranch();
                Assert.NotNull(newBranch);

                newNames.Add(newBranch.Name);
            }

            for (int inner = 0; inner < newNames.Count; inner++)
            {
                for (int outer = 0; inner < newNames.Count; inner++)
                {
                    if (inner == outer)
                    {
                        continue;
                    }
                    Assert.AreNotEqual(newNames[inner], newNames[outer]);
                }
            }
        }
Exemplo n.º 2
0
        public void PossibleBranchLinkPreExisting()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch a = tree.GetStart();

            a.Name = "A";
            BranchTestScriptView branchTest = new BranchTestScriptView();
            TreeBranchVM         aBranch    = new TreeBranchVM(project, branchTest, a);

            branchTest.Branches.Add(aBranch);

            //no other branches so there shouldn't be any possibilities
            TestBranchPossibility(aBranch);

            DialogTreeBranch b = tree.CreateNewBranch();

            b.Name = "B";
            RelationshipCreate(a, b);

            TreeBranchVM bBranch = new TreeBranchVM(project, branchTest, b);

            branchTest.Branches.Add(bBranch);

            //branches already linked so there shouldn't be any possible links
            TestBranchPossibility(aBranch);
            TestBranchPossibility(bBranch);
        }
Exemplo n.º 3
0
        public void AddBranch2()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            for (int i = 0; i < 10; i++)
            {
                DialogTreeBranch newBranch = tree.CreateNewBranch();
                Assert.NotNull(newBranch);
            }

            IReadOnlyList <DialogTreeBranchIdentifier> branches = tree.Branches;

            for (int inner = 0; inner < branches.Count; inner++)
            {
                for (int outer = 0; inner < branches.Count; inner++)
                {
                    if (inner == outer)
                    {
                        continue;
                    }
                    Assert.AreNotEqual(branches[inner], branches[outer]);
                    Assert.AreNotEqual(tree[branches[inner]], tree[branches[outer]]);
                }
            }
        }
Exemplo n.º 4
0
        public void PossibleBranchLinkAdded2()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch a = tree.GetStart();

            a.Name = "A";
            BranchTestScriptView branchTest = new BranchTestScriptView();
            TreeBranchVM         aBranch    = new TreeBranchVM(project, branchTest, a);

            branchTest.Branches.Add(aBranch);

            Assert.IsFalse(aBranch.AreBranchLinksPossible, "Branch links are possible as there are no other branches");
            Assert.AreEqual(0, aBranch.PotentialBranchLinks.Count);

            DialogTreeBranch b = tree.CreateNewBranch();

            b.Name = "B";
            TreeBranchVM bBranch = new TreeBranchVM(project, branchTest, b);

            branchTest.Branches.Add(bBranch);

            //no relation between the branches so all links are possible
            TestBranchPossibility(aBranch, b);
            TestBranchPossibility(bBranch, a);

            // link a to b so that the options for both branches are limited
            RelationshipCreate(a, b);

            //A is parent of B so there should be no possible actions
            TestBranchPossibility(aBranch);
            TestBranchPossibility(bBranch);
        }
        public void DialogGetter(int offset)
        {
            DialogTree tree = m_project.ProjectDialogs.CreateNewDialogTree();

            Assert.IsNotNull(tree);
            Assert.IsNotNull(m_project.ProjectDialogs[tree]);
            DialogTreeIdentifier fakeTreeId = new DialogTreeIdentifier(tree.Id.DialogTreeId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeTreeId]);

            DialogTreeBranch branch = tree.CreateNewBranch();

            Assert.IsNotNull(branch);
            Assert.IsNotNull(m_project.ProjectDialogs[branch]);
            DialogTreeBranchIdentifier fakeBranchId = new DialogTreeBranchIdentifier(branch.Id, branch.Id.DialogTreeBranchId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeBranchId]);

            DialogSegment dialogSegment = branch.CreateNewDialog(CharacterId.DefaultId);

            Assert.IsNotNull(dialogSegment);
            Assert.IsNotNull(m_project.ProjectDialogs[dialogSegment.Id]);
            DialogSegmentIdentifier fakeSegmentId = new DialogSegmentIdentifier(dialogSegment.Id, dialogSegment.Id.DialogSegmentId + offset);

            Assert.IsNull(m_project.ProjectDialogs[fakeSegmentId]);
        }
Exemplo n.º 6
0
        public void ChangeCharacter()
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int bill, "bill") &&
                project.ProjectCharacters.RegisterNewCharacter(out int tommy, "tommy"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(bill);
                Assert.NotNull(segment);
                Assert.AreEqual(segment.CharacterId, bill, "Unexpected Character");

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                segment.ChangeCharacter(tommy);

                Assert.AreEqual(segment.CharacterId, tommy, "Failed change character");
                Assert.IsTrue(callback, "Failed to send callback for character change");

                callback = false;
                segment.ChangeCharacter(bill);

                Assert.AreEqual(segment.CharacterId, bill, "Failed change character");
                Assert.IsTrue(callback, "Failed to send callback for character change");
            }
Exemplo n.º 7
0
        public void ClearElements()
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(id);
                Assert.NotNull(segment);

                DialogText one = DialogTypeStore.Instance.CreateEntity <DialogText>();
                one.Text = "one";
                segment.AddDialogElement(one);

                Assert.IsTrue(segment.SegmentParts.Count > 0);

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                segment.ClearElements();

                Assert.AreEqual(0, segment.SegmentParts.Count);
                Assert.IsTrue(callback, "Failed to send callback for added type");
            }
            else
            {
                Assert.Fail("Failed to create character");
            }
        }
Exemplo n.º 8
0
        public void AddElement(Type dialogType)
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(id);
                Assert.NotNull(segment);

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                int            before  = segment.SegmentParts.Count;
                IDialogElement element = DialogTypeStore.Instance.CreateEntity(dialogType);
                segment.AddDialogElement(element);

                Assert.AreEqual(before + 1, segment.SegmentParts.Count);
                Assert.IsTrue(callback, "Failed to send callback for added type");
            }
            else
            {
                Assert.Fail("Failed to create character");
            }
        }
Exemplo n.º 9
0
        public void ClearBranchListAfterParentRemoteBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch start = tree.GetStart();

            Assert.AreEqual(1, tree.Branches.Count);

            DialogTreeBranch unusedBranch    = tree.CreateNewBranch();
            bool             branchesChanged = false;

            ScriptPanelVM script = new ScriptPanelVM(project, tree);

            script.OnVisibleBranchChange += (t) => branchesChanged = true;
            DialogTreeBranchIdentifier firstChild  = script.AddNewBranch(start, true);
            DialogTreeBranchIdentifier secondChild = script.AddNewBranch(firstChild, true);

            // ensure all 3 branches are currently visible
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == start), $"Should be able to see '{nameof(start)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == firstChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == secondChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsFalse(script.Branches.Any(b => b.DialogBranch == unusedBranch), $"Shouldn't be able to see '{nameof(unusedBranch)}'");
            Assert.IsTrue(branchesChanged, $"Branches changed since creation");

            branchesChanged = false;
            script.ClearBranchListAfterParent(unusedBranch);

            // ensure same branches are still currently visible
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == start), $"Should be able to see '{nameof(start)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == firstChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsTrue(script.Branches.Any(b => b.DialogBranch == secondChild), $"Should be able to see '{nameof(firstChild)}'");
            Assert.IsFalse(script.Branches.Any(b => b.DialogBranch == unusedBranch), $"Shouldn't be able to see '{nameof(unusedBranch)}'");
            Assert.IsFalse(branchesChanged, $"No branches changed");
        }
Exemplo n.º 10
0
        private CharacterDialogVM ElementTextEditTestCreation()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch  = tree.CreateNewBranch();

            Assert.AreEqual(0, branch.Dialog.Count, "This is a new branch and shouldn't have any dialog inside it!");

            int charId;

            Assert.IsTrue(project.ProjectCharacters.RegisterNewCharacter(out charId, "Gerald"));
            DialogSegment dialogSegment = branch.CreateNewDialog(charId);

            Assert.AreEqual(1, branch.Dialog.Count, "Failed to create sample dialog segment");

            dialogSegment.ClearElements();
            Assert.AreEqual(0, dialogSegment.SegmentParts.Count);
            Assert.AreEqual("", dialogSegment.Text);

            CharacterDialogVM testVM = new CharacterDialogVM(project, dialogSegment)
            {
                EditMode         = EditMode.Elements,
                InspectionActive = false
            };

            // make sure creation was valid
            Assert.NotNull(testVM);
            Assert.AreSame(dialogSegment, testVM.DialogSegment);
            Assert.AreEqual(0, testVM.DialogSegment.SegmentParts.Count);

            return(testVM);
        }
Exemplo n.º 11
0
        public void Start()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();

            Assert.NotNull(start, "There should be a default start node when creating a dialog tree");
        }
Exemplo n.º 12
0
        public void DuplicateIdTest()
        {
            DialogTree       tree    = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch1 = tree.CreateNewBranch();
            DialogTreeBranch branch2 = tree.CreateNewBranch();

            Assert.AreEqual(branch1.Id.DialogTreeId, branch2.Id.DialogTreeId);
            Assert.AreNotEqual(branch1.Id.DialogTreeBranchId, branch2.Id.DialogTreeBranchId);
        }
Exemplo n.º 13
0
        public void GetBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.AreSame(aBranch, tree.GetBranch(aBranch));
        }
Exemplo n.º 14
0
        public void DuplicateIdTest()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);
            DialogSegment    two    = branch.CreateNewDialog(13);

            Assert.AreNotEqual(one.Id, two.Id);
        }
Exemplo n.º 15
0
        public void GetBranchFromAnotherTree()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTree     tree2   = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.Null(tree2.GetBranch(aBranch));
        }
Exemplo n.º 16
0
        public void NullRemove()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);

            // remove existing
            Assert.IsFalse(branch.RemoveDialog((DialogSegment)null));
            Assert.IsFalse(branch.RemoveDialog((DialogSegmentIdentifier)null));
        }
Exemplo n.º 17
0
        public BranchNode(NpcChatProject project, DialogTreeBranchIdentifier branchId)
            : this(project)
        {
            if (branchId != null)
            {
                m_branch = branchId;

                DialogTreeBranch branch = project[branchId];
                Name = branch.Name;
                branch.PropertyChanged += BranchChanged;
            }
        }
Exemplo n.º 18
0
        public void RemoveBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.NotNull(aBranch);

            Assert.IsTrue(tree.RemoveBranch(aBranch));
            Assert.IsFalse(tree.RemoveBranch(aBranch), "Removed branch which doesn't exist'");
        }
Exemplo n.º 19
0
        public void AddSelf()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.NotNull(aBranch);
            Assert.IsFalse(start.AddChild(start), "Should be able to add self");
            Assert.IsFalse(start.AddParent(start), "Should be able to add self");
        }
Exemplo n.º 20
0
        public void Contains()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);
            DialogSegment    two    = branch.CreateNewDialog(13);

            Assert.IsTrue(branch.ContainsDialogSegment(one));
            Assert.IsTrue(branch.ContainsDialogSegment(one.Id));

            Assert.IsTrue(branch.ContainsDialogSegment(two));
            Assert.IsTrue(branch.ContainsDialogSegment(two.Id));
        }
Exemplo n.º 21
0
        public void HasTree()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();

            Assert.NotNull(start);
            Assert.IsTrue(tree.HasBranch(start));

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.IsTrue(tree.HasBranch(aBranch));
        }
Exemplo n.º 22
0
        public void Contains2()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);

            Assert.IsTrue(branch.ContainsDialogSegment(one));
            Assert.IsTrue(branch.ContainsDialogSegment(one.Id));

            Assert.IsTrue(branch.RemoveDialog(one));

            Assert.IsFalse(branch.ContainsDialogSegment(one));
            Assert.IsFalse(branch.ContainsDialogSegment(one.Id));
        }
Exemplo n.º 23
0
        public void StartRemove()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();

            Assert.NotNull(start);

            Assert.IsTrue(tree.RemoveBranch(start));
            Assert.IsFalse(tree.HasBranch(start));

            start = tree.GetStart();
            Assert.Null(start);
        }
Exemplo n.º 24
0
        public void HasTreeFromSeparateTree()
        {
            NpcChatProject   project = new NpcChatProject();
            DialogTree       tree    = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start   = tree.GetStart();
            DialogTree       tree2   = project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch start2  = tree2.GetStart();

            Assert.IsTrue(tree.HasBranch(start));
            Assert.IsTrue(tree2.HasBranch(start2));

            Assert.IsFalse(tree2.HasBranch(start));
            Assert.IsFalse(tree.HasBranch(start2));
        }
Exemplo n.º 25
0
        public void DialogHasId()
        {
            DialogTree tree = m_project.ProjectDialogs.CreateNewDialogTree();

            Assert.IsTrue(m_project.ProjectDialogs.HasDialog(tree.Id));

            DialogTreeBranch branch = tree.CreateNewBranch();

            Assert.NotNull(branch);
            Assert.IsTrue(m_project.ProjectDialogs.HasDialog(branch.Id));

            DialogSegment dialogSegment = branch.CreateNewDialog(CharacterId.DefaultId);

            Assert.NotNull(dialogSegment);
            Assert.IsTrue(m_project.ProjectDialogs.HasDialog(dialogSegment.Id));
        }
Exemplo n.º 26
0
        public void Contains3()
        {
            DialogTree       tree   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch branch = tree.CreateNewBranch();
            DialogSegment    one    = branch.CreateNewDialog(12);

            Assert.IsTrue(branch.ContainsDialogSegment(one));
            Assert.IsTrue(branch.ContainsDialogSegment(one.Id));

            //make an id that has a different initial identifier but an id of an existing segment
            DialogTree              tree2   = m_project.ProjectDialogs.CreateNewDialogTree();
            DialogTreeBranch        branch2 = tree2.CreateNewBranch();
            DialogSegmentIdentifier fakeId  = new DialogSegmentIdentifier(branch2.Id, one.Id.DialogSegmentId);

            Assert.IsFalse(branch.ContainsDialogSegment(fakeId));
        }
Exemplo n.º 27
0
        public void RemoveParent()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch start   = tree.GetStart();
            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.IsTrue(aBranch.AddParent(start));
            Assert.AreEqual(1, aBranch.Parents.Count);
            Assert.AreEqual(1, start.Children.Count);

            Assert.IsTrue(aBranch.RemoveParent(start));
            Assert.AreEqual(0, aBranch.Parents.Count);
            Assert.AreEqual(0, start.Children.Count);
        }
Exemplo n.º 28
0
        public void AddBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch start = tree.GetStart();

            Assert.NotNull(start);

            DialogTreeBranch newBranch = tree.CreateNewBranch();

            Assert.NotNull(newBranch);
            Assert.AreNotSame(newBranch, start);
            Assert.AreNotEqual(newBranch, start);
            Assert.AreNotEqual(newBranch.Id, start.Id);
        }
Exemplo n.º 29
0
        public void AddChildCallback()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch start   = tree.GetStart();
            DialogTreeBranch aBranch = tree.CreateNewBranch();

            bool parentCallback = false, childCallback = false;

            aBranch.OnBranchParentAdded += id => parentCallback = true;
            start.OnBranchChildAdded    += id => childCallback = true;

            Assert.IsTrue(start.AddChild(aBranch));
            Assert.IsTrue(parentCallback, "Parent Added Callback failed");
            Assert.IsTrue(childCallback, "Child Added Callback failed");
        }
Exemplo n.º 30
0
        private void RemoveLink()
        {
            DialogTreeBranch parentBranch = m_project[(DialogTreeBranchIdentifier)Parent];

            if (parentBranch == null)
            {
                Logging.Logger.Warn($"Unable to remove branch link as parent '{Parent}' couldn't be found");
                return;
            }

            if (!parentBranch.RemoveChild(Child))
            {
                Logging.Logger.Warn($"Failed to remove link between '{Parent}' and '{Child}'");
            }
            else
            {
                m_script.ClearBranchListAfterParent(Parent);
            }
        }