예제 #1
0
        /// <summary>
        /// Reconstructs the item from a <see cref="JSONObject"/>.
        /// </summary>
        /// <param name="jsonObject"><see cref="JSONObject"/> containing the item data.</param>
        public void FromJSONObject(JSONObject jsonObject)
        {
            var valueStringAlias = CloudOnceUtils.GetAlias(typeof(SyncableItem).Name, jsonObject, aliasValueString, oldAliasValueString);
            var metaDataAlias    = CloudOnceUtils.GetAlias(typeof(SyncableItem).Name, jsonObject, aliasMetadata, oldAliasMetadata);

            valueString = jsonObject[valueStringAlias].String;
            Metadata    = new SyncableItemMetaData(jsonObject[metaDataAlias]);
        }
예제 #2
0
 /// <summary>
 /// Ensures that a specified <see cref="string"/> exists in the local <see cref="GameData"/>.
 /// </summary>
 /// <param name="key">Must be a unique identifier for this specific value.</param>
 /// <param name="persistenceType">
 /// The method of conflict resolution to be used in case of a data conflict. Can happen if the data is altered by a different device.
 /// <see cref="PersistenceType.Latest"/> will prefer the latest (newest) <see cref="string"/>.
 /// <see cref="PersistenceType.Highest"/> will prefer the longest <see cref="string"/>.
 /// <see cref="PersistenceType.Lowest"/> will prefer the shortest <see cref="string"/>.
 /// </param>
 /// <param name="value">The initial value for this <see cref="string"/>.</param>
 public static void InitializeString(string key, PersistenceType persistenceType, string value)
 {
     if (!s_localGameData.SyncableItems.ContainsKey(key))
     {
         var metaData     = new SyncableItemMetaData(DataType.String, persistenceType);
         var syncableItem = new SyncableItem(value, metaData);
         CreateItem(key, syncableItem);
     }
 }
예제 #3
0
        /// <summary>
        /// Ensures that a specified <see cref="decimal"/> exists in the local <see cref="GameData"/>.
        /// </summary>
        /// <param name="key">Must be a unique identifier for this specific value.</param>
        /// <param name="persistenceType">
        /// The persistence type to use in case of a data conflict.
        /// <see cref="PersistenceType.Latest"/> will always prefer the newest data.
        /// <see cref="PersistenceType.Highest"/> will prefer the highest value.
        /// <see cref="PersistenceType.Lowest"/> will prefer the lowest value.
        /// </param>
        /// <param name="value">The initial value for this <see cref="decimal"/>.</param>
        public static void InitializeDecimal(string key, PersistenceType persistenceType, decimal value)
        {
            if (!s_localGameData.SyncableItems.ContainsKey(key))
            {
                var metaData = new SyncableItemMetaData(
                    DataType.Decimal,
                    persistenceType);

                var syncableItem = new SyncableItem(
                    value.ToString(CultureInfo.InvariantCulture),
                    metaData);

                CreateItem(key, syncableItem);
            }
        }
예제 #4
0
        /// <summary>
        /// Used to set a <see cref="decimal"/> that will be stored in the cloud.
        /// </summary>
        /// <param name="key">Must be a unique identifier for this specific value.</param>
        /// <param name="value">The value for this <see cref="decimal"/>.</param>
        /// <param name="persistenceType">The persistence type to use in case of a data conflict (ignored if value has been set before).</param>
        public static void SetDecimal(string key, decimal value, PersistenceType persistenceType)
        {
            if (!s_localGameData.SyncableItems.ContainsKey(key))
            {
                var metaData     = new SyncableItemMetaData(DataType.Decimal, persistenceType);
                var syncableItem = new SyncableItem(value.ToString(CultureInfo.InvariantCulture), metaData);
                s_localGameData.SyncableItems.Add(key, syncableItem);
                IsLocalDataDirty = true;
            }

            if (s_localGameData.SyncableItems[key].Metadata.DataType == DataType.Decimal)
            {
                s_localGameData.SyncableItems[key].ValueString = value.ToString(CultureInfo.InvariantCulture);
                IsLocalDataDirty = true;
            }
            else
            {
                throw new UnexpectedCollectionElementTypeException(key, typeof(decimal));
            }
        }
예제 #5
0
        /// <summary>
        /// Used to set a <see cref="string"/> that will be stored in the cloud. PersistenceType.Latest will be used in case of data conflict.
        /// </summary>
        /// <param name="key">Must be a unique identifier for this specific value.</param>
        /// <param name="value">The value for this <see cref="string"/>.</param>
        /// <param name="persistenceType">The persistence type to use in case of a data conflict (ignored if value has been set before).</param>
        public static void SetString(string key, string value, PersistenceType persistenceType)
        {
            if (!s_localGameData.SyncableItems.ContainsKey(key))
            {
                var metaData     = new SyncableItemMetaData(DataType.String, persistenceType);
                var syncableItem = new SyncableItem(value, metaData);
                s_localGameData.SyncableItems.Add(key, syncableItem);
                IsLocalDataDirty = true;
            }

            if (s_localGameData.SyncableItems[key].Metadata.DataType == DataType.String)
            {
                s_localGameData.SyncableItems[key].ValueString = value;
                IsLocalDataDirty = true;
            }
            else
            {
                throw new UnexpectedCollectionElementTypeException(key, typeof(string));
            }
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncableItem"/> class.
 /// </summary>
 /// <param name="value">The value in <see cref="string"/> form</param>
 /// <param name="metadata">A collection of info about the <see cref="SyncableItem"/></param>
 public SyncableItem(string value, SyncableItemMetaData metadata)
 {
     valueString = value;
     Metadata    = metadata;
 }