using System;
using System.Collections.Generic;
using System.Linq;
namespace StardewModdingAPI.Framework.Content
{
/// Encapsulates access and changes to dictionary content being read from a data file.
internal class AssetDataForDictionary : AssetData>, IAssetDataForDictionary
{
/*********
** Public methods
*********/
/// Construct an instance.
/// The content's locale code, if the content is localised.
/// The normalised asset name being read.
/// The content data being read.
/// Normalises an asset key to match the cache key.
/// A callback to invoke when the data is replaced (if any).
public AssetDataForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath, Action> onDataReplaced)
: base(locale, assetName, data, getNormalisedPath, onDataReplaced) { }
#if !SMAPI_3_0_STRICT
/// Add or replace an entry in the dictionary.
/// The entry key.
/// The entry value.
[Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")]
public void Set(TKey key, TValue value)
{
SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Info);
this.Data[key] = value;
}
/// Add or replace an entry in the dictionary.
/// The entry key.
/// A callback which accepts the current value and returns the new value.
[Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")]
public void Set(TKey key, Func value)
{
SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Info);
this.Data[key] = value(this.Data[key]);
}
/// Dynamically replace values in the dictionary.
/// A lambda which takes the current key and value for an entry, and returns the new value.
[Obsolete("Access " + nameof(AssetData>.Data) + "field directly.")]
public void Set(Func replacer)
{
SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.Info);
foreach (var pair in this.Data.ToArray())
this.Data[pair.Key] = replacer(pair.Key, pair.Value);
}
#endif
}
}