Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Discord Unpause Timer #230

Merged
merged 1 commit into from
May 2, 2023
Merged
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
40 changes: 16 additions & 24 deletions Assets/Script/ThirdParty/DiscordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Activity CurrentActivity {
[SerializeField]
private string defaultState = "Are you ready to rock?"; //smaller 2nd line of text
private string defaultLargeImage = "logo"; // string name comes from the assets uploaded to the app
//private string defaultLargeImage = "https://cld.pt/dl/download/6e981054-9955-427a-9e4a-80b92a503a01/Icon.gif"; // URL to an animated Logo
[SerializeField]
private string defaultLargeText = "Yet Another Rhythm Game"; //Tooltip text for the large icon
[SerializeField]
Expand Down Expand Up @@ -82,8 +83,7 @@ public Activity CurrentActivity {
// A bunch of time handling stuff
private long gameStartTime; //start of YARG, doesn't stop
private float songLengthSeconds; //Length of song in seconds (not milliseconds)
private long pauseTime = 0; //when the song was last pasused
private long pauseAmount = 0; //the total amount of paused time


private void Start() {
Instance = this;
Expand Down Expand Up @@ -125,33 +125,25 @@ private void OnDestroy() {
}

private void OnPauseToggle(bool pause) {
if (pause) {
pauseTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
SetActivity(
currentSmallImage,
currentSmallText,
songName,
"by " + artistName,
0, 0
);
} else { //unpause
pauseAmount += DateTimeOffset.Now.ToUnixTimeMilliseconds() - pauseTime; //adding up all the pause time
SetActivity(
currentSmallImage,
currentSmallText,
songName,
"by " + artistName,
DateTimeOffset.Now.ToUnixTimeMilliseconds(),
DateTimeOffset.Now.AddSeconds(songLengthSeconds).ToUnixTimeMilliseconds() - pauseAmount
);
}
SetActivity(
// State data
pause ? "pause1" : currentSmallImage,
pause ? "Paused" : currentSmallText,

// Song data
songName,
"by " + artistName,

// Time data
pause ? 0 : DateTimeOffset.Now.ToUnixTimeMilliseconds(),
pause ? 0 : DateTimeOffset.Now.AddSeconds(songLengthSeconds - Play.Instance.SongTime).ToUnixTimeMilliseconds()
);
}

private void OnSongStart(SongInfo song) {
songLengthSeconds = song.songLength;
songName = song.SongName;
artistName = song.artistName;
pauseAmount = 0;
SetActivity(
currentSmallImage,
currentSmallText,
Expand Down Expand Up @@ -179,7 +171,7 @@ private void OnInstrumentSelection(YARG.PlayerManager.Player playerInfo) {
"realDrums" => "Really working the skins",
"ghDrums" => "Working the skins +1",
"guitar" => "Making it talk",
"guitarCoop" => "GTR_COOP_PLACEHOLDER",
"guitarCoop" => "GTR_COOP_PLACEHOLDER",
"rhythm" => "RHYTHM_PLACEHOLDER",
"realGuitar" => "Really making it talk",
"bass" => "In the groove",
Expand Down