/// <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, c_aliasValueString, c_oldAliasValueString); var metaDataAlias = CloudOnceUtils.GetAlias(typeof(SyncableItem).Name, jsonObject, c_aliasMetadata, c_oldAliasMetadata); valueString = jsonObject[valueStringAlias].String; Metadata = new SyncableItemMetaData(jsonObject[metaDataAlias]); }
/// <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); } }
/// <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); } }
/// <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; }