sounds and screens with improved matchmaker
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@@ -9,7 +13,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class LoginManager : MonoBehaviour
|
||||
{
|
||||
const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
|
||||
public const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
|
||||
const string PlayerPrefsAuthKey = "WalkInvest.AuthToken";
|
||||
|
||||
const int MIN_USERNAME_LENGTH = 3;
|
||||
@@ -33,6 +37,33 @@ public class LoginManager : MonoBehaviour
|
||||
|
||||
public static string AuthToken { get; private set; }
|
||||
|
||||
/// <summary>Assigned side from the matchmaker <c>your_team</c> field. <c>null</c> until a room is found or after clear.</summary>
|
||||
public static Team? MatchYourTeam { get; private set; }
|
||||
|
||||
/// <summary>Parses matchmaker strings such as <c>"red"</c> / <c>"blue"</c> (case-insensitive).</summary>
|
||||
public static void SetMatchYourTeam(string matchmakerYourTeam)
|
||||
{
|
||||
MatchYourTeam = ParseMatchmakerTeam(matchmakerYourTeam);
|
||||
}
|
||||
|
||||
static Team? ParseMatchmakerTeam(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return null;
|
||||
switch (s.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "red": return Team.Red;
|
||||
case "blue": return Team.Blue;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearMatchYourTeam()
|
||||
{
|
||||
MatchYourTeam = null;
|
||||
}
|
||||
|
||||
/// <summary>Latest user payload from the server. Reading this schedules a refresh (one in flight at a time).</summary>
|
||||
public static UserData CurrentUser
|
||||
{
|
||||
@@ -49,29 +80,6 @@ public class LoginManager : MonoBehaviour
|
||||
static UserData _currentUser;
|
||||
bool _userDataReadRefreshPending;
|
||||
|
||||
[Serializable]
|
||||
class AuthApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public string token;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class AuthUserApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public UserData user;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class PurchaseRcApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
}
|
||||
|
||||
public static LoginManager instance;
|
||||
|
||||
void Awake()
|
||||
@@ -92,13 +100,47 @@ public class LoginManager : MonoBehaviour
|
||||
btnLogin.onClick.AddListener(OnLogin);
|
||||
btnRegister.onClick.AddListener(OnRegister);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Dev: log in with clone-aware credentials instead of resuming a saved session.
|
||||
AuthToken = "";
|
||||
PlayerPrefs.DeleteKey(PlayerPrefsAuthKey);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
bool cloneWorkspace = EditorWorkspaceLooksLikeClone();
|
||||
string devUser = cloneWorkspace ? "warlock2" : "warlock";
|
||||
const string devPass = "12345678";
|
||||
if (usernameInputLogin != null) usernameInputLogin.text = devUser;
|
||||
if (passwordInputLogin != null) passwordInputLogin.text = devPass;
|
||||
|
||||
string loginJson = "{\"username\":\"" + EscapeJsonString(devUser) + "\",\"password\":\"" + EscapeJsonString(devPass) + "\"}";
|
||||
StartCoroutine(AuthPostCoroutine(AuthBaseUrl + "/auth/login", loginJson, "Signed in."));
|
||||
#else
|
||||
if (!string.IsNullOrEmpty(AuthToken))
|
||||
{
|
||||
SetBusy(true);
|
||||
StartCoroutine(ResumeSessionCoroutine());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static bool EditorWorkspaceLooksLikeClone()
|
||||
{
|
||||
// Project folder is parent of Assets (same as editor project path).
|
||||
string projectRoot = Path.GetDirectoryName(Application.dataPath);
|
||||
if (!string.IsNullOrEmpty(projectRoot) &&
|
||||
projectRoot.IndexOf("clone", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
string product = PlayerSettings.productName;
|
||||
if (!string.IsNullOrEmpty(product) &&
|
||||
product.IndexOf("clone", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
IEnumerator ResumeSessionCoroutine()
|
||||
{
|
||||
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
|
||||
@@ -433,39 +475,3 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UserData
|
||||
{
|
||||
public int id;
|
||||
public string username;
|
||||
public int cc;
|
||||
public int rc;
|
||||
public string created_at;
|
||||
public string last_logged_at;
|
||||
}
|
||||
|
||||
/// <summary>Typical <c>pack</c> ids for <see cref="LoginManager.PurchaseRcPack"/>; prefer <see cref="LoginManager.GetRcPacks"/> for the live list.</summary>
|
||||
public static class RcPack
|
||||
{
|
||||
public const string Usd5 = "usd_5";
|
||||
public const string Usd20 = "usd_20";
|
||||
public const string Usd50 = "usd_50";
|
||||
|
||||
public static bool IsValid(string packId)
|
||||
{
|
||||
return packId == Usd5 || packId == Usd20 || packId == Usd50;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CoinHelper{
|
||||
public static float Format(int coins){
|
||||
int whole = coins / 4;
|
||||
int fraction = coins % 4;
|
||||
return float.Parse(whole + "." + fraction);
|
||||
}
|
||||
|
||||
public static string FormatString(int coins){
|
||||
return Format(coins).ToString("N2");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user