/// <summary> /// Restore all restorables /// </summary> /// <param name="restoreDatas">restore datas</param> private void Restore(GameStateStepRestoreEntry restoreDatas) { Assert.IsNotNull(restoreDatas); foreach (var restorable in restorables) { try { var restoreData = restoreDatas[restorable.Key]; restorable.Value.Restore(restoreData); } catch (KeyNotFoundException) { Debug.LogError( string.Format("Key {0} not found in restorableDatas, check if restorable names of " + "Restorables has changed. If that is true, try clear all checkpoint " + "files, or undo the change of the restorable name", restorable.Key)); } } }
/// <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."); } }
/// <summary> /// Set a dialogue to "reached" state and save the restore entry for the dialogue. /// </summary> /// <param name="nodeName">The name of FlowChartNode containing the dialogue.</param> /// <param name="dialogueIndex">The index of the dialogue.</param> /// <param name="entry">Restore entry for the dialogue</param> public void SetReached(string nodeName, int dialogueIndex, GameStateStepRestoreEntry entry) { _globalSave.SavedNodes.Ensure(nodeName).DialogueRestoreEntries[dialogueIndex] = entry; }