Resolve WES-56 "Account switching"
This commit is contained in:
committed by
Jelle De Geest
parent
0ea743354b
commit
b6b863183e
@@ -15,6 +15,11 @@ public class UserCreationScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
private const int MAX_USERNAME_LENGTH = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the error message to display when a certain usernmae is invalid or already exists
|
||||
/// </summary>
|
||||
public GameObject errorMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the input text field for username
|
||||
/// </summary>
|
||||
@@ -57,6 +62,8 @@ public class UserCreationScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
errorMessage.SetActive(false);
|
||||
|
||||
for (int i = 0; i < sprites.Count; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
@@ -100,7 +107,7 @@ public class UserCreationScreen : MonoBehaviour
|
||||
/// <returns><c>true</c> if the username was valid, <c>false</c> otherwise</returns>
|
||||
static public bool IsValidUsername(string username)
|
||||
{
|
||||
return new Regex($@"^[abcdefghijklmnopqrstuvwxyz]{{1,{MAX_USERNAME_LENGTH}}}$").IsMatch(username);
|
||||
return new Regex($@"^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]{{1,{MAX_USERNAME_LENGTH}}}$").IsMatch(username);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,16 +122,22 @@ public class UserCreationScreen : MonoBehaviour
|
||||
if (users.GetUserByUsername(username) == null)
|
||||
{
|
||||
// Create a new entry in the UserList ScriptableObject
|
||||
users.CreateAndAddNewUser(username, sprites[selectedAvatar]);
|
||||
users.ChangeCurrentUser(users.CreateAndAddNewUser(username, sprites[selectedAvatar]));
|
||||
// TODO: change scene, for now just change to StartScreen
|
||||
SceneManager.LoadScene("Common/Scenes/StartScreen");
|
||||
}
|
||||
// TODO: give more feedback to user
|
||||
// Warn user that username already exists
|
||||
else Debug.LogWarning($"Username '{username}' already exists!");
|
||||
else
|
||||
{
|
||||
errorMessage.SetActive(true);
|
||||
errorMessage.GetComponent<TMP_Text>().text = "Deze gebruikersnaam bestaat al! Kies een andere.";
|
||||
}
|
||||
}
|
||||
// TODO: give more feedback to user
|
||||
// Warn user that username is invalid
|
||||
else Debug.LogWarning($"Invalid username '{username}'!");
|
||||
else
|
||||
{
|
||||
errorMessage.SetActive(true);
|
||||
errorMessage.GetComponent<TMP_Text>().text = "Je gebruikersnaam moet bestaan uit minimum 1 en maximum 12 letters (a-z en A-Z) of cijfers (0-9).";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user