-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
54 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
source/SongCore/HarmonyPatches/MainSystemsInitRefreshablePatch.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
using SongCore.HarmonyPatches; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using Zenject; | ||
|
||
namespace SongCore.Installers | ||
{ | ||
internal class AppInstaller : Installer | ||
{ | ||
private const string refreshableID = "SongCore.Loader.Refresh"; | ||
private const string didLoadEventID = "SongCore.Loader.Loaded"; | ||
|
||
public override void InstallBindings() | ||
{ | ||
// TODO | ||
MainSystemsInitRefreshablePatch.Postfix(Container); | ||
Container.Bind<IRefreshable>().WithId(refreshableID).To<SongCoreRefreshable>().AsSingle(); | ||
Container.Bind(typeof(IInitializable), typeof(IDisposable), typeof(SongCoreLoaderDidLoad)).To<SongCoreLoaderDidLoad>().AsSingle(); | ||
var loadEvent = Container.Resolve<SongCoreLoaderDidLoad>() as IObservableChange; | ||
Container.BindInstance(loadEvent).WithId(didLoadEventID).AsSingle(); | ||
} | ||
|
||
private class SongCoreRefreshable : IRefreshable | ||
{ | ||
public void Refresh() | ||
{ | ||
if (Loader.AreSongsLoaded) | ||
{ | ||
Loader.Instance.RefreshSongs(); | ||
} | ||
} | ||
} | ||
|
||
private class SongCoreLoaderDidLoad : IInitializable, IDisposable, IObservableChange | ||
{ | ||
public event Action? didChangeEvent; | ||
|
||
public void Initialize() | ||
{ | ||
Loader.SongsLoadedEvent += Loader_SongsLoadedEvent; | ||
} | ||
|
||
private void Loader_SongsLoadedEvent(Loader _, ConcurrentDictionary<string, BeatmapLevel> __) | ||
{ | ||
didChangeEvent?.Invoke(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent; | ||
} | ||
} | ||
} | ||
} |