Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
new DiscordRpc
Browse files Browse the repository at this point in the history
  • Loading branch information
GuineaPigUuhh committed Mar 19, 2024
1 parent 924bc89 commit 0838817
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 113 deletions.
118 changes: 68 additions & 50 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,72 @@
<project>
<!-- _________________________ Application Settings _________________________ -->

<app
title="Friday Night Funkin'- Null Engine"
version="0.2.8"
<app
title="Friday Night Funkin'- Null Engine"
version="0.2.8"
file="NullEngine"

main="Main"

packageName="com.guineapiguuhh.nullengine"
package="com.guineapiguuhh.nullengine"
company="GuineaPigUuhh"
main="Main"
packageName="com.guineapiguuhh.nullengine"
package="com.guineapiguuhh.nullengine"
company="GuineaPigUuhh"
/>

<!--Switch Export with Unique ApplicationID and Icon-->
<!--Switch
Export with Unique ApplicationID and Icon-->
<set name="APP_ID" value="0x0100f6c013bbc000" />

<!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html file
<!--The
flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a
html file
or you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"-->
<!-- <app preloader="Preloader" resizable="true" /> -->
<app preloader="flixel.system.FlxPreloader" />

<!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2-->
<!--Minimum
without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2-->
<set name="SWF_VERSION" value="11.8" />

<!-- ____________________________ Window Settings ___________________________ -->

<!--These window settings apply to all targets-->
<!--These
window settings apply to all targets-->
<window width="1280" height="720" fps="" background="#000000" hardware="true" vsync="false" />

<!--HTML5-specific-->
<window if="html5" resizable="true" />

<!--Desktop-specific-->
<window if="desktop" orientation="landscape" fullscreen="false" resizable="true" vsync="false"/>
<window if="desktop" orientation="landscape" fullscreen="false" resizable="true" vsync="false" />

<!--Mobile-specific-->
<window if="mobile" orientation="landscape" fullscreen="true" width="0" height="0" resizable="false"/>
<window if="mobile" orientation="landscape" fullscreen="true" width="0" height="0"
resizable="false" />

<!--Switch-specific-->
<window if="switch" orientation="landscape" fullscreen="true" width="0" height="0" resizable="true" />
<window if="switch" orientation="landscape" fullscreen="true" width="0" height="0"
resizable="true" />

<!-- __________________________ CustomDefines _________________________ -->

<define name="MODS_ALLOWED" if="desktop" />
<define name="VIDEOS_ALLOWED" if="desktop || android" />
<!--<define name="DISCORD_ALLOWED" if="desktop" />-->

<haxedef name="CAN_OPEN_LINKS" unless="switch"/>
<define name="DISCORD_ALLOWED" if="desktop" />
<haxedef name="CAN_OPEN_LINKS" unless="switch" />

<!-- _____________________________ Path Settings ____________________________ -->

<set name="BUILD_DIR" value="export/debug" if="debug" />
<set name="BUILD_DIR" value="export/release" unless="debug" />
<set name="BUILD_DIR" value="export/32bit" if="32bit" />

<assets path="assets/engine"/>
<assets path="assets/funkin"/>
<assets path="assets/engine" />
<assets path="assets/funkin" />
<section if="MODS_ALLOWED">
<assets path="mods" embed="false"/>
<assets path="mods" embed="false" />
</section>

<classpath name="source" />

<!-- _______________________________ Libraries ______________________________ -->

<!-- Flixel -->
Expand All @@ -72,59 +76,73 @@
<haxelib name="flixel-addons" />

<!-- Funkin -->
<haxelib name="polymod" if="MODS_ALLOWED"/>
<haxelib name="discord-rpc" if="DISCORD_ALLOWED"/>
<haxelib name="polymod" if="MODS_ALLOWED" />
<haxelib name="hxdiscord_rpc" if="DISCORD_ALLOWED" />

<!-- Null Engine -->
<haxelib name="hscript"/>
<haxelib name="flxanimate"/>
<haxelib name="tjson"/>
<haxelib name="hxCodec" if="VIDEOS_ALLOWED"/>
<haxelib name="hscript" />
<haxelib name="flxanimate" />
<haxelib name="tjson" />
<haxelib name="hxCodec" if="VIDEOS_ALLOWED" />

<!-- Debug -->
<haxelib name="hxcpp-debug-server" if="desktop debug"/>
<haxelib name="hxcpp-debug-server" if="desktop debug" />

<!-- Others -->
<haxedev set='webgl' />
<haxelib name="faxe" if='switch'/>
<haxelib name="faxe" if='switch' />

<!-- ______________________________ Haxedefines _____________________________ -->

<!--Enable the Flixel core recording system-->
<!--<haxedef name="FLX_RECORD" />-->
<!--Enable
the Flixel core recording system-->
<!--<haxedef
name="FLX_RECORD" />-->

<!--Disable the right and middle mouse buttons-->
<!--Disable
the right and middle mouse buttons-->
<!-- <haxedef name="FLX_NO_MOUSE_ADVANCED" /> -->

<!--Disable the native cursor API on Flash-->
<!--<haxedef name="FLX_NO_NATIVE_CURSOR" />-->
<!--Disable
the native cursor API on Flash-->
<!--<haxedef
name="FLX_NO_NATIVE_CURSOR" />-->

<!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
<!--Optimise
inputs, be careful you will get null errors if you don't use conditionals in your game-->
<!-- <haxedef name="FLX_NO_MOUSE" if="mobile" /> -->
<!-- <haxedef name="FLX_NO_KEYBOARD" if="mobile" /> -->
<!-- <haxedef name="FLX_NO_TOUCH" if="desktop" /> -->
<!--<haxedef name="FLX_NO_GAMEPAD" />-->
<!--<haxedef
name="FLX_NO_GAMEPAD" />-->

<!--Disable the Flixel core sound tray-->
<!--<haxedef name="FLX_NO_SOUND_TRAY" />-->
<!--Disable
the Flixel core sound tray-->
<!--<haxedef
name="FLX_NO_SOUND_TRAY" />-->

<!--Disable the Flixel sound management code-->
<!--<haxedef name="FLX_NO_SOUND_SYSTEM" />-->
<!--Disable
the Flixel sound management code-->
<!--<haxedef
name="FLX_NO_SOUND_SYSTEM" />-->

<!--Disable the Flixel core focus lost screen-->
<!--Disable
the Flixel core focus lost screen-->
<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />

<!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<!--Disable
the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<haxedef name="FLX_NO_DEBUG" unless="debug" />

<!--Enable this for Nape release builds for a serious peformance improvement-->
<!--Enable
this for Nape release builds for a serious peformance improvement-->
<haxedef name="NAPE_RELEASE_BUILD" unless="debug" />

<!-- _________________________________ Custom _______________________________ -->

<icon path="assets/engine/flixel-icons/16.png" size='16'/>
<icon path="assets/engine/flixel-icons/32.png" size='32'/>
<icon path="assets/engine/flixel-icons/64.png" size='64'/>
<icon path="assets/engine/flixel-icons/16.png" size='16' />
<icon path="assets/engine/flixel-icons/32.png" size='32' />
<icon path="assets/engine/flixel-icons/64.png" size='64' />
<icon path="assets/engine/flixel-icons/OG.png" />
</project>

</project>
124 changes: 69 additions & 55 deletions source/Discord.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,102 @@ import Sys.sleep;
using StringTools;

#if DISCORD_ALLOWED
import discord_rpc.DiscordRpc;
import hxdiscord_rpc.Discord;
import hxdiscord_rpc.Types;
#end

class DiscordClient
{
#if DISCORD_ALLOWED
public function new()
{
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "814588678700924999",
onReady: onReady,
onError: onError,
onDisconnected: onDisconnected
});
trace("Discord Client started.");
private static var presence:DiscordRichPresence = DiscordRichPresence.create();
public static var connected_user:String = "Unknown";

public static final _defID:String = "1204517234467278979";
public static var clientID(default, set):String = _defID;

while (true)
public static function set_clientID(value:String)
{
if ((clientID != value) && isInitialized)
{
DiscordRpc.process();
sleep(2);
// trace("Discord Client Update");
shutdown();
init();
updatePresence();
}

DiscordRpc.shutdown();
return clientID = value;
}

public static function shutdown()
{
DiscordRpc.shutdown();
}
public static var isInitialized:Bool = false;

static function onReady()
public static function init()
{
DiscordRpc.presence({
details: "In the Menus",
state: null,
largeImageKey: 'icon',
largeImageText: "Friday Night Funkin'"
var handlers:DiscordEventHandlers = DiscordEventHandlers.create();
handlers.ready = cpp.Function.fromStaticFunction(onReady);
handlers.disconnected = cpp.Function.fromStaticFunction(onDisconnected);
handlers.errored = cpp.Function.fromStaticFunction(onError);
Discord.Initialize(clientID, cpp.RawPointer.addressOf(handlers), 1, null);

if (!isInitialized)
trace("new DiscordPrecense(): Created");

sys.thread.Thread.create(() ->
{
var localID:String = clientID;
while (localID == clientID)
{
#if DISCORD_DISABLE_IO_THREAD
Discord.UpdateConnection();
#end
Discord.RunCallbacks();
Sys.sleep(0.5);
}
});
isInitialized = true;
}

static function onError(_code:Int, _message:String)
private static function onReady(request:cpp.RawConstPointer<DiscordUser>):Void
{
trace('Error! $_code : $_message');
}
var requestPtr:cpp.Star<DiscordUser> = cpp.ConstPointer.fromRaw(request).ptr;

static function onDisconnected(_code:Int, _message:String)
{
trace('Disconnected! $_code : $_message');
connected_user = cast(requestPtr.username, String);
if (Std.parseInt(cast(requestPtr.discriminator, String)) != 0)
trace('(Discord) Connected to User (${connected_user}#${cast (requestPtr.discriminator, String)})');
else
trace('(Discord) Connected to User (${connected_user})');

changePresence();
}

public static function initialize()
private static function onError(errorCode:Int, message:cpp.ConstCharStar):Void
trace('Discord: Error ($errorCode: ${cast (message, String)})');

private static function onDisconnected(errorCode:Int, message:cpp.ConstCharStar):Void
trace('Discord: Disconnected ($errorCode: ${cast (message, String)})');

public dynamic static function shutdown()
{
var DiscordDaemon = sys.thread.Thread.create(() ->
{
new DiscordClient();
});
trace("Discord Client initialized");
Discord.Shutdown();
isInitialized = false;
}

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;
public static function updatePresence()
Discord.UpdatePresence(cpp.RawConstPointer.addressOf(presence));

public static function changePresence(details:String = "Nothing", ?state:Null<String>, ?smallImageKey:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float)
{
var startTimestamp:Float = 0;
if (hasStartTimestamp)
startTimestamp = Date.now().getTime();
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)
});
presence.details = details;
presence.state = state;
presence.largeImageKey = 'icon';
presence.smallImageKey = smallImageKey;
presence.startTimestamp = Std.int(startTimestamp / 1000);
presence.endTimestamp = Std.int(endTimestamp / 1000);

// trace('Discord RPC Updated. Arguments: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp');
updatePresence();
}
#end
}
11 changes: 4 additions & 7 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import openfl.media.Video;
import openfl.net.NetConnection;
import openfl.net.NetStream;
import ui.PreferencesMenu;
import Discord.DiscordClient;

class Main extends Sprite
{
Expand Down Expand Up @@ -107,13 +108,9 @@ class Main extends Sprite
PlayerSettings.init();
Highscore.load();

#if discord_rpc
DiscordClient.initialize();

Application.current.onExit.add(function(exitCode)
{
DiscordClient.shutdown();
});
#if DISCORD_ALLOWED
DiscordClient.init();
Application.current.onExit.add(function(exitCode) DiscordClient.shutdown());
#end
}
}
2 changes: 1 addition & 1 deletion source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class PlayState extends MusicBeatState
var camPos:FlxPoint;
var lightFadeShader:BuildingShaders;

var divider:String = "";
final divider:String = "";

var global_scripts:ScriptPack;
var song_scripts:ScriptPack;
Expand Down

0 comments on commit 0838817

Please sign in to comment.