Merge pull request #1 from WorstAquaPlayer/master

More additions to the RPC
This commit is contained in:
Jakkzero 2021-03-02 12:06:16 +00:00 committed by GitHub
commit eb9b1b4f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 130 additions and 17 deletions

View File

@ -116,7 +116,7 @@
<haxelib name="newgrounds"/>
<haxelib name="faxe" if='switch'/>
<haxelib name="polymod"/>
<haxelib name="discord_rpc" unless="web"/>
<haxelib name="discord_rpc" if="desktop"/>
<!-- <haxelib name="hxcpp-debug-server" if="desktop"/> -->
<!-- <haxelib name="markdown" /> -->

View File

@ -57,13 +57,26 @@ class DiscordClient
trace("Discord Client initialized");
}
public static function changePresence(details:String, state:Null<String>)
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'"
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');
}
}

View File

@ -1,6 +1,6 @@
package;
#if !html
#if desktop
import Discord.DiscordClient;
#end
import flash.text.TextField;
@ -48,9 +48,9 @@ class FreeplayState extends MusicBeatState
}
*/
#if !html
#if desktop
// Updating Discord Rich Presence
DiscordClient.changePresence("In the menus.", null);
DiscordClient.changePresence("In the Menus", null);
#end
var isDebug:Bool = false;

View File

@ -1,5 +1,8 @@
package;
#if desktop
import Discord.DiscordClient;
#end
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
@ -33,6 +36,11 @@ class MainMenuState extends MusicBeatState
override function create()
{
#if desktop
// Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);
#end
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;

View File

@ -1,6 +1,6 @@
package;
#if !html
#if desktop
import Discord.DiscordClient;
#end
import Section.SwagSection;
@ -125,6 +125,15 @@ class PlayState extends MusicBeatState
var inCutscene:Bool = false;
#if desktop
// Discord RPC variables
var storyDifficultyText:String = "";
var iconRPC:String = "";
var songLength:Float = 0;
var detailsText:String = "";
var detailsPausedText:String = "";
#end
override public function create()
{
if (FlxG.sound.music != null)
@ -176,9 +185,8 @@ class PlayState extends MusicBeatState
dialogue = CoolUtil.coolTextFile(Paths.txt('thorns/thornsDialogue'));
}
#if !html
#if desktop
// Making difficulty text for Discord Rich Presence.
var storyDifficultyText = "";
switch (storyDifficulty)
{
case 0:
@ -188,15 +196,35 @@ class PlayState extends MusicBeatState
case 2:
storyDifficultyText = "Hard";
}
// Updating Discord Rich Presence.
iconRPC = SONG.player2;
// To avoid having duplicate images in Discord assets
switch (iconRPC)
{
case 'senpai-angry':
iconRPC = 'senpai';
case 'monster-christmas':
iconRPC = 'monster';
case 'mom-car':
iconRPC = 'mom';
}
// String that contains the mode defined here so it isn't necessary to call changePresence for each mode
if (isStoryMode)
{
DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")");
detailsText = "Story Mode: Week " + storyWeek;
}
else
{
DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")");
detailsText = "Freeplay";
}
// String for when the game is paused
detailsPausedText = "Paused - " + detailsText;
// Updating Discord Rich Presence.
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
#end
if (SONG.song.toLowerCase() == 'spookeez' || SONG.song.toLowerCase() == 'monster' || SONG.song.toLowerCase() == 'south')
@ -992,6 +1020,14 @@ class PlayState extends MusicBeatState
FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 1, false);
FlxG.sound.music.onComplete = endSong;
vocals.play();
#if desktop
// Song duration in a float, useful for the time left feature
songLength = FlxG.sound.music.length;
// Updating Discord Rich Presence (with Time Left)
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength);
#end
}
var debugNum:Int = 0;
@ -1232,11 +1268,53 @@ class PlayState extends MusicBeatState
if (!startTimer.finished)
startTimer.active = true;
paused = false;
#if desktop
if (startTimer.finished)
{
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength - Conductor.songPosition);
}
else
{
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
}
#end
}
super.closeSubState();
}
override public function onFocus():Void
{
#if desktop
if (health > 0 && !paused)
{
if (Conductor.songPosition > 0.0)
{
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength - Conductor.songPosition);
}
else
{
DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
}
}
#end
super.onFocus();
}
override public function onFocusLost():Void
{
#if desktop
if (health > 0 && !paused)
{
DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
}
#end
super.onFocusLost();
}
function resyncVocals():Void
{
vocals.pause();
@ -1299,11 +1377,19 @@ class PlayState extends MusicBeatState
}
else
openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
#if desktop
DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
#end
}
if (FlxG.keys.justPressed.SEVEN)
{
FlxG.switchState(new ChartingState());
#if desktop
DiscordClient.changePresence("Chart Editor", null, null, true);
#end
}
// FlxG.watch.addQuick('VOL', vocals.amplitudeLeft);
@ -1499,6 +1585,11 @@ class PlayState extends MusicBeatState
openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
// FlxG.switchState(new GameOverState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
#if desktop
// Game Over doesn't get his own variable because it's only used here
DiscordClient.changePresence("Game Over - " + detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
#end
}
if (unspawnNotes[0] != null)

View File

@ -1,6 +1,6 @@
package;
#if !html
#if desktop
import Discord.DiscordClient;
#end
import flixel.FlxG;
@ -112,9 +112,10 @@ class StoryMenuState extends MusicBeatState
add(grpLocks);
trace("Line 70");
#if !html
#if desktop
// Updating Discord Rich Presence
DiscordClient.changePresence("In the menus.", null);
DiscordClient.changePresence("In the Menus", null);
#end
for (i in 0...weekData.length)

View File

@ -1,6 +1,6 @@
package;
#if !html5
#if desktop
import Discord.DiscordClient;
import sys.thread.Thread;
#end
@ -94,7 +94,7 @@ class TitleState extends MusicBeatState
});
#end
#if !html
#if desktop
DiscordClient.initialize();
#end
}