DiscordUtil + Fix for #51
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
2003
|
||||
2006
|
||||
@@ -54,6 +54,9 @@ class GameOverSubstate extends MusicBeatSubstate
|
||||
|
||||
lossSFX = FlxG.sound.play(Paths.sound(lossSFXName));
|
||||
Conductor.changeBPM(100);
|
||||
|
||||
|
||||
DiscordUtil.changePresence('Game Over', PlayState.SONG.song + " (" + PlayState.difficulty + ")");
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
|
||||
@@ -8,9 +8,6 @@ import flixel.group.FlxSpriteGroup;
|
||||
import funkin.options.Options;
|
||||
import funkin.scripting.Script;
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
#if DISCORD_RPC
|
||||
import funkin.system.Discord.DiscordClient;
|
||||
#end
|
||||
import funkin.system.Section.SwagSection;
|
||||
import funkin.system.Song.SwagSong;
|
||||
import funkin.scripting.ScriptPack;
|
||||
@@ -443,14 +440,9 @@ class PlayState extends MusicBeatState
|
||||
new ComboRating(1, "S++", 0xFF44FFFF),
|
||||
];
|
||||
|
||||
#if DISCORD_RPC
|
||||
// Discord RPC variables
|
||||
public var difficultyText:String = "";
|
||||
public var iconRPC:String = "";
|
||||
public var songLength:Float = 0;
|
||||
public var detailsText:String = "";
|
||||
public var detailsPausedText:String = "";
|
||||
#end
|
||||
|
||||
public function updateRating() {
|
||||
var rating = null;
|
||||
var acc = get_accuracy();
|
||||
@@ -498,10 +490,6 @@ class PlayState extends MusicBeatState
|
||||
|
||||
Conductor.setupSong(SONG);
|
||||
|
||||
#if DISCORD_RPC
|
||||
// TODO: Scriptable custom RPC
|
||||
iconRPC = (dad != null && dad.icon != null) ? dad.icon : SONG.player2;
|
||||
|
||||
detailsText = isStoryMode ? ("Story Mode: " + storyWeek.name) : "Freeplay";
|
||||
|
||||
// Checks if cutscene files exists
|
||||
@@ -512,10 +500,9 @@ class PlayState extends MusicBeatState
|
||||
|
||||
// String for when the game is paused
|
||||
detailsPausedText = "Paused - " + detailsText;
|
||||
|
||||
|
||||
// Updating Discord Rich Presence.
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC);
|
||||
#end
|
||||
dad = new Character(100, 100, SONG.player2);
|
||||
|
||||
|
||||
@@ -656,9 +643,16 @@ class PlayState extends MusicBeatState
|
||||
public override function createPost() {
|
||||
startCutscene();
|
||||
super.createPost();
|
||||
|
||||
updateDiscordPresence();
|
||||
|
||||
scripts.call("postCreate");
|
||||
}
|
||||
|
||||
public dynamic function updateDiscordPresence() {
|
||||
DiscordUtil.changeSongPresence(detailsText, (paused ? "Paused - " : "") + SONG.song + " (" + difficulty + ")", inst, getIconRPC());
|
||||
}
|
||||
|
||||
public function startCutscene() {
|
||||
if (playCutscenes) {
|
||||
var videoCutscene = Paths.video('${PlayState.SONG.song.toLowerCase()}-cutscene');
|
||||
@@ -805,7 +799,7 @@ class PlayState extends MusicBeatState
|
||||
vocals.play();
|
||||
inst.play();
|
||||
|
||||
updateDiscordStatus();
|
||||
updateDiscordPresence();
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
@@ -1048,42 +1042,27 @@ class PlayState extends MusicBeatState
|
||||
startTimer.active = true;
|
||||
paused = false;
|
||||
|
||||
#if DISCORD_RPC
|
||||
if (startTimer.finished)
|
||||
{
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC, true, songLength - Conductor.songPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC);
|
||||
}
|
||||
#end
|
||||
updateDiscordPresence();
|
||||
}
|
||||
|
||||
super.closeSubState();
|
||||
}
|
||||
public inline function getIconRPC():String
|
||||
return (dad != null ? (dad.icon != null ? dad.icon : dad.curCharacter) : SONG.player2);
|
||||
|
||||
var __songPlaying:Bool = false;
|
||||
var __wasAutoPause:Bool = false;
|
||||
override public function onFocus():Void
|
||||
{
|
||||
scripts.call("onFocus");
|
||||
#if DISCORD_RPC
|
||||
if (health > 0 && !paused)
|
||||
{
|
||||
if (Conductor.songPosition > 0.0)
|
||||
{
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC, true, songLength - Conductor.songPosition);
|
||||
|
||||
|
||||
if (__wasAutoPause) {
|
||||
updateDiscordPresence();
|
||||
if (__songPlaying) {
|
||||
inst.play();
|
||||
vocals.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC);
|
||||
}
|
||||
}
|
||||
#end
|
||||
if (__wasAutoPause && __songPlaying) {
|
||||
inst.play();
|
||||
vocals.play();
|
||||
}
|
||||
|
||||
super.onFocus();
|
||||
@@ -1092,12 +1071,7 @@ class PlayState extends MusicBeatState
|
||||
override public function onFocusLost():Void
|
||||
{
|
||||
scripts.call("onFocusLost");
|
||||
#if DISCORD_RPC
|
||||
if (health > 0 && !paused)
|
||||
{
|
||||
DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + difficultyText + ")", iconRPC);
|
||||
}
|
||||
#end
|
||||
updateDiscordPresence();
|
||||
if (__wasAutoPause = FlxG.autoPause) {
|
||||
__songPlaying = inst.playing;
|
||||
inst.pause();
|
||||
@@ -1141,20 +1115,7 @@ class PlayState extends MusicBeatState
|
||||
else
|
||||
openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
|
||||
|
||||
updateDiscordStatus();
|
||||
}
|
||||
|
||||
// TODO: Update Discord Status
|
||||
public function updateDiscordStatus() {
|
||||
// TODO: Cancellable Discord Update Presence
|
||||
#if DISCORD_RPC
|
||||
// Song duration in a float, useful for the time left feature
|
||||
songLength = inst.length;
|
||||
|
||||
// Updating Discord Rich Presence (with Time Left)
|
||||
DiscordClient.changePresence(detailsText, SONG.song + " (" + difficultyText + ")", iconRPC, true, songLength);
|
||||
#end
|
||||
scripts.call("onDiscordPresenceUpdate");
|
||||
updateDiscordPresence();
|
||||
}
|
||||
|
||||
override public function update(elapsed:Float)
|
||||
@@ -1185,10 +1146,6 @@ class PlayState extends MusicBeatState
|
||||
if (FlxG.keys.justPressed.SEVEN)
|
||||
{
|
||||
FlxG.switchState(new ChartingState());
|
||||
|
||||
#if DISCORD_RPC
|
||||
DiscordClient.changePresence("Chart Editor", null, null, true);
|
||||
#end
|
||||
}
|
||||
if (FlxG.keys.justPressed.F5) {
|
||||
Logs.trace('Reloading scripts...', WARNING, YELLOW);
|
||||
@@ -1367,11 +1324,6 @@ class PlayState extends MusicBeatState
|
||||
FlxG.sound.music.stop();
|
||||
|
||||
openSubState(new GameOverSubstate(boyfriend.x, boyfriend.y, character, gameOverSong, lossSFX, retrySFX));
|
||||
|
||||
#if DISCORD_RPC
|
||||
// Game Over doesn't get his own variable because it's only used here
|
||||
DiscordClient.changePresence("Game Over - " + detailsText, SONG.song + " (" + difficultyText + ")", iconRPC);
|
||||
#end
|
||||
}
|
||||
|
||||
function endSong():Void
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package funkin.menus;
|
||||
|
||||
import haxe.io.Path;
|
||||
#if DISCORD_RPC
|
||||
import funkin.system.Discord.DiscordClient;
|
||||
#end
|
||||
import flash.text.TextField;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
@@ -60,10 +57,7 @@ class FreeplayState extends MusicBeatState
|
||||
songList = FreeplaySonglist.get();
|
||||
songs = songList.songs;
|
||||
|
||||
#if DISCORD_RPC
|
||||
// Updating Discord Rich Presence
|
||||
DiscordClient.changePresence("In the Menus", null);
|
||||
#end
|
||||
DiscordUtil.changePresence("In the Menus", null);
|
||||
|
||||
// LOAD CHARACTERS
|
||||
|
||||
@@ -164,7 +158,7 @@ class FreeplayState extends MusicBeatState
|
||||
|
||||
if (controls.BACK)
|
||||
{
|
||||
CoolUtil.playMenuSFX(2, 0.4);
|
||||
CoolUtil.playMenuSFX(2, 0.7);
|
||||
FlxG.switchState(new MainMenuState());
|
||||
}
|
||||
|
||||
@@ -196,7 +190,7 @@ class FreeplayState extends MusicBeatState
|
||||
function changeSelection(change:Int = 0, force:Bool = false)
|
||||
{
|
||||
if (change == 0 && !force) return;
|
||||
CoolUtil.playMenuSFX(0, 0.4);
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
|
||||
curSelected = FlxMath.wrap(curSelected + change, 0, songs.length-1);
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ package funkin.menus;
|
||||
|
||||
import funkin.ui.FunkinText;
|
||||
import funkin.options.Options;
|
||||
#if DISCORD_RPC
|
||||
import funkin.system.Discord.DiscordClient;
|
||||
#end
|
||||
import flixel.FlxG;
|
||||
import funkin.menus.credits.CreditsMain;
|
||||
import flixel.FlxObject;
|
||||
@@ -47,10 +44,7 @@ class MainMenuState extends MusicBeatState
|
||||
{
|
||||
super.create();
|
||||
|
||||
#if DISCORD_RPC
|
||||
// Updating Discord Rich Presence
|
||||
DiscordClient.changePresence("In the Menus", null);
|
||||
#end
|
||||
DiscordUtil.changePresence("In the Menus", null);
|
||||
|
||||
CoolUtil.playMenuSong();
|
||||
|
||||
@@ -198,7 +192,7 @@ class MainMenuState extends MusicBeatState
|
||||
curSelected = event.value;
|
||||
|
||||
if (event.playMenuSFX)
|
||||
CoolUtil.playMenuSFX(0);
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ class ModSwitchMenu extends MusicBeatSubstate {
|
||||
|
||||
curSelected = FlxMath.wrap(curSelected + change, 0, alphabets.length-1);
|
||||
|
||||
CoolUtil.playMenuSFX();
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
|
||||
for(k=>alphabet in alphabets.members) {
|
||||
alphabet.alpha = 0.6;
|
||||
|
||||
@@ -103,6 +103,8 @@ class PauseSubState extends MusicBeatSubstate
|
||||
FlxG.cameras.add(camera, false);
|
||||
|
||||
pauseScript.call("postCreate");
|
||||
|
||||
PlayState.instance.updateDiscordPresence();
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
|
||||
@@ -121,6 +121,8 @@ class StoryMenuState extends MusicBeatState {
|
||||
}
|
||||
|
||||
changeWeek(0, true);
|
||||
|
||||
DiscordUtil.changePresence("In the Menus", null);
|
||||
}
|
||||
|
||||
var __lastDifficultyTween:FlxTween;
|
||||
|
||||
@@ -103,7 +103,7 @@ class OptionsMenu extends MusicBeatState {
|
||||
|
||||
public function changeSelection(change:Int) {
|
||||
if (change == 0) return;
|
||||
CoolUtil.playMenuSFX(0, 0.4);
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
curSelected = FlxMath.wrap(curSelected + change, 0, options.length-1);
|
||||
alphabets.forEach(function(e) {
|
||||
e.alpha = 0.6;
|
||||
|
||||
@@ -107,7 +107,7 @@ class OptionsScreen extends MusicBeatState {
|
||||
|
||||
public function changeSelection(change:Int) {
|
||||
if (change == 0 && curSelected != -1) return;
|
||||
CoolUtil.playMenuSFX(0);
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
if (curSelected != (curSelected = FlxMath.wrap(curSelected + change, 0, options.length - 1))) {
|
||||
for(e in options)
|
||||
e.selected = false;
|
||||
|
||||
@@ -225,7 +225,7 @@ class KeybindsOptions extends MusicBeatSubstate {
|
||||
|
||||
if (controls.LEFT_P || controls.RIGHT_P) {
|
||||
if (alphabets.members[curSelected] != null) {
|
||||
CoolUtil.playMenuSFX(0);
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
alphabets.members[curSelected].p2Selected = (p2Selected = !p2Selected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package funkin.system;
|
||||
|
||||
import Sys.sleep;
|
||||
import discord_rpc.DiscordRpc;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class DiscordClient
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
trace("Discord Client starting...");
|
||||
DiscordRpc.start({
|
||||
// clientID: "814588678700924999",
|
||||
clientID: "1027994136193810442",
|
||||
onReady: onReady,
|
||||
onError: onError,
|
||||
onDisconnected: onDisconnected
|
||||
});
|
||||
trace("Discord Client started.");
|
||||
|
||||
while (true)
|
||||
{
|
||||
DiscordRpc.process();
|
||||
sleep(2);
|
||||
//trace("Discord Client Update");
|
||||
}
|
||||
|
||||
DiscordRpc.shutdown();
|
||||
}
|
||||
|
||||
public static function shutdown()
|
||||
{
|
||||
DiscordRpc.shutdown();
|
||||
}
|
||||
|
||||
static function onReady()
|
||||
{
|
||||
DiscordRpc.presence({
|
||||
details: "In the Menus",
|
||||
state: null,
|
||||
largeImageKey: 'icon',
|
||||
largeImageText: "Friday Night Funkin'"
|
||||
});
|
||||
}
|
||||
|
||||
static function onError(_code:Int, _message:String)
|
||||
{
|
||||
trace('Error! $_code : $_message');
|
||||
}
|
||||
|
||||
static function onDisconnected(_code:Int, _message:String)
|
||||
{
|
||||
trace('Disconnected! $_code : $_message');
|
||||
}
|
||||
|
||||
public static function initialize()
|
||||
{
|
||||
var DiscordDaemon = sys.thread.Thread.create(() ->
|
||||
{
|
||||
new DiscordClient();
|
||||
});
|
||||
trace("Discord Client initialized");
|
||||
}
|
||||
|
||||
public static function changePresence(details:String, state:Null<String>, ?smallImageKey : String, ?hasStartTimestamp : Bool, ?endTimestamp: Float)
|
||||
{
|
||||
var startTimestamp:Float = if(hasStartTimestamp) Date.now().getTime() else 0;
|
||||
|
||||
if (endTimestamp > 0)
|
||||
{
|
||||
endTimestamp = startTimestamp + endTimestamp;
|
||||
}
|
||||
|
||||
DiscordRpc.presence({
|
||||
details: details,
|
||||
state: state,
|
||||
largeImageKey: 'icon',
|
||||
largeImageText: "Friday Night Funkin'",
|
||||
smallImageKey : smallImageKey,
|
||||
// Obtained times are in milliseconds so they are divided so Discord can use it
|
||||
startTimestamp : Std.int(startTimestamp / 1000),
|
||||
endTimestamp : Std.int(endTimestamp / 1000)
|
||||
});
|
||||
|
||||
//trace('Discord RPC Updated. Arguments: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp');
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,6 @@ import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond;
|
||||
import flixel.addons.transition.TransitionData;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.math.FlxRect;
|
||||
#if DISCORD_RPC
|
||||
import funkin.system.Discord.DiscordClient;
|
||||
#end
|
||||
import lime.app.Application;
|
||||
|
||||
#if ALLOW_MULTITHREADING
|
||||
@@ -148,9 +145,7 @@ class Main extends Sprite
|
||||
Paths.init();
|
||||
ModsFolder.init();
|
||||
DesktopMain.init();
|
||||
#if MOD_SUPPORT
|
||||
ModsFolder.switchMod("introMod");
|
||||
#end
|
||||
DiscordUtil.init();
|
||||
#if ALLOW_MULTITASKING
|
||||
funkin.multitasking.MultiTaskingHandler.init();
|
||||
#end
|
||||
@@ -195,19 +190,13 @@ class Main extends Sprite
|
||||
Conductor.init();
|
||||
AudioSwitchFix.init();
|
||||
WindowsAPI.setDarkMode(true);
|
||||
|
||||
|
||||
#if DISCORD_RPC
|
||||
DiscordClient.initialize();
|
||||
|
||||
Application.current.onExit.add (function (exitCode) {
|
||||
DiscordClient.shutdown();
|
||||
});
|
||||
#end
|
||||
|
||||
EventManager.init();
|
||||
FlxG.signals.preStateCreate.add(onStateSwitch);
|
||||
|
||||
#if MOD_SUPPORT
|
||||
ModsFolder.switchMod("introMod");
|
||||
#end
|
||||
|
||||
initTransition();
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ class UpdateAvailableScreen extends MusicBeatState {
|
||||
|
||||
|
||||
public function changeSelection() {
|
||||
CoolUtil.playMenuSFX();
|
||||
CoolUtil.playMenuSFX(0, 0.7);
|
||||
if (installSelected) {
|
||||
installButton.text = "> INSTALL <";
|
||||
skipButton.text = "SKIP";
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package funkin.utils;
|
||||
|
||||
#if DISCORD_RPC
|
||||
import discord_rpc.DiscordRpc;
|
||||
import sys.thread.Thread;
|
||||
import Sys;
|
||||
import lime.app.Application;
|
||||
import flixel.system.FlxSound;
|
||||
#end
|
||||
|
||||
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 function init() {
|
||||
#if DISCORD_RPC
|
||||
changeClientID(defaultClientID);
|
||||
discordThread = Thread.create(function() {
|
||||
while (true)
|
||||
{
|
||||
while(!ready) {
|
||||
Sys.sleep(1/60);
|
||||
}
|
||||
trace("Processing Discord RPC...");
|
||||
DiscordRpc.process();
|
||||
Sys.sleep(2);
|
||||
}
|
||||
});
|
||||
|
||||
Application.current.onExit.add(function(exitCode) {
|
||||
shutdown();
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
public static function changePresence(details:String, state:String, ?smallImageKey : String) {
|
||||
#if DISCORD_RPC
|
||||
changePresenceAdvanced({
|
||||
state: state,
|
||||
details: details,
|
||||
smallImageKey: smallImageKey
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
public static function changeSongPresence(details:String, state:String, audio:FlxSound, ?smallImageKey : String) {
|
||||
#if DISCORD_RPC
|
||||
var start:Float = 0;
|
||||
var end:Float = 0;
|
||||
|
||||
if (audio != null && audio.playing) {
|
||||
start = Date.now().getTime();
|
||||
end = start + (audio.length - audio.time);
|
||||
}
|
||||
|
||||
changePresenceAdvanced({
|
||||
state: state,
|
||||
details: details,
|
||||
smallImageKey: smallImageKey,
|
||||
startTimestamp: Std.int(start / 1000),
|
||||
endTimestamp: Std.int(end / 1000)
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
public static function changePresenceAdvanced(data:#if DISCORD_RPC DiscordPresenceOptions #else Dynamic #end) {
|
||||
#if DISCORD_RPC
|
||||
if (data == null) return;
|
||||
|
||||
if (data.largeImageKey == null)
|
||||
data.largeImageKey = logoKey;
|
||||
if (data.largeImageText == null)
|
||||
data.largeImageText = Application.current.meta.get('title');
|
||||
|
||||
DiscordRpc.presence(data);
|
||||
#end
|
||||
}
|
||||
public static function changeClientID(id:String) {
|
||||
#if DISCORD_RPC
|
||||
if (currentID != null) {
|
||||
DiscordRpc.shutdown();
|
||||
}
|
||||
|
||||
ready = false;
|
||||
|
||||
DiscordRpc.start({
|
||||
clientID: id,
|
||||
onReady: function() {
|
||||
Logs.trace('Discord RPC started');
|
||||
ready = true;
|
||||
},
|
||||
onError: onError,
|
||||
onDisconnected: onDisconnected
|
||||
});
|
||||
currentID = id;
|
||||
|
||||
#end
|
||||
}
|
||||
|
||||
public static function shutdown() {
|
||||
#if DISCORD_RPC
|
||||
DiscordRpc.shutdown();
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
// HANDLERS
|
||||
#if DISCORD_RPC
|
||||
static function onError(_code:Int, _message:String) {
|
||||
Logs.trace('Discord RPC Error: ${_message} (Code: $_code)', ERROR);
|
||||
}
|
||||
|
||||
static function onDisconnected(_code:Int, _message:String) {
|
||||
Logs.trace('Discord RPC Disconnected: ${_message} (Code: $_code)', WARNING);
|
||||
}
|
||||
#end
|
||||
}
|
||||
Reference in New Issue
Block a user