private void RestoreCheckpoint(GameStateCheckpoint entry) { this.RuntimeAssert(entry != null, "Checkpoint is null"); stepNumFromLastCheckpoint = 0; restrainCheckpointNum = entry.restrainCheckpointNum; forceCheckpoint = false; variables.CopyFrom(entry.variables); foreach (var pair in from pair in restorables orderby(pair.Value as IPrioritizedRestorable)?.priority ?? RestorablePriority.Normal descending select pair) { try { pair.Value.Restore(entry.restoreDatas[pair.Key]); } catch (KeyNotFoundException) { Debug.LogWarningFormat("Nova: Key {0} not found in restoreDatas. Check if the restorable name " + "has changed. If that is true, try clear all checkpoint " + "files, or undo the change of the restorable name.", pair.Key); } } }
private bool TryGetCheckpoint(LogParam logParam, bool isLatest, out GameStateCheckpoint checkpoint) { ulong nodeHistoryHash; if (isLatest) { nodeHistoryHash = gameState.nodeHistory.Hash; } else { var backNodeIndex = gameState.nodeHistory.FindLastIndex(x => x.Equals(logParam.nodeHistoryEntry)); nodeHistoryHash = gameState.nodeHistory.GetHashULong(0, backNodeIndex + 1, logParam.dialogueIndex + 1); } var entry = checkpointManager.GetReached(nodeHistoryHash, logParam.nodeHistoryEntry.Key, logParam.dialogueIndex); if (entry is GameStateCheckpoint _checkpoint) { checkpoint = _checkpoint; return(true); } else { checkpoint = null; return(false); } }
public void SaveInitialCheckpoint() { // Save a clean state of game scene if (initialCheckpoint == null) { initialCheckpoint = GetCheckpoint(); } }