Add back Discord RPC

This commit is contained in:
2026-01-31 22:19:38 -07:00
parent e8bac521f7
commit d928fff45e
18 changed files with 809 additions and 309 deletions

View File

@@ -145,7 +145,7 @@ public class CustomGamePlayer : MonoBehaviour
backgroundMusic.volume = BazookaManager.Instance.GetSettingMusicVolume();
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
if (Application.isMobilePlatform) mobileButtons.SetActive(true);
UpdateStats(0, 1);
UpdateStats(0);
}
void MoveBird()
@@ -635,7 +635,7 @@ public class CustomGamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 0f;
antiLeft = 0f;
UpdateStats(0, 1);
UpdateStats(0);
GameObject[] allberries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
@@ -652,11 +652,13 @@ public class CustomGamePlayer : MonoBehaviour
}
}
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount)
void UpdateStats(BigInteger scoreAddAmount)
{
score += scoreAddAmount;
scoreText.text = $"Score: {Tools.FormatWithCommas(score)}";
if (Application.isMobilePlatform) restartButton.interactable = score != 0;
if (DiscordRPCHandler.Instance != null)
DiscordRPCHandler.Instance.UpdateRPC("Playing in custom mode", "Score: " + Tools.FormatWithCommas(score));
}
void CheckIfGrounded()
@@ -721,14 +723,14 @@ public class CustomGamePlayer : MonoBehaviour
{
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Eat"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
Destroy(berry);
UpdateStats(1, 0);
UpdateStats(1);
}
void DoPoisonBerry()
{
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Death"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume());
Respawn();
UpdateStats(0, 0);
UpdateStats(0);
}
void DoSlowBerry(GameObject berry)
@@ -741,7 +743,7 @@ public class CustomGamePlayer : MonoBehaviour
antiLeft = 0f;
if (score > 0)
{
UpdateStats(-1, 0);
UpdateStats(-1);
}
}
@@ -754,12 +756,12 @@ public class CustomGamePlayer : MonoBehaviour
if (slownessLeft > 0f)
{
slownessLeft = 0f;
UpdateStats(1, 0);
UpdateStats(1);
}
else
{
boostLeft += 10f;
UpdateStats(5, 0);
UpdateStats(5);
}
}
@@ -771,7 +773,7 @@ public class CustomGamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 10f;
antiLeft = 0f;
UpdateStats(10, 0);
UpdateStats(10);
}
void DoAntiBerry(GameObject berry)
@@ -782,7 +784,7 @@ public class CustomGamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 0f;
antiLeft = 10f;
UpdateStats(0, 0);
UpdateStats(0);
}
void DoNothingBerry(GameObject berry)

View File

@@ -0,0 +1,83 @@
using DiscordRPC;
using UnityEngine;
public class DiscordRPCHandler : MonoBehaviour
{
public static DiscordRPCHandler Instance;
public DiscordRpcClient client;
private readonly Timestamps timestamp = Timestamps.Now;
private bool isIdle = false;
private string savedDetails;
private string savedState;
void Awake()
{
if (Application.isMobilePlatform || Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
client = new DiscordRpcClient("1421877993176961155");
client.Initialize();
}
void OnDestroy()
{
client.Dispose();
}
void OnApplicationQuit()
{
client.Dispose();
}
void OnApplicationPause(bool pause)
{
isIdle = pause;
if (pause)
{
UpdateRPC("Idle", null, true);
}
else
{
UpdateRPC(savedDetails, savedState, true);
}
}
public void UpdateRPC(string details, string state, bool force = false)
{
if (!force && isIdle)
{
savedDetails = details;
savedState = state;
return;
}
client.SetPresence(new RichPresence
{
Details = details,
State = state,
Assets = new Assets
{
LargeImageKey = "https://games-r2.lncvrt.xyz/icons/berry-dash.png",
LargeImageText = "Berry Dash",
SmallImageKey = "https://cdn.lncvrt.xyz/pfp.png",
SmallImageText = "Made by Lncvrt!"
},
Buttons = new[]
{
new Button { Label = "Website / Download", Url = "https://games.lncvrt.xyz/game/berry-dash" },
new Button { Label = "Lncvrt Games", Url = "https://games.lncvrt.xyz" }
},
Timestamps = timestamp
});
savedDetails = details;
savedState = state;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4cb8a7731f5d84e369d9749362070740

View File

@@ -0,0 +1,12 @@
using UnityEngine;
public class DiscordRPCUpdater : MonoBehaviour
{
public string details;
public string state;
void Awake()
{
if (DiscordRPCHandler.Instance != null) DiscordRPCHandler.Instance.UpdateRPC(details, state);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 24d9e9050ab734f5c9e8e60e4adc1afd

View File

@@ -672,6 +672,8 @@ public class GamePlayer : MonoBehaviour
highScoreText.text = prefix + $"High Score: {Tools.FormatWithCommas(highscore) + suffix} \\u2022 Total Attempts: {Tools.FormatWithCommas(totalAttempts)}";
coinText.text = $"Coins: {Tools.FormatWithCommas(totalCoins)}";
if (Application.isMobilePlatform) restartButton.interactable = score != 0;
if (DiscordRPCHandler.Instance != null)
DiscordRPCHandler.Instance.UpdateRPC("Playing in normal mode", $"Score: {Tools.FormatWithCommas(score)} | High Score: {Tools.FormatWithCommas(highscore)}");
}
void CheckIfGrounded()

View File

@@ -49,6 +49,7 @@ public class IconMarketplaceManager : MonoBehaviour
normalPanel.SetActive(true);
downloadPanel.SetActive(false);
uploadPanel.SetActive(false);
if (DiscordRPCHandler.Instance != null) DiscordRPCHandler.Instance.UpdateRPC("Choosing what to do in the icon marketplace", null);
break;
case 1:
foreach (Transform item in downloadPanelScript.content.transform)
@@ -62,12 +63,14 @@ public class IconMarketplaceManager : MonoBehaviour
downloadPanel.SetActive(true);
uploadPanel.SetActive(false);
downloadPanelScript.Load();
if (DiscordRPCHandler.Instance != null) DiscordRPCHandler.Instance.UpdateRPC("Browsing the icon marketplace", "They have " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance) + " coins");
break;
case 2:
uploadPanelScript.Reset();
normalPanel.SetActive(false);
downloadPanel.SetActive(false);
uploadPanel.SetActive(true);
if (DiscordRPCHandler.Instance != null) DiscordRPCHandler.Instance.UpdateRPC("Uploading an icon to the icon marketplace", null);
break;
}
}

View File

@@ -40,6 +40,8 @@ public class PlayMenu : MonoBehaviour
{
selectionMenu.SetActive(false);
customMenu.SetActive(true);
if (DiscordRPCHandler.Instance != null)
DiscordRPCHandler.Instance.UpdateRPC("Customizing to play the custom mode", "");
});
customBackButton.onClick.AddListener(() =>
{
@@ -55,6 +57,8 @@ public class PlayMenu : MonoBehaviour
antiBerryChance.text = defaultAntiBerryChance.ToString();
nothingBerryChance.text = defaultNothingBerryChance.ToString();
ValidateTotal();
if (DiscordRPCHandler.Instance != null)
DiscordRPCHandler.Instance.UpdateRPC("Picking what mode they want to play", "");
});
customNormalizeButton.onClick.AddListener(() =>
{
@@ -189,6 +193,12 @@ public class PlayMenu : MonoBehaviour
nothingBerryChance.onDeselect.AddListener((value) => OnDeselect(value, nothingBerryChance));
}
void Start()
{
if (DiscordRPCHandler.Instance != null)
DiscordRPCHandler.Instance.UpdateRPC("Picking what mode they want to play", "");
}
void ValidateTotal()
{
customBackButton.interactable = false;