Skip to content

Commit

Permalink
Move refreshable patch to installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Meivyn committed Mar 16, 2024
1 parent 55e05b9 commit e446fa0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 54 deletions.
51 changes: 0 additions & 51 deletions source/SongCore/HarmonyPatches/MainSystemsInitRefreshablePatch.cs

This file was deleted.

43 changes: 40 additions & 3 deletions source/SongCore/Installers/AppInstaller.cs
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;
}
}
}
}

0 comments on commit e446fa0

Please sign in to comment.