1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-09 16:24:42 +00:00

Now shows P2 icon and time left when song starts

This commit is contained in:
WorstAquaPlayer 2021-02-27 18:59:18 -03:00
parent 3d74f869d3
commit 700acb86a1
2 changed files with 51 additions and 6 deletions

View file

@ -57,16 +57,26 @@ class DiscordClient
trace("Discord Client initialized"); trace("Discord Client initialized");
} }
public static function changePresence(details:String, state:Null<String>, ?smallImageKey : String, ?startTimestamp: Int, ?endTimestamp: Int) 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({ DiscordRpc.presence({
details: details, details: details,
state: state, state: state,
largeImageKey: 'icon', largeImageKey: 'icon',
largeImageText: "Friday Night Funkin'", largeImageText: "Friday Night Funkin'",
smallImageKey : smallImageKey, smallImageKey : smallImageKey,
startTimestamp : startTimestamp, // Obtained times are in milliseconds so they are divided so Discord can use it
endTimestamp : endTimestamp startTimestamp : Std.int(startTimestamp / 1000),
endTimestamp : Std.int(endTimestamp / 1000)
}); });
trace('Discord RPC Updated. Argument: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp');
} }
} }

View file

@ -125,6 +125,13 @@ class PlayState extends MusicBeatState
var inCutscene:Bool = false; var inCutscene:Bool = false;
#if !html
// Discord RPC variables
var storyDifficultyText:String = "";
var iconRPC:String = "";
var songLength:Float = 0;
#end
override public function create() override public function create()
{ {
if (FlxG.sound.music != null) if (FlxG.sound.music != null)
@ -178,7 +185,6 @@ class PlayState extends MusicBeatState
#if !html #if !html
// Making difficulty text for Discord Rich Presence. // Making difficulty text for Discord Rich Presence.
var storyDifficultyText = "";
switch (storyDifficulty) switch (storyDifficulty)
{ {
case 0: case 0:
@ -188,14 +194,28 @@ class PlayState extends MusicBeatState
case 2: case 2:
storyDifficultyText = "Hard"; storyDifficultyText = "Hard";
} }
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';
}
// Updating Discord Rich Presence. // Updating Discord Rich Presence.
if (isStoryMode) if (isStoryMode)
{ {
DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")"); DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")", iconRPC);
} }
else else
{ {
DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")"); DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")", iconRPC);
} }
#end #end
@ -992,6 +1012,21 @@ class PlayState extends MusicBeatState
FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 1, false); FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 1, false);
FlxG.sound.music.onComplete = endSong; FlxG.sound.music.onComplete = endSong;
vocals.play(); vocals.play();
#if !html
// Song duration in a float, useful for the time left feature
songLength = FlxG.sound.music.length;
// Updating Discord Rich Presence (with Time Left)
if (isStoryMode)
{
DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength);
}
else
{
DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength);
}
#end
} }
var debugNum:Int = 0; var debugNum:Int = 0;