public void UpdateUser(UserData data) { UserData user; if (UserDataList.ContainsKey(data.Id)) { user = UserDataList[data.Id]; } else { user = new UserData(data.Id); user.Name = data.Name; user.ThumbnailURL = data.ThumbnailURL; OnInitializeUser?.Invoke(user); UserDataList.Add(data.Id, user); } if (user.Location == data.Location) { // インスタンス移動なし // サムネイル変更 if (user.ThumbnailURL != data.ThumbnailURL) { user.ThumbnailURL = data.ThumbnailURL; OnUpdateUser?.Invoke(user); } } else { if (!String.IsNullOrWhiteSpace(user.Location) && LocationDataList.ContainsKey(user.Location)) { var oldLocation = LocationDataList[user.Location]; oldLocation.Users.Remove(user); if (oldLocation.Users.Count == 0) { LocationDataList.Remove(oldLocation.Id); OnLostLocation?.Invoke(oldLocation); } OnRemoveUser?.Invoke(oldLocation, user); } user.Location = data.Location; LocationData newLocation; if (LocationDataList.ContainsKey(data.Location)) { newLocation = LocationDataList[data.Location]; } else { newLocation = new LocationData(data.Location); LocationDataList.Add(data.Location, newLocation); OnInitializeLocation?.Invoke(newLocation); } newLocation.Users.Add(user); OnAddUser?.Invoke(newLocation, user); } }
public Watchdog() { api = APIAdapter.Instance.Login(); data = new DataStore(); log = LogSaver.Instance; data.OnInitializeLocation += (location) => { if (location.WorldID == "offline" || location.WorldID == "private") { location.Name = location.WorldID; } else { api.GetWorldData(location.Id, (l) => { location.SetStructData(l); if (String.IsNullOrWhiteSpace(l.OwnerId)) { OnUpdateLocation?.Invoke(location); } else { api.GetUserData(location.OwnerId, (u) => { location.OwnerId = l.OwnerId; location.OwnerName = u.Name; OnUpdateLocation?.Invoke(location); }); } }); } }; data.OnAddUser += (a, b) => { OnAddUser?.Invoke(a, b); log.LogUser(b); }; data.OnRemoveUser += (a, b) => OnRemoveUser?.Invoke(a, b); data.OnUpdateUser = OnUpdateUser; //ログアウト検知 data.OnLostUser += (a) => { api.GetUserData(a.Id, (b) => { data.UpdateUser(b); }); }; }
void OnRemoveUserPressed(string userId) { OnRemoveUser?.Invoke(userId); }