示例#1
0
        /// <summary>
        /// Merges this <see cref="GameData"/> with another.
        /// </summary>
        /// <param name="otherData">The <see cref="GameData"/> to merge into this one.</param>
        /// <returns>A <see cref="string"/> array of the changed keys. Will be empty if no data changed.</returns>
        public string[] MergeWith(GameData otherData)
        {
            var changedKeys = new List <string>();

            foreach (var otherItem in otherData.SyncableItems)
            {
                SyncableItem localItem;
                if (SyncableItems.TryGetValue(otherItem.Key, out localItem))
                {
                    var selectedItem = ConflictResolver.ResolveConflict(localItem, otherItem.Value);
                    if (!selectedItem.Equals(localItem))
                    {
                        SyncableItems[otherItem.Key] = selectedItem;
                        changedKeys.Add(otherItem.Key);
                    }
                }
                else
                {
                    SyncableItems.Add(otherItem.Key, otherItem.Value);
                    changedKeys.Add(otherItem.Key);
                }
            }

            foreach (var otherCurrency in otherData.SyncableCurrencies)
            {
                SyncableCurrency localCurrency;
                if (SyncableCurrencies.TryGetValue(otherCurrency.Key, out localCurrency))
                {
                    var mergeResult = localCurrency.MergeWith(otherCurrency.Value);
                    if (mergeResult)
                    {
                        changedKeys.Add(otherCurrency.Key);
                    }
                }
                else
                {
                    SyncableCurrencies.Add(otherCurrency.Key, otherCurrency.Value);
                    changedKeys.Add(otherCurrency.Key);
                }
            }

            return(changedKeys.ToArray());
        }