Unstable v0.19.5.0
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public abstract class ContentPackageId
|
||||
{
|
||||
public abstract string StringRepresentation { get; }
|
||||
|
||||
public override string ToString()
|
||||
=> StringRepresentation;
|
||||
|
||||
public abstract override bool Equals(object? obj);
|
||||
|
||||
public abstract override int GetHashCode();
|
||||
|
||||
public static Option<ContentPackageId> Parse(string s)
|
||||
=> ReflectionUtils.ParseDerived<ContentPackageId, string>(s);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
sealed class SteamWorkshopId : ContentPackageId
|
||||
{
|
||||
public readonly UInt64 Value;
|
||||
|
||||
public SteamWorkshopId(UInt64 value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
private const string Prefix = "STEAM_WORKSHOP_";
|
||||
|
||||
public override string StringRepresentation => Value.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
=> obj is SteamWorkshopId otherWorkshopId && otherWorkshopId.Value == Value;
|
||||
|
||||
public override int GetHashCode() => Value.GetHashCode();
|
||||
|
||||
public new static Option<SteamWorkshopId> Parse(string s)
|
||||
{
|
||||
if (s.StartsWith(Prefix)) { s = s[Prefix.Length..]; }
|
||||
if (!UInt64.TryParse(s, out var id) || id == 0) { return Option<SteamWorkshopId>.None(); }
|
||||
return Option<SteamWorkshopId>.Some(new SteamWorkshopId(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user