1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:33:01 +08:00

Add the concept of IOnlineComponents, registered tot he API for handling state changes.

This commit is contained in:
Dean Herbert 2016-11-30 15:15:07 +09:00
parent 6809e2ce0a
commit 34e91c8474
4 changed files with 56 additions and 25 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Desktop.VisualTests.Tests
{
base.Reset();
if (api.State != APIAccess.APIState.Online)
if (api.State != APIState.Online)
api.OnStateChange += delegate { initializeChannels(); };
else
initializeChannels();
@ -65,7 +65,7 @@ namespace osu.Desktop.VisualTests.Tests
{
careChannels = new List<Channel>();
if (api.State != APIAccess.APIState.Online)
if (api.State != APIState.Online)
return;
Add(flow = new FlowContainer

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using osu.Framework;
@ -65,6 +66,18 @@ namespace osu.Game.Online.API
thread.Start();
}
private List<IOnlineComponent> components = new List<IOnlineComponent>();
public void Register(IOnlineComponent component)
{
components.Add(component);
}
public void Unregister(IOnlineComponent component)
{
components.Remove(component);
}
public string AccessToken => authentication.RequestAccessToken();
/// <summary>
@ -221,6 +234,7 @@ namespace osu.Game.Online.API
log.Add($@"We just went {newState}!");
Scheduler.Add(delegate
{
components.ForEach(c => c.APIStateChanged(this, newState));
OnStateChange?.Invoke(oldState, newState);
});
}
@ -237,29 +251,6 @@ namespace osu.Game.Online.API
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
public enum APIState
{
/// <summary>
/// We cannot login (not enough credentials).
/// </summary>
Offline,
/// <summary>
/// We are having connectivity issues.
/// </summary>
Failing,
/// <summary>
/// We are in the process of (re-)connecting.
/// </summary>
Connecting,
/// <summary>
/// We are online.
/// </summary>
Online
}
private void flushQueue(bool failOldRequests = true)
{
var oldQueue = queue;
@ -286,4 +277,27 @@ namespace osu.Game.Online.API
Scheduler.Update();
}
}
public enum APIState
{
/// <summary>
/// We cannot login (not enough credentials).
/// </summary>
Offline,
/// <summary>
/// We are having connectivity issues.
/// </summary>
Failing,
/// <summary>
/// We are in the process of (re-)connecting.
/// </summary>
Connecting,
/// <summary>
/// We are online.
/// </summary>
Online
}
}

View File

@ -0,0 +1,16 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Online.API
{
public interface IOnlineComponent
{
void APIStateChanged(APIAccess api, APIState state);
}
}

View File

@ -69,6 +69,7 @@
<Compile Include="Modes\Objects\HitObjectParser.cs" />
<Compile Include="Modes\Score.cs" />
<Compile Include="Modes\ScoreProcesssor.cs" />
<Compile Include="Online\API\IOnlineComponent.cs" />
<Compile Include="Overlays\DragBar.cs" />
<Compile Include="Overlays\MusicController.cs" />
<Compile Include="Beatmaps\Beatmap.cs" />