blob: 2c30e7e9d47d2df4120dbf4f85777fb0a96c61cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
using System;
using Impostor.Api.Innersloth;
namespace Impostor.Api.Games
{
public readonly struct GameCode : IEquatable<GameCode>
{
public GameCode(int value)
{
Value = value;
Code = GameCodeParser.IntToGameName(value);
}
public GameCode(string code)
{
Value = GameCodeParser.GameNameToInt(code);
Code = code;
}
public string Code { get; }
public int Value { get; }
public static implicit operator string(GameCode code) => code.Code;
public static implicit operator int(GameCode code) => code.Value;
public static implicit operator GameCode(string code) => From(code);
public static implicit operator GameCode(int value) => From(value);
public static bool operator ==(GameCode left, GameCode right)
{
return left.Equals(right);
}
public static bool operator !=(GameCode left, GameCode right)
{
return !left.Equals(right);
}
public static GameCode Create()
{
return new GameCode(GameCodeParser.GenerateCode(6));
}
public static GameCode From(int value) => new GameCode(value);
public static GameCode From(string value) => new GameCode(value);
/// <inheritdoc/>
public bool Equals(GameCode other)
{
return Code == other.Code && Value == other.Value;
}
/// <inheritdoc/>
public override bool Equals(object? obj)
{
return obj is GameCode other && Equals(other);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return HashCode.Combine(Code, Value);
}
public override string ToString()
{
return Code;
}
}
}
|