Rework latest version stuff and add splash texts & more

This commit is contained in:
2026-01-30 22:15:03 -07:00
parent d598c3bd79
commit e2a557812e
19 changed files with 1237 additions and 1094 deletions

View File

@@ -7,16 +7,23 @@ public class BouncyText : MonoBehaviour
[SerializeField] private float frequency = 2f;
[SerializeField] private float minSize = 10f;
[SerializeField] private float maxSize = 12f;
[SerializeField] private bool add;
private TextMeshProUGUI text;
private float startSize = 0;
void Start()
void Awake()
{
text = GetComponent<TextMeshProUGUI>();
if (add)
{
startSize = text.fontSize;
text.enableAutoSizing = false;
}
}
void Update()
{
float newsize = (Mathf.Sin(Time.time * frequency) + 1f) / 2f;
text.fontSize = Mathf.Lerp(minSize, maxSize, newsize);
text.fontSize = Mathf.Lerp(add ? startSize : minSize, maxSize + (add ? startSize : 0), newsize);
}
}

View File

@@ -1,65 +0,0 @@
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class LatestVersionText : MonoBehaviour
{
public static LatestVersionText Instance;
public TMP_Text text;
public Button updateButton;
private string latest = null;
void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
}
void Start()
{
RefreshText();
if (latest == null) GetLatestVersion();
}
void OnEnable()
{
RefreshText();
}
async void GetLatestVersion()
{
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.LATEST_VERSION_ENDPOINT);
request.SetRequestHeader("Requester", "BerryDashClient");
request.SetRequestHeader("ClientVersion", Application.version);
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
await request.SendWebRequest();
if (request.downloadHandler.text == null)
{
latest = "-1";
}
else
{
latest = request.downloadHandler.text;
}
RefreshText();
}
internal void RefreshText()
{
if (text == null || updateButton == null) return;
if (latest == null)
text.text = "Latest: Loading...";
else if (latest == "-1")
text.text = "Latest: N/A";
else
text.text = "Latest: v" + latest;
updateButton.gameObject.SetActive(latest != Application.version);
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: d0ce6d4ae1a102accbe4dfb608a5b75e

View File

@@ -8,6 +8,7 @@ public class MenuScript : MonoBehaviour
[SerializeField] private Button closeButton;
[SerializeField] private TMP_Text updateText;
[SerializeField] private Button updateButton;
[SerializeField] private TMP_Text splashText;
[SerializeField] private Button profileButton;
[SerializeField] private ProfileMenu profilePrefab;
[SerializeField] private TMP_Text copyrightText;
@@ -17,9 +18,19 @@ public class MenuScript : MonoBehaviour
void Awake()
{
LatestVersionText.Instance.text = updateText;
LatestVersionText.Instance.updateButton = updateButton;
LatestVersionText.Instance.RefreshText();
if (PresistentData.latestVersion != null)
{
if (PresistentData.latestVersion != "-1")
{
updateText.text = "Latest: v" + PresistentData.latestVersion ?? "N/A";
updateButton.gameObject.SetActive(PresistentData.latestVersion != Application.version);
}
else
{
updateText.text = "Latest: Loading...";
}
}
if (PresistentData.randomSplashes != null) splashText.text = PresistentData.randomSplashes[Random.Range(0, PresistentData.randomSplashes.Length)];
copyrightText.text = $"\\u00A9 {System.DateTime.Now.Year} Lncvrt. All rights reserved.";
if (!Application.isMobilePlatform && !Application.isEditor)

View File

@@ -6,6 +6,7 @@ public class Endpoints
public const string WS_ENDPOINT = "wss://" + HOST + "/api/ws";
public const string CAN_LOAD_CLIENT_ENDPOINT = BASE_URL + "/can-load-client";
public const string LATEST_VERSION_ENDPOINT = BERRYDASH_ENDPOINT + "/latest-version";
public const string RANDOM_SPLASHES_ENDPOINT = BERRYDASH_ENDPOINT + "/splash-text";
public const string LEADERBOARDS_ENDPOINT = BERRYDASH_ENDPOINT + "/leaderboards";
public const string LEADERBOARDS_SCORE_ENDPOINT = LEADERBOARDS_ENDPOINT + "/score";
public const string LEADERBOARDS_BERRY_ENDPOINT = LEADERBOARDS_ENDPOINT + "/berry";

View File

@@ -0,0 +1,68 @@
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class PresistentData : MonoBehaviour
{
public static PresistentData Instance;
private bool loadingDone = false;
public static string latestVersion = null;
public static string[] randomSplashes = null;
private async void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
if (!loadingDone)
{
loadingDone = true;
await GetLatestVersion();
await GetRandomSplashes();
}
}
private async static Task GetLatestVersion()
{
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.LATEST_VERSION_ENDPOINT);
request.SetRequestHeader("Requester", "BerryDashClient");
request.SetRequestHeader("ClientVersion", Application.version);
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
await request.SendWebRequest();
latestVersion = request.downloadHandler.text ?? "-1";
if (
SceneManager.GetActiveScene().name == "MainMenu" &&
latestVersion != "-1" &&
GameObject.Find("Canvas/LatestVersionText").TryGetComponent<TextMeshProUGUI>(out var text)
)
{
text.text = "Latest: v" + latestVersion ?? "N/A";
text.transform.GetChild(0).gameObject.SetActive(latestVersion != Application.version);
}
}
private async static Task GetRandomSplashes()
{
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.RANDOM_SPLASHES_ENDPOINT);
request.SetRequestHeader("Requester", "BerryDashClient");
request.SetRequestHeader("ClientVersion", Application.version);
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
await request.SendWebRequest();
randomSplashes = request.downloadHandler.text.Split("\n") ?? null;
if (
SceneManager.GetActiveScene().name == "MainMenu" &&
randomSplashes != null &&
GameObject.Find("Canvas/SplashText").TryGetComponent<TextMeshProUGUI>(out var text)
)
{
text.text = randomSplashes[Random.Range(0, randomSplashes.Length)];
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b7c4b6fcc4a8a4129a4d105a62f13a29