Resolve WES-117 "Persistent data handling"

This commit is contained in:
Dries Van Schuylenbergh
2023-04-04 17:00:47 +00:00
parent 3499e61bb0
commit 5f4408063f
82 changed files with 1963 additions and 1190 deletions

View File

@@ -34,20 +34,9 @@ public class UserCreationScreen : MonoBehaviour
/// </summary>
public GameObject avatarPrefab;
/// <summary>
/// List of all sprites that are supported as avatars
/// </summary>
public List<Sprite> sprites = new List<Sprite>();
/// <summary>
/// Reference to the UserList ScriptableObject
/// </summary>
public UserList users;
/// <summary>
/// Current selected avatar
/// </summary>
[SerializeField]
private int selectedAvatar = 0;
/// <summary>
@@ -63,7 +52,7 @@ public class UserCreationScreen : MonoBehaviour
{
errorMessage.SetActive(false);
for (int i = 0; i < sprites.Count; i++)
for (int i = 0; i < UserList.AVATARS.Count; i++)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(avatarPrefab, avatarsContainer);
@@ -79,7 +68,7 @@ public class UserCreationScreen : MonoBehaviour
// Set background color
background.color = selectedAvatar == i ? Color.blue : Color.gray;
// Find correct component for setting the sprite
instance.transform.Find("Image").GetComponent<Image>().sprite = sprites[i];
instance.transform.Find("Image").GetComponent<Image>().sprite = UserList.AVATARS[i];
}
}
@@ -113,10 +102,10 @@ public class UserCreationScreen : MonoBehaviour
string username = inputName.text;
if (IsValidUsername(username))
{
if (users.GetUserByUsername(username) == null)
if (UserList.GetUserByUsername(username) == null)
{
// Create a new entry in the UserList ScriptableObject
users.ChangeCurrentUser(users.CreateAndAddNewUser(username, sprites[selectedAvatar]));
UserList.AddUser(username, UserList.AVATARS[selectedAvatar]);
SystemController.GetInstance().BackToPreviousScene();
}
// Warn user that username already exists