you can mess with discord rpc now
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
<!DOCTYPE codename-config >
|
||||
<mod name="Codename Engine" desc="New FNF engine designed to make mod making easier, both in source and via softcoding!">
|
||||
<!-- This line is ignored if in source assets. Use the project.xml to change settings. !-->
|
||||
<window icon="icon.ico" title="Friday Night Funkin' - Codename Engine" width="1280" height="720" />
|
||||
|
||||
|
||||
</mod>
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"clientID": "1027994136193810442",
|
||||
"logoKey": "logo"
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
2149
|
||||
2152
|
||||
@@ -85,8 +85,9 @@ class ModsFolder {
|
||||
FlxG.sound.music.fadeOut(0.25, 0, function(t) {
|
||||
FlxG.sound.music.stop();
|
||||
});
|
||||
DiscordUtil.reloadJsonData();
|
||||
TitleState.initialized = false;
|
||||
FlxG.switchState(new TitleState());
|
||||
FlxG.switchState(new TitleState());
|
||||
}
|
||||
|
||||
public static function unloadMod(mod:String) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.scripting;
|
||||
|
||||
import funkin.scripting.events.CancellableEvent;
|
||||
import funkin.system.Conductor;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxState;
|
||||
@@ -80,6 +81,12 @@ class GlobalScript {
|
||||
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
|
||||
}
|
||||
|
||||
public static function event<T:CancellableEvent>(name:String, event:T):T {
|
||||
if (script == null) return event;
|
||||
script.call(name, [event]);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static function call(name:String, ?args:Array<Dynamic>) {
|
||||
if (script == null) return;
|
||||
script.call(name, args);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package funkin.scripting.events;
|
||||
|
||||
#if DISCORD_RPC
|
||||
import discord_rpc.DiscordRpc.DiscordPresenceOptions;
|
||||
#end
|
||||
|
||||
class DiscordPresenceUpdateEvent extends CancellableEvent {
|
||||
/**
|
||||
* Object containing all of the data for the presence. Can be altered.
|
||||
*/
|
||||
public var presenceData:#if DISCORD_RPC DiscordPresenceOptions #else Dynamic #end;
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package funkin.utils;
|
||||
|
||||
import funkin.scripting.events.DiscordPresenceUpdateEvent;
|
||||
import haxe.Json;
|
||||
import openfl.utils.Assets;
|
||||
#if DISCORD_RPC
|
||||
import discord_rpc.DiscordRpc;
|
||||
import sys.thread.Thread;
|
||||
@@ -12,16 +15,11 @@ class DiscordUtil {
|
||||
public static var currentID:String = null;
|
||||
public static var discordThread:#if DISCORD_RPC Thread #else Dynamic #end = null;
|
||||
public static var ready:Bool = false;
|
||||
|
||||
/**
|
||||
* CHANGE SETTINGS HERE FOR CUSTOM DISCORD RPC ON SOURCE
|
||||
*/
|
||||
public static final defaultClientID:String = "1027994136193810442";
|
||||
public static final logoKey:String = "icon";
|
||||
public static var data:DiscordJson = null;
|
||||
|
||||
public static function init() {
|
||||
#if DISCORD_RPC
|
||||
changeClientID(defaultClientID);
|
||||
reloadJsonData();
|
||||
discordThread = Thread.create(function() {
|
||||
while (true)
|
||||
{
|
||||
@@ -40,6 +38,26 @@ class DiscordUtil {
|
||||
#end
|
||||
}
|
||||
|
||||
public static function reloadJsonData() {
|
||||
#if DISCORD_RPC
|
||||
data = {};
|
||||
var jsonPath = Paths.json("config/discord");
|
||||
if (Assets.exists(jsonPath)) {
|
||||
try {
|
||||
data = Json.parse(Assets.getText(jsonPath));
|
||||
} catch(e) {
|
||||
Logs.trace('Couldn\'t load Discord RPC configuration: ${e.toString()}', ERROR);
|
||||
}
|
||||
}
|
||||
trace(data);
|
||||
data.setFieldDefault("clientID", "1027994136193810442");
|
||||
data.setFieldDefault("logoKey", "icon");
|
||||
data.setFieldDefault("logoText", Application.current.meta.get('title'));
|
||||
|
||||
changeClientID(data.clientID);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function changePresence(details:String, state:String, ?smallImageKey : String) {
|
||||
#if DISCORD_RPC
|
||||
changePresenceAdvanced({
|
||||
@@ -75,10 +93,15 @@ class DiscordUtil {
|
||||
if (data == null) return;
|
||||
|
||||
if (data.largeImageKey == null)
|
||||
data.largeImageKey = logoKey;
|
||||
data.largeImageKey = DiscordUtil.data.logoKey;
|
||||
if (data.largeImageText == null)
|
||||
data.largeImageText = Application.current.meta.get('title');
|
||||
data.largeImageText = DiscordUtil.data.logoText;
|
||||
|
||||
#if GLOBAL_SCRIPT
|
||||
var event = funkin.scripting.GlobalScript.event("onDiscordPresenceUpdate", EventManager.get(DiscordPresenceUpdateEvent).recycle(data));
|
||||
if (event.cancelled) return;
|
||||
|
||||
#end
|
||||
DiscordRpc.presence(data);
|
||||
#end
|
||||
}
|
||||
@@ -121,4 +144,10 @@ class DiscordUtil {
|
||||
Logs.trace('Discord RPC Disconnected: ${_message} (Code: $_code)', WARNING);
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
typedef DiscordJson = {
|
||||
var ?clientID:String;
|
||||
var ?logoKey:String;
|
||||
var ?logoText:String;
|
||||
}
|
||||
Reference in New Issue
Block a user