mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge branch 'master' into present-recommended
This commit is contained in:
@ -39,9 +39,15 @@ namespace osu.Game.Online.API
|
||||
|
||||
private string password;
|
||||
|
||||
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
|
||||
public IBindable<User> LocalUser => localUser;
|
||||
public IBindableList<User> Friends => friends;
|
||||
public IBindable<UserActivity> Activity => activity;
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
private Bindable<User> localUser { get; } = new Bindable<User>(createGuestUser());
|
||||
|
||||
private BindableList<User> friends { get; } = new BindableList<User>();
|
||||
|
||||
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
||||
|
||||
@ -61,10 +67,10 @@ namespace osu.Game.Online.API
|
||||
authentication.TokenString = config.Get<string>(OsuSetting.Token);
|
||||
authentication.Token.ValueChanged += onTokenChanged;
|
||||
|
||||
LocalUser.BindValueChanged(u =>
|
||||
localUser.BindValueChanged(u =>
|
||||
{
|
||||
u.OldValue?.Activity.UnbindFrom(Activity);
|
||||
u.NewValue.Activity.BindTo(Activity);
|
||||
u.OldValue?.Activity.UnbindFrom(activity);
|
||||
u.NewValue.Activity.BindTo(activity);
|
||||
}, true);
|
||||
|
||||
var thread = new Thread(run)
|
||||
@ -134,23 +140,37 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
|
||||
var userReq = new GetUserRequest();
|
||||
|
||||
userReq.Success += u =>
|
||||
{
|
||||
LocalUser.Value = u;
|
||||
localUser.Value = u;
|
||||
|
||||
// todo: save/pull from settings
|
||||
LocalUser.Value.Status.Value = new UserStatusOnline();
|
||||
localUser.Value.Status.Value = new UserStatusOnline();
|
||||
|
||||
failureCount = 0;
|
||||
};
|
||||
|
||||
if (!handleRequest(userReq))
|
||||
{
|
||||
failConnectionProcess();
|
||||
continue;
|
||||
}
|
||||
|
||||
// getting user's friends is considered part of the connection process.
|
||||
var friendsReq = new GetFriendsRequest();
|
||||
|
||||
friendsReq.Success += res =>
|
||||
{
|
||||
friends.AddRange(res);
|
||||
|
||||
//we're connected!
|
||||
state.Value = APIState.Online;
|
||||
};
|
||||
|
||||
if (!handleRequest(userReq))
|
||||
if (!handleRequest(friendsReq))
|
||||
{
|
||||
if (State.Value == APIState.Connecting)
|
||||
state.Value = APIState.Failing;
|
||||
failConnectionProcess();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -186,6 +206,13 @@ namespace osu.Game.Online.API
|
||||
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
|
||||
void failConnectionProcess()
|
||||
{
|
||||
// if something went wrong during the connection process, we want to reset the state (but only if still connecting).
|
||||
if (State.Value == APIState.Connecting)
|
||||
state.Value = APIState.Failing;
|
||||
}
|
||||
}
|
||||
|
||||
public void Perform(APIRequest request)
|
||||
@ -322,7 +349,7 @@ namespace osu.Game.Online.API
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsLoggedIn => LocalUser.Value.Id > 1;
|
||||
public bool IsLoggedIn => localUser.Value.Id > 1;
|
||||
|
||||
public void Queue(APIRequest request)
|
||||
{
|
||||
@ -352,8 +379,12 @@ namespace osu.Game.Online.API
|
||||
password = null;
|
||||
authentication.Clear();
|
||||
|
||||
// Scheduled prior to state change such that the state changed event is invoked with the correct user present
|
||||
Schedule(() => LocalUser.Value = createGuestUser());
|
||||
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
|
||||
Schedule(() =>
|
||||
{
|
||||
localUser.Value = createGuestUser();
|
||||
friends.Clear();
|
||||
});
|
||||
|
||||
state.Value = APIState.Offline;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ namespace osu.Game.Online.API
|
||||
Id = 1001,
|
||||
});
|
||||
|
||||
public BindableList<User> Friends { get; } = new BindableList<User>();
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
public string AccessToken => "token";
|
||||
@ -86,5 +88,9 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
|
||||
public void SetState(APIState newState) => state.Value = newState;
|
||||
|
||||
IBindable<User> IAPIProvider.LocalUser => LocalUser;
|
||||
IBindableList<User> IAPIProvider.Friends => Friends;
|
||||
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,19 @@ namespace osu.Game.Online.API
|
||||
/// The local user.
|
||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||
/// </summary>
|
||||
Bindable<User> LocalUser { get; }
|
||||
IBindable<User> LocalUser { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user's friends.
|
||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||
/// </summary>
|
||||
IBindableList<User> Friends { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current user's activity.
|
||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||
/// </summary>
|
||||
Bindable<UserActivity> Activity { get; }
|
||||
IBindable<UserActivity> Activity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the OAuth access token.
|
||||
|
@ -7,16 +7,16 @@ namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetBeatmapSetRequest : APIRequest<APIBeatmapSet>
|
||||
{
|
||||
private readonly int id;
|
||||
private readonly BeatmapSetLookupType type;
|
||||
public readonly int ID;
|
||||
public readonly BeatmapSetLookupType Type;
|
||||
|
||||
public GetBeatmapSetRequest(int id, BeatmapSetLookupType type = BeatmapSetLookupType.SetId)
|
||||
{
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
ID = id;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
protected override string Target => type == BeatmapSetLookupType.SetId ? $@"beatmapsets/{id}" : $@"beatmapsets/lookup?beatmap_id={id}";
|
||||
protected override string Target => Type == BeatmapSetLookupType.SetId ? $@"beatmapsets/{ID}" : $@"beatmapsets/lookup?beatmap_id={ID}";
|
||||
}
|
||||
|
||||
public enum BeatmapSetLookupType
|
||||
|
@ -80,7 +80,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
|
||||
public BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets)
|
||||
{
|
||||
return new BeatmapSetInfo
|
||||
var beatmapSet = new BeatmapSetInfo
|
||||
{
|
||||
OnlineBeatmapSetID = OnlineBeatmapSetID,
|
||||
Metadata = this,
|
||||
@ -104,8 +104,17 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
Genre = genre,
|
||||
Language = language
|
||||
},
|
||||
Beatmaps = beatmaps?.Select(b => b.ToBeatmap(rulesets)).ToList(),
|
||||
};
|
||||
|
||||
beatmapSet.Beatmaps = beatmaps?.Select(b =>
|
||||
{
|
||||
var beatmap = b.ToBeatmap(rulesets);
|
||||
beatmap.BeatmapSet = beatmapSet;
|
||||
beatmap.Metadata = beatmapSet.Metadata;
|
||||
return beatmap;
|
||||
}).ToList();
|
||||
|
||||
return beatmapSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user