mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add the concept of IOnlineComponents, registered tot he API for handling state changes.
This commit is contained in:
@ -45,7 +45,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
|
|
||||||
if (api.State != APIAccess.APIState.Online)
|
if (api.State != APIState.Online)
|
||||||
api.OnStateChange += delegate { initializeChannels(); };
|
api.OnStateChange += delegate { initializeChannels(); };
|
||||||
else
|
else
|
||||||
initializeChannels();
|
initializeChannels();
|
||||||
@ -65,7 +65,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
{
|
{
|
||||||
careChannels = new List<Channel>();
|
careChannels = new List<Channel>();
|
||||||
|
|
||||||
if (api.State != APIAccess.APIState.Online)
|
if (api.State != APIState.Online)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Add(flow = new FlowContainer
|
Add(flow = new FlowContainer
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
@ -65,6 +66,18 @@ namespace osu.Game.Online.API
|
|||||||
thread.Start();
|
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();
|
public string AccessToken => authentication.RequestAccessToken();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -221,6 +234,7 @@ namespace osu.Game.Online.API
|
|||||||
log.Add($@"We just went {newState}!");
|
log.Add($@"We just went {newState}!");
|
||||||
Scheduler.Add(delegate
|
Scheduler.Add(delegate
|
||||||
{
|
{
|
||||||
|
components.ForEach(c => c.APIStateChanged(this, newState));
|
||||||
OnStateChange?.Invoke(oldState, newState);
|
OnStateChange?.Invoke(oldState, newState);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -237,29 +251,6 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
|
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)
|
private void flushQueue(bool failOldRequests = true)
|
||||||
{
|
{
|
||||||
var oldQueue = queue;
|
var oldQueue = queue;
|
||||||
@ -286,4 +277,27 @@ namespace osu.Game.Online.API
|
|||||||
Scheduler.Update();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
osu.Game/Online/API/IOnlineComponent.cs
Normal file
16
osu.Game/Online/API/IOnlineComponent.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -69,6 +69,7 @@
|
|||||||
<Compile Include="Modes\Objects\HitObjectParser.cs" />
|
<Compile Include="Modes\Objects\HitObjectParser.cs" />
|
||||||
<Compile Include="Modes\Score.cs" />
|
<Compile Include="Modes\Score.cs" />
|
||||||
<Compile Include="Modes\ScoreProcesssor.cs" />
|
<Compile Include="Modes\ScoreProcesssor.cs" />
|
||||||
|
<Compile Include="Online\API\IOnlineComponent.cs" />
|
||||||
<Compile Include="Overlays\DragBar.cs" />
|
<Compile Include="Overlays\DragBar.cs" />
|
||||||
<Compile Include="Overlays\MusicController.cs" />
|
<Compile Include="Overlays\MusicController.cs" />
|
||||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||||
|
Reference in New Issue
Block a user