using System; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using xTile; namespace StardewModdingAPI { /// An API that provides access to a content pack. public interface IContentPack { /********* ** Accessors *********/ /// The full path to the content pack's folder. string DirectoryPath { get; } /// The content pack's manifest. IManifest Manifest { get; } /// Provides translations stored in the content pack's i18n folder. See for more info. ITranslationHelper Translation { get; } /// An API for loading content assets from the content pack's files. IModContentHelper ModContent { get; } /********* ** Public methods *********/ /// Get whether a given file exists in the content pack. /// The relative file path within the content pack (case-insensitive). bool HasFile(string path); /// Read a JSON file from the content pack folder. /// The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types. /// The relative file path within the content pack (case-insensitive). /// Returns the deserialized model, or null if the file doesn't exist or is empty. /// The is not relative or contains directory climbing (../). TModel? ReadJsonFile(string path) where TModel : class; /// Save data to a JSON file in the content pack's folder. /// The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types. /// The relative file path within the content pack (case-insensitive). /// The arbitrary data to save. /// The is not relative or contains directory climbing (../). void WriteJsonFile(string path, TModel data) where TModel : class; /// Load content from the content pack folder (if not already cached), and return it. When loading a .png file, this must be called outside the game's draw loop. /// The expected data type. The main supported types are , , and dictionaries; other types may be supported by the game's content pipeline. /// The relative file path within the content pack (case-insensitive). /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). [Obsolete($"Use {nameof(IContentPack.ModContent)}.{nameof(IModContentHelper.Load)} instead. This method will be removed in SMAPI 4.0.0.")] T LoadAsset(string key) where T : notnull; /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. /// The relative file path within the content pack (case-insensitive). /// The is empty or contains invalid characters. [Obsolete($"Use {nameof(IContentPack.ModContent)}.{nameof(IModContentHelper.GetInternalAssetName)} instead. This method will be removed in SMAPI 4.0.0.")] string GetActualAssetKey(string key); } }