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

No discord (optional) #241

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ClientPrefs
public static var arrowHSV:Array<Array<Int>> = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]];
public static var imagesPersist:Bool = false;
public static var ghostTapping:Bool = true;
public static var discord:Bool = true;
public static var timeBarType:String = 'Time Left';
public static var scoreZoom:Bool = true;
public static var noReset:Bool = false;
Expand Down Expand Up @@ -126,6 +127,7 @@ class ClientPrefs

public static function saveSettings()
{
FlxG.save.data.discord = discord;
FlxG.save.data.noteSkin = noteSkin;
FlxG.save.data.winningIcon = winningIcon;
//FlxG.save.data.multiplicativeValue = multiplicativeValue;
Expand Down Expand Up @@ -190,6 +192,8 @@ class ClientPrefs

public static function loadPrefs()
{
if(FlxG.save.data.discord != null) discord = FlxG.save.data.discord;

if (FlxG.save.data.comboStacking != null)
comboStacking = FlxG.save.data.comboStacking;

Expand Down
103 changes: 56 additions & 47 deletions source/Discord.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,43 @@ class DiscordClient
public static var isInitialized:Bool = false;
public function new()
{
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "863222024192262205",
onReady: onReady,
onError: onError,
onDisconnected: onDisconnected
});
trace("Discord Client started.");

while (true)
{
DiscordRpc.process();
sleep(2);
//trace("Discord Client Update");
if(ClientPrefs.discord) {
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "863222024192262205",
onReady: onReady,
onError: onError,
onDisconnected: onDisconnected
});
trace("Discord Client started.");

while (true)
{
DiscordRpc.process();
sleep(2);
//trace("Discord Client Update");
}

DiscordRpc.shutdown();
}

DiscordRpc.shutdown();
}

public static function shutdown()
{
DiscordRpc.shutdown();
if(ClientPrefs.discord)
DiscordRpc.shutdown();
}

static function onReady()
{
DiscordRpc.presence({
details: "In the Menus",
state: null,
largeImageKey: 'icon',
largeImageText: "Theoyeah Engine"
});
if(ClientPrefs.discord) {
DiscordRpc.presence({
details: "In the Menus",
state: null,
largeImageKey: 'icon',
largeImageText: "Theoyeah Engine"
});
}
}

static function onError(_code:Int, _message:String)
Expand All @@ -63,35 +68,39 @@ class DiscordClient

public static function initialize()
{
var DiscordDaemon = sys.thread.Thread.create(() ->
{
new DiscordClient();
});
trace("Discord Client initialized");
isInitialized = true;
if(ClientPrefs.discord) {
var DiscordDaemon = sys.thread.Thread.create(() ->
{
new DiscordClient();
});
trace("Discord Client initialized");
isInitialized = true;
}
}

public static function changePresence(details:String, ?state:String, ?smallImageKey:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float)
{
var startTimestamp:Float = if(hasStartTimestamp) Date.now().getTime() else 0;

if (endTimestamp > 0)
{
endTimestamp = startTimestamp + endTimestamp;
if(ClientPrefs.discord) {
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: "Engine Version: " + MainMenuState.theoyeahEngineVersion,
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');
}

DiscordRpc.presence({
details: details,
state: state,
largeImageKey: 'icon',
largeImageText: "Engine Version: " + MainMenuState.theoyeahEngineVersion,
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');
}

#if LUA_ALLOWED
Expand Down
28 changes: 27 additions & 1 deletion source/options/GraphicsSettingsSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,35 @@ class GraphicsSettingsSubState extends BaseOptionsMenu
addOption(option);
#end

#if desktop
var option:Option = new Option('Use Discord',
'If unchecked, discord will not be used and\nthere will be less lag\nIT WILL RESTART THE GAME WHEN CHANGED!',
'discord',
'bool',
true);
option.onChange = onChangeDiscord;
addOption(option);
#end

super();
}

#if desktop
function onChangeDiscord() {
ClientPrefs.saveSettings();
//MusicBeatState.switchState(new TitleState());
TitleState.initialized = false;
TitleState.closedState = false;
FlxG.sound.music.fadeOut(0.3);
if(FreeplayState.vocals != null)
{
FreeplayState.vocals.fadeOut(0.3);
FreeplayState.vocals = null;
}
FlxG.camera.fade(FlxColor.BLACK, 0.5, false, FlxG.resetGame, false);
}
#end

function onChangeAntiAliasing()
{
for (sprite in members)
Expand All @@ -109,7 +135,7 @@ class GraphicsSettingsSubState extends BaseOptionsMenu

function onChangeFramerate()
{
if(ClientPrefs.framerate > FlxG.drawFramerate)
if(ClientPrefs.framerate > FlxG.drawFramerate) // bro, why?
{
FlxG.updateFramerate = ClientPrefs.framerate;
FlxG.drawFramerate = ClientPrefs.framerate;
Expand Down