add compile flag for experimental mod dependencies features

This commit is contained in:
Jesse Plamondon-Willard 2017-05-16 23:04:38 -04:00
parent bf02c54f8b
commit 89d7a3f846
5 changed files with 18 additions and 0 deletions

View File

@ -70,7 +70,9 @@ namespace StardewModdingAPI.Tests
[nameof(IManifest.UniqueID)] = $"{Sample.String()}.{Sample.String()}",
[nameof(IManifest.EntryDll)] = $"{Sample.String()}.dll",
[nameof(IManifest.MinimumApiVersion)] = $"{Sample.Int()}.{Sample.Int()}-{Sample.String()}",
#if EXPERIMENTAL
[nameof(IManifest.Dependencies)] = new[] { originalDependency },
#endif
["ExtraString"] = Sample.String(),
["ExtraInt"] = Sample.Int()
};
@ -107,9 +109,11 @@ namespace StardewModdingAPI.Tests
Assert.AreEqual(original["ExtraString"], mod.Manifest.ExtraFields["ExtraString"], "The manifest's extra fields should contain an 'ExtraString' value.");
Assert.AreEqual(original["ExtraInt"], mod.Manifest.ExtraFields["ExtraInt"], "The manifest's extra fields should contain an 'ExtraInt' value.");
#if EXPERIMENTAL
Assert.IsNotNull(mod.Manifest.Dependencies, "The dependencies field should not be null.");
Assert.AreEqual(1, mod.Manifest.Dependencies.Length, "The dependencies field should contain one value.");
Assert.AreEqual(originalDependency[nameof(IManifestDependency.UniqueID)], mod.Manifest.Dependencies[0].UniqueID, "The first dependency's unique ID doesn't match.");
#endif
}
/****
@ -211,6 +215,7 @@ namespace StardewModdingAPI.Tests
// if Moq doesn't throw a method-not-setup exception, the validation didn't override the status.
}
#if EXPERIMENTAL
/****
** ProcessDependencies
****/
@ -339,6 +344,7 @@ namespace StardewModdingAPI.Tests
modD.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "Mod D was expected to fail since it's part of a dependency loop.");
modE.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "Mod E was expected to fail since it's part of a dependency loop.");
}
#endif
/*********
@ -361,6 +367,7 @@ namespace StardewModdingAPI.Tests
return manifest;
}
#if EXPERIMENTAL
/// <summary>Get a randomised basic manifest.</summary>
/// <param name="uniqueID">The mod's name and unique ID.</param>
/// <param name="dependencies">The dependencies this mod requires.</param>
@ -387,5 +394,6 @@ namespace StardewModdingAPI.Tests
}
return mod;
}
#endif
}
}

View File

@ -126,6 +126,7 @@ namespace StardewModdingAPI.Framework.ModLoading
}
}
#if EXPERIMENTAL
/// <summary>Sort the given mods by the order they should be loaded.</summary>
/// <param name="mods">The mods to process.</param>
public IEnumerable<IModMetadata> ProcessDependencies(IEnumerable<IModMetadata> mods)
@ -138,11 +139,13 @@ namespace StardewModdingAPI.Framework.ModLoading
return sortedMods.Reverse();
}
#endif
/*********
** Private methods
*********/
#if EXPERIMENTAL
/// <summary>Sort a mod's dependencies by the order they should be loaded, and remove any mods that can't be loaded due to missing or conflicting dependencies.</summary>
/// <param name="mods">The full list of mods being validated.</param>
/// <param name="mod">The mod whose dependencies to process.</param>
@ -257,6 +260,7 @@ namespace StardewModdingAPI.Framework.ModLoading
return states[mod] = ModDependencyStatus.Sorted;
}
}
#endif
/// <summary>Get all mod folders in a root folder, passing through empty folders as needed.</summary>
/// <param name="rootPath">The root folder path to search.</param>

View File

@ -30,9 +30,11 @@ namespace StardewModdingAPI.Framework.Models
/// <summary>The name of the DLL in the directory that has the <see cref="Mod.Entry"/> method.</summary>
public string EntryDll { get; set; }
#if EXPERIMENTAL
/// <summary>The other mods that must be loaded before this mod.</summary>
[JsonConverter(typeof(ManifestFieldConverter))]
public IManifestDependency[] Dependencies { get; set; }
#endif
/// <summary>The unique mod ID.</summary>
public string UniqueID { get; set; }

View File

@ -29,8 +29,10 @@ namespace StardewModdingAPI
/// <summary>The name of the DLL in the directory that has the <see cref="Mod.Entry"/> method.</summary>
string EntryDll { get; }
#if EXPERIMENTAL
/// <summary>The other mods that must be loaded before this mod.</summary>
IManifestDependency[] Dependencies { get; }
#endif
/// <summary>Any manifest fields which didn't match a valid field.</summary>
IDictionary<string, object> ExtraFields { get; }

View File

@ -357,8 +357,10 @@ namespace StardewModdingAPI
}
}
#if EXPERIMENTAL
// process dependencies
mods = resolver.ProcessDependencies(mods).ToArray();
#endif
// load mods
modsLoaded = this.LoadMods(mods, new JsonHelper(), (SContentManager)Game1.content, deprecationWarnings);