mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Remove IOnlineComponent and change existing components to use bindable flow
This commit is contained in:
@ -21,34 +21,23 @@ namespace osu.Game.Online.API
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
public bool IsLoggedIn => State == APIState.Online;
|
||||
public bool IsLoggedIn => State.Value == APIState.Online;
|
||||
|
||||
public string ProvidedUsername => LocalUser.Value.Username;
|
||||
|
||||
public string Endpoint => "http://localhost";
|
||||
|
||||
private APIState state = APIState.Online;
|
||||
|
||||
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
|
||||
|
||||
/// <summary>
|
||||
/// Provide handling logic for an arbitrary API request.
|
||||
/// </summary>
|
||||
public Action<APIRequest> HandleRequest;
|
||||
|
||||
public APIState State
|
||||
{
|
||||
get => state;
|
||||
set
|
||||
{
|
||||
if (state == value)
|
||||
return;
|
||||
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
|
||||
|
||||
state = value;
|
||||
|
||||
Scheduler.Add(() => components.ForEach(c => c.APIStateChanged(this, value)));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The current connectivity state of the API.
|
||||
/// </summary>
|
||||
public IBindable<APIState> State => state;
|
||||
|
||||
public DummyAPIAccess()
|
||||
{
|
||||
@ -72,17 +61,6 @@ namespace osu.Game.Online.API
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Register(IOnlineComponent component)
|
||||
{
|
||||
Scheduler.Add(delegate { components.Add(component); });
|
||||
component.APIStateChanged(this, state);
|
||||
}
|
||||
|
||||
public void Unregister(IOnlineComponent component)
|
||||
{
|
||||
Scheduler.Add(delegate { components.Remove(component); });
|
||||
}
|
||||
|
||||
public void Login(string username, string password)
|
||||
{
|
||||
LocalUser.Value = new User
|
||||
@ -91,13 +69,13 @@ namespace osu.Game.Online.API
|
||||
Id = 1001,
|
||||
};
|
||||
|
||||
State = APIState.Online;
|
||||
state.Value = APIState.Online;
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
LocalUser.Value = new GuestUser();
|
||||
State = APIState.Offline;
|
||||
state.Value = APIState.Offline;
|
||||
}
|
||||
|
||||
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
|
||||
@ -105,5 +83,7 @@ namespace osu.Game.Online.API
|
||||
Thread.Sleep(200);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetState(APIState newState) => state.Value = newState;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user