enable string versions in manifest.json (#308)

This commit is contained in:
Jesse Plamondon-Willard 2017-06-18 22:08:56 -04:00
parent 3e50c90230
commit b46776a4fb
2 changed files with 20 additions and 6 deletions

View File

@ -5,6 +5,7 @@
See [log](https://github.com/Pathoschild/SMAPI/compare/1.10...2.0). See [log](https://github.com/Pathoschild/SMAPI/compare/1.10...2.0).
For mod developers: For mod developers:
* The manifest.json version can now be specified as a string.
* Added `ContentEvents.AssetLoading` event with a helper which lets you intercept the XNB content * Added `ContentEvents.AssetLoading` event with a helper which lets you intercept the XNB content
load, and dynamically adjust or replace the content being loaded (including support for patching load, and dynamically adjust or replace the content being loaded (including support for patching
images). images).

View File

@ -36,7 +36,12 @@ namespace StardewModdingAPI.Framework.Serialisation
// semantic version // semantic version
if (objectType == typeof(ISemanticVersion)) if (objectType == typeof(ISemanticVersion))
{ {
JObject obj = JObject.Load(reader); JToken token = JToken.Load(reader);
switch (token.Type)
{
case JTokenType.Object:
{
JObject obj = (JObject)token;
int major = obj.Value<int>(nameof(ISemanticVersion.MajorVersion)); int major = obj.Value<int>(nameof(ISemanticVersion.MajorVersion));
int minor = obj.Value<int>(nameof(ISemanticVersion.MinorVersion)); int minor = obj.Value<int>(nameof(ISemanticVersion.MinorVersion));
int patch = obj.Value<int>(nameof(ISemanticVersion.PatchVersion)); int patch = obj.Value<int>(nameof(ISemanticVersion.PatchVersion));
@ -44,6 +49,14 @@ namespace StardewModdingAPI.Framework.Serialisation
return new SemanticVersion(major, minor, patch, build); return new SemanticVersion(major, minor, patch, build);
} }
case JTokenType.String:
return new SemanticVersion(token.Value<string>());
default:
throw new FormatException($"Can't parse {token.Type} token as a semantic version, must be an object or string.");
}
}
// manifest dependency // manifest dependency
if (objectType == typeof(IManifestDependency[])) if (objectType == typeof(IManifestDependency[]))
{ {