-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from SpaceWarpDev/v1.2.0
1.2.0 release
- Loading branch information
Showing
30 changed files
with
1,150 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
*.cs text diff=csharp | ||
*.csx text diff=csharp | ||
*.sln text eol=crlf | ||
*.csproj text eol=crlf | ||
|
||
*.csv text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
SpaceWarp/API/Mods/JSON/Converters/SpecVersionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace SpaceWarp.API.Mods.JSON.Converters; | ||
|
||
internal class SpecVersionConverter : JsonConverter<SpecVersion> | ||
{ | ||
public override void WriteJson(JsonWriter writer, SpecVersion value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value.ToString()); | ||
} | ||
|
||
public override SpecVersion ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
SpecVersion existingValue, | ||
bool hasExistingValue, | ||
JsonSerializer serializer | ||
) | ||
{ | ||
var specVersion = (string)reader.Value; | ||
return new SpecVersion(specVersion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using SpaceWarp.API.Mods.JSON.Converters; | ||
|
||
namespace SpaceWarp.API.Mods.JSON; | ||
|
||
/// <summary> | ||
/// Represents the version of the API specification from the swinfo.json file. | ||
/// </summary> | ||
[JsonConverter(typeof(SpecVersionConverter))] | ||
public sealed record SpecVersion | ||
{ | ||
private const int DefaultMajor = 1; | ||
private const int DefaultMinor = 0; | ||
|
||
public int Major { get; } = DefaultMajor; | ||
public int Minor { get; } = DefaultMinor; | ||
|
||
// ReSharper disable InconsistentNaming | ||
|
||
/// <summary> | ||
/// Specification version 1.0 (SpaceWarp < 1.2), used if "spec" is not specified in the swinfo.json file. | ||
/// </summary> | ||
public static SpecVersion Default { get; } = new(); | ||
|
||
/// <summary> | ||
/// Specification version 1.2 (SpaceWarp 1.2.x), replaces SpaceWarp's proprietary ModID with BepInEx plugin GUID. | ||
/// </summary> | ||
public static SpecVersion V1_2 { get; } = new(1, 2); | ||
|
||
// ReSharper restore InconsistentNaming | ||
|
||
/// <summary> | ||
/// Creates a new SpecVersion object with the version "major.minor". | ||
/// </summary> | ||
/// <param name="major">Major version number</param> | ||
/// <param name="minor">Minor version number</param> | ||
public SpecVersion(int major, int minor) | ||
{ | ||
Major = major; | ||
Minor = minor; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new SpecVersion object from a string. | ||
/// </summary> | ||
/// <param name="version">Specification version in the format "major.minor"</param> | ||
/// <exception cref="InvalidSpecVersionException">Thrown if the string format is invalid</exception> | ||
public SpecVersion(string version = null) | ||
{ | ||
if (version == null) | ||
{ | ||
return; | ||
} | ||
|
||
var split = version.Split('.'); | ||
if (split.Length != 2 || !int.TryParse(split[0], out var major) || !int.TryParse(split[1], out var minor)) | ||
{ | ||
throw new InvalidSpecVersionException(version); | ||
} | ||
|
||
Major = major; | ||
Minor = minor; | ||
} | ||
|
||
public override string ToString() => $"{Major}.{Minor}"; | ||
|
||
public static bool operator <(SpecVersion a, SpecVersion b) => Compare(a, b) < 0; | ||
public static bool operator >(SpecVersion a, SpecVersion b) => Compare(a, b) > 0; | ||
public static bool operator <=(SpecVersion a, SpecVersion b) => Compare(a, b) <= 0; | ||
public static bool operator >=(SpecVersion a, SpecVersion b) => Compare(a, b) >= 0; | ||
|
||
private static int Compare(SpecVersion a, SpecVersion b) | ||
{ | ||
if (a.Major != b.Major) | ||
{ | ||
return a.Major - b.Major; | ||
} | ||
|
||
return a.Minor - b.Minor; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Thrown if the specification version string is invalid. | ||
/// </summary> | ||
public sealed class InvalidSpecVersionException : Exception | ||
{ | ||
public InvalidSpecVersionException(string version) : base( | ||
$"Invalid spec version: {version}. The correct format is \"major.minor\".") | ||
{ | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Thrown if a property is deprecated in the current specification version. | ||
/// </summary> | ||
public sealed class DeprecatedSwinfoPropertyException : Exception | ||
{ | ||
public DeprecatedSwinfoPropertyException(string property, SpecVersion deprecationVersion) : base( | ||
$"The swinfo.json property \"{property}\" is deprecated in the spec version {deprecationVersion} and will be removed completely in the future." | ||
) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace SpaceWarp.API.Mods.JSON; | ||
|
||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum VersionCheckType | ||
{ | ||
[EnumMember(Value = "swinfo")] | ||
SwInfo, | ||
[EnumMember(Value = "csproj")] | ||
Csproj | ||
} |
Oops, something went wrong.