/// <summary> /// Move back to a previously stepped node, the lazy execution block and callbacks at the target dialogue entry /// will be executed again. /// </summary> /// <param name="nodeName">the node to move to</param> /// <param name="dialogueIndex">the index of the dialogue to move to</param> /// <param name="variablesHash">hash of variables of the target</param> /// <param name="clearFuture">clear saved checkpoints in the future</param> public void MoveBackTo(string nodeName, int dialogueIndex, string variablesHash, bool clearFuture = false) { if (CheckActionRunning()) { return; } // animation should stop NovaAnimation.StopAll(AnimationType.All ^ AnimationType.UI); // restore history var backNodeIndex = walkedThroughNodes.FindLastIndex(x => x == nodeName); Assert.IsFalse(backNodeIndex < 0, $"Nova: move back to node {nodeName} that has not been walked through."); // state should be normal when goes backward state = State.Normal; if (clearFuture) { // all save data of nodes to be removed are deleted for (var i = backNodeIndex + 1; i < walkedThroughNodes.Count; i++) { checkpointManager.UnsetReached(walkedThroughNodes[i]); } // all save data of later dialogues are deleted for (var i = dialogueIndex + 1; i < flowChartTree.GetNode(nodeName).dialogueEntryCount; i++) { checkpointManager.UnsetReached(nodeName, i); } } var nodeHistoryRemoveLength = walkedThroughNodes.Count - backNodeIndex - 1; walkedThroughNodes.RemoveRange(backNodeIndex + 1, nodeHistoryRemoveLength); currentNode = flowChartTree.GetNode(walkedThroughNodes.Last()); currentIndex = dialogueIndex; // restore status var entry = checkpointManager.IsReached(nodeName, dialogueIndex, variablesHash); if (entry == null) { Debug.LogWarning( $"Nova: Unable to find node with varhash = {variablesHash}, falling back to any variable."); entry = checkpointManager.IsReachedForAnyVariables(nodeName, dialogueIndex); } Restore(entry); }
public void MoveBackTo(NodeHistoryEntry nodeHistoryEntry, int dialogueIndex, bool clearFuture = false, Action onFinish = null) { // Debug.Log($"MoveBackTo begin {nodeHistoryEntry.Key} {nodeHistoryEntry.Value} {dialogueIndex}"); CancelAction(); // Animation should stop NovaAnimation.StopAll(AnimationType.All ^ AnimationType.UI); // Restore history var backNodeIndex = nodeHistory.FindLastIndex(x => x.Equals(nodeHistoryEntry)); if (backNodeIndex < 0) { Debug.LogWarning($"Nova: Move back to node {nodeHistoryEntry.Key} that has not been walked through."); } if (clearFuture) { // All save data of nodes to be removed are deleted for (var i = backNodeIndex + 1; i < nodeHistory.Count; ++i) { checkpointManager.UnsetReached(nodeHistory.GetHashULong(0, i + 1)); } // All save data of later dialogues are deleted checkpointManager.UnsetReachedAfter(nodeHistory, dialogueIndex); } nodeHistory.RemoveRange(backNodeIndex + 1, nodeHistory.Count - (backNodeIndex + 1)); if (backNodeIndex < 0) { nodeHistory.Add(nodeHistoryEntry.Key); } nodeHistory.RemoveInterruptsAfter(backNodeIndex, dialogueIndex); currentNode = flowChartTree.GetNode(nodeHistoryEntry.Key); currentIndex = dialogueIndex; // Restore data var entry = checkpointManager.GetReached(nodeHistory, dialogueIndex); this.RuntimeAssert(entry != null, $"Unable to find restore entry with {nodeHistory} {nodeHistory.Hash}, dialogueIndex {dialogueIndex}"); Restore(entry, onFinish); // Debug.Log($"MoveBackTo end {nodeHistoryEntry.Key} {nodeHistoryEntry.Value} {dialogueIndex}"); }