Example #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();
        }
Example #2
0
 private void Update()
 {
     if (Input.anyKey)
     {
         NovaAnimation.StopAll(AnimationType.UI);
     }
 }
Example #3
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();
                }
            }
        }
Example #4
0
 private void Awake()
 {
     currentView    = CurrentViewType.UI;
     gameController = Utils.FindNovaGameController();
     uiAnimation    = gameController.transform.Find("NovaAnimation/UI").GetComponent <NovaAnimation>();
     screenCapturer = GetComponent <ScreenCapturer>();
     this.RuntimeAssert(screenCapturer != null, "Missing ScreenCapturer.");
 }
Example #5
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);
        }
Example #6
0
 private void ReloadScriptOnly()
 {
     if (!gameState)
     {
         return;
     }
     NovaAnimation.StopAll();
     gameState.ReloadScripts();
 }
Example #7
0
        private void MoveBackward()
        {
            NovaAnimation.StopAll();
            dialogueBoxController.state = DialogueBoxState.Normal;

            if (gameState.SeekBackStep(1, out var nodeName, out var dialogueIndex))
            {
                gameState.MoveBackTo(nodeName, dialogueIndex);
            }
Example #8
0
    static int Do(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Nova.NovaAnimation      obj  = (Nova.NovaAnimation)ToLua.CheckObject <Nova.NovaAnimation>(L, 1);
                Nova.IAnimationProperty arg0 = (Nova.IAnimationProperty)ToLua.CheckObject <Nova.IAnimationProperty>(L, 2);
                Nova.AnimationEntry     o    = obj.Do(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Nova.NovaAnimation      obj  = (Nova.NovaAnimation)ToLua.CheckObject <Nova.NovaAnimation>(L, 1);
                Nova.IAnimationProperty arg0 = (Nova.IAnimationProperty)ToLua.CheckObject <Nova.IAnimationProperty>(L, 2);
                float arg1            = (float)LuaDLL.luaL_checknumber(L, 3);
                Nova.AnimationEntry o = obj.Do(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4)
            {
                Nova.NovaAnimation      obj  = (Nova.NovaAnimation)ToLua.CheckObject <Nova.NovaAnimation>(L, 1);
                Nova.IAnimationProperty arg0 = (Nova.IAnimationProperty)ToLua.CheckObject <Nova.IAnimationProperty>(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                Nova.AnimationEntry.EasingFunction arg2 = (Nova.AnimationEntry.EasingFunction)ToLua.CheckDelegate <Nova.AnimationEntry.EasingFunction>(L, 4);
                Nova.AnimationEntry o = obj.Do(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 5)
            {
                Nova.NovaAnimation      obj  = (Nova.NovaAnimation)ToLua.CheckObject <Nova.NovaAnimation>(L, 1);
                Nova.IAnimationProperty arg0 = (Nova.IAnimationProperty)ToLua.CheckObject <Nova.IAnimationProperty>(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                Nova.AnimationEntry.EasingFunction arg2 = (Nova.AnimationEntry.EasingFunction)ToLua.CheckDelegate <Nova.AnimationEntry.EasingFunction>(L, 4);
                int arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
                Nova.AnimationEntry o = obj.Do(arg0, arg1, arg2, arg3);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Nova.NovaAnimation.Do"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #9
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);
        }
Example #10
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
        }
Example #11
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}");
        }
Example #12
0
        private void Awake()
        {
            GameState            = FindComponent <GameState>();
            CheckpointManager    = FindComponent <CheckpointManager>();
            ConfigManager        = FindComponent <ConfigManager>();
            InputMapper          = FindComponent <InputMapper>();
            AssetLoader          = FindComponent <AssetLoader>();
            CheckpointHelper     = FindComponent <CheckpointHelper>();
            InputHelper          = FindComponent <InputHelper>();
            PerDialogueAnimation = FindComponent <NovaAnimation>("NovaAnimation/PerDialogue");
            PersistAnimation     = FindComponent <NovaAnimation>("NovaAnimation/Persistent");

            inputEnabled = true;
        }
Example #13
0
 static int DebugPrintEntries(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Nova.NovaAnimation obj = (Nova.NovaAnimation)ToLua.CheckObject <Nova.NovaAnimation>(L, 1);
         obj.DebugPrintEntries();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #14
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
        }
Example #15
0
    static int set_type(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Nova.NovaAnimation obj  = (Nova.NovaAnimation)o;
            Nova.AnimationType arg0 = (Nova.AnimationType)ToLua.CheckObject(L, 2, typeof(Nova.AnimationType));
            obj.type = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index type on a nil value"));
        }
    }
Example #16
0
    static int get_totalTimeRemaining(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Nova.NovaAnimation obj = (Nova.NovaAnimation)o;
            float ret = obj.totalTimeRemaining;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index totalTimeRemaining on a nil value"));
        }
    }
Example #17
0
    static int get_isStopped(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Nova.NovaAnimation obj = (Nova.NovaAnimation)o;
            bool ret = obj.isStopped;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index isStopped on a nil value"));
        }
    }
Example #18
0
    static int get_type(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Nova.NovaAnimation obj = (Nova.NovaAnimation)o;
            Nova.AnimationType ret = obj.type;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index type on a nil value"));
        }
    }
Example #19
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.");
            }
        }
 private void Awake()
 {
     spriteRenderer = GetComponent <SpriteRenderer>();
     image          = GetComponent <Image>();
     this.RuntimeAssert(spriteRenderer != null || image != null, "Missing SpriteRenderer or Image.");
     novaAnimation = Utils.FindNovaGameController().PerDialogueAnimation;
     ghost         = new GameObject("SpriteChangerGhost");
     ghost.transform.SetParent(transform);
     ghost.SetActive(false);
     // Show ghost in front of original sprite
     ghost.transform.localPosition = 0.001f * Vector3.back;
     if (spriteRenderer != null)
     {
         ghostSpriteRenderer = ghost.AddComponent <SpriteRenderer>();
     }
     else
     {
         ghostImage = ghost.AddComponent <Image>();
         RectTransform rectTransform      = GetComponent <RectTransform>();
         RectTransform ghostRectTransform = ghost.GetComponent <RectTransform>();
         ghostRectTransform.sizeDelta = rectTransform.sizeDelta;
     }
 }
Example #21
0
 private void _returnTitle()
 {
     NovaAnimation.StopAll();
     viewManager.titlePanel.SetActive(true);
     this.SwitchView <TitleController>();
 }
Example #22
0
 private static void RemoveAnimation(NovaAnimation animation)
 {
     // Debug.LogFormat("RemoveAnimation {0}", Utils.GetPath(animation));
     Animations.Remove(animation);
 }
Example #23
0
 private static void AddAnimation(NovaAnimation animation)
 {
     // Debug.LogFormat("AddAnimation {0}", Utils.GetPath(animation));
     Animations.Add(animation);
 }
Example #24
0
 public void OnPointerClick(PointerEventData eventData)
 {
     NovaAnimation.StopAll(AnimationType.UI);
 }