Ejemplo n.º 1
0
        private void ReloadAndRefreshNode()
        {
            if (!gameState)
            {
                return;
            }
            NovaAnimation.StopAll();
            var currentNode  = gameState.currentNode;
            var currentIndex = gameState.currentIndex;

            SuppressSound(true);
            gameState.MoveBackTo(currentNode.name, 0, currentNodeInitialVariablesHash, clearFuture: true);
            gameState.ReloadScripts();

            // step back to current index
            for (var i = 0; i < currentIndex - 1; i++)
            {
                NovaAnimation.StopAll(AnimationType.PerDialogue | AnimationType.Text);
                gameState.Step();
            }

            NovaAnimation.StopAll(AnimationType.PerDialogue | AnimationType.Text);
            SuppressSound(false); // only the last step can play sound
            gameState.Step();
        }
Ejemplo n.º 2
0
        public void MoveBackAndFastForward(NodeHistoryEntry nodeHistoryEntry, int dialogueIndex, int stepCount,
                                           bool clearFuture, Action onFinish)
        {
            isRestoring = true;
            MoveBackTo(nodeHistoryEntry, dialogueIndex, clearFuture);
            if (actionPauseLock.isLocked)
            {
                Debug.LogWarning("Nova: GameState paused by action when restoring");
                isRestoring = false;
                return;
            }

            for (var i = 0; i < stepCount; ++i)
            {
                var isLast = i == stepCount - 1;
                if (isLast)
                {
                    isRestoring = false;
                }

                NovaAnimation.StopAll(AnimationType.PerDialogue | AnimationType.Text);
                Step();
                if (actionPauseLock.isLocked)
                {
                    Debug.LogWarning("Nova: GameState paused by action when restoring");
                    isRestoring = false;
                    return;
                }

                if (isLast)
                {
                    onFinish?.Invoke();
                }
            }
        }
Ejemplo n.º 3
0
 private void Update()
 {
     if (Input.anyKey)
     {
         NovaAnimation.StopAll(AnimationType.UI);
     }
 }
Ejemplo n.º 4
0
 private void ReloadScriptOnly()
 {
     if (!gameState)
     {
         return;
     }
     NovaAnimation.StopAll();
     gameState.ReloadScripts();
 }
Ejemplo n.º 5
0
        private void MoveBackward()
        {
            NovaAnimation.StopAll();
            dialogueBoxController.state = DialogueBoxState.Normal;

            if (gameState.SeekBackStep(1, out var nodeName, out var dialogueIndex))
            {
                gameState.MoveBackTo(nodeName, dialogueIndex);
            }
Ejemplo n.º 6
0
        private void ReloadScripts()
        {
            NovaAnimation.StopAll();
            dialogueBoxController.state = DialogueBoxState.Normal;
            gameState.ReloadScripts();
            var nodeHistoryEntry = gameState.nodeHistory.GetCounted(gameState.currentNode.name);

            gameState.MoveBackAndFastForward(nodeHistoryEntry, 0, gameState.currentIndex, true, null);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        public static void Quit()
        {
            NovaAnimation.StopAll();

#if UNITY_EDITOR
            SaveAll();
            UnityEditor.EditorApplication.isPlaying = false;
#else
            ForceQuit = true;
            Application.Quit();
            // All components write to disk in OnDestroy
#endif
        }
Ejemplo n.º 9
0
        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}");
        }
Ejemplo n.º 10
0
        public static void Exit()
        {
            NovaAnimation.StopAll();

            var gameController = FindNovaGameController();

            gameController.CheckpointManager.UpdateGlobalSave();
            gameController.ConfigManager.Apply();

#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            ForceQuit = true;
            Application.Quit();
#endif
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Restore all restorables. The lazy execution block in the target entry will be executed again.
        /// </summary>
        /// <param name="restoreDatas">restore datas</param>
        private void Restore(GameStateStepRestoreEntry restoreDatas)
        {
            // Debug.LogFormat("Steps from last ckpt: {0}", restoreDatas.stepNumFromLastCheckpoint);

            if (restoreDatas is GameStateStepRestoreCheckpointEntry checkpointEntry)
            {
                RestoreRaw(checkpointEntry);
                UpdateGameState(true, true, false, false);
            }
            else if (restoreDatas is GameStateStepRestoreSimpleEntry simpleEntry)
            {
                // Debug.Log($"Nova: Restoring simple entry from lastCheckpointVariablesHash = {simpleEntry.lastCheckpointVariablesHash}");

                if (!SeekBackStep(simpleEntry.stepNumFromLastCheckpoint, out string storedNode,
                                  out int storedDialogueIndex))
                {
                    Debug.LogErrorFormat("Nova: Failed to seek back, invalid stepNumFromLastCheckpoint: {0}",
                                         simpleEntry.stepNumFromLastCheckpoint);
                }

                isMovingBack = true;
                MoveBackTo(storedNode, storedDialogueIndex, simpleEntry.lastCheckpointVariablesHash);
                for (var i = 0; i < simpleEntry.stepNumFromLastCheckpoint; i++)
                {
                    if (i == simpleEntry.stepNumFromLastCheckpoint - 1)
                    {
                        isMovingBack = false;
                    }

                    // Make sure there is no blocking action running
                    NovaAnimation.StopAll(AnimationType.PerDialogue | AnimationType.Text);
                    Step();
                }
            }
            else
            {
                throw new ArgumentException($"Nova: {restoreDatas} is not supported.");
            }
        }
Ejemplo n.º 12
0
 private void _returnTitle()
 {
     NovaAnimation.StopAll();
     viewManager.titlePanel.SetActive(true);
     this.SwitchView <TitleController>();
 }
Ejemplo n.º 13
0
 public void OnPointerClick(PointerEventData eventData)
 {
     NovaAnimation.StopAll(AnimationType.UI);
 }