forked from chrislee0419/EnhancedSearchAndFilters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
117 lines (97 loc) · 4.1 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Linq;
using System.Collections.Generic;
using IPA;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;
using IPAPluginManager = IPA.Loader.PluginManager;
using SongCore;
using CustomUI.Utilities;
using EnhancedSearchAndFilters.Tweaks;
using EnhancedSearchAndFilters.SongData;
using WordPredictionEngine = EnhancedSearchAndFilters.Search.WordPredictionEngine;
namespace EnhancedSearchAndFilters
{
public class Plugin : IBeatSaberPlugin
{
public void Init(IPALogger logger)
{
Logger.log = logger;
}
public void OnApplicationStart()
{
BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh;
Loader.DeletingSong += SongCoreLoaderDeletingSong;
Loader.LoadingStartedEvent += SongCoreLoaderLoadingStarted;
Loader.SongsLoadedEvent += SongCoreLoaderFinishedLoading;
}
public void OnApplicationQuit()
{
WordPredictionEngine.Instance.CancelTasks();
BeatmapDetailsLoader.Instance.CancelLoading();
BeatmapDetailsLoader.Instance.CancelPopulatingCache();
BeatmapDetailsLoader.Instance.SaveCacheToFile();
}
public void OnFixedUpdate()
{
}
public void OnUpdate()
{
}
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
{
if (nextScene.name == "MenuCore")
{
WordPredictionEngine.Instance.ResumeTasks();
if (BeatmapDetailsLoader.Instance.IsCaching)
BeatmapDetailsLoader.Instance.StartPopulatingCache();
}
if (prevScene.name == "MenuCore" || nextScene.name == "GameCore")
{
WordPredictionEngine.Instance.PauseTasks();
if (BeatmapDetailsLoader.Instance.IsCaching)
BeatmapDetailsLoader.Instance.PausePopulatingCache();
}
}
private void OnMenuSceneLoadedFresh()
{
#pragma warning disable CS0618 // remove PluginManager.Plugins is obsolete warning
BeatSaverDownloaderTweaks.ModLoaded = IPAPluginManager.GetPluginFromId("BeatSaverDownloader") != null || IPAPluginManager.GetPlugin("BeatSaver Downloader") != null;
SongBrowserTweaks.ModLoaded = IPAPluginManager.GetPluginFromId("SongBrowser") != null || IPAPluginManager.GetPlugin("Song Browser") != null || IPAPluginManager.Plugins.Any(x => x.Name == "Song Browser");
SongDataCoreTweaks.ModLoaded = IPAPluginManager.GetPluginFromId("SongDataCore") != null;
#pragma warning restore CS0618
// reset initialization status if settings were applied
BeatSaverDownloaderTweaks.Initialized = false;
SongBrowserTweaks.Initialized = false;
UI.SongListUI.Instance.OnMenuSceneLoadedFresh();
}
public void SongCoreLoaderDeletingSong()
{
WordPredictionEngine.Instance.CancelTasks();
BeatmapDetailsLoader.Instance.CancelPopulatingCache();
Loader.OnLevelPacksRefreshed += SongCoreLoaderOnLevelPacksRefreshed;
}
public void SongCoreLoaderOnLevelPacksRefreshed()
{
Loader.OnLevelPacksRefreshed -= SongCoreLoaderOnLevelPacksRefreshed;
BeatmapDetailsLoader.Instance.StartPopulatingCache();
WordPredictionEngine.Instance.ClearCache();
}
public void SongCoreLoaderLoadingStarted(Loader loader)
{
WordPredictionEngine.Instance.CancelTasks();
BeatmapDetailsLoader.Instance.CancelPopulatingCache();
}
public void SongCoreLoaderFinishedLoading(Loader loader, Dictionary<string, CustomPreviewBeatmapLevel> beatmaps)
{
// force load, since there might be new songs that can be cached
BeatmapDetailsLoader.Instance.StartPopulatingCache(true);
WordPredictionEngine.Instance.ClearCache();
}
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
{
}
public void OnSceneUnloaded(Scene scene)
{
}
}
}