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

@ -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
}
}