Exemplo n.º 1
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="contentCore">SMAPI's core content logic.</param>
 /// <param name="modFolderPath">The absolute path to the mod folder.</param>
 /// <param name="modID">The unique ID of the relevant mod.</param>
 /// <param name="modName">The friendly mod name for use in errors.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 public ContentHelper(ContentCoordinator contentCore, string modFolderPath, string modID, string modName, IMonitor monitor)
     : base(modID)
 {
     this.ContentCore        = contentCore;
     this.GameContentManager = contentCore.CreateGameContentManager(this.ContentCore.GetManagedAssetPrefix(modID) + ".content");
     this.ModContentManager  = contentCore.CreateModContentManager(this.ContentCore.GetManagedAssetPrefix(modID), modFolderPath, this.GameContentManager);
     this.ModName            = modName;
     this.Monitor            = monitor;
 }
Exemplo n.º 2
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="contentCore">SMAPI's core content logic.</param>
 /// <param name="contentManager">The content manager for this mod.</param>
 /// <param name="modFolderPath">The absolute path to the mod folder.</param>
 /// <param name="modID">The unique ID of the relevant mod.</param>
 /// <param name="modName">The friendly mod name for use in errors.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 public ContentHelper(ContentCoordinator contentCore, SContentManager contentManager, string modFolderPath, string modID, string modName, IMonitor monitor)
     : base(modID)
 {
     this.ContentCore    = contentCore;
     this.ContentManager = contentManager;
     this.ModFolderPath  = modFolderPath;
     this.ModName        = modName;
     this.Monitor        = monitor;
 }
Exemplo n.º 3
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="contentCore">SMAPI's core content logic.</param>
        /// <param name="modFolderPath">The absolute path to the mod folder.</param>
        /// <param name="modID">The unique ID of the relevant mod.</param>
        /// <param name="modName">The friendly mod name for use in errors.</param>
        /// <param name="gameContentManager">The game content manager used for map tilesheets not provided by the mod.</param>
        /// <param name="relativePathCache">A case-insensitive lookup of relative paths within the <paramref name="relativePathCache"/>.</param>
        public ModContentHelper(ContentCoordinator contentCore, string modFolderPath, string modID, string modName, IContentManager gameContentManager, CaseInsensitivePathCache relativePathCache)
            : base(modID)
        {
            string managedAssetPrefix = contentCore.GetManagedAssetPrefix(modID);

            this.ContentCore       = contentCore;
            this.ModContentManager = contentCore.CreateModContentManager(managedAssetPrefix, modName, modFolderPath, gameContentManager);
            this.ModName           = modName;
            this.RelativePathCache = relativePathCache;
        }
Exemplo n.º 4
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="contentCore">SMAPI's core content logic.</param>
        /// <param name="modID">The unique ID of the relevant mod.</param>
        /// <param name="modName">The friendly mod name for use in errors.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        public GameContentHelper(ContentCoordinator contentCore, string modID, string modName, IMonitor monitor)
            : base(modID)
        {
            string managedAssetPrefix = contentCore.GetManagedAssetPrefix(modID);

            this.ContentCore        = contentCore;
            this.GameContentManager = contentCore.CreateGameContentManager(managedAssetPrefix + ".content");
            this.ModName            = modName;
            this.Monitor            = monitor;
        }
Exemplo n.º 5
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
        /// <param name="serviceProvider">The service provider to use to locate services.</param>
        /// <param name="rootDirectory">The root directory to search for content.</param>
        /// <param name="currentCulture">The current culture for which to localise content.</param>
        /// <param name="coordinator">The central coordinator which manages content managers.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="reflection">Simplifies access to private code.</param>
        /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
        /// <param name="isModFolder">Whether this content manager is for a mod folder.</param>
        protected BaseContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing, bool isModFolder)
            : base(serviceProvider, rootDirectory, currentCulture)
        {
            // init
            this.Name                = name;
            this.Coordinator         = coordinator ?? throw new ArgumentNullException(nameof(coordinator));
            this.Cache               = new ContentCache(this, reflection);
            this.Monitor             = monitor ?? throw new ArgumentNullException(nameof(monitor));
            this.OnDisposing         = onDisposing;
            this.IsModContentManager = isModFolder;

            // get asset data
            this.LanguageCodes = this.GetKeyLocales().ToDictionary(p => p.Value, p => p.Key, StringComparer.InvariantCultureIgnoreCase);
        }
Exemplo n.º 6
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
        /// <param name="serviceProvider">The service provider to use to locate services.</param>
        /// <param name="rootDirectory">The root directory to search for content.</param>
        /// <param name="currentCulture">The current culture for which to localize content.</param>
        /// <param name="coordinator">The central coordinator which manages content managers.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="reflection">Simplifies access to private code.</param>
        /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
        /// <param name="isNamespaced">Whether this content manager handles managed asset keys (e.g. to load assets from a mod folder).</param>
        protected BaseContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing, bool isNamespaced)
            : base(serviceProvider, rootDirectory, currentCulture)
        {
            // init
            this.Name         = name;
            this.Coordinator  = coordinator ?? throw new ArgumentNullException(nameof(coordinator));
            this.Cache        = new ContentCache(this, reflection);
            this.Monitor      = monitor ?? throw new ArgumentNullException(nameof(monitor));
            this.OnDisposing  = onDisposing;
            this.IsNamespaced = isNamespaced;

            // get asset data
            this.LanguageCodes            = this.GetKeyLocales().ToDictionary(p => p.Value, p => p.Key, StringComparer.OrdinalIgnoreCase);
            this.BaseDisposableReferences = reflection.GetField <List <IDisposable> >(this, "disposableAssets").GetValue();
        }
Exemplo n.º 7
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
        /// <param name="serviceProvider">The service provider to use to locate services.</param>
        /// <param name="rootDirectory">The root directory to search for content.</param>
        /// <param name="currentCulture">The current culture for which to localize content.</param>
        /// <param name="coordinator">The central coordinator which manages content managers.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="reflection">Simplifies access to private code.</param>
        /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
        /// <param name="isNamespaced">Whether this content manager handles managed asset keys (e.g. to load assets from a mod folder).</param>
        /// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
        protected BaseContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing, bool isNamespaced, bool aggressiveMemoryOptimizations)
            : base(serviceProvider, rootDirectory, currentCulture)
        {
            // init
            this.Name         = name;
            this.Coordinator  = coordinator ?? throw new ArgumentNullException(nameof(coordinator));
            this.Cache        = new ContentCache(this, reflection);
            this.Monitor      = monitor ?? throw new ArgumentNullException(nameof(monitor));
            this.OnDisposing  = onDisposing;
            this.IsNamespaced = isNamespaced;
            this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations;

            // get asset data
            this.BaseDisposableReferences = reflection.GetField <List <IDisposable> >(this, "disposableAssets").GetValue();
        }
Exemplo n.º 8
0
        public override bool OnGame1_CreateContentManager_Prefix(Game1 _, IServiceProvider serviceProvider, string rootDirectory, ref LocalizedContentManager __result)
        {
            // Game1._temporaryContent initialising from SGame constructor
            // NOTE: this method is called before the SGame constructor runs. Don't depend on anything being initialised at this point.
            if (this.ContentCore == null)
            {
                this.ContentCore = new ContentCoordinator(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, SGame.ConstructorHack.Monitor, SGame.ConstructorHack.Reflection, SGame.ConstructorHack.JsonHelper, SGame.OnLoadingFirstAsset ?? SGame.ConstructorHack?.OnLoadingFirstAsset);
                this.NextContentManagerIsMain = true;
                this.core.RunInteractively(this.ContentCore);
                __result = this.ContentCore.CreateGameContentManager("Game1._temporaryContent");
            }
            // Game1.content initialising from LoadContent
            if (this.NextContentManagerIsMain)
            {
                this.NextContentManagerIsMain = false;
                __result = this.ContentCore.MainContentManager;
            }

            // any other content manager
            __result = this.ContentCore.CreateGameContentManager("(generated)");
            return(false);
        }
Exemplo n.º 9
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
 /// <param name="gameContentManager">The game content manager used for map tilesheets not provided by the mod.</param>
 /// <param name="serviceProvider">The service provider to use to locate services.</param>
 /// <param name="modName">The mod display name to show in errors.</param>
 /// <param name="rootDirectory">The root directory to search for content.</param>
 /// <param name="currentCulture">The current culture for which to localize content.</param>
 /// <param name="coordinator">The central coordinator which manages content managers.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
 /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
 public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action <BaseContentManager> onDisposing)
     : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true)
 {
     this.GameContentManager = gameContentManager;
     this.JsonHelper         = jsonHelper;
     this.ModName            = modName;
 }
Exemplo n.º 10
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
 /// <param name="serviceProvider">The service provider to use to locate services.</param>
 /// <param name="rootDirectory">The root directory to search for content.</param>
 /// <param name="currentCulture">The current culture for which to localise content.</param>
 /// <param name="coordinator">The central coordinator which manages content managers.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
 public GameContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing)
     : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isModFolder: false)
 {
     this.IsLocalisableLookup = reflection.GetField <IDictionary <string, bool> >(this, "_localizedAsset").GetValue();
 }
Exemplo n.º 11
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
 /// <param name="serviceProvider">The service provider to use to locate services.</param>
 /// <param name="rootDirectory">The root directory to search for content.</param>
 /// <param name="currentCulture">The current culture for which to localize content.</param>
 /// <param name="coordinator">The central coordinator which manages content managers.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
 /// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
 /// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
 public GameContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing, Action onLoadingFirstAsset, bool aggressiveMemoryOptimizations)
     : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: false, aggressiveMemoryOptimizations: aggressiveMemoryOptimizations)
 {
     this.OnLoadingFirstAsset = onLoadingFirstAsset;
 }
Exemplo n.º 12
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
 /// <param name="serviceProvider">The service provider to use to locate services.</param>
 /// <param name="rootDirectory">The root directory to search for content.</param>
 /// <param name="currentCulture">The current culture for which to localise content.</param>
 /// <param name="coordinator">The central coordinator which manages content managers.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
 public ModContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing)
     : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isModFolder: true)
 {
 }
Exemplo n.º 13
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param>
        /// <param name="gameContentManager">The game content manager used for map tilesheets not provided by the mod.</param>
        /// <param name="serviceProvider">The service provider to use to locate services.</param>
        /// <param name="modName">The mod display name to show in errors.</param>
        /// <param name="rootDirectory">The root directory to search for content.</param>
        /// <param name="currentCulture">The current culture for which to localize content.</param>
        /// <param name="coordinator">The central coordinator which manages content managers.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="reflection">Simplifies access to private code.</param>
        /// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
        /// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
        /// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
        /// <param name="relativePathCache">A case-insensitive lookup of relative paths within the <paramref name="rootDirectory"/>.</param>
        public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action <BaseContentManager> onDisposing, bool aggressiveMemoryOptimizations, CaseInsensitivePathCache relativePathCache)
            : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true, aggressiveMemoryOptimizations: aggressiveMemoryOptimizations)
        {
            this.GameContentManager = gameContentManager;
            this.RelativePathCache  = relativePathCache;
            this.JsonHelper         = jsonHelper;
            this.ModName            = modName;

            this.TryLocalizeKeys = false;
        }
Exemplo n.º 14
0
 /*********
 ** Public methods
 *********/
 /// <inheritdoc />
 public GameContentManagerForAssetPropagation(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action <BaseContentManager> onDisposing, Action onLoadingFirstAsset, Action <BaseContentManager, IAssetName> onAssetLoaded, bool aggressiveMemoryOptimizations)
     : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, onLoadingFirstAsset, onAssetLoaded, aggressiveMemoryOptimizations)
 {
 }