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"); }
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); }
/// <summary> /// Would adding <see cref="potentialChild"/> as a child of <see cref="parent"/> result in a circular dependency? /// </summary> /// <returns>true if adding this item would have a circular dependency</returns> public static bool CheckForCircularDependency(this DialogTree tree, DialogTreeBranchIdentifier parent, DialogTreeBranchIdentifier potentialChild) { if (!tree.Id.Compatible(parent) || !tree.Id.Compatible(potentialChild) || !tree.HasBranch(parent) || !tree.HasBranch(potentialChild)) { // If the segment isn't compatible with the tree there can't be a circular dependency return(false); } if (parent == potentialChild) { // Adding yourself would defiantly cause a circular dependency return(true); } foreach (DialogTreeBranchIdentifier childParent in tree[parent].Parents) { if (childParent == potentialChild || CheckCircularDependencyParents(tree, childParent, potentialChild)) { return(true); } } return(false); }
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]); }
public void BranchToTree() { DialogTreeIdentifier id1 = new DialogTreeIdentifier(23); DialogTreeBranchIdentifier id2 = new DialogTreeBranchIdentifier(666, 2); Assert.IsFalse(id1.Compatible(id2)); id2 = new DialogTreeBranchIdentifier(23, 2); Assert.IsTrue(id1.Compatible(id2)); }
public void SegmentToBranch() { DialogTreeBranchIdentifier id1 = new DialogTreeBranchIdentifier(23, 2); DialogSegmentIdentifier id2 = new DialogSegmentIdentifier(666, 2, 5); Assert.IsFalse(id1.Compatible(id2)); id2 = new DialogSegmentIdentifier(23, 2, 5); Assert.IsTrue(id1.Compatible(id2)); id2 = new DialogSegmentIdentifier(23, 2, 343); Assert.IsTrue(id1.Compatible(id2)); }
public BranchNode(NpcChatProject project, DialogTreeBranchIdentifier branchId) : this(project) { if (branchId != null) { m_branch = branchId; DialogTreeBranch branch = project[branchId]; Name = branch.Name; branch.PropertyChanged += BranchChanged; } }
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"; }
private static bool CheckCircularDependencyParents(DialogTree tree, DialogTreeBranchIdentifier parent, DialogTreeBranchIdentifier potentialChild) { foreach (DialogTreeBranchIdentifier childParent in tree[parent].Parents) { if (childParent == potentialChild || CheckCircularDependencyParents(tree, childParent, potentialChild)) { return(true); } } return(false); }
public void ClearBranchListAfterParent(DialogTreeBranchIdentifier parent) { throw new NotImplementedException(); }
public void RebaseBranchList(DialogTreeBranchIdentifier parent, DialogTreeBranchIdentifier child) { RebaseHistory.Add(parent); }
public DialogTreeBranchIdentifier AddNewBranch(DialogTreeBranchIdentifier parentId, bool updateView) { throw new NotImplementedException(); }
public bool HasDialog(DialogTreeBranchIdentifier id) { DialogTreeBranch branch = this[id]; return(branch != null); }
public DialogTreeBranch this[DialogTreeBranchIdentifier id] => GetDialog(id)?[id];
public DialogTreeBranch this[DialogTreeBranchIdentifier id] => ProjectDialogs[id];