示例#1
0
 /// <summary>
 /// Save all buttons assigned to zones to the game file so the state can be recreated
 /// </summary>
 /// <param name="gameFile">Add the buttons to this file</param>
 private void AddZoneButtonsToGameFile(GameFile gameFile)
 {
     foreach (var cardGroup in _appData.Game.AllCardGroups)
     {
         foreach (var cardZone in cardGroup.CardZones)
         {
             foreach (var button in cardZone.CardButtons)
             {
                 gameFile.ZoneButtons.Add(new ZoneButton {
                     CardGroupId = cardGroup.Id,
                     ZoneIndex   = cardZone.ZoneIndex,
                     Name        = button.CardInfo.Name
                 });
             }
         }
     }
 }
示例#2
0
        internal void Save(string fileName)
        {
            _logger.LogMessage($"Saving game file: {fileName}.");
            var gameFile = new GameFile();

            _appData.Game.CopyTo(gameFile);

            foreach (var player in _appData.Game.Players)
            {
                gameFile.DeckIds.Add(player.DeckId);
            }

            AddDeckIdsToGameFile(gameFile);
            AddZoneButtonsToGameFile(gameFile);

            try {
                File.WriteAllText(fileName, JsonConvert.SerializeObject(gameFile));
                _appData.Configuration.LastSavedFileName = fileName;
                _logger.LogMessage($"Finished writing to game file: {fileName}.");
            } catch (Exception ex) {
                _logger.LogException(ex, $"Error saving game file: {fileName}.");
            }
        }