BGC Tools
Static Public Member Functions | Data Fields | Static Public Attributes | Properties | Private Attributes | Static Private Attributes
BGC.Users.PlayerData Class Reference
Collaboration diagram for BGC.Users.PlayerData:
Collaboration graph
[legend]

Static Public Member Functions

static void Save ()
 Serialize the current user's data More...
 
static bool HasKey (string key)
 
static void RemoveKey (string key)
 
static void SetInt (string key, int value)
 
static void SetBool (string key, bool value)
 
static void SetString (string key, string value)
 
static void SetFloat (string key, float value)
 
static void SetDouble (string key, double value)
 
static void SetJsonValue (string key, JsonValue value)
 
static void SetJsonArray (string key, JsonArray value)
 
static int GetInt (string key, int defaultReturn=0)
 
static bool GetBool (string key, bool defaultReturn=false)
 
static string GetString (string key, string defaultReturn="")
 
static float GetFloat (string key, float defaultReturn=0f)
 
static double GetDouble (string key, double defaultReturn=0.0)
 
static JsonValue GetJsonValue (string key, JsonValue defaultReturn=default(JsonValue))
 
static JsonArray GetJsonArray (string key, JsonArray defaultReturn=default(JsonArray))
 
static void DeserializeUsers ()
 Load all usernames More...
 
static IEnumerable< string > GetUserNames ()
 Returns an enumeration of all loaded usernames More...
 
static bool UserExists (string userName)
 Does the requested user already exist? More...
 
static bool LogIn (string userName, Action userChangingCallback=null)
 Attempts to log in with userName More...
 
static void LogOut ()
 Save and clear the current user More...
 
static bool AddUser (string userName)
 Add a new user. More...
 
static void DeleteUserData (string userName)
 Deserialize, delete, and remove a user More...
 
static IEnumerable< MigrationDataGetMigrationData (string pushLogsKey, string organizationKey, string studyKey)
 Get the migration preferences of all profiles. More...
 

Data Fields

const string UserDataDir = "SaveData"
 

Static Public Attributes

static DefaultData DefaultData => _defaultData ?? (_defaultData = new DefaultData())
 The default profile data. More...
 
static ProfileData ProfileData => _currentUserData as ProfileData ?? DefaultData
 Profile Data of the current user. Or default if none are logged in. More...
 
static string UserName => ProfileData.UserName
 The Current Profile UserName More...
 
static bool IsDefault => ProfileData.IsDefault
 The Current Profile IsDefault Status More...
 

Properties

static bool IsLocked [get, set]
 Is the device currently in a Locked mode? More...
 
static bool EverUnlocked [get, set]
 Has the device ever been unlocked? More...
 

Private Attributes

const string LockStateKey = "LockState"
 
const string EverUnlockedKey = "EverUnlocked"
 

Static Private Attributes

static DefaultData _defaultData = null
 
static UserData _currentUserData = null
 
static bool initialized = false
 
static string previousUser = ""
 
static readonly List< string > users = new List<string>()
 

Detailed Description

Definition at line 11 of file PlayerData.cs.

Member Function Documentation

◆ AddUser()

static bool BGC.Users.PlayerData.AddUser ( string  userName)
inlinestatic

Add a new user.

Returns
Returns if the operation was successful

Definition at line 167 of file PlayerData.cs.

References BGC.Users.ProfileData.Serialize().

168  {
169  if (!initialized)
170  {
171  //If deleteUser is attempted without first loading data
172  Debug.LogError($"Tried to AddUser before initializing PlayerData. userName: {userName}");
173  return false;
174  }
175 
176  if (users.Contains(userName))
177  {
178  return false;
179  }
180 
181  UserData newUser = new UserData(userName);
182  users.Add(userName);
183  newUser.Serialize();
184 
185  return true;
186  }
static readonly List< string > users
Definition: PlayerData.cs:28
static bool initialized
Definition: PlayerData.cs:24
Here is the call graph for this function:

◆ DeleteUserData()

static void BGC.Users.PlayerData.DeleteUserData ( string  userName)
inlinestatic

Deserialize, delete, and remove a user

Definition at line 189 of file PlayerData.cs.

References BGC.Users.ProfileData.DeletePlayerData(), and BGC.Users.ProfileData.Deserialize().

190  {
191  UserData tempUserData = new UserData(userName);
192  if (tempUserData.Deserialize())
193  {
194  tempUserData.DeletePlayerData();
195  }
196 
197  users.Remove(userName);
198  }
static readonly List< string > users
Definition: PlayerData.cs:28
Here is the call graph for this function:

◆ DeserializeUsers()

static void BGC.Users.PlayerData.DeserializeUsers ( )
inlinestatic

Load all usernames

Definition at line 98 of file PlayerData.cs.

References BGC.IO.DataManagement.GetDataFiles(), and BGC.IO.FileExtensions.JSON.

99  {
100  //Load up saved information
101  users.Clear();
102 
103  foreach (string fileName in DataManagement.GetDataFiles(UserDataDir))
104  {
105  if (Path.GetExtension(fileName) == FileExtensions.JSON)
106  {
107  string newUserName = Path.GetFileNameWithoutExtension(fileName);
108 
109  if (newUserName != "Default")
110  {
111  users.Add(newUserName);
112  }
113  }
114  }
115 
116  initialized = true;
117  }
const string UserDataDir
Definition: PlayerData.cs:13
static IEnumerable< string > GetDataFiles(string dataDirectory)
Get a list of all data files in sub directory of os data directory
static readonly List< string > users
Definition: PlayerData.cs:28
static bool initialized
Definition: PlayerData.cs:24
Here is the call graph for this function:

◆ GetBool()

static bool BGC.Users.PlayerData.GetBool ( string  key,
bool  defaultReturn = false 
)
static

◆ GetDouble()

static double BGC.Users.PlayerData.GetDouble ( string  key,
double  defaultReturn = 0.0 
)
static

◆ GetFloat()

static float BGC.Users.PlayerData.GetFloat ( string  key,
float  defaultReturn = 0f 
)
static

◆ GetInt()

static int BGC.Users.PlayerData.GetInt ( string  key,
int  defaultReturn = 0 
)
static

◆ GetJsonArray()

static JsonArray BGC.Users.PlayerData.GetJsonArray ( string  key,
JsonArray  defaultReturn = default(JsonArray) 
)
static

◆ GetJsonValue()

static JsonValue BGC.Users.PlayerData.GetJsonValue ( string  key,
JsonValue  defaultReturn = default(JsonValue) 
)
static

◆ GetMigrationData()

static IEnumerable<MigrationData> BGC.Users.PlayerData.GetMigrationData ( string  pushLogsKey,
string  organizationKey,
string  studyKey 
)
inlinestatic

Get the migration preferences of all profiles.

Definition at line 201 of file PlayerData.cs.

References BGC.Users.ProfileData.Deserialize(), BGC.Users.ProfileData.GetBool(), BGC.Users.ProfileData.GetString(), and BGC.Users.ProfileData.UserName.

205  {
206  List<MigrationData> migrationData = new List<MigrationData>();
207 
208  if (initialized == false)
209  {
211  }
212 
213  foreach (string userName in users)
214  {
215  UserData data = new UserData(userName);
216  //Load in the data first
217 
218  if (data.Deserialize() && data.GetBool(pushLogsKey, false))
219  {
220  migrationData.Add(new MigrationData
221  {
222  userName = data.UserName,
223  organization = data.GetString(organizationKey, "braingamecenter"),
224  study = data.GetString(studyKey, "default")
225  });
226  }
227  }
228 
229  return migrationData;
230  }
static void DeserializeUsers()
Load all usernames
Definition: PlayerData.cs:98
static readonly List< string > users
Definition: PlayerData.cs:28
static bool initialized
Definition: PlayerData.cs:24
Here is the call graph for this function:

◆ GetString()

static string BGC.Users.PlayerData.GetString ( string  key,
string  defaultReturn = "" 
)
static

◆ GetUserNames()

static IEnumerable<string> BGC.Users.PlayerData.GetUserNames ( )
static

Returns an enumeration of all loaded usernames

◆ HasKey()

static bool BGC.Users.PlayerData.HasKey ( string  key)
static

◆ LogIn()

static bool BGC.Users.PlayerData.LogIn ( string  userName,
Action  userChangingCallback = null 
)
inlinestatic

Attempts to log in with userName

Parameters
userNameName of user to log into
userChangingCallbackOptional callback invoked when the user will change. Typically clearing logs, for example.
Returns
Whether the user was successfully logged in

Definition at line 132 of file PlayerData.cs.

References BGC.Users.ProfileData.Deserialize().

135  {
136  //If we're logging into a new user...
137  if (previousUser != userName)
138  {
139  userChangingCallback?.Invoke();
140  previousUser = userName;
141  }
142 
143  _currentUserData = new UserData(userName);
144 
145  if (_currentUserData.Deserialize() == false)
146  {
147  //Failed to load user
148  _currentUserData = null;
149  previousUser = "";
150 
151  Debug.LogError($"Failed to load selected user data: {userName}");
152  return false;
153  }
154 
155  return true;
156  }
static UserData _currentUserData
Definition: PlayerData.cs:19
static string previousUser
Definition: PlayerData.cs:26
bool Deserialize()
Load user contents from file
Definition: ProfileData.cs:298
Here is the call graph for this function:

◆ LogOut()

static void BGC.Users.PlayerData.LogOut ( )
inlinestatic

Save and clear the current user

Definition at line 159 of file PlayerData.cs.

160  {
161  Save();
162  _currentUserData = null;
163  }
static void Save()
Serialize the current user&#39;s data
static UserData _currentUserData
Definition: PlayerData.cs:19

◆ RemoveKey()

static void BGC.Users.PlayerData.RemoveKey ( string  key)
static

◆ Save()

static void BGC.Users.PlayerData.Save ( )
static

Serialize the current user's data

Referenced by BGC.Study.ProtocolManager.ExecuteNextElement().

Here is the caller graph for this function:

◆ SetBool()

static void BGC.Users.PlayerData.SetBool ( string  key,
bool  value 
)
static

◆ SetDouble()

static void BGC.Users.PlayerData.SetDouble ( string  key,
double  value 
)
static

◆ SetFloat()

static void BGC.Users.PlayerData.SetFloat ( string  key,
float  value 
)
static

◆ SetInt()

static void BGC.Users.PlayerData.SetInt ( string  key,
int  value 
)
static

◆ SetJsonArray()

static void BGC.Users.PlayerData.SetJsonArray ( string  key,
JsonArray  value 
)
static

◆ SetJsonValue()

static void BGC.Users.PlayerData.SetJsonValue ( string  key,
JsonValue  value 
)
static

◆ SetString()

static void BGC.Users.PlayerData.SetString ( string  key,
string  value 
)
static

◆ UserExists()

static bool BGC.Users.PlayerData.UserExists ( string  userName)
static

Does the requested user already exist?

Field Documentation

◆ _currentUserData

UserData BGC.Users.PlayerData._currentUserData = null
staticprivate

Definition at line 19 of file PlayerData.cs.

◆ _defaultData

DefaultData BGC.Users.PlayerData._defaultData = null
staticprivate

Definition at line 15 of file PlayerData.cs.

◆ DefaultData

DefaultData BGC.Users.PlayerData.DefaultData => _defaultData ?? (_defaultData = new DefaultData())
static

The default profile data.

Definition at line 17 of file PlayerData.cs.

◆ EverUnlockedKey

const string BGC.Users.PlayerData.EverUnlockedKey = "EverUnlocked"
private

Definition at line 32 of file PlayerData.cs.

◆ initialized

bool BGC.Users.PlayerData.initialized = false
staticprivate

Definition at line 24 of file PlayerData.cs.

◆ IsDefault

bool BGC.Users.PlayerData.IsDefault => ProfileData.IsDefault
static

The Current Profile IsDefault Status

Definition at line 71 of file PlayerData.cs.

◆ LockStateKey

const string BGC.Users.PlayerData.LockStateKey = "LockState"
private

Definition at line 31 of file PlayerData.cs.

◆ previousUser

string BGC.Users.PlayerData.previousUser = ""
staticprivate

Definition at line 26 of file PlayerData.cs.

◆ ProfileData

ProfileData BGC.Users.PlayerData.ProfileData => _currentUserData as ProfileData ?? DefaultData
static

Profile Data of the current user. Or default if none are logged in.

Definition at line 21 of file PlayerData.cs.

◆ UserDataDir

const string BGC.Users.PlayerData.UserDataDir = "SaveData"

Definition at line 13 of file PlayerData.cs.

◆ UserName

string BGC.Users.PlayerData.UserName => ProfileData.UserName
static

The Current Profile UserName

Definition at line 69 of file PlayerData.cs.

◆ users

readonly List<string> BGC.Users.PlayerData.users = new List<string>()
staticprivate

Definition at line 28 of file PlayerData.cs.

Property Documentation

◆ EverUnlocked

bool BGC.Users.PlayerData.EverUnlocked
staticgetset

Has the device ever been unlocked?

Definition at line 54 of file PlayerData.cs.

◆ IsLocked

bool BGC.Users.PlayerData.IsLocked
staticgetset

Is the device currently in a Locked mode?

Definition at line 36 of file PlayerData.cs.


The documentation for this class was generated from the following file: