public static void LoadAvatars() { var change = new SChange { Action = EAction.LoadAvatars }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void EditAvatar(CAvatar editAvatar) { if (editAvatar == null) { return; } var change = new SChange { Action = EAction.EditAvatar, Avatar = editAvatar }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void AddAvatar(CAvatar newAvatar) { if (newAvatar == null) { return; } var change = new SChange { Action = EAction.AddAvatar, Avatar = newAvatar }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void DeleteProfile(Guid profileID) { if (!IsProfileIDValid(profileID)) { return; } var change = new SChange { Action = EAction.DeleteProfile, ProfileID = profileID }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void EditProfile(CProfile editProfile) { if (editProfile == null) { return; } var change = new SChange { Action = EAction.EditProfile, Profile = editProfile }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void AddProfile(CProfile newProfile) { if (newProfile == null) { return; } var change = new SChange { Action = EAction.AddProfile, Profile = newProfile }; lock (_QueueMutex) { _Queue.Enqueue(change); } }
public static void Update() { lock (_QueueMutex) { while (_Queue.Count > 0) { SChange change = _Queue.Dequeue(); switch (change.Action) { case EAction.LoadProfiles: _LoadProfiles(); _ProfilesChanged = true; _AvatarsChanged = true; break; case EAction.LoadAvatars: _LoadAvatars(); _AvatarsChanged = true; break; case EAction.AddProfile: CProfile newProf = change.Profile; if (newProf == null) { break; } newProf.ID = Guid.NewGuid(); if (newProf.Avatar == null) { newProf.Avatar = _Avatars.Values.First(); } else if (newProf.Avatar.ID < 0) { newProf.Avatar.ID = _AvatarIDs.Dequeue(); _Avatars.Add(newProf.Avatar.ID, newProf.Avatar); _AvatarsChanged = true; } newProf.SaveProfile(); _Profiles.Add(newProf.ID, newProf); _ProfilesChanged = true; break; case EAction.EditProfile: if (change.Profile == null) { break; } if (!IsProfileIDValid(change.Profile.ID)) { return; } _Profiles[change.Profile.ID] = change.Profile; _ProfilesChanged = true; break; case EAction.DeleteProfile: if (!IsProfileIDValid(change.ProfileID)) { break; } _DeleteProfile(change.ProfileID); _ProfilesChanged = true; break; case EAction.AddAvatar: if (change.Avatar == null) { break; } change.Avatar.ID = _AvatarIDs.Dequeue(); _Avatars.Add(change.Avatar.ID, change.Avatar); _AvatarsChanged = true; break; case EAction.EditAvatar: if (change.Avatar == null) { break; } if (!IsAvatarIDValid(change.Avatar.ID)) { return; } _Avatars[change.Avatar.ID] = change.Avatar; _AvatarsChanged = true; break; } } } if (_ProfileChangedCallbacks.Count == 0) { return; } var flags = EProfileChangedFlags.None; if (_AvatarsChanged) { flags = EProfileChangedFlags.Avatar; } if (_ProfilesChanged) { flags |= EProfileChangedFlags.Profile; } if (flags != EProfileChangedFlags.None) { int index = 0; while (index < _ProfileChangedCallbacks.Count) { try { _ProfileChangedCallbacks[index](flags); } catch (Exception) { _ProfileChangedCallbacks.RemoveAt(index); } index++; } } _AvatarsChanged = false; _ProfilesChanged = false; }