Esempio n. 1
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);
        }
Esempio n. 2
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]);
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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");
            }
        }
Esempio n. 5
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]]);
                }
            }
        }
Esempio n. 6
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");
        }
Esempio n. 7
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");
            }
Esempio 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");
            }
        }
Esempio n. 9
0
        public void NameChangeCallback()
        {
            const string   person  = "Person";
            NpcChatProject project = new NpcChatProject();
            bool           result  = project.ProjectCharacters.RegisterNewCharacter(out int gen, person);

            Assert.IsTrue(result);

            //register for callbacks
            bool callbackTriggered = false;

            project.ProjectCharacters.CharacterChanged += (id, changed) =>
            {
                Assert.AreEqual(gen, id);
                callbackTriggered = true;
            };

            Character character = project.ProjectCharacters.GetCharacter(gen);

            const string person2 = person + "_NEW!";

            character.Name = person2;

            Assert.AreEqual(person2, character.Name);
            Assert.IsTrue(callbackTriggered, "Change callback not fired, though the character name was changed!");
        }
Esempio 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);
        }
Esempio n. 11
0
        public TreeBranchLinkInfoVM([NotNull] NpcChatProject project, [NotNull] IScriptPanelVM script,
                                    DialogTreeBranchIdentifier parent, DialogTreeBranchIdentifier child)
        {
            m_project = project;
            m_script  = script;
            Parent    = parent;
            Child     = child;

            if (!project[parent].Children.Contains(child))
            {
                Logging.Logger.Warn($"Tree Branch link created with a parent '{parent}' that doesn't have the child '{child}' as a Child relationship");
                //todo should this throw?
            }

            m_project[child].PropertyChanged += OnChanged;
            RebaseScriptView = new DelegateCommand(() =>
            {
                if (Parent == Child)
                {
                    Logging.Logger.Warn($"Tree Branch link invalid, parent and child identicle '{Parent}'");
                    return;
                }

                m_script.RebaseBranchList(Parent, Child);
            });
            RemoveLinkCommand = new DelegateCommand(RemoveLink);
        }
Esempio n. 12
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");
        }
Esempio n. 13
0
        public BranchInput(NpcChatProject project)
        {
            Name           = "Parents";
            MaxConnections = int.MaxValue;
            m_project      = project;

            ConnectionValidator = ValidatePendingConnection;
        }
Esempio n. 14
0
        public void NewCharIdTestPlain(string name)
        {
            NpcChatProject project = new NpcChatProject();
            bool           result  = project.ProjectCharacters.RegisterNewCharacter(out int gen, name);

            Assert.IsTrue(result);
            Assert.AreNotEqual(NpcChatSystem.Data.Character.Character.PreRegisteredId, gen);
            Assert.AreEqual(project.ProjectCharacters.GetCharacter(gen).Id, gen);
        }
Esempio n. 15
0
        public void NoCharacter()
        {
            NpcChatProject project = new NpcChatProject();

            DialogCharacterTrait element = DialogTypeStore.Instance.CreateEntity <DialogCharacterTrait>(project);

            Assert.IsFalse(project.ProjectCharacters.HasCharacter(element.CharacterId));
            Assert.AreEqual("<???>", element.Text, "missing character should return a fallback value");
        }
Esempio n. 16
0
        public void GetBranch()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            DialogTreeBranch aBranch = tree.CreateNewBranch();

            Assert.AreSame(aBranch, tree.GetBranch(aBranch));
        }
Esempio n. 17
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));
        }
        public override IEvaluationContainer CreateEntity(Type elementType, NpcChatProject project = null)
        {
            if (!m_elementLookup.ContainsValue(elementType))
            {
                return(null);
            }

            KeyValuePair <string, Type> key = m_elementLookup.First(k => k.Value == elementType);

            return(CreateEntity(key.Key));
        }
Esempio n. 19
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'");
        }
        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");
        }
Esempio n. 21
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;
            }
        }
Esempio n. 22
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));
        }
Esempio n. 23
0
        public BranchNode(NpcChatProject project)
        {
            m_project = project;
            m_branch  = null;

            ParentPin = new BranchInput(m_project, this);
            ChildPin  = new BranchOutput(this);
            Inputs.Add(ParentPin);
            Outputs.Add(ChildPin);
            CanBeRemovedByUser = false;

            Name = "Dialog Branch";
        }
Esempio n. 24
0
        public TE CreateEntity <TE>(NpcChatProject project = null) where TE : class, T
        {
            Type desiredType = typeof(TE);

            if (!m_elementLookup.ContainsValue(desiredType))
            {
                Logging.Logger.Warn($"Unable to instantiate '{typeof(TE).FullName}'");
                return(null);
            }

            KeyValuePair <string, Type> key = m_elementLookup.First(k => k.Value == desiredType);

            return(CreateEntity(key.Key, project) as TE);
        }
Esempio n. 25
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);
        }
Esempio n. 26
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));
        }
Esempio n. 27
0
        public ProjectOverviewVM(NpcChatProject project)
        {
            m_project = project;
            Title     = "Project Overview";

            project.ProjectCharacters.CharacterAdded   += id => RaisePropertyChanged(nameof(CharacterCount));
            project.ProjectCharacters.CharacterRemoved += id => RaisePropertyChanged(nameof(CharacterCount));
            RefreshCharacterDataCommand = new DelegateCommand(RefreshCharacterData);
            RefreshCharacterDataCommand.Execute(null); // force update

            project.ProjectDialogs.OnDialogTreeAdded   += id => RaisePropertyChanged(nameof(DialogTreeCount));
            project.ProjectDialogs.OnDialogTreeRemoved += id => RaisePropertyChanged(nameof(DialogTreeCount));
            RefreshDialogDataCommand = new DelegateCommand(RefreshDialogData);
            RefreshDialogDataCommand.Execute(null); // force update
        }
Esempio n. 28
0
        public void AddNewBranchCommand()
        {
            NpcChatProject project = new NpcChatProject();
            DialogTree     tree    = project.ProjectDialogs.CreateNewDialogTree();

            bool          branchesChanged = false;
            ScriptPanelVM script          = new ScriptPanelVM(project, tree);

            script.OnVisibleBranchChange += (t) => branchesChanged = true;
            Assert.AreEqual(1, tree.Branches.Count);

            script.NewBranchCommand.Execute(null);
            Assert.AreEqual(2, tree.Branches.Count);
            Assert.IsTrue(branchesChanged, $"Command should have triggered change event");
        }
        public override IEvaluationContainer CreateEntity(string elementName, NpcChatProject project = null)
        {
            if (m_elementLookup.ContainsKey(elementName))
            {
                Type type = m_elementLookup[elementName];

                if (type.GetConstructors().Any(c => c.GetParameters().Length == 0))
                {
                    return(Activator.CreateInstance(type) as IEvaluationContainer);
                }
            }

            Logging.Logger.Warn($"Unable to instantiate '{elementName}'");
            return(null);
        }
Esempio n. 30
0
        public void CharacterList()
        {
            const string   name1   = "Person";
            const string   name2   = "Person2";
            const string   name3   = "Person3";
            NpcChatProject project = new NpcChatProject();

            Assert.AreEqual(0, project.ProjectCharacters.AvailableCharacters().Count);

            bool result = project.ProjectCharacters.RegisterNewCharacter(out int gen1, name1);

            Assert.IsTrue(result);
            Assert.AreEqual(1, project.ProjectCharacters.AvailableCharacters().Count);
            Assert.Contains(name1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());

            result = project.ProjectCharacters.RegisterNewCharacter(out int gen2, name2);
            Assert.IsTrue(result);
            Assert.AreEqual(2, project.ProjectCharacters.AvailableCharacters().Count);
            Assert.Contains(name1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.Contains(name2, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen2, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());

            result = project.ProjectCharacters.RegisterNewCharacter(out int gen3, name3);
            Assert.IsTrue(result);
            Assert.AreEqual(3, project.ProjectCharacters.AvailableCharacters().Count);
            Assert.Contains(name1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.Contains(name2, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen2, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.Contains(name3, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen3, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());

            const string name4 = name2 + "00";
            Character    char2 = project.ProjectCharacters.GetCharacter(gen2);

            char2.Name = name4;
            Assert.AreEqual(3, project.ProjectCharacters.AvailableCharacters().Count);
            Assert.Contains(name1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen1, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.Contains(name4, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen2, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.Contains(name3, project.ProjectCharacters.AvailableCharacters().Select(i => i.Name).ToList());
            Assert.Contains(gen3, project.ProjectCharacters.AvailableCharacters().Select(i => i.Id).ToList());
            Assert.IsFalse(project.ProjectCharacters.AvailableCharacters().Any(i => i.Name == name2),
                           "Available Characters list still contains old name which should have been renamed (and thereby removed)");
        }