This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve multi platform support, fix signatures again
- Loading branch information
Showing
16 changed files
with
315 additions
and
144 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Reactor.Greenhouse.Setup | ||
{ | ||
public class GameVersion | ||
{ | ||
private static readonly Regex _regex = new Regex(@"^(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)(?<platform>[sia])?", RegexOptions.Compiled); | ||
|
||
public static GamePlatform GamePlatformFromShorthand(string shorthand) | ||
{ | ||
return shorthand switch | ||
{ | ||
"s" => GamePlatform.Steam, | ||
"i" => GamePlatform.Itch, | ||
"a" => GamePlatform.Android, | ||
_ => throw new ArgumentOutOfRangeException(nameof(shorthand)) | ||
}; | ||
} | ||
|
||
public int Major { get; } | ||
public int Minor { get; } | ||
public int Patch { get; } | ||
public GamePlatform? Platform { get; } | ||
|
||
public GameVersion(string version) | ||
{ | ||
var match = _regex.Match(version); | ||
|
||
Major = int.Parse(match.Groups["major"].Value); | ||
Minor = int.Parse(match.Groups["minor"].Value); | ||
Patch = int.Parse(match.Groups["patch"].Value); | ||
|
||
var platform = match.Groups["platform"]; | ||
Platform = platform.Success && !string.IsNullOrEmpty(platform.Value) ? GamePlatformFromShorthand(platform.Value) : null; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{Major}.{Minor}.{Patch}" + Platform switch | ||
{ | ||
GamePlatform.Steam => "s", | ||
GamePlatform.Itch => "i", | ||
GamePlatform.Android => "a", | ||
null => string.Empty, | ||
_ => throw new ArgumentOutOfRangeException() | ||
}; | ||
} | ||
|
||
public bool Equals(GameVersion other, bool ignorePlatform = false) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
|
||
return Major == other.Major && Minor == other.Minor && Patch == other.Patch && (ignorePlatform || Platform == other.Platform); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals((GameVersion) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return HashCode.Combine(Major, Minor, Patch, Platform); | ||
} | ||
} | ||
|
||
public enum GamePlatform | ||
{ | ||
Steam, | ||
Itch, | ||
Android | ||
} | ||
} |
Oops, something went wrong.