|
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Text;
- using SUISS.Core;
- using SUISS.Storage;
- using UnityEngine;
-
- public class CloudStorage
- {
- public CloudStorage()
- {
- this.Deserialize();
- Storage.NewGameEvent += this.OnNewGame;
- }
-
- public bool CloudStorageAvailable
- {
- get
- {
- return false;
- }
- }
-
- public bool Authenticated
- {
- get
- {
- return false;
- }
- }
-
- public CloudGameState LastCloudGameState { get; private set; }
-
- public ConflictResolver.ConflictSolution LastResolutionResult { get; private set; }
-
- private bool CanPush
- {
- get
- {
- return this.Authenticated && SingletonMonobehaviour<CIGGameState>.IsAvailable && this.LastResolutionResult == ConflictResolver.ConflictSolution.None;
- }
- }
-
- private LocalGameState LocalGameState
- {
- get
- {
- return new LocalGameState(new Version("3.0.6"), this._saveStateGuid, this._installGuid, Storage.Get(StorageLifecycle.Game).UpdateTimestamp == DateTime.MinValue);
- }
- }
-
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event CloudStorage.ConflictResolutionCompleteEventHandler ConflictResolutionComplete;
-
- private void FireConflictResolutionCompleteEvent(ConflictResolver.ConflictSolution result)
- {
- if (this.ConflictResolutionComplete != null)
- {
- this.ConflictResolutionComplete(result);
- }
- }
-
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event CloudStorage.ConflictResolvedEventHandler ConflictResolved;
-
- private void FireConflictResolvedEvent()
- {
- if (this.ConflictResolved != null)
- {
- this.ConflictResolved();
- }
- }
-
- public void Authenticate(Action<bool> onComplete)
- {
- {
- onComplete(false);
- }
- }
-
- public void Deauthenticate()
- {
- }
-
- public void Push()
- {
- if (!this.CanPush)
- {
- return;
- }
- this._saveStateGuid = Guid.NewGuid().ToString();
- this.Serialize();
- Dictionary<string, object> storage = new Dictionary<string, object>
- {
- {
- "Game",
- Storage.Get(StorageLifecycle.Game).Root
- },
- {
- "GameVersion",
- "3.0.6"
- },
- {
- "Level",
- SingletonMonobehaviour<CIGGameState>.Instance.Level
- },
- {
- "SaveStateGuid",
- this._saveStateGuid
- },
- {
- "SaveGuid",
- this._saveGuid
- },
- {
- "InstallGuid",
- this._installGuid
- }
- };
- string s = Storage.DictToString(storage);
- byte[] bytes = Encoding.UTF8.GetBytes(s);
- }
-
- public void Pull(Action<bool> onComplete)
- {
- if (!this.Authenticated)
- {
- onComplete(false);
- return;
- }
- }
-
- public void OnConflictResolved()
- {
- this.LastResolutionResult = ConflictResolver.ConflictSolution.None;
- this.FireConflictResolvedEvent();
- }
-
- public void LoadLastCloudSaveGame()
- {
- if (this.LastCloudGameState != null)
- {
- this._saveGuid = this.LastCloudGameState.SaveGuid;
- this.Serialize();
- StorageController.ReplaceGameDictionary(this.LastCloudGameState.SaveGame);
- }
- }
-
- private void Serialize()
- {
- Dictionary<string, object> dictionary = Storage.Get(StorageLifecycle.Forever).GetDictionary("CloudStorage");
- dictionary["SaveGuid"] = this._saveGuid;
- dictionary["SaveStateGuid"] = this._saveStateGuid;
- dictionary["InstallGuid"] = this._installGuid;
- }
-
- private void Deserialize()
- {
- Dictionary<string, object> dictionary = Storage.Get(StorageLifecycle.Forever).GetDictionary("CloudStorage");
- this._saveGuid = dictionary.GetString("SaveGuid", Guid.NewGuid().ToString());
- this._saveStateGuid = dictionary.GetString("SaveStateGuid", null);
- this._installGuid = dictionary.GetString("InstallGuid", Guid.NewGuid().ToString());
- }
-
- private void OnNewGame()
- {
- this._saveGuid = Guid.NewGuid().ToString();
- this.Serialize();
- }
-
- private void OnPullCompleted(Dictionary<string, object> cloudStorageDict, Action<bool> onComplete)
- {
- this.LastCloudGameState = this.GetCloudGameState(cloudStorageDict);
- if (this.LastCloudGameState != null)
- {
- this.LastResolutionResult = ConflictResolver.Resolve(this.LocalGameState, this.LastCloudGameState);
- this.FireConflictResolutionCompleteEvent(this.LastResolutionResult);
- onComplete(true);
- }
- else
- {
- UnityEngine.Debug.LogErrorFormat("{0} Cloud gamestate is null. Cloud data may have been invalid.", new object[]
- {
- "[Cloud Save]"
- });
- onComplete(false);
- }
- }
-
- private CloudGameState GetCloudGameState(Dictionary<string, object> cloudStorageDict)
- {
- Dictionary<string, object> gameDict = (Dictionary<string, object>)cloudStorageDict.Get("Game", null);
- string @string = cloudStorageDict.GetString("SaveGuid", null);
- string string2 = cloudStorageDict.GetString("SaveStateGuid", null);
- string string3 = cloudStorageDict.GetString("InstallGuid", null);
- int @int = cloudStorageDict.GetInt("Level", 1);
- Version gameVersion = new Version(cloudStorageDict.GetString("GameVersion", "0.0.0"));
- return new CloudGameState(gameDict, @string, string2, string3, @int, gameVersion);
- }
-
- private const string LogPrefix = "[Cloud Save]";
-
- private const string GameRootKey = "Game";
-
- private const string CloudStorageKey = "CloudStorage";
-
- private const string GameVersionKey = "GameVersion";
-
- private const string LevelKey = "Level";
-
- private const string SaveStateGuidKey = "SaveStateGuid";
-
- private const string SaveGuidKey = "SaveGuid";
-
- private const string InstallGuidKey = "InstallGuid";
-
- private string _saveGuid;
-
- private string _saveStateGuid;
-
- private string _installGuid;
-
- public delegate void ConflictResolutionCompleteEventHandler(ConflictResolver.ConflictSolution result);
-
- public delegate void ConflictResolvedEventHandler();
- }
|