diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-07 21:53:18 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-07 21:53:18 -0400 |
commit | d4ff9f3f5c108493452879938aa224adb556b7c3 (patch) | |
tree | 51c3f6e3623ea1084c0457634ac1a762860628f0 /src/SMAPI/Framework | |
parent | 709638f197093ed9aaa9a3a764c85d40f4c19eac (diff) | |
download | SMAPI-d4ff9f3f5c108493452879938aa224adb556b7c3.tar.gz SMAPI-d4ff9f3f5c108493452879938aa224adb556b7c3.tar.bz2 SMAPI-d4ff9f3f5c108493452879938aa224adb556b7c3.zip |
log fake content packs created by mods
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 10 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index 9f4a7ceb..6bc091fa 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -42,7 +42,15 @@ namespace StardewModdingAPI.Framework.ModHelpers public IContentPack CreateFake(string directoryPath) { string id = Guid.NewGuid().ToString("N"); - return this.CreateTemporary(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + string relativePath = Path.GetRelativePath(Constants.ModsPath, directoryPath); + return this.CreateTemporary( + directoryPath: directoryPath, + id: id, + name: $"{this.Mod.DisplayName} (fake content pack: {relativePath})", + description: $"A temporary content pack created by the {this.Mod.DisplayName} mod.", + author: "???", + new SemanticVersion(1, 0, 0) + ); } /// <inheritdoc /> diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index c8dcf747..0465b6f1 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1846,7 +1846,7 @@ namespace StardewModdingAPI.Framework IContentPackHelper contentPackHelper = new ContentPackHelper( mod: mod, contentPacks: new Lazy<IContentPack[]>(GetContentPacks), - createContentPack: (dirPath, manifest) => this.CreateFakeContentPack(dirPath, manifest, contentCore, mod) + createContentPack: (dirPath, fakeManifest) => this.CreateFakeContentPack(dirPath, fakeManifest, contentCore, mod) ); IDataHelper dataHelper = new DataHelper(mod, mod.DirectoryPath, jsonHelper); IReflectionHelper reflectionHelper = new ReflectionHelper(mod, mod.DisplayName, this.Reflection); @@ -1883,8 +1883,10 @@ namespace StardewModdingAPI.Framework /// <param name="parentMod">The mod for which the content pack is being created.</param> private IContentPack CreateFakeContentPack(string packDirPath, IManifest packManifest, ContentCoordinator contentCore, IModMetadata parentMod) { + // create fake mod info + string relativePath = Path.GetRelativePath(Constants.ModsPath, packDirPath); IModMetadata fakeMod = new ModMetadata( - displayName: $"{parentMod.DisplayName} (fake content pack: {Path.GetRelativePath(Constants.ModsPath, packDirPath)})", + displayName: packManifest.Name, directoryPath: packDirPath, rootPath: Constants.ModsPath, manifest: packManifest, @@ -1892,16 +1894,22 @@ namespace StardewModdingAPI.Framework isIgnored: false ); + // create mod helpers IMonitor packMonitor = this.LogManager.GetMonitor(packManifest.Name); IFilePathLookup relativePathCache = this.GetFilePathLookup(packDirPath); - GameContentHelper gameContentHelper = new(contentCore, fakeMod, packManifest.Name, packMonitor, this.Reflection); IModContentHelper packContentHelper = new ModContentHelper(contentCore, packDirPath, fakeMod, packManifest.Name, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection); TranslationHelper packTranslationHelper = new(fakeMod, contentCore.GetLocale(), contentCore.Language); + // add content pack ContentPack contentPack = new(packDirPath, packManifest, packContentHelper, packTranslationHelper, this.Toolkit.JsonHelper, relativePathCache); this.ReloadTranslationsForTemporaryContentPack(parentMod, contentPack); parentMod.FakeContentPacks.Add(new WeakReference<ContentPack>(contentPack)); + + // log change + string pathLabel = packDirPath.Contains("..") ? packDirPath : relativePath; + this.Monitor.Log($"{parentMod.DisplayName} created dynamic content pack '{packManifest.Name}' (unique ID: {packManifest.UniqueID}{(packManifest.Name.Contains(pathLabel) ? "" : $", path: {pathLabel}")})."); + return contentPack; } |