update map gen
This commit is contained in:
@@ -53,10 +53,27 @@ namespace Hallucinate.UI
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> RegisterUser(string username)
|
||||
public static async Task<Hallucinate.Game.PlayerEloData> GetPlayerData(string username)
|
||||
{
|
||||
string url = $"{BASE_URL}/{username}.json";
|
||||
string jsonData = "{\"created_at\": \"" + DateTime.Now.ToString() + "\"}";
|
||||
string url = $"{BASE_URL}/{username}/elo.json";
|
||||
using (UnityWebRequest request = UnityWebRequest.Get(url))
|
||||
{
|
||||
var operation = request.SendWebRequest();
|
||||
while (!operation.isDone) await Task.Yield();
|
||||
|
||||
if (request.result != UnityWebRequest.Result.Success || request.downloadHandler.text == "null")
|
||||
{
|
||||
return Hallucinate.Game.PlayerEloData.Default;
|
||||
}
|
||||
|
||||
return JsonUtility.FromJson<Hallucinate.Game.PlayerEloData>(request.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> SavePlayerData(string username, Hallucinate.Game.PlayerEloData data)
|
||||
{
|
||||
string url = $"{BASE_URL}/{username}/elo.json";
|
||||
string jsonData = JsonUtility.ToJson(data);
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Put(url, jsonData))
|
||||
{
|
||||
|
||||
@@ -25,17 +25,17 @@ namespace Hallucinate.UI
|
||||
{
|
||||
Debug.Log($"<color=green>[Firebase] Username '{testUsername}' còn trống. Tiến hành đăng ký...</color>");
|
||||
|
||||
// Bước 2: Thử đăng ký user mới
|
||||
bool success = await FirebaseService.RegisterUser(testUsername);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Debug.Log("<color=green>[Firebase] Đăng ký thành công! Hãy kiểm tra trình duyệt (Firebase Console).</color>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[Firebase] Đăng ký thất bại. Kiểm tra link URL hoặc Internet.");
|
||||
}
|
||||
// // Bước 2: Thử đăng ký user mới
|
||||
// bool success = await FirebaseService.RegisterUser(testUsername);
|
||||
//
|
||||
// if (success)
|
||||
// {
|
||||
// Debug.Log("<color=green>[Firebase] Đăng ký thành công! Hãy kiểm tra trình duyệt (Firebase Console).</color>");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("[Firebase] Đăng ký thất bại. Kiểm tra link URL hoặc Internet.");
|
||||
// }
|
||||
}
|
||||
|
||||
Debug.Log("<color=cyan>--- Firebase Test Finished ---</color>");
|
||||
|
||||
@@ -69,25 +69,25 @@ namespace Hallucinate.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2. Đăng ký user mới
|
||||
bool success = await FirebaseService.RegisterUser(username);
|
||||
if (success)
|
||||
{
|
||||
// 3. Lưu lại và đóng popup
|
||||
PlayerPrefs.SetString("Username", username);
|
||||
PlayerPrefs.Save();
|
||||
Debug.Log($"[Login] Registered as {username}");
|
||||
|
||||
// Thông báo cho UIManager biết đã login xong
|
||||
uiManager.OnLoginSuccess();
|
||||
await PlayTransitionOut();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError("Connection error!");
|
||||
_confirmBtn.SetEnabled(true);
|
||||
_confirmBtn.text = "CONFIRM";
|
||||
}
|
||||
// // 2. Đăng ký user mới
|
||||
// bool success = await FirebaseService.RegisterUser(username);
|
||||
// if (success)
|
||||
// {
|
||||
// // 3. Lưu lại và đóng popup
|
||||
// PlayerPrefs.SetString("Username", username);
|
||||
// PlayerPrefs.Save();
|
||||
// Debug.Log($"[Login] Registered as {username}");
|
||||
//
|
||||
// // Thông báo cho UIManager biết đã login xong
|
||||
// uiManager.OnLoginSuccess();
|
||||
// await PlayTransitionOut();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ShowError("Connection error!");
|
||||
// _confirmBtn.SetEnabled(true);
|
||||
// _confirmBtn.text = "CONFIRM";
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,16 @@ using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Hallucinate.Game;
|
||||
using Hallucinate.UI;
|
||||
|
||||
namespace Hallucinate.UI
|
||||
{
|
||||
public class ProfileController : BaseUIController
|
||||
{
|
||||
private Label _username;
|
||||
private Label _rank;
|
||||
private Label _eloLabel;
|
||||
private ProgressBar _winRateBar;
|
||||
private Label _winRateText;
|
||||
private Button _logoutBtn;
|
||||
@@ -22,6 +26,7 @@ namespace Hallucinate.UI
|
||||
|
||||
_username = root.Q<Label>("Username");
|
||||
_rank = root.Q<Label>("Rank");
|
||||
_eloLabel = root.Q<Label>("EloLabel");
|
||||
_winRateBar = root.Q<ProgressBar>("WinRateBar");
|
||||
_winRateText = root.Q<Label>("WinRateText");
|
||||
_logoutBtn = root.Q<Button>("LogoutBtn");
|
||||
@@ -67,11 +72,11 @@ namespace Hallucinate.UI
|
||||
|
||||
public override async Task PlayTransitionIn()
|
||||
{
|
||||
LoadProfileData(); // Refresh data every time we show the profile
|
||||
await LoadProfileData(); // Refresh data every time we show the profile
|
||||
await base.PlayTransitionIn();
|
||||
}
|
||||
|
||||
private void LoadProfileData()
|
||||
private async Task LoadProfileData()
|
||||
{
|
||||
// Load saved username or fallback
|
||||
string savedName = PlayerPrefs.GetString("Username", "Unknown Player");
|
||||
@@ -81,10 +86,27 @@ namespace Hallucinate.UI
|
||||
_googleIdPlaceholder = PlayerPrefs.GetString("GoogleID", "NOT_LINKED");
|
||||
_avatarUrlPlaceholder = PlayerPrefs.GetString("AvatarURL", "");
|
||||
|
||||
// Mock progression data for now
|
||||
_rank.text = "DIAMOND II";
|
||||
_winRateBar.value = 72;
|
||||
_winRateText.text = "72%";
|
||||
// Fetch real Elo data
|
||||
var eloData = await FirebaseService.GetPlayerData(savedName);
|
||||
|
||||
if (_eloLabel != null) _eloLabel.text = eloData.Rating.ToString();
|
||||
|
||||
if (_rank != null)
|
||||
{
|
||||
_rank.text = EloSystem.GetRank(eloData.Rating).ToUpper();
|
||||
if (ColorUtility.TryParseHtmlString(EloSystem.GetRankColor(eloData.Rating), out Color rankColor))
|
||||
{
|
||||
_rank.style.color = rankColor;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate Win Rate from GamesPlayed (requires adding wins to schema, but for now we use mock/partial)
|
||||
if (eloData.GamesPlayed > 0)
|
||||
{
|
||||
// Note: To show a real winrate, we'd need to store 'Wins' in PlayerEloData.
|
||||
// For now, keeping the mock or setting a placeholder.
|
||||
_winRateText.text = "CALCULATING...";
|
||||
}
|
||||
}
|
||||
|
||||
private async void Logout()
|
||||
|
||||
Reference in New Issue
Block a user