Skip to content

Commit 7225fb5

Browse files
committed
chore: moved all entities into their own folder
1 parent 9ac313a commit 7225fb5

File tree

10 files changed

+660
-605
lines changed

10 files changed

+660
-605
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ All contributions are welcome and I am happy for any contribution. However, ther
3030
- Getters with `=>` are allowed and so are string interpolation with `$"{value}"`
3131
- Planned to update the rest of the codebase with them.
3232

33+
## The Entities/ folder
34+
I plan to move all objects into their own namespace called `DiscordRPC.Entity`, however this is a major breaking change and will likely be a `v2.0.0` release.
35+
For now, to ease in maintainability, entities are within the `Entity/` folder but **do not have the correct namespace**. This is intentional.
36+
37+
> [!NOTE]
38+
> Plans to also update the root namespace to either `Lachee.DiscordRPC`, `Lachee.DiscordIPC`, or simply `Lachee.Discord.RPC`.
39+
> A discussion is needed for the merit of a change like this.
40+
3341
## 🫡 Getting Started
3442
1. Make sure .NET is installed
3543
2. Install Visual Studio or Visual Studio Code
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using DiscordRPC.Exceptions;
2+
using DiscordRPC.Helper;
3+
using Newtonsoft.Json;
4+
using System;
5+
6+
namespace DiscordRPC
7+
{
8+
/// <summary>
9+
/// Rich Presence activity type
10+
/// </summary>
11+
public enum ActivityType
12+
{
13+
// Streaming (1) and Custom (4) are not supported via RPC
14+
/// <summary>
15+
/// Playing status type. Displays as "Playing ..."
16+
/// </summary>
17+
Playing = 0,
18+
/// <summary>
19+
/// Listening status type. Displays as "Listening to ..."
20+
/// </summary>
21+
Listening = 2,
22+
/// <summary>
23+
/// Watching status type. Displays as "Watching ..."
24+
/// </summary>
25+
Watching = 3,
26+
/// <summary>
27+
/// Competing status type. Displays as "Competing in ..."
28+
/// </summary>
29+
Competing = 5
30+
}
31+
}

DiscordRPC/Entities/Assets.cs

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
using DiscordRPC.Exceptions;
2+
using DiscordRPC.Helper;
3+
using Newtonsoft.Json;
4+
using System;
5+
6+
namespace DiscordRPC
7+
{
8+
/// <summary>
9+
/// Information about the pictures used in the Rich Presence.
10+
/// </summary>
11+
[Serializable]
12+
public class Assets
13+
{
14+
/// <summary>
15+
/// Name of the uploaded image for the large profile artwork.
16+
/// <para>Max 256 characters.</para>
17+
/// </summary>
18+
/// <remarks>Allows URL to directly link to images.</remarks>
19+
[JsonProperty("large_image", NullValueHandling = NullValueHandling.Ignore)]
20+
public string LargeImageKey
21+
{
22+
get { return _largeimagekey; }
23+
set
24+
{
25+
if (!BaseRichPresence.ValidateString(value, out _largeimagekey, false, 256))
26+
throw new StringOutOfRangeException(256);
27+
28+
//Get if this is a external link
29+
_islargeimagekeyexternal = _largeimagekey?.StartsWith("mp:external/") ?? false;
30+
31+
//Reset the large image ID
32+
_largeimageID = null;
33+
}
34+
}
35+
private string _largeimagekey;
36+
37+
/// <summary>
38+
/// Gets if the large square image is from an external link
39+
/// </summary>
40+
[JsonIgnore]
41+
public bool IsLargeImageKeyExternal
42+
{
43+
get { return _islargeimagekeyexternal; }
44+
}
45+
private bool _islargeimagekeyexternal;
46+
47+
/// <summary>
48+
/// The tooltip for the large square image. For example, "Summoners Rift" or "Horizon Lunar Colony".
49+
/// <para>Max 128 characters.</para>
50+
/// </summary>
51+
[JsonProperty("large_text", NullValueHandling = NullValueHandling.Ignore)]
52+
public string LargeImageText
53+
{
54+
get { return _largeimagetext; }
55+
set
56+
{
57+
if (!BaseRichPresence.ValidateString(value, out _largeimagetext, false, 128))
58+
throw new StringOutOfRangeException(128);
59+
}
60+
}
61+
private string _largeimagetext;
62+
63+
/// <summary>
64+
/// URL that is linked to when clicking on the large image in the activity card.
65+
/// <para>Max 256 characters.</para>
66+
/// </summary>
67+
[JsonProperty("large_url", NullValueHandling = NullValueHandling.Ignore)]
68+
public string LargeImageUrl
69+
{
70+
get { return _largeimageurl; }
71+
set
72+
{
73+
if (!BaseRichPresence.ValidateString(value, out _largeimageurl, false, 256))
74+
throw new StringOutOfRangeException(256);
75+
76+
if (!BaseRichPresence.ValidateUrl(_largeimageurl))
77+
throw new ArgumentException("Url must be a valid URI");
78+
}
79+
}
80+
private string _largeimageurl;
81+
82+
/// <summary>
83+
/// Name of the uploaded image for the small profile artwork.
84+
/// <para>Max 256 characters.</para>
85+
/// </summary>
86+
/// <remarks>Allows URL to directly link to images.</remarks>
87+
[JsonProperty("small_image", NullValueHandling = NullValueHandling.Ignore)]
88+
public string SmallImageKey
89+
{
90+
get { return _smallimagekey; }
91+
set
92+
{
93+
if (!BaseRichPresence.ValidateString(value, out _smallimagekey, false, 256))
94+
throw new StringOutOfRangeException(256);
95+
96+
//Get if this is a external link
97+
_issmallimagekeyexternal = _smallimagekey?.StartsWith("mp:external/") ?? false;
98+
99+
//Reset the small image id
100+
_smallimageID = null;
101+
}
102+
}
103+
private string _smallimagekey;
104+
105+
/// <summary>
106+
/// Gets if the small profile artwork is from an external link
107+
/// </summary>
108+
[JsonIgnore]
109+
public bool IsSmallImageKeyExternal
110+
{
111+
get { return _issmallimagekeyexternal; }
112+
}
113+
private bool _issmallimagekeyexternal;
114+
115+
/// <summary>
116+
/// The tooltip for the small circle image. For example, "LvL 6" or "Ultimate 85%".
117+
/// <para>Max 128 characters.</para>
118+
/// </summary>
119+
[JsonProperty("small_text", NullValueHandling = NullValueHandling.Ignore)]
120+
public string SmallImageText
121+
{
122+
get { return _smallimagetext; }
123+
set
124+
{
125+
if (!BaseRichPresence.ValidateString(value, out _smallimagetext, false, 128))
126+
throw new StringOutOfRangeException(128);
127+
}
128+
}
129+
private string _smallimagetext;
130+
131+
/// <summary>
132+
/// URL that is linked to when clicking on the small image in the activity card.
133+
/// <para>Max 256 characters.</para>
134+
/// </summary>
135+
[JsonProperty("small_url", NullValueHandling = NullValueHandling.Ignore)]
136+
public string SmallImageUrl
137+
{
138+
get { return _smallimageurl; }
139+
set
140+
{
141+
if (!BaseRichPresence.ValidateString(value, out _smallimageurl, false, 256))
142+
throw new StringOutOfRangeException(256);
143+
144+
if (!BaseRichPresence.ValidateUrl(_smallimageurl))
145+
throw new ArgumentException("Url must be a valid URI");
146+
}
147+
}
148+
private string _smallimageurl;
149+
150+
/// <summary>
151+
/// The ID of the large image. This is only set after Update Presence and will automatically become null when <see cref="LargeImageKey"/> is changed.
152+
/// </summary>
153+
[JsonIgnore]
154+
public ulong? LargeImageID { get { return _largeimageID; } }
155+
private ulong? _largeimageID;
156+
157+
/// <summary>
158+
/// The ID of the small image. This is only set after Update Presence and will automatically become null when <see cref="SmallImageKey"/> is changed.
159+
/// </summary>
160+
[JsonIgnore]
161+
public ulong? SmallImageID { get { return _smallimageID; } }
162+
private ulong? _smallimageID;
163+
164+
/// <summary>
165+
/// Merges this asset with the other, taking into account for ID's instead of keys.
166+
/// </summary>
167+
/// <param name="other"></param>
168+
internal void Merge(Assets other)
169+
{
170+
//Copy over the names
171+
_smallimagetext = other._smallimagetext;
172+
_smallimageurl = other._smallimageurl;
173+
_largeimagetext = other._largeimagetext;
174+
_largeimageurl = other._largeimageurl;
175+
176+
//Convert large ID
177+
ulong largeID;
178+
if (ulong.TryParse(other._largeimagekey, out largeID))
179+
{
180+
_largeimageID = largeID;
181+
}
182+
else
183+
{
184+
_largeimagekey = other._largeimagekey;
185+
_largeimageID = null;
186+
}
187+
188+
//Convert the small ID
189+
ulong smallID;
190+
if (ulong.TryParse(other._smallimagekey, out smallID))
191+
{
192+
_smallimageID = smallID;
193+
}
194+
else
195+
{
196+
_smallimagekey = other._smallimagekey;
197+
_smallimageID = null;
198+
}
199+
}
200+
}
201+
202+
}

DiscordRPC/Entities/Button.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using DiscordRPC.Exceptions;
2+
using DiscordRPC.Helper;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Text;
6+
7+
namespace DiscordRPC
8+
{
9+
/// <summary>
10+
/// A Rich Presence button.
11+
/// </summary>
12+
public class Button
13+
{
14+
/// <summary>
15+
/// Text shown on the button
16+
/// <para>Max 31 bytes.</para>
17+
/// </summary>
18+
[JsonProperty("label")]
19+
public string Label
20+
{
21+
get { return _label; }
22+
set
23+
{
24+
if (!BaseRichPresence.ValidateString(value, out _label, true, 31, Encoding.UTF8))
25+
throw new StringOutOfRangeException(31);
26+
}
27+
}
28+
private string _label;
29+
30+
/// <summary>
31+
/// The URL opened when clicking the button.
32+
/// <para>Max 512 characters.</para>
33+
/// </summary>
34+
[JsonProperty("url")]
35+
public string Url
36+
{
37+
get { return _url; }
38+
set
39+
{
40+
if (!BaseRichPresence.ValidateString(value, out _url, false, 512))
41+
throw new StringOutOfRangeException(512);
42+
43+
if (!BaseRichPresence.ValidateUrl(_url))
44+
throw new ArgumentException("Url must be a valid URI");
45+
}
46+
}
47+
private string _url;
48+
}
49+
50+
}

DiscordRPC/Entities/Party.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using DiscordRPC.Exceptions;
2+
using DiscordRPC.Helper;
3+
using Newtonsoft.Json;
4+
using System;
5+
6+
namespace DiscordRPC
7+
{
8+
/// <summary>
9+
/// Structure representing the part the player is in.
10+
/// </summary>
11+
[Serializable]
12+
public class Party
13+
{
14+
/// <summary>
15+
/// Privacy of the party
16+
/// </summary>
17+
public enum PrivacySetting
18+
{
19+
/// <summary>
20+
/// The party is private, invites only.
21+
/// </summary>
22+
Private = 0,
23+
24+
/// <summary>
25+
/// The party is public, anyone can join.
26+
/// </summary>
27+
Public = 1
28+
}
29+
30+
/// <summary>
31+
/// A unique ID for the player's current party / lobby / group. If this is not supplied, they player will not be in a party and the rest of the information will not be sent.
32+
/// <para>Max 128 Bytes</para>
33+
/// </summary>
34+
[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
35+
public string ID { get { return _partyid; } set { _partyid = value.GetNullOrString(); } }
36+
private string _partyid;
37+
38+
/// <summary>
39+
/// The current size of the players party / lobby / group.
40+
/// </summary>
41+
[JsonIgnore]
42+
public int Size { get; set; }
43+
44+
/// <summary>
45+
/// The maxium size of the party / lobby / group. This is required to be larger than <see cref="Size"/>. If it is smaller than the current party size, it will automatically be set too <see cref="Size"/> when the presence is sent.
46+
/// </summary>
47+
[JsonIgnore]
48+
public int Max { get; set; }
49+
50+
/// <summary>
51+
/// The privacy of the party
52+
/// </summary>
53+
[JsonProperty("privacy", NullValueHandling = NullValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Include)]
54+
public PrivacySetting Privacy { get; set; }
55+
56+
[JsonProperty("size", NullValueHandling = NullValueHandling.Ignore)]
57+
private int[] _size
58+
{
59+
get
60+
{
61+
//see issue https://github.com/discordapp/discord-rpc/issues/111
62+
int size = Math.Max(1, Size);
63+
return new int[] { size, Math.Max(size, Max) };
64+
}
65+
66+
set
67+
{
68+
if (value.Length != 2)
69+
{
70+
Size = 0;
71+
Max = 0;
72+
}
73+
else
74+
{
75+
Size = value[0];
76+
Max = value[1];
77+
}
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)