From cb8aa3d17557e8d470da150bd2db1c01a943a680 Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 12:27:32 +0000 Subject: [PATCH 01/15] Adding updated source files --- source/Discord.hx | 71 +++++++++++++++++++++++++++++++++ source/FreeplayState.hx | 14 +++++-- source/PlayState.hx | 85 +++++++++++++++++++++++----------------- source/StoryMenuState.hx | 7 ++++ source/TitleState.hx | 12 +++++- 5 files changed, 149 insertions(+), 40 deletions(-) create mode 100644 source/Discord.hx diff --git a/source/Discord.hx b/source/Discord.hx new file mode 100644 index 000000000..eb0c1f8d4 --- /dev/null +++ b/source/Discord.hx @@ -0,0 +1,71 @@ +package; + +import discord_rpc.DiscordRpc; +import haxe.Timer; + +using StringTools; + +class DiscordClient +{ + public function new() + { + trace("Discord Client starting..."); + DiscordRpc.start({ + clientID: "814588678700924999", + onReady: onReady, + onError: onError, + onDisconnected: onDisconnected + }); + trace("Discord Client started."); + + while (true) + { + trace("process called"); + DiscordRpc.process(); + trace("pre-delay"); + Timer.delay(continue, 2000); + trace("post-delay"); + } + + 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) + { + DiscordRpc.presence({ + details: details, + state: state, + largeImageKey: 'icon', + largeImageText: "Friday Night Funkin'" + }); + } +} diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index f8bb333e9..789897b20 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -1,5 +1,8 @@ package; +#if !html +import Discord.DiscordClient; +#end import flash.text.TextField; import flixel.FlxG; import flixel.FlxSprite; @@ -45,6 +48,11 @@ class FreeplayState extends MusicBeatState } */ + #if !html + // Updating Discord Rich Presence + DiscordClient.changePresence("In the menus.", null); + #end + var isDebug:Bool = false; #if debug @@ -229,9 +237,9 @@ class FreeplayState extends MusicBeatState function changeSelection(change:Int = 0) { - #if !switch - NGio.logEvent('Fresh'); - #end + // #if !switch + // NGio.logEvent('Fresh'); + // #end // NGio.logEvent('Fresh'); FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); diff --git a/source/PlayState.hx b/source/PlayState.hx index aabb992f5..0356dd58a 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,5 +1,8 @@ package; +#if !html +import Discord.DiscordClient; +#end import Section.SwagSection; import Song.SwagSong; import WiggleEffect.WiggleEffectType; @@ -124,7 +127,6 @@ class PlayState extends MusicBeatState override public function create() { - if (FlxG.sound.music != null) FlxG.sound.music.stop(); @@ -174,6 +176,29 @@ class PlayState extends MusicBeatState dialogue = CoolUtil.coolTextFile(Paths.txt('thorns/thornsDialogue')); } + #if !html + // Making difficulty text for Discord Rich Presence. + var storyDifficultyText = ""; + switch (storyDifficulty) + { + case 0: + storyDifficultyText = "Easy"; + case 1: + storyDifficultyText = "Normal"; + case 2: + storyDifficultyText = "Hard"; + } + // Updating Discord Rich Presence. + if (isStoryMode) + { + DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")"); + } + else + { + DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")"); + } + #end + if (SONG.song.toLowerCase() == 'spookeez' || SONG.song.toLowerCase() == 'monster' || SONG.song.toLowerCase() == 'south') { curStage = "spooky"; @@ -870,16 +895,8 @@ class PlayState extends MusicBeatState var introAssets:Map> = new Map>(); introAssets.set('default', ['ready', "set", "go"]); - introAssets.set('school', [ - 'weeb/pixelUI/ready-pixel', - 'weeb/pixelUI/set-pixel', - 'weeb/pixelUI/date-pixel' - ]); - introAssets.set('schoolEvil', [ - 'weeb/pixelUI/ready-pixel', - 'weeb/pixelUI/set-pixel', - 'weeb/pixelUI/date-pixel' - ]); + introAssets.set('school', ['weeb/pixelUI/ready-pixel', 'weeb/pixelUI/set-pixel', 'weeb/pixelUI/date-pixel']); + introAssets.set('schoolEvil', ['weeb/pixelUI/ready-pixel', 'weeb/pixelUI/set-pixel', 'weeb/pixelUI/date-pixel']); var introAlts:Array = introAssets.get('default'); var altSuffix:String = ""; @@ -1059,9 +1076,7 @@ class PlayState extends MusicBeatState { swagNote.x += FlxG.width / 2; // general offset } - else - { - } + else {} } daBeats += 1; } @@ -1920,29 +1935,29 @@ class PlayState extends MusicBeatState */ // trace(daNote.noteData); /* - switch (daNote.noteData) + switch (daNote.noteData) + { + case 2: // NOTES YOU JUST PRESSED + if (upP || rightP || downP || leftP) + noteCheck(upP, daNote); + case 3: + if (upP || rightP || downP || leftP) + noteCheck(rightP, daNote); + case 1: + if (upP || rightP || downP || leftP) + noteCheck(downP, daNote); + case 0: + if (upP || rightP || downP || leftP) + noteCheck(leftP, daNote); + } + + //this is already done in noteCheck / goodNoteHit + if (daNote.wasGoodHit) { - case 2: // NOTES YOU JUST PRESSED - if (upP || rightP || downP || leftP) - noteCheck(upP, daNote); - case 3: - if (upP || rightP || downP || leftP) - noteCheck(rightP, daNote); - case 1: - if (upP || rightP || downP || leftP) - noteCheck(downP, daNote); - case 0: - if (upP || rightP || downP || leftP) - noteCheck(leftP, daNote); + daNote.kill(); + notes.remove(daNote, true); + daNote.destroy(); } - - //this is already done in noteCheck / goodNoteHit - if (daNote.wasGoodHit) - { - daNote.kill(); - notes.remove(daNote, true); - daNote.destroy(); - } */ } else diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index 1156ccade..0e4b06558 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -1,5 +1,8 @@ package; +#if !html +import Discord.DiscordClient; +#end import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.transition.FlxTransitionableState; @@ -109,6 +112,10 @@ class StoryMenuState extends MusicBeatState add(grpLocks); trace("Line 70"); + #if !html + // Updating Discord Rich Presence + DiscordClient.changePresence("In the menus.", null); + #end for (i in 0...weekData.length) { diff --git a/source/TitleState.hx b/source/TitleState.hx index 3a3041678..842e37fbf 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -1,5 +1,8 @@ package; +#if !html5 +import Discord.DiscordClient; +#end import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; @@ -23,6 +26,7 @@ import flixel.util.FlxTimer; import io.newgrounds.NG; import lime.app.Application; import openfl.Assets; +import sys.thread.Thread; using StringTools; @@ -45,7 +49,7 @@ class TitleState extends MusicBeatState #if polymod polymod.Polymod.init({modRoot: "mods", dirs: ['introMod']}); #end - + PlayerSettings.init(); curWacky = FlxG.random.getObject(getIntroTextShit()); @@ -89,6 +93,10 @@ class TitleState extends MusicBeatState startIntro(); }); #end + + #if !html + DiscordClient.initialize(); + #end } var logoBl:FlxSprite; @@ -282,12 +290,12 @@ class TitleState extends MusicBeatState if (version.trim() != NGio.GAME_VER_NUMS.trim() && !OutdatedSubState.leftState) { + FlxG.switchState(new OutdatedSubState()); trace('OLD VERSION!'); trace('old ver'); trace(version.trim()); trace('cur ver'); trace(NGio.GAME_VER_NUMS.trim()); - FlxG.switchState(new OutdatedSubState()); } else { From 17a18f080ef6dfe4d13c96f46d3bbd4bcd4882b0 Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 12:34:31 +0000 Subject: [PATCH 02/15] Adding discord_rpc as a library --- Project.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.xml b/Project.xml index 7edddb77c..23de20a24 100644 --- a/Project.xml +++ b/Project.xml @@ -116,6 +116,7 @@ + From 580f41f09d23388fce6f8d228f860f3313f4ac2e Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 12:52:40 +0000 Subject: [PATCH 03/15] fixed endless discord updates I'm an idiot and had no idea what I was doing with haxe.Timer.delay() so I'm using Sys.sleep() and it seems to work fine. --- source/Discord.hx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/Discord.hx b/source/Discord.hx index eb0c1f8d4..3a20ebabe 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -1,7 +1,7 @@ package; +import Sys.sleep; import discord_rpc.DiscordRpc; -import haxe.Timer; using StringTools; @@ -20,11 +20,9 @@ class DiscordClient while (true) { - trace("process called"); DiscordRpc.process(); - trace("pre-delay"); - Timer.delay(continue, 2000); - trace("post-delay"); + sleep(2); + trace("Discord Client Update"); } DiscordRpc.shutdown(); From 4ccf1ad21b4e7f72d884605c2784da4ba3eaac64 Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 13:18:35 +0000 Subject: [PATCH 04/15] Update README.md --- README.md | 100 ++++++------------------------------------------------ 1 file changed, 10 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 2c40ffc1c..5a4364f9c 100644 --- a/README.md +++ b/README.md @@ -1,94 +1,14 @@ -# Friday Night Funkin +# Friday Night Funkin Discord RPC -This is the repository for Friday Night Funkin, a game originally made for Ludum Dare 47 "Stuck In a Loop". +This is a fork that adds Discord RPC (custom status) to Funkin'. -Play the Ludum Dare prototype here: https://ninja-muffin24.itch.io/friday-night-funkin -Play the Newgrounds one here: https://www.newgrounds.com/portal/view/770371 -Support the project on the itch.io page: https://ninja-muffin24.itch.io/funkin +## Before you use +Please note that due to the way Discord's system works, apps that have not been approved are on a whitelist. +If you want to try this out, please dm me on Discord at Jak_#0768 and I will add you to the whitelist when I can. -## Credits / shoutouts +## Building +This won't build on html5, because I put pre-compiler tags to stop it from doing so. This should mean it only builds on desktop, but it will work on Android and stuff, so if that's what you're going for you should probably change the tags. -- [ninjamuffin99 (me!)](https://twitter.com/ninja_muffin99) - Programmer -- [PhantomArcade3K](https://twitter.com/phantomarcade3k) and [Evilsk8r](https://twitter.com/evilsk8r) - Art -- [Kawaisprite](https://twitter.com/kawaisprite) - Musician - -This game was made with love to Newgrounds and it's community. Extra love to Tom Fulp. - -## Build instructions - -THESE INSTRUCTIONS ARE FOR COMPILING THE GAME'S SOURCE CODE!!! - -IF YOU WANT TO JUST DOWNLOAD AND INSTALL AND PLAY THE GAME NORMALLY, GO TO ITCH.IO TO DOWNLOAD THE GAME FOR PC, MAC, AND LINUX!! - -https://ninja-muffin24.itch.io/friday-night-funkin - -IF YOU WANT TO COMPILE THE GAME YOURSELF, CONTINUE READING!!! - -### Installing the Required Programs - -First you need to install Haxe and HaxeFlixel. I'm too lazy to write and keep updated with that setup (which is pretty simple). -1. [Install Haxe 4.1.5](https://haxe.org/download/version/4.1.5/) (Download 4.1.5 instead of 4.2.0 because 4.2.0 is broken and is not working with gits properly...) -2. [Install HaxeFlixel](https://haxeflixel.com/documentation/install-haxeflixel/) after downloading Haxe - -Other installations you'd need is the additional libraries, a fully updated list will be in `Project.xml` in the project root. Currently, these are all of the things you need to install: -``` -flixel -flixel-addons -flixel-ui -hscript -newgrounds -``` -So for each of those type `haxelib install [library]` so shit like `haxelib install newgrounds` - -You'll also need to install polymod. To do this, you need to do a few things first. -1. Download [git-scm](https://git-scm.com/downloads). Works for Windows, Mac, and Linux, just select your build. -2. Follow instructions to install the application properly. -3. Run `haxelib git polymod https://github.com/larsiusprime/polymod.git` in terminal/command-prompt after your git program is installed. - -You should have everything ready for compiling the game! Follow the guide below to continue! - -### Ignored files - -I gitignore the API keys for the game, so that no one can nab them and post fake highscores on the leaderboards. But because of that the game -doesn't compile without it. - -Just make a file in `/source` and call it `APIStuff.hx`, and copy paste this into it - -```haxe -package; - -class APIStuff -{ - public static var API:String = ""; - public static var EncKey:String = ""; -} - -``` - -and you should be good to go there. - -### Compiling game - -Once you have all those installed, it's pretty easy to compile the game. You just need to run 'lime test html5 -debug' in the root of the project to build and run the HTML5 version. (command prompt navigation guide can be found here: [https://ninjamuffin99.newgrounds.com/news/post/1090480](https://ninjamuffin99.newgrounds.com/news/post/1090480)) - -To run it from your desktop (Windows, Mac, Linux) it can be a bit more involved. For Linux, you only need to open a terminal in the project directory and run 'lime test linux -debug' and then run the executible file in export/release/linux/bin. For Windows, you need to install Visual Studio Community 2019. While installing VSC, don't click on any of the options to install workloads. Instead, go to the individual components tab and choose the following: -* MSVC v142 - VS 2019 C++ x64/x86 build tools -* Windows SDK (10.0.17763.0) -* C++ Profiling tools -* C++ CMake tools for windows -* C++ ATL for v142 build tools (x86 & x64) -* C++ MFC for v142 build tools (x86 & x64) -* C++/CLI support for v142 build tools (14.21) -* C++ Modules for v142 build tools (x64/x86) -* Clang Compiler for Windows -* Windows 10 SDK (10.0.17134.0) -* Windows 10 SDK (10.0.16299.0) -* MSVC v141 - VS 2017 C++ x64/x86 build tools -* MSVC v140 - VS 2015 C++ build tools (v14.00) - -This will install about 22GB of crap, but once that is done you can open up a command line in the project's directory and run `lime test windows -debug`. Once that command finishes (it takes forever even on a higher end PC), you can run FNF from the .exe file under export\release\windows\bin -As for Mac, 'lime test mac -debug' should work, if not the internet surely has a guide on how to compile Haxe stuff for Mac. - -### Additional guides - -- [Command line basics](https://ninjamuffin99.newgrounds.com/news/post/1090480) +This uses a haxelib library called linc_discord-rpc which you should be able to download with: +```haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc``` +This library has a dependency for hxcpp, which should be downloaded automatically. From ad0e707c57df5ec70a1d99972527600e509aa870 Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 13:23:03 +0000 Subject: [PATCH 05/15] forgot to comment out debug trace --- source/Discord.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Discord.hx b/source/Discord.hx index 3a20ebabe..b7f5e711b 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -22,7 +22,7 @@ class DiscordClient { DiscordRpc.process(); sleep(2); - trace("Discord Client Update"); + //trace("Discord Client Update"); } DiscordRpc.shutdown(); From bd2228f3f52189544d2cccd653a35bdbf0db866c Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Fri, 26 Feb 2021 13:25:55 +0000 Subject: [PATCH 06/15] put the thread import in the right place --- source/TitleState.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/TitleState.hx b/source/TitleState.hx index 842e37fbf..4bc6ef63f 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -2,6 +2,7 @@ package; #if !html5 import Discord.DiscordClient; +import sys.thread.Thread; #end import flixel.FlxG; import flixel.FlxSprite; @@ -26,7 +27,6 @@ import flixel.util.FlxTimer; import io.newgrounds.NG; import lime.app.Application; import openfl.Assets; -import sys.thread.Thread; using StringTools; From 8c2ebcd5e87096fd55f280c011c155bfe975c17e Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Sat, 27 Feb 2021 02:23:15 +0000 Subject: [PATCH 07/15] Update README.md --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5a4364f9c..2c40ffc1c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,94 @@ -# Friday Night Funkin Discord RPC +# Friday Night Funkin -This is a fork that adds Discord RPC (custom status) to Funkin'. +This is the repository for Friday Night Funkin, a game originally made for Ludum Dare 47 "Stuck In a Loop". -## Before you use -Please note that due to the way Discord's system works, apps that have not been approved are on a whitelist. -If you want to try this out, please dm me on Discord at Jak_#0768 and I will add you to the whitelist when I can. +Play the Ludum Dare prototype here: https://ninja-muffin24.itch.io/friday-night-funkin +Play the Newgrounds one here: https://www.newgrounds.com/portal/view/770371 +Support the project on the itch.io page: https://ninja-muffin24.itch.io/funkin -## Building -This won't build on html5, because I put pre-compiler tags to stop it from doing so. This should mean it only builds on desktop, but it will work on Android and stuff, so if that's what you're going for you should probably change the tags. +## Credits / shoutouts -This uses a haxelib library called linc_discord-rpc which you should be able to download with: -```haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc``` -This library has a dependency for hxcpp, which should be downloaded automatically. +- [ninjamuffin99 (me!)](https://twitter.com/ninja_muffin99) - Programmer +- [PhantomArcade3K](https://twitter.com/phantomarcade3k) and [Evilsk8r](https://twitter.com/evilsk8r) - Art +- [Kawaisprite](https://twitter.com/kawaisprite) - Musician + +This game was made with love to Newgrounds and it's community. Extra love to Tom Fulp. + +## Build instructions + +THESE INSTRUCTIONS ARE FOR COMPILING THE GAME'S SOURCE CODE!!! + +IF YOU WANT TO JUST DOWNLOAD AND INSTALL AND PLAY THE GAME NORMALLY, GO TO ITCH.IO TO DOWNLOAD THE GAME FOR PC, MAC, AND LINUX!! + +https://ninja-muffin24.itch.io/friday-night-funkin + +IF YOU WANT TO COMPILE THE GAME YOURSELF, CONTINUE READING!!! + +### Installing the Required Programs + +First you need to install Haxe and HaxeFlixel. I'm too lazy to write and keep updated with that setup (which is pretty simple). +1. [Install Haxe 4.1.5](https://haxe.org/download/version/4.1.5/) (Download 4.1.5 instead of 4.2.0 because 4.2.0 is broken and is not working with gits properly...) +2. [Install HaxeFlixel](https://haxeflixel.com/documentation/install-haxeflixel/) after downloading Haxe + +Other installations you'd need is the additional libraries, a fully updated list will be in `Project.xml` in the project root. Currently, these are all of the things you need to install: +``` +flixel +flixel-addons +flixel-ui +hscript +newgrounds +``` +So for each of those type `haxelib install [library]` so shit like `haxelib install newgrounds` + +You'll also need to install polymod. To do this, you need to do a few things first. +1. Download [git-scm](https://git-scm.com/downloads). Works for Windows, Mac, and Linux, just select your build. +2. Follow instructions to install the application properly. +3. Run `haxelib git polymod https://github.com/larsiusprime/polymod.git` in terminal/command-prompt after your git program is installed. + +You should have everything ready for compiling the game! Follow the guide below to continue! + +### Ignored files + +I gitignore the API keys for the game, so that no one can nab them and post fake highscores on the leaderboards. But because of that the game +doesn't compile without it. + +Just make a file in `/source` and call it `APIStuff.hx`, and copy paste this into it + +```haxe +package; + +class APIStuff +{ + public static var API:String = ""; + public static var EncKey:String = ""; +} + +``` + +and you should be good to go there. + +### Compiling game + +Once you have all those installed, it's pretty easy to compile the game. You just need to run 'lime test html5 -debug' in the root of the project to build and run the HTML5 version. (command prompt navigation guide can be found here: [https://ninjamuffin99.newgrounds.com/news/post/1090480](https://ninjamuffin99.newgrounds.com/news/post/1090480)) + +To run it from your desktop (Windows, Mac, Linux) it can be a bit more involved. For Linux, you only need to open a terminal in the project directory and run 'lime test linux -debug' and then run the executible file in export/release/linux/bin. For Windows, you need to install Visual Studio Community 2019. While installing VSC, don't click on any of the options to install workloads. Instead, go to the individual components tab and choose the following: +* MSVC v142 - VS 2019 C++ x64/x86 build tools +* Windows SDK (10.0.17763.0) +* C++ Profiling tools +* C++ CMake tools for windows +* C++ ATL for v142 build tools (x86 & x64) +* C++ MFC for v142 build tools (x86 & x64) +* C++/CLI support for v142 build tools (14.21) +* C++ Modules for v142 build tools (x64/x86) +* Clang Compiler for Windows +* Windows 10 SDK (10.0.17134.0) +* Windows 10 SDK (10.0.16299.0) +* MSVC v141 - VS 2017 C++ x64/x86 build tools +* MSVC v140 - VS 2015 C++ build tools (v14.00) + +This will install about 22GB of crap, but once that is done you can open up a command line in the project's directory and run `lime test windows -debug`. Once that command finishes (it takes forever even on a higher end PC), you can run FNF from the .exe file under export\release\windows\bin +As for Mac, 'lime test mac -debug' should work, if not the internet surely has a guide on how to compile Haxe stuff for Mac. + +### Additional guides + +- [Command line basics](https://ninjamuffin99.newgrounds.com/news/post/1090480) From 1eb5ae69de688018850b981c555a3e6b37d2b5f0 Mon Sep 17 00:00:00 2001 From: Jakkzero <50273567+Jakkzero@users.noreply.github.com> Date: Sat, 27 Feb 2021 02:28:01 +0000 Subject: [PATCH 08/15] Update FreeplayState.hx --- source/FreeplayState.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index 789897b20..edc68b1a8 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -237,9 +237,9 @@ class FreeplayState extends MusicBeatState function changeSelection(change:Int = 0) { - // #if !switch - // NGio.logEvent('Fresh'); - // #end + #if !switch + NGio.logEvent('Fresh'); + #end // NGio.logEvent('Fresh'); FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); From 3d74f869d30f14e2da48b55651a20f599423e8cb Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 16:58:07 -0300 Subject: [PATCH 09/15] Added changePresence arguments --- source/Discord.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/Discord.hx b/source/Discord.hx index b7f5e711b..668ea85e6 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -57,13 +57,16 @@ class DiscordClient trace("Discord Client initialized"); } - public static function changePresence(details:String, state:Null) + public static function changePresence(details:String, state:Null, ?smallImageKey : String, ?startTimestamp: Int, ?endTimestamp: Int) { DiscordRpc.presence({ details: details, state: state, largeImageKey: 'icon', - largeImageText: "Friday Night Funkin'" + largeImageText: "Friday Night Funkin'", + smallImageKey : smallImageKey, + startTimestamp : startTimestamp, + endTimestamp : endTimestamp }); } } From 700acb86a1095877229bb2c1876a9e40fcccba67 Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 18:59:18 -0300 Subject: [PATCH 10/15] Now shows P2 icon and time left when song starts --- source/Discord.hx | 16 +++++++++++++--- source/PlayState.hx | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/source/Discord.hx b/source/Discord.hx index 668ea85e6..39875a37d 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -57,16 +57,26 @@ class DiscordClient trace("Discord Client initialized"); } - public static function changePresence(details:String, state:Null, ?smallImageKey : String, ?startTimestamp: Int, ?endTimestamp: Int) + public static function changePresence(details:String, state:Null, ?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, - startTimestamp : startTimestamp, - endTimestamp : endTimestamp + // 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. Argument: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp'); } } diff --git a/source/PlayState.hx b/source/PlayState.hx index 0356dd58a..f191a1798 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -125,6 +125,13 @@ class PlayState extends MusicBeatState var inCutscene:Bool = false; + #if !html + // Discord RPC variables + var storyDifficultyText:String = ""; + var iconRPC:String = ""; + var songLength:Float = 0; + #end + override public function create() { if (FlxG.sound.music != null) @@ -178,7 +185,6 @@ class PlayState extends MusicBeatState #if !html // Making difficulty text for Discord Rich Presence. - var storyDifficultyText = ""; switch (storyDifficulty) { case 0: @@ -188,14 +194,28 @@ class PlayState extends MusicBeatState case 2: 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. if (isStoryMode) { - DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")"); + DiscordClient.changePresence("Story Mode: Week " + storyWeek, SONG.song + " (" + storyDifficultyText + ")", iconRPC); } else { - DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")"); + DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")", iconRPC); } #end @@ -992,6 +1012,21 @@ class PlayState extends MusicBeatState FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 1, false); FlxG.sound.music.onComplete = endSong; 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; From dee03abd3f994db090cf1ea1643275535a2e287f Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 20:23:50 -0300 Subject: [PATCH 11/15] Pausing and unpausing updates RPC --- source/PlayState.hx | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/source/PlayState.hx b/source/PlayState.hx index f191a1798..13e95d896 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -130,6 +130,8 @@ class PlayState extends MusicBeatState var storyDifficultyText:String = ""; var iconRPC:String = ""; var songLength:Float = 0; + var detailsText:String = ""; + var detailsPausedText:String = ""; #end override public function create() @@ -207,16 +209,22 @@ class PlayState extends MusicBeatState case 'mom-car': iconRPC = 'mom'; } - - // Updating Discord Rich Presence. + + // 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 + ")", iconRPC); + detailsText = "Story Mode: Week " + storyWeek; } else { - DiscordClient.changePresence("Freeplay", SONG.song + " (" + storyDifficultyText + ")", iconRPC); + 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') @@ -1018,14 +1026,7 @@ class PlayState extends MusicBeatState 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); - } + DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength); #end } @@ -1267,6 +1268,17 @@ class PlayState extends MusicBeatState if (!startTimer.finished) startTimer.active = true; paused = false; + + #if !html + 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(); @@ -1334,6 +1346,10 @@ class PlayState extends MusicBeatState } else openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); + + #if !html + DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC); + #end } if (FlxG.keys.justPressed.SEVEN) From 34a5175ce55909812264bb41af59c3d7fd82aa30 Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 20:49:53 -0300 Subject: [PATCH 12/15] Alt+Tab and Game Over updates RPC --- source/PlayState.hx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/source/PlayState.hx b/source/PlayState.hx index 13e95d896..3f80deb92 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1284,6 +1284,37 @@ class PlayState extends MusicBeatState super.closeSubState(); } + override public function onFocus():Void + { + #if !html + 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 !html + if (health > 0 && !paused) + { + DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC); + } + #end + + super.onFocusLost(); + } + function resyncVocals():Void { vocals.pause(); @@ -1550,6 +1581,9 @@ class PlayState extends MusicBeatState openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); // FlxG.switchState(new GameOverState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); + + // Game Over doesn't get his own variable because it's only used here + DiscordClient.changePresence("Game Over - " + detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC); } if (unspawnNotes[0] != null) From b1993259bf8765cfb20d9d6e42167c87032eb133 Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 21:06:30 -0300 Subject: [PATCH 13/15] Changed RPC !html and added Debug Status --- source/Discord.hx | 2 +- source/FreeplayState.hx | 6 +++--- source/PlayState.hx | 20 ++++++++++++-------- source/StoryMenuState.hx | 7 ++++--- source/TitleState.hx | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/source/Discord.hx b/source/Discord.hx index 39875a37d..253a4f59a 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -77,6 +77,6 @@ class DiscordClient endTimestamp : Std.int(endTimestamp / 1000) }); - trace('Discord RPC Updated. Argument: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp'); + //trace('Discord RPC Updated. Arguments: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp'); } } diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index edc68b1a8..7dbc84f3a 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -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; diff --git a/source/PlayState.hx b/source/PlayState.hx index 3f80deb92..4ac546024 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,6 +1,6 @@ package; -#if !html +#if desktop import Discord.DiscordClient; #end import Section.SwagSection; @@ -125,7 +125,7 @@ class PlayState extends MusicBeatState var inCutscene:Bool = false; - #if !html + #if desktop // Discord RPC variables var storyDifficultyText:String = ""; var iconRPC:String = ""; @@ -185,7 +185,7 @@ class PlayState extends MusicBeatState dialogue = CoolUtil.coolTextFile(Paths.txt('thorns/thornsDialogue')); } - #if !html + #if desktop // Making difficulty text for Discord Rich Presence. switch (storyDifficulty) { @@ -1021,7 +1021,7 @@ class PlayState extends MusicBeatState FlxG.sound.music.onComplete = endSong; vocals.play(); - #if !html + #if desktop // Song duration in a float, useful for the time left feature songLength = FlxG.sound.music.length; @@ -1269,7 +1269,7 @@ class PlayState extends MusicBeatState startTimer.active = true; paused = false; - #if !html + #if desktop if (startTimer.finished) { DiscordClient.changePresence(detailsText, SONG.song + " (" + storyDifficultyText + ")", iconRPC, true, songLength - Conductor.songPosition); @@ -1286,7 +1286,7 @@ class PlayState extends MusicBeatState override public function onFocus():Void { - #if !html + #if desktop if (health > 0 && !paused) { if (Conductor.songPosition > 0.0) @@ -1305,7 +1305,7 @@ class PlayState extends MusicBeatState override public function onFocusLost():Void { - #if !html + #if desktop if (health > 0 && !paused) { DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC); @@ -1378,7 +1378,7 @@ class PlayState extends MusicBeatState else openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); - #if !html + #if desktop DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconRPC); #end } @@ -1386,6 +1386,10 @@ class PlayState extends MusicBeatState 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); diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index 0e4b06558..6d1f8f20c 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -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) diff --git a/source/TitleState.hx b/source/TitleState.hx index 4bc6ef63f..c91dc54eb 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -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 } From 5e7bbc3b66b7710b7f7faa5a2c139d1dd075b10b Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sat, 27 Feb 2021 21:34:49 -0300 Subject: [PATCH 14/15] Exiting through the pause menu updates RPC --- source/MainMenuState.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index 4b3a8f110..35fb50e8a 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -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; From 3dd24abf078421b09d2984d4fe5b29e70924cc07 Mon Sep 17 00:00:00 2001 From: WorstAquaPlayer Date: Sun, 28 Feb 2021 18:50:06 -0300 Subject: [PATCH 15/15] Added missing #if to RPC call --- Project.xml | 2 +- source/PlayState.hx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.xml b/Project.xml index 23de20a24..08b9a5a47 100644 --- a/Project.xml +++ b/Project.xml @@ -116,7 +116,7 @@ - + diff --git a/source/PlayState.hx b/source/PlayState.hx index 4ac546024..aa41737ea 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1586,8 +1586,10 @@ class PlayState extends MusicBeatState // 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)