Ejemplo n.º 1
0
 private void SaveGameProcessing(SavedGameRequestStatus status, ISavedGameMetadata metaData,
                                 ISaveGame game, SocialCallbackSaveGame saveResult)
 {
     #if UNITY_ANDROID
     if (status == SavedGameRequestStatus.Success)
     {
         byte[] data = game.ObjectToBytes();
         SavedGameMetadataUpdate.Builder builder         = new SavedGameMetadataUpdate.Builder();
         SavedGameMetadataUpdate         updatedMetadata = builder.Build();
         ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(metaData, updatedMetadata, data,
                                                                   //Lamda Result
                                                                   (SavedGameRequestStatus statusCommit, ISavedGameMetadata metaDataCommit) => {
             if (statusCommit == SavedGameRequestStatus.Success)
             {
                 saveResult.Invoke(ESocialCloudState.ESocialCloudState_Completed);
             }
             else
             {
                 saveResult.Invoke(ESocialCloudState.ESocialCloudState_Failure_CannotSaveGame);
             }
         });
     }
     else
     {
         saveResult.Invoke(ESocialCloudState.ESocialCloudState_Failure_CannotOpenSavedGame);
     }
     #else
     saveResult.Invoke(ESocialCloudState.ESocialCloudState_Failure_CannotOpenSavedGame);
     #endif
 }
Ejemplo n.º 2
0
        private static BaseCombatant LoadCombatantFromReference(ISaveGame saveGame, CombatantReference reference)
        {
            var character = BaseCharacterDatabase.Instance.GetCharacter(reference.CharacterId);

            if (saveGame != null)
            {
                var savedCharacter = saveGame.GetCharacterByName(reference.Name);
                if (savedCharacter != null)
                {
                    character = savedCharacter;
                }
            }

            var id = reference.Id;

            if (id == null)
            {
                id = Guid.NewGuid().ToString();
            }

            var result = new BaseCombatant(character, reference.Army)
            {
                Position = reference.Position,
                Id       = id
            };

            return(result);
        }
        public override async Task <ISaveGame> CreateSave(ISaveGame saveGame)
        {
            var oldLatestFile = this.ProfileRoot.OpenFile("latest");

            // todo decide on some way to organize these saves.
            var newGuid          = Guid.NewGuid();
            var saveName         = $"{DateTimeOffset.UtcNow.ToString(DateFormat)}-{newGuid}";
            var saveDirectory    = this.ProfileRoot.OpenDirectory(saveName);
            var contentDirectory = saveDirectory.OpenDirectory("content");

            // Copy it twice, once for backup, once for head.
            await saveGame.ExtractSave(contentDirectory);

            // Delete the old head
            if (oldLatestFile.Created)
            {
                var oldLatestName = oldLatestFile.ReadAllText();
                var oldLatest     = this.ProfileRoot.OpenDirectory(oldLatestName);
                // Delete the old head
                oldLatest.Delete();
            }
            this.ProfileRoot.OpenFile("latest").WriteAllText(saveName, Encoding.UTF8);

            return(this.GetSave(saveDirectory));
        }
Ejemplo n.º 4
0
        private static void SaveFile(ISaveGame save)
        {
            var json = JsonConvert.SerializeObject(save, Formatting.Indented, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });

            File.WriteAllText(save.Path, json);
        }
Ejemplo n.º 5
0
        public void SetSaveGame(ISaveGame saveGame)
        {
            SaveGame = saveGame;

            var id = transform.Find("id").GetComponent <Text>();

            id.text = saveGame.Id;
        }
Ejemplo n.º 6
0
 void InitSaveData(ISaveGame save)
 {
     //Make sure there is no null data, else get calls will fail.
     //Namespace in case someone uses the same key
     if (!Utils.HasSaveData(save, "DominionsPermaDeath"))
     {
         Utils.SetSaveData(save, "DominionsPermaDeath", new List <string>());
     }
 }
Ejemplo n.º 7
0
 void OnSelected(ISaveGame save)
 {
     if (save == null)
     {
         EmptySaveSlotSelectedSignal.Dispatch();
     }
     else
     {
         SaveGameSelectedSignal.Dispatch(save);
     }
 }
Ejemplo n.º 8
0
        public void Overwrite(ISaveGame previousSave, ISaveGame newSave)
        {
            var previousPath = previousSave.Path;

            if (previousPath == null)
            {
                throw new ArgumentException(string.Format("Previous save {0} has no path.", previousSave.Id));
            }
            newSave.Path = previousPath;
            Persist(newSave);
        }
Ejemplo n.º 9
0
        public override async Task <ISaveGame> CreateSave(ISaveGame saveGame)
        {
            // Get a random directory
            using var tempDirectory = this.ProfileRoot.OpenDirectory($"temp-{Guid.NewGuid()}").AsDisposable();

            // Extract directory contents
            await saveGame.ExtractSave(tempDirectory);

            var created = await this.CreateSave(tempDirectory.AsReadOnly());

            return(created);
        }
Ejemplo n.º 10
0
        public override async Task <ISaveGame> CreateSave(ISaveGame saveGame)
        {
            var newGuid          = Guid.NewGuid();
            var saveName         = $"{DateTimeOffset.UtcNow.ToString(DateFormat)}-{newGuid}";
            var saveDirectory    = this.ProfileRoot.OpenDirectory(saveName);
            var contentDirectory = saveDirectory.OpenDirectory("content");

            await saveGame.ExtractSave(contentDirectory);

            this.ProfileRoot.OpenFile("latest").WriteAllText(saveName, Encoding.UTF8);
            return(this.GetSave(saveDirectory) !);
        }
Ejemplo n.º 11
0
        public void Persist(ISaveGame saveGame)
        {
            var previousSaveTime = saveGame.LastSaveTime;

            if (saveGame.Path == null)
            {
                saveGame.Path = Path.Combine(_rootPath, GenerateNewFileName());
            }

            try {
                saveGame.LastSaveTime = new DateTime();
                SaveFile(saveGame);
            } catch {
                saveGame.LastSaveTime = previousSaveTime;
            }
        }
Ejemplo n.º 12
0
 public void SaveGame(ISaveGame objectToSave, SocialCallbackSaveGame saveDelegate)
 {
     if (IsUserConnected())
     {
         #if UNITY_ANDROID
         //TODO Implement Async. StartCoroutine?UniTask?
         ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(CLOUD_SAVE_FILENAME,
                                                                                          DataSource.ReadCacheOrNetwork,
                                                                                          ConflictResolutionStrategy.UseLongestPlaytime,
                                                                                          (SavedGameRequestStatus s, ISavedGameMetadata m) => SaveGameProcessing(s, m, objectToSave, saveDelegate));
         #else
         saveDelegate.Invoke(ESocialCloudState.ESocialCloudState_Failure_CannotSaveGame);
         #endif
     }
     else
     {
         saveDelegate.Invoke(ESocialCloudState.ESocialCloudState_NotAuthenticated);
     }
 }
Ejemplo n.º 13
0
        void SetPermaDeath(ISaveGame save, string uid, bool add = true)
        {
            List <string> playerIds = Utils.GetSaveData <List <string> >(save, "DominionsPermaDeath");

            if (add)
            {
                if (IsPermaDeath(save, @uid))
                {
                    return;
                }
                playerIds.Add(@uid);
            }
            else
            {
                playerIds.Remove(@uid);
            }

            Utils.SetSaveData(save, "DominionsPermaDeath", playerIds);
        }
Ejemplo n.º 14
0
        public void Load(BinaryReader reader)
        {
            this.Id                 = reader.ReadInt32();
            this.IsDungeon          = reader.ReadBoolean();
            this.DungeonId          = reader.ReadInt32();
            this.Area               = reader.ReadString();
            this.IsRoomTransition   = reader.ReadBoolean();
            this.RoomFlags          = (RoomFlags)reader.ReadInt32();
            this.DifficultyModifier = reader.ReadSingle();
            this.X = reader.ReadInt32();
            this.Y = reader.ReadInt32();
            this.VariationIndex   = reader.ReadInt32();
            this.SpawnIndex       = reader.ReadInt32();
            this.TemplateId       = reader.ReadInt32();
            this.PlayerEntersLeft = reader.ReadBoolean();
            int count = reader.ReadInt32();

            LeftDoors = new Dictionary <int, LinkDefinition>(count);
            for (int i = 0; i < count; i++)
            {
                int            key   = reader.ReadInt32();
                LinkDefinition value = default(LinkDefinition);
                value.Load(reader);
                this.LeftDoors.Add(key, value);
            }
            count      = reader.ReadInt32();
            RightDoors = new Dictionary <int, LinkDefinition>(count);
            for (int j = 0; j < count; j++)
            {
                int            key   = reader.ReadInt32();
                LinkDefinition value = default(LinkDefinition);
                value.Load(reader);
                this.RightDoors.Add(key, value);
            }
            count       = reader.ReadInt32();
            CustomDoors = new Dictionary <int, LinkDefinition>(count);
            for (int k = 0; k < count; k++)
            {
                int            key   = reader.ReadInt32();
                LinkDefinition value = default(LinkDefinition);
                value.Load(reader);
                this.CustomDoors.Add(key, value);
            }
            count     = reader.ReadInt32();
            EnemyInfo = new List <EnemyInfo>(count);
            for (int l = 0; l < count; l++)
            {
                EnemyInfo item = default(EnemyInfo);
                item.Load(reader);
                this.EnemyInfo.Add(item);
            }
            count       = reader.ReadInt32();
            RandomProps = new List <PropData>(count);
            for (int m = 0; m < count; m++)
            {
                string fullName  = reader.ReadString();
                string localName = fullName.IndexOf("ComboLock", StringComparison.OrdinalIgnoreCase) > -1
                    ? "ComboLockHint"
                    : fullName.Substring(fullName.LastIndexOf(".", StringComparison.OrdinalIgnoreCase) + 1);
                Type        type        = Type.GetType("ChasmDeserializer.Model.SaveGameData.WorldState.Saveable." + localName);
                GenericProp genericProp = Activator.CreateInstance(type) as GenericProp;
                this.RandomProps.Add(new PropData(fullName, genericProp));
                ISaveGame saveGame = genericProp as ISaveGame;
                saveGame.LoadGame(reader);
            }
            count           = reader.ReadInt32();
            AreaConnections = new List <AreaConnectionDef>(count);
            for (int n = 0; n < count; n++)
            {
                this.AreaConnections.Add(AreaConnectionDef.Load(reader));
            }
            this.IsDark      = reader.ReadBoolean();
            this.IsBacktrack = reader.ReadBoolean();
            count            = reader.ReadInt32();
            LocalVaribles    = new Dictionary <string, string>(count);
            for (int num4 = 0; num4 < count; num4++)
            {
                string key   = reader.ReadString();
                string value = reader.ReadString();
                this.LocalVaribles.Add(key, value);
            }
            this.IsHub     = reader.ReadBoolean();
            count          = reader.ReadInt32();
            IdTranslations = new List <KeyValuePair <int, int> >(count);
            for (int num6 = 0; num6 < count; num6++)
            {
                int key   = reader.ReadInt32();
                int value = reader.ReadInt32();
                this.IdTranslations.Add(new KeyValuePair <int, int>(key, value));
            }
        }
Ejemplo n.º 15
0
 public void Save(BinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(this.IsDungeon);
     writer.Write(this.DungeonId);
     writer.Write(this.Area.NullCheck());
     writer.Write(this.IsRoomTransition);
     writer.Write((int)this.RoomFlags);
     writer.Write(this.DifficultyModifier);
     writer.Write(this.X);
     writer.Write(this.Y);
     writer.Write(this.VariationIndex);
     writer.Write(this.SpawnIndex);
     writer.Write(this.TemplateId);
     writer.Write(this.PlayerEntersLeft);
     writer.Write(this.LeftDoors.Count);
     foreach (int num in this.LeftDoors.Keys)
     {
         writer.Write(num);
         this.LeftDoors[num].Save(writer);
     }
     writer.Write(this.RightDoors.Count);
     foreach (int num2 in this.RightDoors.Keys)
     {
         writer.Write(num2);
         this.RightDoors[num2].Save(writer);
     }
     writer.Write(this.CustomDoors.Count);
     foreach (int num3 in this.CustomDoors.Keys)
     {
         writer.Write(num3);
         this.CustomDoors[num3].Save(writer);
     }
     writer.Write(this.EnemyInfo.Count);
     foreach (EnemyInfo enemyInfo in this.EnemyInfo)
     {
         enemyInfo.Save(writer);
     }
     writer.Write(RandomProps.Count);
     foreach (var item in RandomProps)
     {
         writer.Write(item.PropFullName);
         ISaveGame prop = item.PopData as ISaveGame;
         prop.SaveGame(writer);
     }
     writer.Write(this.AreaConnections.Count);
     foreach (AreaConnectionDef areaConnectionDef in this.AreaConnections)
     {
         areaConnectionDef.Save(writer);
     }
     writer.Write(this.IsDark);
     writer.Write(this.IsBacktrack);
     writer.Write(this.LocalVaribles.Count);
     foreach (string text in this.LocalVaribles.Keys)
     {
         writer.Write(text);
         writer.Write(this.LocalVaribles[text]);
     }
     writer.Write(this.IsHub);
     if (this.IdTranslations == null)
     {
         writer.Write(0);
         return;
     }
     writer.Write(this.IdTranslations.Count);
     for (int i = 0; i < this.IdTranslations.Count; i++)
     {
         KeyValuePair <int, int> keyValuePair = this.IdTranslations[i];
         writer.Write(keyValuePair.Key);
         writer.Write(keyValuePair.Value);
     }
 }
Ejemplo n.º 16
0
 public CombatantDatabase(IEnumerable <CombatantReference> combatantReferences, ISaveGame saveGame)
 {
     _combatants = combatantReferences.Select(reference => {
         return(LoadCombatantFromReference(saveGame, reference));
     })
                   .Cast <ICombatant>()
                   .ToLookup(c => c.Army, c => c);
 }
Ejemplo n.º 17
0
 public static void Check(ISaveGame saveGame)
 {
     // Character names must be unique
 }
Ejemplo n.º 18
0
 public static void WriteSaveGame(string fileName, ISaveGame saveGame)
 {
     File.WriteAllBytes(fileName, saveGame.BinData);
 }
Ejemplo n.º 19
0
 public void Choose(ISaveGame saveGame)
 {
     CurrentSave = saveGame;
 }
Ejemplo n.º 20
0
 public void Overwrite(ISaveGame existingSave, ISaveGame newSave)
 {
     Repository.Overwrite(existingSave, newSave);
 }
Ejemplo n.º 21
0
 public override Task <ISaveGame> CreateSave(ISaveGame saveGame)
 {
     return(Task.FromResult <ISaveGame>(new EmptySaveGame(DateTimeOffset.UtcNow, Guid.NewGuid(), this.SaveType)));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Called when the engine saves the game.
 /// </summary>
 /// <param name="pSaveGame"></param>
 public override void OnSaveGame(ISaveGame pSaveGame)
 {
     Log.Info <GameFramework>("OnSaveGame");
 }
Ejemplo n.º 23
0
 public void Choose(ISaveGame saveGame)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 24
0
 public void Overwrite(ISaveGame previousSave, ISaveGame newSave)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 25
0
 public LoadedSaveGame(string path, ISaveGame save)
 {
     Path = path;
     Save = save;
 }
 public void SaveGame(ISaveGame objectToSave, SocialCallbackSaveGame saveDelegate)
 {
     Debug.Log("SocialMacPc, SaveGame : Not implemented so far on PC/Mac");
     saveDelegate.Invoke(ESocialCloudState.ESocialCloudState_NotSupportedByPlatform);
 }
Ejemplo n.º 27
0
 public override void OnSaveGame(ISaveGame pSaveGame)
 {
     Debug.Log("OnSaveGame");
 }
Ejemplo n.º 28
0
 public override void OnSaveGame(ISaveGame pSaveGame)
 {
 }
Ejemplo n.º 29
0
 public void Persist(ISaveGame saveGame)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 30
0
 public void Write(ISaveGame saveGame)
 {
     Repository.Persist(saveGame);
 }