diff --git a/Capy64/Assets/default.json b/Capy64/Assets/default.json
index 648f6a8..85dca20 100644
--- a/Capy64/Assets/default.json
+++ b/Capy64/Assets/default.json
@@ -6,5 +6,11 @@
"Enable": true,
"MaxActiveConnections": 5
}
+ },
+ "Integrations": {
+ "Discord": {
+ "Enable": true,
+ "ApplicationId": "1068654606357377074"
+ }
}
}
diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs
index 1818423..bc46a6a 100644
--- a/Capy64/Capy64.cs
+++ b/Capy64/Capy64.cs
@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Capy64.Utils;
+using Capy64.Integrations;
namespace Capy64;
@@ -33,6 +34,8 @@ public class Capy64 : Game, IGame
public Drawing Drawing { get; private set; }
public LuaState LuaRuntime { get; set; }
public EventEmitter EventEmitter { get; private set; }
+ public DiscordIntegration Discord { get; set; }
+
public Borders Borders = new()
{
Top = 0,
diff --git a/Capy64/Capy64.csproj b/Capy64/Capy64.csproj
index cbbc1fb..3001c6b 100644
--- a/Capy64/Capy64.csproj
+++ b/Capy64/Capy64.csproj
@@ -32,6 +32,7 @@
+
diff --git a/Capy64/IGame.cs b/Capy64/IGame.cs
index 78e08b1..c516c5c 100644
--- a/Capy64/IGame.cs
+++ b/Capy64/IGame.cs
@@ -1,6 +1,7 @@
using Capy64.API;
using Capy64.Core;
using Capy64.Eventing;
+using Capy64.Integrations;
using Capy64.Runtime;
using Microsoft.Xna.Framework;
using System;
@@ -27,4 +28,7 @@ public interface IGame
event EventHandler Exiting;
void Run();
void Exit();
+
+ // Integrations
+ DiscordIntegration Discord { get; }
}
diff --git a/Capy64/Integrations/DiscordIntegration.cs b/Capy64/Integrations/DiscordIntegration.cs
new file mode 100644
index 0000000..d119735
--- /dev/null
+++ b/Capy64/Integrations/DiscordIntegration.cs
@@ -0,0 +1,64 @@
+using Capy64.API;
+using DiscordRPC;
+using DiscordRPC.Logging;
+using DiscordRPC.Message;
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Capy64.Integrations;
+
+public class DiscordIntegration : IPlugin
+{
+ public DiscordRpcClient Client { get; private set; }
+ private readonly IConfiguration _configuration;
+
+ public DiscordIntegration(IConfiguration configuration)
+ {
+ _configuration = configuration;
+
+ var discordConfig = _configuration.GetSection("Integrations:Discord");
+ Client = new(discordConfig["ApplicationId"])
+ {
+ Logger = new ConsoleLogger() { Level = LogLevel.Warning }
+ };
+
+ Capy64.Instance.Discord = this;
+
+ Client.OnReady += OnReady;
+ Client.OnPresenceUpdate += OnPresenceUpdate;
+
+ if (discordConfig.GetValue("Enable", false))
+ {
+ Client.Initialize();
+ }
+ }
+
+ public void SetPresence(string details, string? state = null)
+ {
+ Client.SetPresence(new RichPresence()
+ {
+ Details = details,
+ State = state,
+ Assets = new Assets()
+ {
+ LargeImageKey = "image_large",
+ LargeImageText = "Capy64",
+ SmallImageKey = "image_small"
+ }
+ });
+ }
+
+ private void OnReady(object sender, ReadyMessage e)
+ {
+ Console.WriteLine("Received Ready from user {0}", e.User.Username);
+ }
+
+ private void OnPresenceUpdate(object sender, PresenceMessage e)
+ {
+ Console.WriteLine("Received Update! {0}", e.Presence);
+ }
+}
diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs
index ab740e8..bfcbcff 100644
--- a/Capy64/Runtime/RuntimeManager.cs
+++ b/Capy64/Runtime/RuntimeManager.cs
@@ -84,6 +84,8 @@ internal class RuntimeManager : IPlugin
private void InitBIOS()
{
+ _game.Discord.SetPresence("Booting up...");
+
luaState = new LuaState();
_game.LuaRuntime = luaState;
@@ -115,6 +117,8 @@ internal class RuntimeManager : IPlugin
private void InitOS()
{
+ _game.Discord.SetPresence("On CapyOS");
+
luaState = new LuaState();
_game.LuaRuntime = luaState;