Skip to content

Commit

Permalink
custom rpc support
Browse files Browse the repository at this point in the history
  • Loading branch information
corecathx committed Feb 24, 2024
1 parent f31882b commit 3eef272
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/game/cdev/CDevConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CDevConfig
public static var debug:Bool = false;
public static var elapsedGameTime:Float;
public static var engineVersion:String = "1.6.3";
public static var RPC_ID:String = "947735855672475679";
public static var utils(default, null):CDevUtils = new CDevUtils();

public static var DEPRECATED_STUFFS:Map<String, String>;
Expand Down
37 changes: 37 additions & 0 deletions source/game/cdev/CDevUtils.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package game.cdev;

import sys.io.File;
import haxe.Json;
import game.song.Song.SwagSong;
import meta.substates.CustomSubstate;
import meta.states.MusicBeatState;
Expand Down Expand Up @@ -31,6 +33,13 @@ using StringTools;

enum TemplateData {
CHART;
DISCORD;
}

typedef DiscordJson = {
var clientID:String; //client id, take it from discord developer portal
var imageKey:String; //big image
var imageTxt:String; //idk
}

/**
Expand All @@ -56,6 +65,15 @@ class CDevUtils
validScore: false
};

/**
* Discord RPC Template
*/
public var RPC_TEMPLATE:DiscordJson = {
clientID: CDevConfig.RPC_ID,
imageKey: 'icon',
imageTxt: 'CDEV Engine v.' + CDevConfig.engineVersion
};

/**
* Contains bunch of blacklisted names for a folder / file in Windows.
*/
Expand All @@ -81,6 +99,8 @@ class CDevUtils
switch (type){
case CHART:
return CHART_TEMPLATE;
case DISCORD:
return RPC_TEMPLATE;
}
return null;
}
Expand Down Expand Up @@ -200,6 +220,23 @@ class CDevUtils
return FlxMath.bound(toConvert, min, max); // ye
}

/**
* Custom RPC ID based on `mod`
* @return DiscordJson
*/
public function getRpcJSON():DiscordJson
{
var path:String = Paths.modsPath + "/" + Paths.currentMod +"/data/game/Discord.json";
trace("Looking for Discord.json in: " + path);
if (FileSystem.exists(path)){
trace("File Exists!");
var a:DiscordJson = cast Json.parse(File.getContent(path));
return a;
}
trace("Couldn't find any.");
return getTemplate(DISCORD);
}

/**
* Removes Symbols from a string.
* @param input String that will be used for filtering.
Expand Down
9 changes: 6 additions & 3 deletions source/game/cdev/engineutils/Discord.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package game.cdev.engineutils;

import game.cdev.CDevUtils.DiscordJson;
import game.cdev.CDevConfig;
import Sys.sleep;
#if DISCORD_RPC
Expand All @@ -11,12 +12,14 @@ using StringTools;
class DiscordClient
{
public static var initialized:Bool = false;
public static var RPC_DATA:DiscordJson = null;
#if DISCORD_RPC
public function new()
{
RPC_DATA = CDevConfig.utils.getRpcJSON();
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "947735855672475679",
clientID: (RPC_DATA != null ? RPC_DATA.clientID : CDevConfig.RPC_ID),
onReady: onReady,
onError: onError,
onDisconnected: onDisconnected
Expand All @@ -43,8 +46,8 @@ class DiscordClient
DiscordRpc.presence({
details: "In the Menus",
state: null,
largeImageKey: 'icon',
largeImageText: 'CDEV Engine v.' + CDevConfig.engineVersion
largeImageKey: RPC_DATA.imageKey,
largeImageText: RPC_DATA.imageTxt
});
}

Expand Down

0 comments on commit 3eef272

Please sign in to comment.